Pricing manual

This commit is contained in:
2026-04-10 07:52:59 +02:00
parent 90eab73430
commit b68f475e22
6 changed files with 177 additions and 63 deletions

View File

@@ -247,13 +247,15 @@ class PurchaseTradeTestCase(ModuleTestCase):
self.assertEqual(pricing_model.save.call_args_list[1].args[0][0].unfixed_qt, Decimal('12'))
def test_pricing_manual_fields_are_editable_except_eod(self):
'manual pricing rows can edit fixed and unfixed values while eod stays computed'
'manual pricing rows only edit quantity and settlement while derived values stay computed'
Pricing = Pool().get('pricing.pricing')
self.assertFalse(Pricing.fixed_qt.readonly)
self.assertFalse(Pricing.fixed_qt_price.readonly)
self.assertFalse(Pricing.unfixed_qt.readonly)
self.assertFalse(Pricing.unfixed_qt_price.readonly)
self.assertFalse(Pricing.quantity.readonly)
self.assertFalse(Pricing.settl_price.readonly)
self.assertTrue(Pricing.fixed_qt.readonly)
self.assertTrue(Pricing.fixed_qt_price.readonly)
self.assertTrue(Pricing.unfixed_qt.readonly)
self.assertTrue(Pricing.unfixed_qt_price.readonly)
self.assertTrue(Pricing.eod_price.readonly)
def test_pricing_eod_uses_weighted_average_for_manual_rows(self):
@@ -322,6 +324,52 @@ class PurchaseTradeTestCase(ModuleTestCase):
self.assertEqual(super_mock.return_value.write.call_args_list[1].args[0], [first])
self.assertEqual(super_mock.return_value.write.call_args_list[1].args[1], {'last': True})
def test_pricing_sync_manual_values_recomputes_manual_group_from_quantity_and_settl(self):
'manual pricing rows derive fixed/unfixed values from quantity and settlement price'
Pricing = Pool().get('pricing.pricing')
sale_line = Mock(id=10)
sale_line._get_pricing_base_quantity = Mock(return_value=Decimal('10'))
component = Mock(id=33, auto=False)
first = Mock(
id=1,
price_component=component,
sale_line=sale_line,
line=None,
pricing_date=datetime.date(2026, 4, 10),
quantity=Decimal('4'),
settl_price=Decimal('100'),
)
second = Mock(
id=2,
price_component=component,
sale_line=sale_line,
line=None,
pricing_date=datetime.date(2026, 4, 11),
quantity=Decimal('3'),
settl_price=Decimal('110'),
)
with patch.object(Pricing, 'search', return_value=[first, second]), patch(
'trytond.modules.purchase_trade.pricing.super') as super_mock:
Pricing._sync_manual_values([first, second])
first_values = super_mock.return_value.write.call_args_list[0].args[1]
self.assertEqual(first_values['fixed_qt'], Decimal('4'))
self.assertEqual(first_values['fixed_qt_price'], Decimal('100.0000'))
self.assertEqual(first_values['unfixed_qt'], Decimal('6'))
self.assertEqual(first_values['unfixed_qt_price'], Decimal('100'))
self.assertEqual(first_values['eod_price'], Decimal('100.0000'))
self.assertFalse(first_values['last'])
second_values = super_mock.return_value.write.call_args_list[1].args[1]
self.assertEqual(second_values['fixed_qt'], Decimal('7'))
self.assertEqual(second_values['fixed_qt_price'], Decimal('104.2857'))
self.assertEqual(second_values['unfixed_qt'], Decimal('3'))
self.assertEqual(second_values['unfixed_qt_price'], Decimal('110'))
self.assertEqual(second_values['eod_price'], Decimal('106.0000'))
self.assertTrue(second_values['last'])
def test_sale_and_purchase_trader_operator_domains_use_explicit_categories(self):
'sale and purchase trader/operator fields are filtered by TRADER/OPERATOR categories'
Sale = Pool().get('sale.sale')