diff --git a/modules/sale_gift_card/sale_reporting.py b/modules/sale_gift_card/sale_reporting.py new file mode 100644 index 0000000000..d9dc69e051 --- /dev/null +++ b/modules/sale_gift_card/sale_reporting.py @@ -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 --git a/modules/sale_gift_card/tests/scenario_sale_gift_card.rst b/modules/sale_gift_card/tests/scenario_sale_gift_card.rst index 09f98e163a..3b7d89b540 100644 --- a/modules/sale_gift_card/tests/scenario_sale_gift_card.rst +++ b/modules/sale_gift_card/tests/scenario_sale_gift_card.rst @@ -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') diff --git a/modules/sale_gift_card/tryton.cfg b/modules/sale_gift_card/tryton.cfg index a1688a6c54..0429f63273 100644 --- a/modules/sale_gift_card/tryton.cfg +++ b/modules/sale_gift_card/tryton.cfg @@ -45,3 +45,6 @@ model: sale.POSPayGiftCard wizard: sale.POSPay + +[register_mixin] +sale_reporting.AbstractMixin: trytond.modules.sale.sale_reporting.Abstract