From to + pricing component

This commit is contained in:
2026-04-28 19:48:29 +02:00
parent 30d4362c09
commit ff2b897b7a
7 changed files with 67 additions and 24 deletions

View File

@@ -2,7 +2,7 @@
# this repository contains the full copyright notices and license terms. # this repository contains the full copyright notices and license terms.
from trytond.model import fields from trytond.model import fields
from trytond.pool import Pool, PoolMeta 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.model import (ModelSQL, ModelView)
from trytond.exceptions import UserError from trytond.exceptions import UserError
from trytond.tools import is_full_text, lstrip_wildcard from trytond.tools import is_full_text, lstrip_wildcard
@@ -333,11 +333,11 @@ class Pricing(ModelSQL,ModelView):
pricing_date = fields.Date("Date") pricing_date = fields.Date("Date")
price_component = fields.Many2One( price_component = fields.Many2One(
'pricing.component', "Component", 'pricing.component', "Component",
domain=[ domain=[If(Bool(Eval('line')),
'OR', ('line', '=', Eval('line')),
('line', '=', Eval('line', -1)), If(Bool(Eval('sale_line')),
('sale_line', '=', Eval('sale_line', -1)), ('sale_line', '=', Eval('sale_line')),
], ('id', '=', -1)))],
depends=['line', 'sale_line'])#, ondelete='CASCADE') depends=['line', 'sale_line'])#, ondelete='CASCADE')
quantity = fields.Numeric("Qt",digits='unit') quantity = fields.Numeric("Qt",digits='unit')
settl_price = fields.Numeric("Settl. price",digits='unit') settl_price = fields.Numeric("Settl. price",digits='unit')

View File

@@ -1101,6 +1101,19 @@ class Line(metaclass=PoolMeta):
and bool(line.to_del) and bool(line.to_del)
and line.from_del > 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) quantity_theorical = fields.Numeric("Contractual Qt", digits='unit', readonly=False)
price_type = fields.Selection([ price_type = fields.Selection([
('cash', 'Cash Price'), ('cash', 'Cash Price'),

View File

@@ -1084,6 +1084,19 @@ class SaleLine(metaclass=PoolMeta):
and bool(line.to_del) and bool(line.to_del)
and line.from_del > 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") del_period = fields.Many2One('product.month',"Delivery Period")
lots = fields.One2Many('lot.lot','sale_line',"Lots",readonly=True) lots = fields.One2Many('lot.lot','sale_line',"Lots",readonly=True)
fees = fields.One2Many('fee.fee', 'sale_line', 'Fees') fees = fields.One2Many('fee.fee', 'sale_line', 'Fees')

View File

@@ -6,7 +6,7 @@ from decimal import Decimal
from unittest.mock import Mock, patch from unittest.mock import Mock, patch
from trytond.pool import Pool 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.tests.test_tryton import ModuleTestCase, with_transaction
from trytond.exceptions import UserError from trytond.exceptions import UserError
from trytond.modules.purchase_trade import valuation as valuation_module 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 component choices are limited to the purchase or sale line'
Pricing = Pool().get('pricing.pricing') Pricing = Pool().get('pricing.pricing')
self.assertEqual(Pricing.price_component.domain, [ self.assertEqual(Pricing.price_component.domain, [If(Bool(Eval('line')),
'OR', ('line', '=', Eval('line')),
('line', '=', Eval('line', -1)), If(Bool(Eval('sale_line')),
('sale_line', '=', Eval('sale_line', -1)), ('sale_line', '=', Eval('sale_line')),
]) ('id', '=', -1)))])
def test_pricing_component_must_belong_to_pricing_owner(self): def test_pricing_component_must_belong_to_pricing_owner(self):
'pricing rows reject components from another purchase or sale line' '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(PurchaseLine._has_invalid_delivery_period(valid))
self.assertFalse(SaleLine._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): def test_pricing_eod_uses_weighted_average_for_manual_rows(self):
'manual pricing eod uses the weighted average of fixed and unfixed legs' 'manual pricing eod uses the weighted average of fixed and unfixed legs'
Pricing = Pool().get('pricing.pricing') Pricing = Pool().get('pricing.pricing')

View File

@@ -1,7 +1,9 @@
<form> <form>
<label name="pricing_date"/> <field name="line" invisible="1"/>
<field name="pricing_date"/> <field name="sale_line" invisible="1"/>
<label name="price_component"/> <label name="pricing_date"/>
<field name="pricing_date"/>
<label name="price_component"/>
<field name="price_component"/> <field name="price_component"/>
<label name="quantity"/> <label name="quantity"/>
<field name="quantity"/> <field name="quantity"/>

View File

@@ -1,7 +1,9 @@
<tree> <tree>
<field name="pricing_date"/> <field name="line" tree_invisible="1"/>
<field name="price_component"/> <field name="sale_line" tree_invisible="1"/>
<field name="quantity"/> <field name="pricing_date"/>
<field name="price_component"/>
<field name="quantity"/>
<field name="settl_price"/> <field name="settl_price"/>
<field name="fixed_qt"/> <field name="fixed_qt"/>
<field name="fixed_qt_price"/> <field name="fixed_qt_price"/>

View File

@@ -1,7 +1,9 @@
<tree> <tree>
<field name="pricing_date"/> <field name="line" tree_invisible="1"/>
<field name="price_component"/> <field name="sale_line" tree_invisible="1"/>
<field name="quantity"/> <field name="pricing_date"/>
<field name="price_component"/>
<field name="quantity"/>
<field name="settl_price"/> <field name="settl_price"/>
<field name="fixed_qt"/> <field name="fixed_qt"/>
<field name="fixed_qt_price"/> <field name="fixed_qt_price"/>