details: https://code.tryton.org/tryton/commit/9c7de9240347
branch: default
user: Cédric Krier <[email protected]>
date: Fri Dec 12 15:31:45 2025 +0100
description:
Exclude sale lines of gift cards from sale reporting
Closes #14418
diffstat:
modules/sale_gift_card/sale_reporting.py | 38 ++++++++++++++++
modules/sale_gift_card/tests/scenario_sale_gift_card.rst | 7 ++
modules/sale_gift_card/tryton.cfg | 3 +
3 files changed, 48 insertions(+), 0 deletions(-)
diffs (73 lines):
diff -r 3583fa0162e2 -r 9c7de9240347 modules/sale_gift_card/sale_reporting.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/sale_gift_card/sale_reporting.py Fri Dec 12 15:31:45 2025 +0100
@@ -0,0 +1,38 @@
+# This file is part of Tryton. The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+
+from sql import Literal
+
+from trytond.pool import Pool
+
+
+class AbstractMixin:
+ __slots__ = ()
+
+ @classmethod
+ def _joins(cls):
+ pool = Pool()
+ Product = pool.get('product.product')
+ Template = pool.get('product.template')
+ from_item, tables, withs = super()._joins()
+ if 'line.product' not in tables:
+ product = Product.__table__()
+ tables['line.product'] = product
+ line = tables['line']
+ from_item = (from_item
+ .join(product, condition=line.product == product.id))
+ else:
+ product = tables['line.product']
+ if 'line.product.template' not in tables:
+ template = Template.__table__()
+ tables['line.product.template'] = template
+ from_item = (from_item
+ .join(template, condition=product.template == template.id))
+ return from_item, tables, withs
+
+ @classmethod
+ def _where(cls, tables, withs):
+ template = tables['line.product.template']
+ where = super()._where(tables, withs)
+ where &= template.gift_card != Literal(True)
+ return where
diff -r 3583fa0162e2 -r 9c7de9240347
modules/sale_gift_card/tests/scenario_sale_gift_card.rst
--- a/modules/sale_gift_card/tests/scenario_sale_gift_card.rst Fri Dec 12
15:31:11 2025 +0100
+++ b/modules/sale_gift_card/tests/scenario_sale_gift_card.rst Fri Dec 12
15:31:45 2025 +0100
@@ -31,6 +31,7 @@
>>> ProductUoM = Model.get('product.uom')
>>> Sale = Model.get('sale.sale')
>>> SaleConfig = Model.get('sale.configuration')
+ >>> SaleReporting = Model.get('sale.reporting.main')
>>> Sequence = Model.get('ir.sequence')
>>> SequenceType = Model.get('ir.sequence.type')
@@ -182,3 +183,9 @@
>>> gift_card_line.quantity
-1.0
>>> assertEqual(gift_card_line.account, gift_card_revenue)
+
+Check sale reporting::
+
+ >>> report, = SaleReporting.find([])
+ >>> report.revenue
+ Decimal('100.00')
diff -r 3583fa0162e2 -r 9c7de9240347 modules/sale_gift_card/tryton.cfg
--- a/modules/sale_gift_card/tryton.cfg Fri Dec 12 15:31:11 2025 +0100
+++ b/modules/sale_gift_card/tryton.cfg Fri Dec 12 15:31:45 2025 +0100
@@ -45,3 +45,6 @@
sale.POSPayGiftCard
wizard:
sale.POSPay
+
+[register_mixin]
+sale_reporting.AbstractMixin: trytond.modules.sale.sale_reporting.Abstract