Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][IMP] stock_barcodes: Add update_barcodes_wiz_after_changes method #662

Open
wants to merge 4 commits into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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
11 changes: 11 additions & 0 deletions stock_barcodes/static/src/js/form_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
/**
Expand All @@ -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();
}
},
});
});
3 changes: 3 additions & 0 deletions stock_barcodes/tests/test_stock_barcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion stock_barcodes/wizard/stock_barcodes_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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 @@
# 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 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 @@
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
9 changes: 5 additions & 4 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 @@
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 Expand Up @@ -146,7 +144,10 @@
):
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"

Check warning on line 150 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#L150

Added line #L150 was not covered by tests

@api.model
def fields_to_fill_from_pending_line(self):
Expand Down
13 changes: 12 additions & 1 deletion stock_barcodes/wizard/stock_barcodes_read_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,17 @@
</div>
<!-- HACK: To avoid inheritance crash -->
<button name="action_manual_entry" invisible="1" />
<!-- Hide button in view to allow do onclick in JS. Use d-none instead of
invisible attribute to be allocated by jquery selector
-->
<button
name="dummy_on_barcode_scanned"
id="dummy_on_barcode_scanned"
type="object"
data-hotkey="99"
invisible="0"
class="d-none"
/>
<!-- // -->
<button
name="action_clean_values"
Expand All @@ -472,7 +483,7 @@
name="action_confirm"
type="object"
class="btn-success ml-auto oe_kanban_action_button btn-sm pl-3 pr-3"
attrs="{'invisible': ['|', '|','&amp;', ('is_manual_confirm', '=', False), ('manual_entry', '=', False), ('display_menu', '=', True), ('visible_force_done', '=', True)]}"
attrs="{'invisible': ['|', '|','&amp;', '&amp;', ('is_manual_confirm', '=', False), ('manual_entry', '=', False), ('is_manual_qty', '=', False), ('display_menu', '=', True), ('visible_force_done', '=', True)]}"
data-hotkey="8"
>
<i class="fa fa-check" title="Confirm" />
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 @@
# 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
Loading