Mark as finished
This commit is contained in:
@@ -381,6 +381,68 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
company_defaults._book_year_suffix(datetime.date(2026, 4, 1)),
|
||||
'26')
|
||||
|
||||
def test_itsa_bulk_unit_default_prefers_bulk_uom(self):
|
||||
'ITSA bulk unit default resolves the Bulk UoM'
|
||||
bulk = Mock(id=42)
|
||||
Uom = Mock()
|
||||
Uom.search.side_effect = [[bulk]]
|
||||
pool = Mock()
|
||||
pool.get.return_value = Uom
|
||||
|
||||
with patch.object(company_defaults, 'Pool', return_value=pool):
|
||||
self.assertEqual(company_defaults.default_itsa_bulk_unit(), 42)
|
||||
Uom.search.assert_called_once_with(
|
||||
[('symbol', '=', 'Bulk')], limit=1)
|
||||
|
||||
def test_itsa_add_physical_lot_defaults(self):
|
||||
'ITSA Add Physical lot defaults packing to 1 Bulk and weight unit to Mt'
|
||||
with patch('trytond.modules.purchase_trade.lot.is_itsa_company',
|
||||
return_value=True), patch(
|
||||
'trytond.modules.purchase_trade.lot.default_itsa_bulk_unit',
|
||||
return_value=42), patch(
|
||||
'trytond.modules.purchase_trade.lot.default_itsa_unit',
|
||||
return_value=7):
|
||||
self.assertEqual(
|
||||
lot_module.LotAddLine.default_lot_qt(), Decimal('1'))
|
||||
self.assertEqual(lot_module.LotAddLine.default_lot_unit(), 42)
|
||||
self.assertEqual(lot_module.LotAddLine.default_lot_unit_line(), 7)
|
||||
|
||||
def test_itsa_add_physical_lot_defaults_gross_from_net(self):
|
||||
'ITSA Add Physical lot copies net weight to empty gross weight'
|
||||
line = lot_module.LotAddLine()
|
||||
line.lot_quantity = Decimal('12.500')
|
||||
line.lot_gross_quantity = None
|
||||
|
||||
with patch('trytond.modules.purchase_trade.lot.is_itsa_company',
|
||||
return_value=True):
|
||||
line.on_change_lot_quantity()
|
||||
|
||||
self.assertEqual(line.lot_gross_quantity, Decimal('12.500'))
|
||||
|
||||
def test_itsa_add_physical_lot_keeps_existing_gross_weight(self):
|
||||
'ITSA Add Physical lot does not overwrite an existing gross weight'
|
||||
line = lot_module.LotAddLine()
|
||||
line.lot_quantity = Decimal('12.500')
|
||||
line.lot_gross_quantity = Decimal('13.000')
|
||||
|
||||
with patch('trytond.modules.purchase_trade.lot.is_itsa_company',
|
||||
return_value=True):
|
||||
line.on_change_lot_quantity()
|
||||
|
||||
self.assertEqual(line.lot_gross_quantity, Decimal('13.000'))
|
||||
|
||||
def test_non_itsa_add_physical_lot_does_not_default_gross_weight(self):
|
||||
'non-ITSA Add Physical lot does not copy net weight to gross weight'
|
||||
line = lot_module.LotAddLine()
|
||||
line.lot_quantity = Decimal('12.500')
|
||||
line.lot_gross_quantity = None
|
||||
|
||||
with patch('trytond.modules.purchase_trade.lot.is_itsa_company',
|
||||
return_value=False):
|
||||
line.on_change_lot_quantity()
|
||||
|
||||
self.assertIsNone(line.lot_gross_quantity)
|
||||
|
||||
@with_transaction()
|
||||
def test_purchase_list_fields_use_first_trade_line(self):
|
||||
'purchase list helper fields use the first real purchase line'
|
||||
@@ -762,9 +824,10 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
self.assertEqual(wizard.default_ship(None), {})
|
||||
|
||||
def test_lot_shipping_link_creates_shipment_from_dialog_supplier(self):
|
||||
'link to transport creates shipment in from dialog supplier'
|
||||
'link to transport creates shipment in from dialog broker'
|
||||
wizard = lot_module.LotShipping()
|
||||
supplier = Mock(id=30)
|
||||
vessel = Mock(id=50)
|
||||
created_shipment = Mock(id=40)
|
||||
ShipmentIn = Mock()
|
||||
ShipmentIn.create.return_value = [created_shipment]
|
||||
@@ -776,6 +839,7 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
shipment_internal=None,
|
||||
create_new_shipment=True,
|
||||
shipment_supplier=supplier,
|
||||
shipment_vessel=vessel,
|
||||
planned_from_location=Mock(id=10),
|
||||
planned_to_location=Mock(id=20),
|
||||
)
|
||||
@@ -794,10 +858,93 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
'supplier': 30,
|
||||
'from_location': 10,
|
||||
'to_location': 20,
|
||||
'vessel': 50,
|
||||
}])
|
||||
self.assertEqual(wizard.ship.shipment_in, created_shipment)
|
||||
Lot.assert_lines_quantity_consistency.assert_called_once_with([])
|
||||
|
||||
def test_lot_shipping_start_uses_broker_label(self):
|
||||
'link to transport uses the shipment in Broker label'
|
||||
self.assertEqual(
|
||||
lot_module.LotShippingStart.shipment_supplier.string, 'Broker')
|
||||
|
||||
def test_lotqt_mark_lines_finished_saves_selected_lines(self):
|
||||
'mark finished helper can finish purchase and sale lines'
|
||||
purchase_line = Mock()
|
||||
sale_line = Mock()
|
||||
lqt = Mock(
|
||||
lot_p=Mock(line=purchase_line),
|
||||
lot_s=Mock(sale_line=sale_line))
|
||||
PurchaseLine = Mock()
|
||||
SaleLine = Mock()
|
||||
pool = Mock()
|
||||
pool.get.side_effect = lambda name: {
|
||||
'purchase.line': PurchaseLine,
|
||||
'sale.line': SaleLine,
|
||||
}[name]
|
||||
|
||||
with patch('trytond.modules.purchase_trade.lot.Pool',
|
||||
return_value=pool):
|
||||
affected = lot_module.LotQt.mark_lines_finished_from_lotqt(
|
||||
lqt, mark_purchase=True, mark_sale=True)
|
||||
|
||||
self.assertTrue(purchase_line.finished)
|
||||
self.assertTrue(sale_line.finished)
|
||||
PurchaseLine.save.assert_called_once_with([purchase_line])
|
||||
SaleLine.save.assert_called_once_with([sale_line])
|
||||
self.assertEqual(affected, [purchase_line, sale_line])
|
||||
|
||||
def test_lotqt_mark_lines_finished_can_unmatch(self):
|
||||
'mark finished helper can release a matched virtual quantity'
|
||||
purchase_line = Mock()
|
||||
sale_line = Mock()
|
||||
lot_s = Mock(sale_line=sale_line)
|
||||
lot_p = Mock(line=purchase_line)
|
||||
lot_p.updateVirtualPart.side_effect = [False, False, True]
|
||||
lqt = Mock(
|
||||
lot_p=lot_p,
|
||||
lot_s=lot_s,
|
||||
lot_quantity=Decimal('12.5'),
|
||||
lot_shipment_origin='stock.shipment.in,10')
|
||||
PurchaseLine = Mock()
|
||||
pool = Mock()
|
||||
pool.get.return_value = PurchaseLine
|
||||
|
||||
with patch('trytond.modules.purchase_trade.lot.Pool',
|
||||
return_value=pool):
|
||||
affected = lot_module.LotQt.mark_lines_finished_from_lotqt(
|
||||
lqt, mark_purchase=True, unmatch=True)
|
||||
|
||||
self.assertTrue(purchase_line.finished)
|
||||
PurchaseLine.save.assert_called_once_with([purchase_line])
|
||||
lot_p.createVirtualPart.assert_any_call(
|
||||
Decimal('12.5'), 'stock.shipment.in,10', None)
|
||||
lot_p.createVirtualPart.assert_any_call(
|
||||
Decimal('12.5'), 'stock.shipment.in,10', lot_s, 'only sale')
|
||||
lot_p.updateVirtualPart.assert_any_call(
|
||||
-Decimal('12.5'), 'stock.shipment.in,10', lot_s)
|
||||
self.assertEqual(affected, [
|
||||
purchase_line, purchase_line, sale_line])
|
||||
|
||||
def test_lot_mark_finished_requires_matched_virtual_lotqt(self):
|
||||
'mark finished action rejects non matched rows'
|
||||
wizard = lot_module.LotMarkFinished()
|
||||
wizard.start = Mock(
|
||||
mark_purchase_line_finished=True,
|
||||
mark_sale_line_finished=False)
|
||||
wizard.records = [Mock(id=10000007)]
|
||||
Lot = Mock()
|
||||
Lot.skip_quantity_consistency.return_value.__enter__ = Mock()
|
||||
Lot.skip_quantity_consistency.return_value.__exit__ = Mock()
|
||||
LotQt = Mock(return_value=Mock(lot_p=Mock(), lot_s=None))
|
||||
pool = Mock()
|
||||
pool.get.side_effect = [Lot, LotQt]
|
||||
|
||||
with patch('trytond.modules.purchase_trade.lot.Pool',
|
||||
return_value=pool):
|
||||
with self.assertRaises(UserError):
|
||||
wizard.transition_marking()
|
||||
|
||||
def test_lot_shipping_rejects_existing_and_new_shipment(self):
|
||||
'link to transport rejects choosing existing shipment and create new'
|
||||
wizard = lot_module.LotShipping()
|
||||
|
||||
Reference in New Issue
Block a user