Exclude sale lines of gift cards from sale reporting

Closes #14418
This commit is contained in:
Cédric Krier
2025-12-12 15:31:45 +01:00
parent d3eb2c9e87
commit d9b73072df
3 changed files with 48 additions and 0 deletions
+38
View File
@@ -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
@@ -31,6 +31,7 @@ Activate modules::
>>> 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 @@ Check the invoice::
>>> 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')
+3
View File
@@ -45,3 +45,6 @@ model:
sale.POSPayGiftCard
wizard:
sale.POSPay
[register_mixin]
sale_reporting.AbstractMixin: trytond.modules.sale.sale_reporting.Abstract