You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.8 KiB

  1. # Copyright 2019 Tecnativa <vicent.cubells@tecnativa.com>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from dateutil.relativedelta import relativedelta
  4. from odoo import api, fields, models
  5. import odoo.addons.decimal_precision as dp
  6. class CreateRevisionLineWizard(models.TransientModel):
  7. _name = 'create.revision.line.wizard'
  8. date_start = fields.Date(
  9. required=True,
  10. )
  11. date_end = fields.Date()
  12. variation_percent = fields.Float(
  13. digits=dp.get_precision('Product Price'),
  14. required=True,
  15. string='Variation %',
  16. )
  17. @api.multi
  18. def action_apply(self):
  19. contract_obj = self.env['account.analytic.account']
  20. line_obj = self.env['account.analytic.invoice.line']
  21. active_ids = self.env.context['active_ids']
  22. line_news = line_obj
  23. for item in contract_obj.browse(active_ids).mapped(
  24. 'recurring_invoice_line_ids').filtered(
  25. lambda x: not x.automatic_price):
  26. line_news |= item.copy({
  27. 'date_start': self.date_start,
  28. 'date_end': self.date_end,
  29. 'previous_revision_id': item.id,
  30. 'price_unit': item.price_unit * (
  31. 1.0 + self.variation_percent / 100.0),
  32. })
  33. item.date_end = (fields.Date.from_string(self.date_start) -
  34. relativedelta(days=1))
  35. action = self.env.ref(
  36. 'contract.action_account_analytic_sale_overdue_all').read()[0]
  37. if len(active_ids) > 1: # pragma: no cover
  38. action['domain'] = [('id', 'in', active_ids)]
  39. elif active_ids:
  40. action['views'] = [(
  41. self.env.ref('contract.account_analytic_account_sale_form').id,
  42. 'form')]
  43. action['res_id'] = active_ids[0]
  44. return action