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.

32 lines
1.1 KiB

  1. # Copyright (C) 2017 - Today: GRAP (http://www.grap.coop)
  2. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import api, fields, models
  5. import openerp.addons.decimal_precision as dp
  6. class PosOrderLine(models.Model):
  7. _inherit = 'pos.order.line'
  8. # Columns Section
  9. margin = fields.Float(
  10. 'Margin', compute='_compute_multi_margin', store=True,
  11. multi='multi_margin', digits=dp.get_precision('Product Price'))
  12. purchase_price = fields.Float(
  13. 'Cost Price', compute='_compute_multi_margin', store=True,
  14. multi='multi_margin', digits=dp.get_precision('Product Price'))
  15. # Compute Section
  16. @api.multi
  17. @api.depends('product_id', 'qty', 'price_subtotal')
  18. def _compute_multi_margin(self):
  19. for line in self:
  20. if not line.product_id:
  21. line.purchase_price = 0
  22. line.margin = 0
  23. else:
  24. line.purchase_price = line.product_id.standard_price
  25. line.margin = line.price_subtotal - (
  26. line.product_id.standard_price * line.qty)