diff --git a/stock_vertical_lift/models/vertical_lift_operation_base.py b/stock_vertical_lift/models/vertical_lift_operation_base.py index bd2d471be..415cd92f0 100644 --- a/stock_vertical_lift/models/vertical_lift_operation_base.py +++ b/stock_vertical_lift/models/vertical_lift_operation_base.py @@ -36,6 +36,20 @@ class VerticalLiftOperationBase(models.AbstractModel): ) ] + def onchange(self, values, field_name, field_onchange): + if field_name == "_barcode_scanned": + # _barcode_scanner is implemented (in the barcodes module) as an + # onchange, which is really annoying when we want it to act as a + # normal button and actually have side effect in the database + # (update line, go to the next step, ...). This override shorts the + # onchange call and calls the scanner method as a normal method. + self.on_barcode_scanned(values['_barcode_scanned']) + # We can't know which fields on_barcode_scanned changed, refresh + # everything. + return {"value": self.read()[0]} + else: + return super().onchange(values, field_name, field_onchange) + @api.depends() def _compute_number_of_ops(self): for record in self: @@ -164,7 +178,7 @@ class VerticalLiftOperationTransfer(models.AbstractModel): location_dest_id = fields.Many2one( string="Destination", related="current_move_line_id.location_dest_id", - readonly=True, + readonly=False, ) # TODO add a glue addon with product_expiry to add the field diff --git a/stock_vertical_lift/models/vertical_lift_operation_pick.py b/stock_vertical_lift/models/vertical_lift_operation_pick.py index 04d5d795d..452301a7d 100644 --- a/stock_vertical_lift/models/vertical_lift_operation_pick.py +++ b/stock_vertical_lift/models/vertical_lift_operation_pick.py @@ -11,15 +11,10 @@ class VerticalLiftOperationPick(models.Model): def on_barcode_scanned(self, barcode): self.ensure_one() - if not self.current_move_line_id or self.current_move_line_id == "done": + if not self.current_move_line_id or self.current_move_line_id.state == "done": return location = self.env["stock.location"].search([("barcode", "=", barcode)]) if location: - self.current_move_line_id.location_dest_id = location - # even if location_dest_id is a related, we need to set it, otherwise - # it's not refreshed on the view. We need both updates otherwise the - # line is not updated, probably because on_barcode_scanner is called - # in an onchange. (Even if the related is not readonly, tested.) self.location_dest_id = location self.operation_descr = _("Save") else: diff --git a/stock_vertical_lift/views/vertical_lift_operation_base_views.xml b/stock_vertical_lift/views/vertical_lift_operation_base_views.xml index d2767d6aa..2a4667ee8 100644 --- a/stock_vertical_lift/views/vertical_lift_operation_base_views.xml +++ b/stock_vertical_lift/views/vertical_lift_operation_base_views.xml @@ -140,6 +140,7 @@