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
This commit is contained in:
@@ -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'),
|
||||
]
|
||||
|
||||
@@ -249,7 +249,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="context_model">purchase.reporting.context</field>
|
||||
<field
|
||||
name="domain"
|
||||
eval="[('supplier', '=', Eval('active_id', -1))]"
|
||||
eval="[('supplier_currency', '=', Eval('active_id', -1))]"
|
||||
pyson="1"/>
|
||||
<field name="order" eval="[('date', 'DESC')]" pyson="1"/>
|
||||
</record>
|
||||
@@ -326,7 +326,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="name">Purchases per Product</field>
|
||||
<field name="res_model">purchase.reporting.product</field>
|
||||
<field name="context_model">purchase.reporting.context</field>
|
||||
<field name="context" eval="{'supplier': Eval('active_id')}" pyson="1"/>
|
||||
<field name="context" eval="{'supplier_currency': Eval('active_id')}" pyson="1"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_reporting_product_view1">
|
||||
<field name="sequence" eval="10"/>
|
||||
@@ -400,7 +400,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="res_model">purchase.reporting.product.time_series</field>
|
||||
<field name="context_model">purchase.reporting.context</field>
|
||||
<field name="domain"
|
||||
eval="[('product', '=', Eval('active_id', -1))]"
|
||||
eval="[('product_currency', '=', Eval('active_id', -1))]"
|
||||
pyson="1"/>
|
||||
<field name="order" eval="[('date', 'DESC')]" pyson="1"/>
|
||||
</record>
|
||||
|
||||
@@ -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([])
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tree keyword_open="1">
|
||||
<field name="number" sum="1"/>
|
||||
<field name="expense" sum="1"/>
|
||||
<field name="expense"/>
|
||||
<field name="expense_trend" expand="1"/>
|
||||
</tree>
|
||||
|
||||
@@ -4,5 +4,5 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<tree>
|
||||
<field name="date"/>
|
||||
<field name="number" sum="1"/>
|
||||
<field name="expense" sum="1"/>
|
||||
<field name="expense"/>
|
||||
</tree>
|
||||
|
||||
Reference in New Issue
Block a user