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.

25 lines
836 B

  1. # -*- coding: utf-8 -*-
  2. # Copyright (C) 2017 - Today: GRAP (http://www.grap.coop)
  3. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from openerp import api, fields, models
  6. import openerp.addons.decimal_precision as dp
  7. class PosOrder(models.Model):
  8. _inherit = 'pos.order'
  9. # Columns Section
  10. margin = fields.Float(
  11. 'Margin', compute='_compute_margin', store=True,
  12. digits_compute=dp.get_precision('Product Price'),
  13. help="It gives profitability by calculating the difference between"
  14. " the Unit Price and the cost price.")
  15. # Compute Section
  16. @api.multi
  17. @api.depends('lines.margin')
  18. def _compute_margin(self):
  19. for order in self:
  20. order.margin = sum(order.mapped('lines.margin'))