[MIG] sale_margin_no_onchange from v14 to v16

This commit is contained in:
Alexis de Lattre
2025-01-16 19:19:19 +01:00
parent 699ebd5893
commit 2ca1279cb5
7 changed files with 221 additions and 138 deletions

View File

@@ -1,4 +1,4 @@
# Copyright 2018-2019 Akretion (http://www.akretion.com)
# Copyright 2018-2025 Akretion France (https://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
@@ -10,10 +10,14 @@ class SaleReport(models.Model):
margin = fields.Float(string='Margin', readonly=True)
def _query(self, with_clause='', fields={}, groupby='', from_clause=''):
fields['margin_company_currency'] =\
", SUM(l.margin_company_currency) AS margin"
res = super(SaleReport, self)._query(
with_clause=with_clause, fields=fields, groupby=groupby,
from_clause=from_clause)
def _select_additional_fields(self):
res = super()._select_additional_fields()
margin_sum = f"""
CASE WHEN l.product_id IS NOT NULL THEN SUM(l.margin_sale_currency
/ {self._case_value_or_one('s.currency_rate')}
* {self._case_value_or_one('currency_table.rate')}
) ELSE 0
END
"""
res["margin"] = margin_sum
return res