diff --git a/bemade_margin_vendor_pricelist/__manifest__.py b/bemade_margin_vendor_pricelist/__manifest__.py index e1d8a65..e0f4245 100644 --- a/bemade_margin_vendor_pricelist/__manifest__.py +++ b/bemade_margin_vendor_pricelist/__manifest__.py @@ -24,7 +24,12 @@ "author": "Bemade Inc.", "website": "https://www.bemade.org", "license": "LGPL-3", - "depends": ["sale_stock_margin", "sale_management", "stock"], + "depends": [ + "sale_stock_margin", + "sale_management", + "stock", + "product_pricelist_supplierinfo", + ], "data": ["views/sale_order.xml"], "installable": True, "auto_install": False, diff --git a/bemade_margin_vendor_pricelist/models/sale_order.py b/bemade_margin_vendor_pricelist/models/sale_order.py index 9f11863..5b0741d 100644 --- a/bemade_margin_vendor_pricelist/models/sale_order.py +++ b/bemade_margin_vendor_pricelist/models/sale_order.py @@ -3,21 +3,23 @@ from odoo.tools.float_utils import float_is_zero, float_compare class SaleOrder(models.Model): - _inherit = 'sale.order' + _inherit = "sale.order" - gross_profit = fields.Monetary("Gross Profit", compute='_compute_margin_actual', store=False) - - gross_profit_percent = fields.Float( - string='Gross Profit (%)', - compute='_compute_margin_actual', - store=False, - group_operator='avg' + gross_profit = fields.Monetary( + "Gross Profit", compute="_compute_margin_actual", store=False ) - @api.depends('order_line.gross_profit', 'amount_untaxed') + gross_profit_percent = fields.Float( + string="Gross Profit (%)", + compute="_compute_margin_actual", + store=False, + aggregator="avg", + ) + + @api.depends("order_line.gross_profit", "amount_untaxed") def _compute_margin_actual(self): for order in self: - order.gross_profit = sum(order.order_line.mapped('gross_profit')) - order.gross_profit_percent = order.amount_untaxed and order.gross_profit / order.amount_untaxed - - + order.gross_profit = sum(order.order_line.mapped("gross_profit")) + order.gross_profit_percent = ( + order.amount_untaxed and order.gross_profit / order.amount_untaxed + )