diff --git a/__init__.py b/__init__.py index 27cb624..b10a7b0 100644 --- a/__init__.py +++ b/__init__.py @@ -4,6 +4,7 @@ from trytond.pool import Pool from .sale import SaleLine, Sale from .unit_load import UnitLoad from .cost import CostType, CostTemplate, CostLineSale, CostSale +from . import sale_reporting def register(): @@ -11,8 +12,8 @@ def register(): Sale, SaleLine, UnitLoad, + sale_reporting.Product, module='sale_unit_load', type_='model') - Pool.register( CostType, CostTemplate, diff --git a/locale/es.po b/locale/es.po index 382ff11..550c1b9 100644 --- a/locale/es.po +++ b/locale/es.po @@ -60,4 +60,13 @@ msgstr "Bultos" msgctxt "selection:sale.cost,distribution_method:" msgid "ULs quantity" -msgstr "UdCs" \ No newline at end of file +msgstr "UdCs" + +msgctxt "field:sale.reporting.product,cases_quantity:" +msgid "Cases" +msgstr "Bultos" + +msgctxt "field:sale.reporting.product,ul_quantity:" +msgid "ULs" +msgstr "UdCs" + diff --git a/sale_reporting.py b/sale_reporting.py new file mode 100644 index 0000000..a25df40 --- /dev/null +++ b/sale_reporting.py @@ -0,0 +1,36 @@ +# The COPYRIGHT file at the top level of this repository contains the full +# copyright notices and license terms. +from trytond.pool import PoolMeta, Pool +from trytond.model import fields +from trytond.pyson import Eval +from sql.aggregate import Sum +from sql.conditionals import Coalesce + +__all__ = ['Product'] + + +class Product: + __name__ = 'sale.reporting.product' + __metaclass__ = PoolMeta + + cases_quantity = fields.Float('Cases', + digits=(16, Eval('cases_digits', 2)), + depends=['cases_digits']) + ul_quantity = fields.Float('ULs', digits=(16, 0)) + cases_digits = fields.Function(fields.Integer('Cases Digits'), + 'get_cases_digits') + + def get_cases_digits(self, name): + pool = Pool() + Modeldata = pool.get('ir.model.data') + Uom = pool.get('product.uom') + return Uom(Modeldata.get_id('product', 'uom_unit')).digits + + @classmethod + def _columns(cls, tables): + line = tables['line'] + return super(Product, cls)._columns(tables) + [ + Sum(Coalesce(line.ul_cases_quantity, 0) * + Coalesce(line.ul_quantity, 0)).as_('cases_quantity'), + Sum(Coalesce(line.ul_quantity, 0)).as_('ul_quantity') + ] diff --git a/sale_reporting.xml b/sale_reporting.xml new file mode 100644 index 0000000..0ae0e4d --- /dev/null +++ b/sale_reporting.xml @@ -0,0 +1,13 @@ + + + + + + + sale.reporting.product + + reporting_product_list + + + \ No newline at end of file diff --git a/tryton.cfg b/tryton.cfg index f78f516..5975591 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -11,3 +11,4 @@ extras_depend: xml: sale.xml + sale_reporting.xml diff --git a/view/reporting_product_list.xml b/view/reporting_product_list.xml new file mode 100644 index 0000000..23e54e8 --- /dev/null +++ b/view/reporting_product_list.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file