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.

34 lines
1.0 KiB

  1. # Copyright 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
  2. # Copyright 2017-2019 Tecnativa - Pedro M. Baeza
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import fields, models
  5. class PurchaseReport(models.Model):
  6. _inherit = "purchase.report"
  7. discount = fields.Float(
  8. string="Discount (%)", digits="Discount", group_operator="avg"
  9. )
  10. def _select(self):
  11. res = super()._select()
  12. # There are 3 matches
  13. res = res.replace("l.price_unit", self._get_discounted_price_unit_exp())
  14. res += ", l.discount AS discount"
  15. return res
  16. def _group_by(self):
  17. res = super()._group_by()
  18. res += ", l.discount"
  19. return res
  20. def _get_discounted_price_unit_exp(self):
  21. """Inheritable method for getting the SQL expression used for
  22. calculating the unit price with discount(s).
  23. :rtype: str
  24. :return: SQL expression for discounted unit price.
  25. """
  26. return "(1.0 - COALESCE(l.discount, 0.0) / 100.0) * l.price_unit"