02.04.26
This commit is contained in:
@@ -6,7 +6,9 @@ from unittest.mock import Mock, patch
|
||||
|
||||
from trytond.pool import Pool
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.modules.purchase_trade import valuation as valuation_module
|
||||
from trytond.modules.purchase_trade.service import ContractFactory
|
||||
|
||||
|
||||
class PurchaseTradeTestCase(ModuleTestCase):
|
||||
@@ -201,5 +203,35 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
'USC 70.2500 PER POUND (SEVENTY USC AND TWENTY FIVE CENTS) ON ICE Cotton #2 MAY 2026',
|
||||
])
|
||||
|
||||
def test_contract_factory_uses_one_line_per_selected_source(self):
|
||||
'matched multi-lot contract creation keeps one generated line per source lot'
|
||||
contract_detail = Mock(quantity=Decimal('2000'))
|
||||
ct = Mock(matched=True)
|
||||
line_a = Mock()
|
||||
line_b = Mock()
|
||||
sources = [
|
||||
{'lot': Mock(), 'trade_line': line_a, 'quantity': Decimal('1000')},
|
||||
{'lot': Mock(), 'trade_line': line_b, 'quantity': Decimal('1000')},
|
||||
]
|
||||
|
||||
result = ContractFactory._get_line_sources(contract_detail, sources, ct)
|
||||
|
||||
self.assertEqual(len(result), 2)
|
||||
self.assertEqual([r['quantity'] for r in result], [
|
||||
Decimal('1000'), Decimal('1000')])
|
||||
self.assertTrue(all(r['use_source_delivery'] for r in result))
|
||||
|
||||
def test_contract_factory_rejects_multi_lot_quantity_mismatch(self):
|
||||
'matched multi-lot contract creation rejects totals that do not match the selection'
|
||||
contract_detail = Mock(quantity=Decimal('1500'))
|
||||
ct = Mock(matched=True)
|
||||
sources = [
|
||||
{'lot': Mock(), 'trade_line': Mock(), 'quantity': Decimal('1000')},
|
||||
{'lot': Mock(), 'trade_line': Mock(), 'quantity': Decimal('1000')},
|
||||
]
|
||||
|
||||
with self.assertRaises(UserError):
|
||||
ContractFactory._get_line_sources(contract_detail, sources, ct)
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
|
||||
Reference in New Issue
Block a user