[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 e248420348
[2] rev d8548e0771
This commit is contained in:
Simon Lejeune
2017-02-06 12:00:36 +01:00
parent 71773e1f1c
commit 7d2cccfc12
2 changed files with 7 additions and 7 deletions
+3 -5
View File
@@ -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
+4 -2
View File
@@ -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()