diff --git a/modules/purchase_trade/pricing.py b/modules/purchase_trade/pricing.py index fb5cc27..4737b13 100755 --- a/modules/purchase_trade/pricing.py +++ b/modules/purchase_trade/pricing.py @@ -2,7 +2,7 @@ # this repository contains the full copyright notices and license terms. from trytond.model import fields from trytond.pool import Pool, PoolMeta -from trytond.pyson import Bool, Eval, Id +from trytond.pyson import Bool, Eval, Id, If from trytond.model import (ModelSQL, ModelView) from trytond.exceptions import UserError from trytond.tools import is_full_text, lstrip_wildcard @@ -333,11 +333,11 @@ class Pricing(ModelSQL,ModelView): pricing_date = fields.Date("Date") price_component = fields.Many2One( 'pricing.component', "Component", - domain=[ - 'OR', - ('line', '=', Eval('line', -1)), - ('sale_line', '=', Eval('sale_line', -1)), - ], + domain=[If(Bool(Eval('line')), + ('line', '=', Eval('line')), + If(Bool(Eval('sale_line')), + ('sale_line', '=', Eval('sale_line')), + ('id', '=', -1)))], depends=['line', 'sale_line'])#, ondelete='CASCADE') quantity = fields.Numeric("Qt",digits='unit') settl_price = fields.Numeric("Settl. price",digits='unit') diff --git a/modules/purchase_trade/purchase.py b/modules/purchase_trade/purchase.py index 77bf92c..a36075d 100755 --- a/modules/purchase_trade/purchase.py +++ b/modules/purchase_trade/purchase.py @@ -1101,6 +1101,19 @@ class Line(metaclass=PoolMeta): and bool(line.to_del) and line.from_del > line.to_del) + def _check_delivery_period(self): + if self._has_invalid_delivery_period(self): + raise UserError( + "Delivery period From date must be before To date.") + + @fields.depends('from_del', 'to_del') + def on_change_from_del(self): + self._check_delivery_period() + + @fields.depends('from_del', 'to_del') + def on_change_to_del(self): + self._check_delivery_period() + quantity_theorical = fields.Numeric("Contractual Qt", digits='unit', readonly=False) price_type = fields.Selection([ ('cash', 'Cash Price'), diff --git a/modules/purchase_trade/sale.py b/modules/purchase_trade/sale.py index 9a443e9..5226ff2 100755 --- a/modules/purchase_trade/sale.py +++ b/modules/purchase_trade/sale.py @@ -1084,6 +1084,19 @@ class SaleLine(metaclass=PoolMeta): and bool(line.to_del) and line.from_del > line.to_del) + def _check_delivery_period(self): + if self._has_invalid_delivery_period(self): + raise UserError( + "Delivery period From date must be before To date.") + + @fields.depends('from_del', 'to_del') + def on_change_from_del(self): + self._check_delivery_period() + + @fields.depends('from_del', 'to_del') + def on_change_to_del(self): + self._check_delivery_period() + del_period = fields.Many2One('product.month',"Delivery Period") lots = fields.One2Many('lot.lot','sale_line',"Lots",readonly=True) fees = fields.One2Many('fee.fee', 'sale_line', 'Fees') diff --git a/modules/purchase_trade/tests/test_module.py b/modules/purchase_trade/tests/test_module.py index fef9330..3443b35 100644 --- a/modules/purchase_trade/tests/test_module.py +++ b/modules/purchase_trade/tests/test_module.py @@ -6,7 +6,7 @@ from decimal import Decimal from unittest.mock import Mock, patch from trytond.pool import Pool -from trytond.pyson import Eval +from trytond.pyson import Bool, Eval, If from trytond.tests.test_tryton import ModuleTestCase, with_transaction from trytond.exceptions import UserError from trytond.modules.purchase_trade import valuation as valuation_module @@ -528,11 +528,11 @@ class PurchaseTradeTestCase(ModuleTestCase): 'pricing component choices are limited to the purchase or sale line' Pricing = Pool().get('pricing.pricing') - self.assertEqual(Pricing.price_component.domain, [ - 'OR', - ('line', '=', Eval('line', -1)), - ('sale_line', '=', Eval('sale_line', -1)), - ]) + self.assertEqual(Pricing.price_component.domain, [If(Bool(Eval('line')), + ('line', '=', Eval('line')), + If(Bool(Eval('sale_line')), + ('sale_line', '=', Eval('sale_line')), + ('id', '=', -1)))]) def test_pricing_component_must_belong_to_pricing_owner(self): 'pricing rows reject components from another purchase or sale line' @@ -579,6 +579,17 @@ class PurchaseTradeTestCase(ModuleTestCase): self.assertFalse(PurchaseLine._has_invalid_delivery_period(valid)) self.assertFalse(SaleLine._has_invalid_delivery_period(valid)) + purchase_line = PurchaseLine() + purchase_line.from_del = invalid.from_del + purchase_line.to_del = invalid.to_del + sale_line = SaleLine() + sale_line.from_del = invalid.from_del + sale_line.to_del = invalid.to_del + with self.assertRaises(UserError): + purchase_line.on_change_from_del() + with self.assertRaises(UserError): + sale_line.on_change_to_del() + def test_pricing_eod_uses_weighted_average_for_manual_rows(self): 'manual pricing eod uses the weighted average of fixed and unfixed legs' Pricing = Pool().get('pricing.pricing') diff --git a/modules/purchase_trade/view/pricing_form.xml b/modules/purchase_trade/view/pricing_form.xml index 7165894..50f6095 100755 --- a/modules/purchase_trade/view/pricing_form.xml +++ b/modules/purchase_trade/view/pricing_form.xml @@ -1,7 +1,9 @@ -
-