From 7d2cccfc124c46a07ae433e9fe900e35739e5cf2 Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Fri, 3 Feb 2017 17:56:51 +0100 Subject: [PATCH] [FIX] stock: manually process a pack Before this patch, it was not possible to manually process a pack (i.e. checking the "is_done" box), because the field was always reset *before* saving. It was still possible to process it by hitting "validate", but it was not possible to put a pack in a pack. Manually process a pack means hitting the checkbox "is_done" on the pack operation. This "is_done" field is a boolean computed field with a reverse function, and this reverse function set the "qty_done" on the pack operation to 1.0. The compute field doesn't have any depends declared, so the value was invalidated after any changes in the form view. The computed method was used to check the checkbox is the "qty_done" is set to 1.0. It was probably used to check the checkbox when opening later a picking for which the pack was already processed. The issue is that the "qty_done" was never updated, because the inverse method is only called when saving, and the compute method already reset the "is_done" field to False, as the "qty_done" was not updated. To fix this issue, we do not use an inverse method but an onchange. Indeed, this was the expected behavior: hitting the checkbox should change the "qty_done". We already have a test covering this use case, committed in v9 [1]. It didn't discovered this regression because the test was using directly the "qty_done" field on the pack operation, not the "is_done" field used in the view. We change the test to use the "is_done" field and manually trigger the onchanges. This is due to a bad new API migration [2]. [1] rev e248420348587e844630b15ac840c6ef0021540c [2] rev d8548e07713ae4fed3abb88237fc3ac79bc81f28 --- addons/stock/models/stock_pack_operation.py | 8 +++----- addons/stock/tests/test_stock_flow.py | 6 ++++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/addons/stock/models/stock_pack_operation.py b/addons/stock/models/stock_pack_operation.py index 023d9ac57f5..22c91bfe0b4 100644 --- a/addons/stock/models/stock_pack_operation.py +++ b/addons/stock/models/stock_pack_operation.py @@ -34,8 +34,7 @@ class PackOperation(models.Model): product_qty = fields.Float('To Do', default=0.0, digits=dp.get_precision('Product Unit of Measure'), required=True) ordered_qty = fields.Float('Ordered Quantity', digits=dp.get_precision('Product Unit of Measure')) qty_done = fields.Float('Done', default=0.0, digits=dp.get_precision('Product Unit of Measure')) - # TDE FIXME: what what what what ?? - is_done = fields.Boolean(compute='_compute_is_done', inverse='_set_is_done', string='Done', oldname='processed_boolean') + is_done = fields.Boolean(compute='_compute_is_done', string='Done', readonly=False, oldname='processed_boolean') package_id = fields.Many2one('stock.quant.package', 'Source Package') pack_lot_ids = fields.One2many('stock.pack.operation.lot', 'operation_id', 'Lots Used') result_package_id = fields.Many2one( @@ -73,9 +72,8 @@ class PackOperation(models.Model): def _compute_is_done(self): self.is_done = self.qty_done > 0.0 - @api.one - def _set_is_done(self): - # TDE FIXME: whuuuut ??? + @api.onchange('is_done') + def on_change_is_done(self): if not self.product_id: if self.is_done and self.qty_done == 0: self.qty_done = 1.0 diff --git a/addons/stock/tests/test_stock_flow.py b/addons/stock/tests/test_stock_flow.py index 3f09260ed26..2f980b8214d 100644 --- a/addons/stock/tests/test_stock_flow.py +++ b/addons/stock/tests/test_stock_flow.py @@ -1324,7 +1324,8 @@ class TestStockFlow(TestStockCommon): # set the pack in pack operation to 'done' for pack in picking_pack.pack_operation_pack_ids: - pack.qty_done = 1.0 + pack.is_done = True + pack.on_change_is_done() # Put in a pack picking_pack.put_in_pack() @@ -1342,7 +1343,8 @@ class TestStockFlow(TestStockCommon): # set the pack in pack operation to 'done' for pack in picking_out.pack_operation_pack_ids: - pack.qty_done = 1.0 + pack.is_done = True + pack.on_change_is_done() # Validate picking picking_out.do_new_transfer()