Skip to content

Commit

Permalink
[IMP] stock_barcodes: Add update_barcodes_wiz_after_changes method
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdauden committed Dec 4, 2024
1 parent 53850a5 commit 93c33f3
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 41 deletions.
23 changes: 12 additions & 11 deletions stock_barcodes/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Check warning on line 32 in stock_barcodes/models/stock_move_line.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/models/stock_move_line.py#L30-L32

Added lines #L30 - L32 were not covered by tests
# TODO: Any alternative to cover all cases without reassign?
stock_moves._action_assign()

Check warning on line 34 in stock_barcodes/models/stock_move_line.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/models/stock_move_line.py#L34

Added line #L34 was not covered by tests
# HACK: To force refresh wizard values
wiz_barcode = self.env["wiz.stock.barcodes.read.picking"].browse(

Check warning on line 36 in stock_barcodes/models/stock_move_line.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/models/stock_move_line.py#L36

Added line #L36 was not covered by tests
self.env.context.get("wiz_barcode_id", False)
)
wiz_barcode.with_context(

Check warning on line 39 in stock_barcodes/models/stock_move_line.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/models/stock_move_line.py#L39

Added line #L39 was not covered by tests
skip_clean_values=True
).update_barcodes_wiz_after_changes()
3 changes: 1 addition & 2 deletions stock_barcodes/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
3 changes: 1 addition & 2 deletions stock_barcodes/models/stock_picking_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
42 changes: 22 additions & 20 deletions stock_barcodes/wizard/stock_barcodes_read_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Check warning on line 186 in stock_barcodes/wizard/stock_barcodes_read_picking.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/wizard/stock_barcodes_read_picking.py#L186

Added line #L186 was not covered by tests

def get_sorted_move_lines(self, move_lines):
location_field = self.option_group_id.location_field_to_sort
Expand Down Expand Up @@ -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)

Check warning on line 306 in stock_barcodes/wizard/stock_barcodes_read_picking.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/wizard/stock_barcodes_read_picking.py#L306

Added line #L306 was not covered by tests
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()

Check warning on line 315 in stock_barcodes/wizard/stock_barcodes_read_picking.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/wizard/stock_barcodes_read_picking.py#L315

Added line #L315 was not covered by tests
self.action_show_step()
if keep_vals:
self.update_keep_values(keep_vals)

Check warning on line 318 in stock_barcodes/wizard/stock_barcodes_read_picking.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/wizard/stock_barcodes_read_picking.py#L318

Added line #L318 was not covered by tests

def action_done(self):
# Skip read log creation to be able to pass log_detail when available.
res = super(
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions stock_barcodes/wizard/stock_barcodes_read_todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Check warning on line 102 in stock_barcodes/wizard/stock_barcodes_read_todo.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/wizard/stock_barcodes_read_todo.py#L102

Added line #L102 was not covered by tests

def action_back_line(self):
if self.position_index > 0:
Expand Down
3 changes: 1 addition & 2 deletions stock_barcodes_picking_batch/models/stock_picking_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def action_barcode_scan(self):
if option_group.get_option_value("location_dest_id", "filled_default"):
vals["location_dest_id"] = first_picking.location_dest_id.id
wiz = self.env["wiz.stock.barcodes.read.picking"].create(vals)
wiz.determine_todo_action()
wiz.fill_pending_moves()
wiz.with_context(skip_clean_values=True).update_barcodes_wiz_after_changes()
action = self.env["ir.actions.act_window"]._for_xml_id(
"stock_barcodes_picking_batch.action_stock_barcodes_read_picking_batch"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def onchange_picking_batch_id(self):
# We are in a wizard view, so for create a candidate picking batch
# with the same default picking batch we need create it in this onchange
self._set_default_picking_batch()
self.determine_todo_action()
self.update_barcodes_wiz_after_changes()

Check warning on line 85 in stock_barcodes_picking_batch/wizard/stock_barcodes_read_picking_batch.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes_picking_batch/wizard/stock_barcodes_read_picking_batch.py#L85

Added line #L85 was not covered by tests

def get_sorted_move_lines(self, move_lines):
if self.picking_mode != "picking_batch":
Expand Down

0 comments on commit 93c33f3

Please sign in to comment.