From 41993306bf760a96f7d963281edd95bee4670b59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 5 May 2025 15:07:27 +0200 Subject: [PATCH] Use pairing to generate unique ID for purchase reporting Purchase reporting are also grouped by currency so they should be part of the ID. Closes #13743 --- modules/purchase/purchase_reporting.py | 36 ++++++++++++++++--- modules/purchase/purchase_reporting.xml | 6 ++-- .../tests/scenario_purchase_reporting.rst | 1 + .../view/purchase_reporting_main_list.xml | 2 +- ...rchase_reporting_main_time_series_list.xml | 2 +- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/modules/purchase/purchase_reporting.py b/modules/purchase/purchase_reporting.py index 3da911f0e6..ec2d667e8b 100644 --- a/modules/purchase/purchase_reporting.py +++ b/modules/purchase/purchase_reporting.py @@ -12,7 +12,7 @@ from trytond.model import ModelSQL, ModelView, fields from trytond.modules.currency.fields import Monetary from trytond.pool import Pool from trytond.pyson import Eval, If -from trytond.tools import pairwise_longest +from trytond.tools import pairwise_longest, sql_pairing, unpair from trytond.tools.chart import sparkline from trytond.transaction import Transaction @@ -282,12 +282,22 @@ class Supplier(SupplierMixin, Abstract, ModelView): @classmethod def _column_id(cls, tables): purchase = tables['line.purchase'] - return purchase.party + return sql_pairing(purchase.party, purchase.currency) class SupplierTimeseries(SupplierMixin, AbstractTimeseries, ModelView): __name__ = 'purchase.reporting.supplier.time_series' + supplier_currency = fields.Integer("Supplier - Currency") + + @classmethod + def _columns(cls, tables): + purchase = tables['line.purchase'] + return super()._columns(tables) + [ + sql_pairing( + purchase.party, purchase.currency).as_('supplier_currency'), + ] + class ProductMixin(object): __slots__ = () @@ -321,7 +331,13 @@ class ProductMixin(object): purchase = tables['line.purchase'] where = super()._where(tables) where &= line.product != Null - where &= purchase.party == context.get('supplier') + if context.get('supplier_currency') is not None: + supplier, currency = unpair(context['supplier_currency']) + else: + supplier = context.get('supplier') + currency = context.get('currency') + where &= purchase.party == supplier + where &= purchase.currency == currency return where def get_rec_name(self, name): @@ -355,8 +371,20 @@ class Product(ProductMixin, Abstract, ModelView): @classmethod def _column_id(cls, tables): line = tables['line'] - return line.product + purchase = tables['line.purchase'] + return sql_pairing(line.product, purchase.currency) class ProductTimeseries(ProductMixin, AbstractTimeseries, ModelView): __name__ = 'purchase.reporting.product.time_series' + + product_currency = fields.Integer("Product - Currency") + + @classmethod + def _columns(cls, tables): + line = tables['line'] + purchase = tables['line.purchase'] + return super()._columns(tables) + [ + sql_pairing( + line.product, purchase.currency).as_('product_currency'), + ] diff --git a/modules/purchase/purchase_reporting.xml b/modules/purchase/purchase_reporting.xml index 65a8ac56d7..3816db0c62 100644 --- a/modules/purchase/purchase_reporting.xml +++ b/modules/purchase/purchase_reporting.xml @@ -249,7 +249,7 @@ this repository contains the full copyright notices and license terms. --> purchase.reporting.context @@ -326,7 +326,7 @@ this repository contains the full copyright notices and license terms. --> Purchases per Product purchase.reporting.product purchase.reporting.context - + @@ -400,7 +400,7 @@ this repository contains the full copyright notices and license terms. --> purchase.reporting.product.time_series purchase.reporting.context diff --git a/modules/purchase/tests/scenario_purchase_reporting.rst b/modules/purchase/tests/scenario_purchase_reporting.rst index 2eac40d8c3..069600f9da 100644 --- a/modules/purchase/tests/scenario_purchase_reporting.rst +++ b/modules/purchase/tests/scenario_purchase_reporting.rst @@ -126,6 +126,7 @@ Check purchase reporting per product without supplier:: Check purchase reporting per product with supplier:: >>> context['supplier'] = supplier1.id + >>> context['currency'] = purchase1.currency.id >>> with config.set_context(context=context): ... reports = Product.find([]) ... time_series = ProductTimeseries.find([]) diff --git a/modules/purchase/view/purchase_reporting_main_list.xml b/modules/purchase/view/purchase_reporting_main_list.xml index 5ef4ed4368..f5b788321b 100644 --- a/modules/purchase/view/purchase_reporting_main_list.xml +++ b/modules/purchase/view/purchase_reporting_main_list.xml @@ -3,6 +3,6 @@ this repository contains the full copyright notices and license terms. --> - + diff --git a/modules/purchase/view/purchase_reporting_main_time_series_list.xml b/modules/purchase/view/purchase_reporting_main_time_series_list.xml index 279c561b47..458676ed5a 100644 --- a/modules/purchase/view/purchase_reporting_main_time_series_list.xml +++ b/modules/purchase/view/purchase_reporting_main_time_series_list.xml @@ -4,5 +4,5 @@ this repository contains the full copyright notices and license terms. --> - +