diff --git a/membership_initial_discount/models/account_move_line.py b/membership_initial_discount/models/account_move_line.py index 175695c..be8e0db 100644 --- a/membership_initial_discount/models/account_move_line.py +++ b/membership_initial_discount/models/account_move_line.py @@ -6,16 +6,17 @@ from odoo import api, models, _ class AccountMoveLine(models.Model): _inherit = "account.move.line" - def _get_computed_price_unit(self): - res = super()._get_computed_price_unit() - if self.move_id.is_invoice() and self.initial_membership_check(): - product = self.product_id - if product.initial_discount == "fixed" and product.fixed_discount: - res -= product.fixed_discount - return res + @api.depends("product_id", "product_uom_id") + def _compute_price_unit(self): + super()._compute_price_unit() + for line in self: + if line.move_id.is_invoice() and line.initial_membership_check(): + product = line.product_id + if product.initial_discount == "fixed" and product.fixed_discount: + line.price_unit -= product.fixed_discount @api.onchange("product_id") - def _onchange_product_id(self): + def _inverse_product_id(self): super()._onchange_product_id() for line in self: if not line.product_id or line.display_type in ( diff --git a/membership_initial_discount/models/product_product.py b/membership_initial_discount/models/product_product.py index 3ddb988..111e84a 100644 --- a/membership_initial_discount/models/product_product.py +++ b/membership_initial_discount/models/product_product.py @@ -2,12 +2,6 @@ from odoo import models, fields, api, _ from odoo.exceptions import ValidationError -DISCOUNTS = [ - ("none", _("No initial discount")), - ("fixed", _("Fixed amount")), - ("percent", _("Percentage of the price")), -] - class ProductProduct(models.Model): _inherit = "product.product" diff --git a/membership_initial_discount/models/product_template.py b/membership_initial_discount/models/product_template.py index 8cae669..53ada89 100644 --- a/membership_initial_discount/models/product_template.py +++ b/membership_initial_discount/models/product_template.py @@ -3,9 +3,9 @@ from odoo import models, fields, api, _ from odoo.exceptions import ValidationError DISCOUNTS = [ - ("none", _("No initial discount")), - ("fixed", _("Fixed amount")), - ("percent", _("Percentage of the price")), + ("none", "No initial discount"), + ("fixed", "Fixed amount"), + ("percent", "Percentage of the price"), ]