Check From To + pricing component domain filter
This commit is contained in:
@@ -6,6 +6,7 @@ from decimal import Decimal
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Eval
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.modules.purchase_trade import valuation as valuation_module
|
||||
@@ -523,6 +524,61 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
self.assertTrue(Pricing.unfixed_qt_price.readonly)
|
||||
self.assertTrue(Pricing.eod_price.readonly)
|
||||
|
||||
def test_pricing_component_domain_is_limited_to_owner_line(self):
|
||||
'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)),
|
||||
])
|
||||
|
||||
def test_pricing_component_must_belong_to_pricing_owner(self):
|
||||
'pricing rows reject components from another purchase or sale line'
|
||||
Pricing = Pool().get('pricing.pricing')
|
||||
owner = Mock(id=10)
|
||||
other = Mock(id=11)
|
||||
|
||||
self.assertTrue(Pricing._component_matches_owner(Mock(
|
||||
line=owner,
|
||||
sale_line=None,
|
||||
price_component=Mock(line=owner, sale_line=None),
|
||||
)))
|
||||
self.assertFalse(Pricing._component_matches_owner(Mock(
|
||||
line=owner,
|
||||
sale_line=None,
|
||||
price_component=Mock(line=other, sale_line=None),
|
||||
)))
|
||||
self.assertTrue(Pricing._component_matches_owner(Mock(
|
||||
line=None,
|
||||
sale_line=owner,
|
||||
price_component=Mock(line=None, sale_line=owner),
|
||||
)))
|
||||
self.assertFalse(Pricing._component_matches_owner(Mock(
|
||||
line=None,
|
||||
sale_line=owner,
|
||||
price_component=Mock(line=None, sale_line=other),
|
||||
)))
|
||||
|
||||
def test_purchase_and_sale_delivery_period_reject_from_after_to(self):
|
||||
'delivery period dates must be chronological on purchase and sale lines'
|
||||
PurchaseLine = Pool().get('purchase.line')
|
||||
SaleLine = Pool().get('sale.line')
|
||||
invalid = Mock(
|
||||
from_del=datetime.date(2026, 5, 1),
|
||||
to_del=datetime.date(2026, 4, 30),
|
||||
)
|
||||
valid = Mock(
|
||||
from_del=datetime.date(2026, 4, 1),
|
||||
to_del=datetime.date(2026, 4, 30),
|
||||
)
|
||||
|
||||
self.assertTrue(PurchaseLine._has_invalid_delivery_period(invalid))
|
||||
self.assertTrue(SaleLine._has_invalid_delivery_period(invalid))
|
||||
self.assertFalse(PurchaseLine._has_invalid_delivery_period(valid))
|
||||
self.assertFalse(SaleLine._has_invalid_delivery_period(valid))
|
||||
|
||||
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')
|
||||
|
||||
Reference in New Issue
Block a user