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.

33 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 odoo 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', digits=dp.get_precision('Product Price'))
  13. purchase_price = fields.Float(
  14. 'Cost Price', compute='_compute_multi_margin', store=True,
  15. multi='multi_margin', digits=dp.get_precision('Product Price'))
  16. # Compute Section
  17. @api.multi
  18. @api.depends('product_id', 'qty', 'price_subtotal')
  19. def _compute_multi_margin(self):
  20. for line in self:
  21. if not line.product_id:
  22. line.purchase_price = 0
  23. line.margin = 0
  24. else:
  25. line.purchase_price = line.product_id.standard_price
  26. line.margin = line.price_subtotal - (
  27. line.product_id.standard_price * line.qty)