Lot virtual packing update

This commit is contained in:
2026-07-16 18:53:55 +02:00
parent a0bd6f0e28
commit 4c85f80412
6 changed files with 131 additions and 17 deletions

View File

@@ -210,6 +210,62 @@ class PurchaseTradeTestCase(ModuleTestCase):
self.assertEqual(
line.get_coffee_quality_status(), 'approved')
def test_purchase_line_syncs_packing_to_virtual_lot(self):
'purchase line packing updates the existing virtual lot'
package_unit = Mock(id=60)
lot = Mock(lot_type='virtual', lot_qt=None, lot_unit=None)
line = Mock(
lots=[lot],
coffee_packing_count=440,
coffee_packing_unit=package_unit)
lot_model = Mock()
pool = Mock()
pool.get.return_value = lot_model
with patch.object(purchase_module, 'Pool', return_value=pool):
purchase_module.Line._sync_virtual_lot_packing(line)
self.assertEqual(lot.lot_qt, 440)
self.assertEqual(lot.lot_unit, package_unit)
lot_model.save.assert_called_once_with([lot])
def test_sale_line_syncs_packing_to_virtual_lot(self):
'sale line packing updates the existing virtual lot'
package_unit = Mock(id=90)
old_unit = Mock(id=60)
lot = Mock(lot_type='virtual', lot_qt=440, lot_unit=old_unit)
line = Mock(
lots=[lot],
coffee_packing_count=300,
coffee_packing_unit=package_unit)
lot_model = Mock()
pool = Mock()
pool.get.return_value = lot_model
with patch.object(sale_module, 'Pool', return_value=pool):
sale_module.SaleLine._sync_virtual_lot_packing(line)
self.assertEqual(lot.lot_qt, 300)
self.assertEqual(lot.lot_unit, package_unit)
lot_model.save.assert_called_once_with([lot])
def test_purchase_line_does_not_resave_aligned_virtual_lot_packing(self):
'aligned purchase packing does not resave the virtual lot'
package_unit = Mock(id=60)
lot = Mock(lot_type='virtual', lot_qt=440, lot_unit=Mock(id=60))
line = Mock(
lots=[lot],
coffee_packing_count=440,
coffee_packing_unit=package_unit)
lot_model = Mock()
pool = Mock()
pool.get.return_value = lot_model
with patch.object(purchase_module, 'Pool', return_value=pool):
purchase_module.Line._sync_virtual_lot_packing(line)
lot_model.save.assert_not_called()
def test_itsa_book_year_suffix_uses_april_fiscal_start(self):
'ITSA book year changes on April 1st'
self.assertEqual(