diff --git a/stock_barcodes/models/stock_move_line.py b/stock_barcodes/models/stock_move_line.py index 159be24ee989..76a041b0f813 100644 --- a/stock_barcodes/models/stock_move_line.py +++ b/stock_barcodes/models/stock_move_line.py @@ -27,14 +27,15 @@ def _barcodes_process_line_to_unlink(self): self.qty_done = 0.0 def action_barcode_detailed_operation_unlink(self): - for sml in self: - stock_move = sml.move_id - stock_move.barcode_backorder_action = "pending" - sml.unlink() - # HACK: To force refresh wizard values - wiz_barcode = self.env["wiz.stock.barcodes.read.picking"].browse( - self.env.context.get("wiz_barcode_id", False) - ) - stock_move._action_assign() - wiz_barcode.fill_todo_records() - wiz_barcode.determine_todo_action() + stock_moves = self.move_id + self.unlink() + stock_moves.barcode_backorder_action = "pending" + # TODO: Any alternative to cover all cases without reassign? + stock_moves._action_assign() + # HACK: To force refresh wizard values + wiz_barcode = self.env["wiz.stock.barcodes.read.picking"].browse( + self.env.context.get("wiz_barcode_id", False) + ) + wiz_barcode.with_context( + skip_clean_values=True + ).update_barcodes_wiz_after_changes() diff --git a/stock_barcodes/models/stock_picking.py b/stock_barcodes/models/stock_picking.py index 13219a5d4d70..83829a591ebb 100644 --- a/stock_barcodes/models/stock_picking.py +++ b/stock_barcodes/models/stock_picking.py @@ -32,8 +32,7 @@ def action_barcode_scan(self, option_group=False): wiz = self.env["wiz.stock.barcodes.read.picking"].create( self._prepare_barcode_wiz_vals(option_group) ) - wiz.fill_pending_moves() - wiz.determine_todo_action() + wiz.with_context(skip_clean_values=True).update_barcodes_wiz_after_changes() action = self.env["ir.actions.actions"]._for_xml_id( "stock_barcodes.action_stock_barcodes_read_picking" ) diff --git a/stock_barcodes/models/stock_picking_type.py b/stock_barcodes/models/stock_picking_type.py index c57fc0ee5884..3ecb8df12a62 100644 --- a/stock_barcodes/models/stock_picking_type.py +++ b/stock_barcodes/models/stock_picking_type.py @@ -44,8 +44,7 @@ def action_barcode_scan(self): ): vals["location_dest_id"] = self.default_location_dest_id.id wiz = self.env["wiz.stock.barcodes.read.picking"].create(vals) - wiz.fill_pending_moves() - wiz.determine_todo_action() + wiz.with_context(skip_clean_values=True).update_barcodes_wiz_after_changes() action = self.env["ir.actions.actions"]._for_xml_id( "stock_barcodes.action_stock_barcodes_read_picking" ) diff --git a/stock_barcodes/static/src/js/form_view.js b/stock_barcodes/static/src/js/form_view.js index 1973c2c090c2..04de61d1c9ec 100644 --- a/stock_barcodes/static/src/js/form_view.js +++ b/stock_barcodes/static/src/js/form_view.js @@ -5,6 +5,7 @@ odoo.define("stock_barcodes.FormView", function (require) { "use strict"; var FormView = require("web.FormView"); + var FormController = require("web.FormController"); FormView.include({ /** @@ -21,4 +22,14 @@ odoo.define("stock_barcodes.FormView", function (require) { return params; }, }); + + FormController.include({ + _barcodeActiveScanned: function () { + this._super(...arguments); + var record = this.model.get(this.handle); + if (record.model.includes("wiz.stock.barcodes.read")) { + $("#dummy_on_barcode_scanned").click(); + } + }, + }); }); diff --git a/stock_barcodes/tests/test_stock_barcodes.py b/stock_barcodes/tests/test_stock_barcodes.py index b9f5a9033644..b19ae33bd8ec 100644 --- a/stock_barcodes/tests/test_stock_barcodes.py +++ b/stock_barcodes/tests/test_stock_barcodes.py @@ -164,6 +164,9 @@ def _create_barcode_option_group(cls): def action_barcode_scanned(self, wizard, barcode): wizard._barcode_scanned = barcode wizard._on_barcode_scanned() + # Method to call all methods outside of onchange environment for pickings read + if wizard._name != "wiz.stock.barcodes.new.lot": + wizard.dummy_on_barcode_scanned() def test_wizard_scan_location(self): self.action_barcode_scanned(self.wiz_scan, "8411322222568") diff --git a/stock_barcodes/wizard/stock_barcodes_read.py b/stock_barcodes/wizard/stock_barcodes_read.py index 5441a1436dd3..4265abdc31db 100644 --- a/stock_barcodes/wizard/stock_barcodes_read.py +++ b/stock_barcodes/wizard/stock_barcodes_read.py @@ -459,7 +459,10 @@ def _clean_barcode_scanned(self, barcode): def on_barcode_scanned(self, barcode): self.barcode = self._clean_barcode_scanned(barcode) - self.process_barcode(barcode) + + def dummy_on_barcode_scanned(self): + """To avoid execute operations in onchange environment""" + self.process_barcode(self.barcode) def check_location_contidion(self): if not self.location_id: diff --git a/stock_barcodes/wizard/stock_barcodes_read_picking.py b/stock_barcodes/wizard/stock_barcodes_read_picking.py index 42cd8216418b..a5e6b2b2c62c 100644 --- a/stock_barcodes/wizard/stock_barcodes_read_picking.py +++ b/stock_barcodes/wizard/stock_barcodes_read_picking.py @@ -183,8 +183,7 @@ def onchange_picking_id(self): # view, so for create a candidate picking with the same default picking # we need create it in this onchange self._set_default_picking() - self.fill_pending_moves() - self.determine_todo_action() + self.update_barcodes_wiz_after_changes() def get_sorted_move_lines(self, move_lines): location_field = self.option_group_id.location_field_to_sort @@ -298,6 +297,26 @@ def determine_todo_action(self, forced_todo_line=False): def update_fields_after_determine_todo(self, move_line): self.picking_product_qty = move_line.qty_done + def update_barcodes_wiz_after_changes(self): + if not self.keep_screen_values or self.todo_line_id.state != "pending": + if not self.env.context.get("skip_clean_values", False): + self.action_clean_values() + keep_vals = {} + else: + keep_vals = self._convert_to_write(self._cache) + self.fill_todo_records() + if self.forced_todo_key: + self.todo_line_id = self.pending_move_ids.filtered( + lambda ln: str(self._group_key(ln)) == self.forced_todo_key + )[:1] + self.selected_pending_move_id = self.todo_line_id + self.determine_todo_action(self.todo_line_id) + else: + self.determine_todo_action() + self.action_show_step() + if keep_vals: + self.update_keep_values(keep_vals) + def action_done(self): # Skip read log creation to be able to pass log_detail when available. res = super( @@ -310,24 +329,7 @@ def action_done(self): self[self._field_candidate_ids].scan_count += 1 if self.env.context.get("force_create_move"): self.move_line_ids.barcode_scan_state = "done_forced" - if not self.keep_screen_values or self.todo_line_id.state != "pending": - if not self.env.context.get("skip_clean_values", False): - self.action_clean_values() - keep_vals = {} - else: - keep_vals = self._convert_to_write(self._cache) - self.fill_todo_records() - if self.forced_todo_key: - self.todo_line_id = self.pending_move_ids.filtered( - lambda ln: str(self._group_key(ln)) == self.forced_todo_key - )[:1] - self.selected_pending_move_id = self.todo_line_id - self.determine_todo_action(self.todo_line_id) - else: - self.determine_todo_action() - self.action_show_step() - if keep_vals: - self.update_keep_values(keep_vals) + self.update_barcodes_wiz_after_changes() # Force refresh candidate pickings to show green if not pending moves if not self.pending_move_ids: self._set_candidate_pickings(self.picking_id) diff --git a/stock_barcodes/wizard/stock_barcodes_read_todo.py b/stock_barcodes/wizard/stock_barcodes_read_todo.py index 3b6a76b29fe6..7d9284781b7b 100644 --- a/stock_barcodes/wizard/stock_barcodes_read_todo.py +++ b/stock_barcodes/wizard/stock_barcodes_read_todo.py @@ -99,9 +99,7 @@ def action_reset_lines(self): self.state = "pending" self.line_ids.barcode_scan_state = "pending" self.line_ids.qty_done = 0.0 - self.wiz_barcode_id.action_clean_values() - self.wiz_barcode_id.fill_todo_records() - self.wiz_barcode_id.determine_todo_action() + self.wiz_barcode_id.update_barcodes_wiz_after_changes() def action_back_line(self): if self.position_index > 0: @@ -146,7 +144,10 @@ def _compute_state(self): ): rec.state = "done" else: - rec.state = "pending" + if rec.stock_move_ids[:1].barcode_backorder_action == "pending": + rec.state = "pending" + else: + rec.state = "done_forced" @api.model def fields_to_fill_from_pending_line(self): diff --git a/stock_barcodes/wizard/stock_barcodes_read_views.xml b/stock_barcodes/wizard/stock_barcodes_read_views.xml index 13aabb20cf66..0ed327b040a8 100644 --- a/stock_barcodes/wizard/stock_barcodes_read_views.xml +++ b/stock_barcodes/wizard/stock_barcodes_read_views.xml @@ -458,6 +458,17 @@