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.

35 lines
1.2 KiB

  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 PosOrderLine(models.Model):
  8. _inherit = 'pos.order.line'
  9. # Columns Section
  10. margin = fields.Float(
  11. 'Margin', compute='_compute_multi_margin', store=True,
  12. multi='multi_margin',
  13. digits_compute=dp.get_precision('Product Price'))
  14. purchase_price = fields.Float(
  15. 'Cost Price', compute='_compute_multi_margin', store=True,
  16. multi='multi_margin',
  17. digits_compute=dp.get_precision('Product Price'))
  18. # Compute Section
  19. @api.multi
  20. @api.depends('product_id', 'qty', 'price_subtotal')
  21. def _compute_multi_margin(self):
  22. for line in self:
  23. if not line.product_id:
  24. line.purchase_price = 0
  25. line.margin = 0
  26. else:
  27. line.purchase_price = line.product_id.standard_price
  28. line.margin = line.price_subtotal - (
  29. line.product_id.standard_price * line.qty)