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.

39 lines
1.2 KiB

  1. # Copyright 2019 Tecnativa <vicent.cubells@tecnativa.com>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models
  4. import odoo.addons.decimal_precision as dp
  5. class AccountAnalyticINvoiceLine(models.Model):
  6. _inherit = "account.analytic.invoice.line"
  7. date_start = fields.Date(
  8. string='Start Date',
  9. )
  10. date_end = fields.Date(
  11. string='End Date',
  12. )
  13. previous_revision_id = fields.Many2one(
  14. comodel_name='account.analytic.invoice.line',
  15. string='Previous revision',
  16. help='Relation with previous revision',
  17. )
  18. previous_price = fields.Float(
  19. related='previous_revision_id.price_unit',
  20. readonly=True,
  21. )
  22. variation_percent = fields.Float(
  23. compute='_compute_variation_percent',
  24. store=True,
  25. digits=dp.get_precision('Product Price'),
  26. string='Variation %',
  27. )
  28. @api.multi
  29. @api.depends('price_unit', 'previous_revision_id.price_unit')
  30. def _compute_variation_percent(self):
  31. for line in self:
  32. if not (line.price_unit and line.previous_price):
  33. continue
  34. line.variation_percent = (
  35. (line.price_unit / line.previous_price - 1) * 100)