This commit is contained in:
AzureAD\SylvainDUVERNAY
2026-07-14 16:13:24 +02:00
8 changed files with 123 additions and 336 deletions

View File

@@ -706,6 +706,9 @@ class PurchaseTradeTestCase(ModuleTestCase):
lot_quantity=Decimal('40'),
lot_p=lot,
lot_s=sale_lot,
lot_shipment_in=Mock(),
lot_shipment_internal=None,
lot_shipment_out=None,
lot_shipment_origin='stock.shipment.in,12',
)
lqt.is_planned_transport.return_value = True
@@ -724,14 +727,53 @@ class PurchaseTradeTestCase(ModuleTestCase):
state = wizard.transition_start()
self.assertEqual(state, 'end')
lot.updateVirtualPart.assert_called_once_with(
Decimal('-40'), 'stock.shipment.in,12', sale_lot, 'both')
lot.updateVirtualPart.assert_not_called()
LotQt.restore_planned_open_quantity.assert_called_once_with(
lqt, Decimal('40'))
LotQt.delete.assert_called_once_with([lqt])
lot.createVirtualPart.assert_not_called()
Lot.assert_lines_quantity_consistency.assert_called_once_with([
purchase_line, sale_line])
def test_lot_unship_deletes_zero_scheduled_lotqt_without_restore(self):
'unlinking a residual zero scheduled lot.qt only cleans the shipment tab'
wizard = lot_module.LotUnship()
wizard.records = [Mock(id=10000007, r_lot_type='virtual')]
purchase_line = Mock()
sale_line = Mock()
lot = Mock(line=purchase_line)
sale_lot = Mock(sale_line=sale_line)
lqt = Mock(
lot_quantity=Decimal('0'),
lot_p=lot,
lot_s=sale_lot,
lot_shipment_in=Mock(),
lot_shipment_internal=None,
lot_shipment_out=None,
)
lqt.is_planned_transport.return_value = True
Lot = Mock()
Lot.return_value = Mock()
Lot.skip_quantity_consistency.return_value.__enter__ = Mock()
Lot.skip_quantity_consistency.return_value.__exit__ = Mock()
LotQt = Mock()
LotQt.return_value = lqt
Move = Mock()
pool = Mock()
pool.get.side_effect = [Lot, LotQt, Move]
with patch('trytond.modules.purchase_trade.lot.Pool',
return_value=pool):
state = wizard.transition_start()
self.assertEqual(state, 'end')
LotQt.restore_planned_open_quantity.assert_not_called()
lot.updateVirtualPart.assert_not_called()
lot.createVirtualPart.assert_not_called()
LotQt.delete.assert_called_once_with([lqt])
Lot.assert_lines_quantity_consistency.assert_called_once_with([
purchase_line, sale_line])
def test_add_physical_lots_requires_linked_transport(self):
'physical lots can only be added from a scheduled quantity'
LotQt = Pool().get('lot.qt')
@@ -6795,7 +6837,7 @@ description</t></is></c>
shipment.bl_date = datetime.date(2026, 4, 30)
freight_product = SimpleNamespace(
rec_name='[Maritime Freight] Maritime freight',
name='Maritime freight')
name='[Maritime Freight] Maritime freight')
shipment.fees = [
SimpleNamespace(
id=201, product=freight_product, price=Decimal('10'),
@@ -6890,83 +6932,9 @@ description</t></is></c>
self.assertIn('80.000 USD/MT', shipment.report_linkage_pricing_input_prices)
self.assertIn('100.000 USD/MT', shipment.report_linkage_pricing_input_prices)
def test_lotqt_linkage_helpers_use_single_matching(self):
'lot.qt linkage helpers expose only the selected matching'
LotQt = Pool().get('lot.qt')
lotqt = LotQt()
currency = SimpleNamespace(code='USD')
unit = SimpleNamespace(symbol='MT')
product = SimpleNamespace(
rec_name='Sulphuric Acid',
name='Sulphuric Acid',
code='H2SO4')
purchase = SimpleNamespace(
id=1,
number='P-10',
reference='26.0001',
currency=currency,
party=SimpleNamespace(rec_name='SUPPLIER SA'),
to_location=SimpleNamespace(rec_name='Odda'),
incoterm=SimpleNamespace(code='FOB'),
operator=SimpleNamespace(rec_name='Operator A'))
sale = SimpleNamespace(
id=2,
number='S-20',
reference='26.0001',
currency=currency,
party=SimpleNamespace(rec_name='CLIENT SA'),
to_location=SimpleNamespace(rec_name='Mejillones'),
incoterm=SimpleNamespace(code='CFR'))
period = SimpleNamespace(rec_name='Chile FY26')
purchase_line = SimpleNamespace(
id=11,
product=product,
purchase=purchase,
quantity_theorical=Decimal('100'),
quantity=Decimal('100'),
unit_price=Decimal('80'),
unit=unit,
price_type='fixed',
del_period=period,
period_at='laycan',
from_del=datetime.date(2026, 4, 30),
to_del=datetime.date(2026, 5, 8),
fees=[],
mtm=[])
sale_line = SimpleNamespace(
id=12,
product=product,
sale=sale,
quantity_theorical=Decimal('100'),
quantity=Decimal('100'),
unit_price=Decimal('100'),
unit=unit,
price_type='fixed',
del_period=period,
period_at='laycan',
from_del=datetime.date(2026, 4, 30),
to_del=datetime.date(2026, 4, 30),
fees=[],
mtm=[])
lotqt.lot_p = SimpleNamespace(id=101, line=purchase_line)
lotqt.lot_s = SimpleNamespace(id=102, sale_line=sale_line)
lotqt.lot_shipment_in = SimpleNamespace(
bl_date=datetime.date(2026, 4, 30),
fees=[])
self.assertEqual(
lotqt.report_linkage_title, 'Linkage P-10/S-20 26.0001')
self.assertEqual(lotqt.report_linkage_desk, 'Sulphuric Acid')
self.assertEqual(lotqt.report_linkage_book, 'H2SO4 Chile FY26')
self.assertEqual(
lotqt.report_linkage_bl_date, 'Thursday, April 30, 2026')
self.assertIn('Purchases', lotqt.report_linkage_summary_groups)
self.assertIn('Sales', lotqt.report_linkage_summary_groups)
self.assertIn('P-10', lotqt.report_linkage_movement_references)
self.assertIn('S-20', lotqt.report_linkage_movement_references)
self.assertIn('80.000 USD/MT', lotqt.report_linkage_pricing_input_prices)
self.assertIn('100.000 USD/MT', lotqt.report_linkage_pricing_input_prices)
def test_linkage_report_does_not_extend_lotqt_model(self):
'linkage report must not alter the lot.qt ORM model'
self.assertFalse(hasattr(stock_module, 'LotQt'))
def test_lot_report_linkage_rejects_non_physical_lines(self):
'lot.report linkage report is only available for physical lines'