Document rules and enforce price value uniqueness
This commit is contained in:
@@ -6,7 +6,9 @@ from datetime import date
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from trytond.model.exceptions import ValidationError
|
||||
from trytond.pool import Pool
|
||||
from trytond.modules.price.price_value import PriceValue
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.modules.purchase_trade.pricing import ImportPrices
|
||||
|
||||
@@ -306,6 +308,37 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
self.assertIn('Errors:', message)
|
||||
self.assertIn('Row 2 - LME Copper / 2026-03-27', message)
|
||||
|
||||
def test_price_value_unique_rejects_duplicate_create(self):
|
||||
'price value uniqueness rejects duplicate model creation'
|
||||
price_value = SimpleNamespace(
|
||||
id=None,
|
||||
price=SimpleNamespace(id=1),
|
||||
price_date=date(2026, 3, 27),
|
||||
)
|
||||
|
||||
with patch.object(
|
||||
PriceValue, 'search',
|
||||
return_value=[SimpleNamespace(id=2)]):
|
||||
with self.assertRaises(ValidationError):
|
||||
PriceValue.check_unique_price_date([price_value])
|
||||
|
||||
def test_price_value_unique_rejects_duplicate_write(self):
|
||||
'price value uniqueness excludes current record on write'
|
||||
price_value = SimpleNamespace(
|
||||
id=2,
|
||||
price=SimpleNamespace(id=1),
|
||||
price_date=date(2026, 3, 27),
|
||||
)
|
||||
|
||||
with patch.object(
|
||||
PriceValue, 'search',
|
||||
return_value=[SimpleNamespace(id=3)]) as search:
|
||||
with self.assertRaises(ValidationError):
|
||||
PriceValue.check_unique_price_date([price_value])
|
||||
|
||||
domain = search.call_args[0][0]
|
||||
self.assertIn(('id', '!=', 2), domain[1])
|
||||
|
||||
|
||||
class _FakePriceModel:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user