diff --git a/modules/purchase_trade/lot.py b/modules/purchase_trade/lot.py index 78c3cbf..550df35 100755 --- a/modules/purchase_trade/lot.py +++ b/modules/purchase_trade/lot.py @@ -3236,11 +3236,18 @@ class LotPlanTransport(Wizard): if not self.records: return {} lines = [] + default_lotqt = None + default_unit = None for record in self.records: quantity = record.r_lot_quantity or record.r_lot_matched or 0 if record.id < 10000000: raise UserError( "Only open quantity lines can be planned.") + if len(self.records) == 1: + default_lotqt = record.id - 10000000 + default_unit = ( + record.r_lot_unit_line.id + if record.r_lot_unit_line else None) lines.append({ 'lotqt': record.id - 10000000, 'quantity': quantity, @@ -3265,7 +3272,11 @@ class LotPlanTransport(Wizard): 'planned_to_date': record.r_planned_to_date, 'planned_note': record.r_planned_note, }) - return {'lines': lines} + return { + 'default_lotqt': default_lotqt, + 'default_unit': default_unit, + 'lines': lines, + } def transition_planning(self): Lot = Pool().get('lot.lot') @@ -3305,8 +3316,17 @@ class LotPlanTransportStart(ModelView): "Plan lot to transport" __name__ = "lot.plan_transport.start" + default_lotqt = fields.Many2One( + 'lot.qt', "Default quantity line", readonly=True) + default_unit = fields.Many2One( + 'product.uom', "Default unit", readonly=True) lines = fields.One2Many( - 'lot.plan_transport.line', 'plan', "Planning lines") + 'lot.plan_transport.line', 'plan', "Planning lines", + context={ + 'lot_plan_transport_default_lotqt': Eval('default_lotqt'), + 'lot_plan_transport_default_unit': Eval('default_unit'), + }, + depends=['default_lotqt', 'default_unit']) class LotPlanTransportLine(ModelView): @@ -3341,6 +3361,16 @@ class LotPlanTransportLine(ModelView): def default_cancel_plan(cls): return False + @classmethod + def default_lotqt(cls): + return Transaction().context.get( + 'lot_plan_transport_default_lotqt') + + @classmethod + def default_unit(cls): + return Transaction().context.get( + 'lot_plan_transport_default_unit') + class QtWarning(UserWarning): pass diff --git a/modules/purchase_trade/tests/test_module.py b/modules/purchase_trade/tests/test_module.py index 587840e..78faab2 100644 --- a/modules/purchase_trade/tests/test_module.py +++ b/modules/purchase_trade/tests/test_module.py @@ -244,6 +244,44 @@ class PurchaseTradeTestCase(ModuleTestCase): self.assertEqual(values['lines'][1]['lotqt'], 2) self.assertEqual(values['lines'][1]['quantity'], Decimal('200')) self.assertFalse(values['lines'][1]['cancel_plan']) + self.assertIsNone(values['default_lotqt']) + self.assertIsNone(values['default_unit']) + + def test_plan_transport_defaults_single_line_for_new_rows(self): + 'plan transport wizard gives new rows the current quantity line' + wizard = lot_module.LotPlanTransport() + wizard.records = [ + Mock( + id=10002242, + r_lot_quantity=Decimal('1000'), + r_lot_matched=Decimal('0'), + r_lot_unit_line=Mock(id=3), + r_planned_from_location=None, + r_planned_to_location=None, + r_planned_transport_type=None, + r_planned_from_date=None, + r_planned_to_date=None, + r_planned_note=None), + ] + + values = wizard.default_plan(None) + + self.assertEqual(values['default_lotqt'], 2242) + self.assertEqual(values['default_unit'], 3) + + def test_plan_transport_line_defaults_from_context(self): + 'new planning lines read their lot.qt and unit from the parent context' + context = { + 'lot_plan_transport_default_lotqt': 2242, + 'lot_plan_transport_default_unit': 3, + } + with patch.object( + lot_module, 'Transaction', + return_value=Mock(context=context)): + self.assertEqual( + lot_module.LotPlanTransportLine.default_lotqt(), 2242) + self.assertEqual( + lot_module.LotPlanTransportLine.default_unit(), 3) def test_plan_transport_applies_each_planning_line(self): 'plan transport wizard applies each line independently' diff --git a/modules/purchase_trade/view/lot_plan_transport_start_form.xml b/modules/purchase_trade/view/lot_plan_transport_start_form.xml index fc5b850..817bdee 100644 --- a/modules/purchase_trade/view/lot_plan_transport_start_form.xml +++ b/modules/purchase_trade/view/lot_plan_transport_start_form.xml @@ -1,4 +1,6 @@
+ +