Skip to content

Commit

Permalink
[IMP] stock_weighing: Do not break workflow to record weight is user …
Browse files Browse the repository at this point in the history
…wants to print labels

TT51483
  • Loading branch information
sergio-teruel committed Nov 6, 2024
1 parent 965a7d0 commit 922c2a5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
7 changes: 6 additions & 1 deletion stock_weighing/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
"website": "https://github.com/OCA/stock-weighing",
"license": "AGPL-3",
"category": "Inventory",
"depends": ["stock", "web_filter_header_button", "web_widget_numeric_step"],
"depends": [
"stock",
"web_filter_header_button",
"web_widget_numeric_step",
"web_ir_actions_act_multi",
],
"data": [
"security/ir.model.access.csv",
"views/start_screen_banner.xml",
Expand Down
25 changes: 23 additions & 2 deletions stock_weighing/wizards/weighing_wizard.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Copyright 2024 Tecnativa - David Vidal
# Copyright 2024 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.tools.misc import clean_context

from odoo.addons.web.controllers.main import clean_action


class StockMoveWeightWizard(models.TransientModel):
_name = "weighing.wizard"
Expand Down Expand Up @@ -127,15 +130,33 @@ def record_weight(self):
# Unlock the operation
selected_line.move_id.action_unlock_weigh_operation()
self.weight = 0.0
action_list = []
other_action = False

Check warning on line 134 in stock_weighing/wizards/weighing_wizard.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/wizards/weighing_wizard.py#L133-L134

Added lines #L133 - L134 were not covered by tests
if self.print_label:
action = selected_line.action_print_weight_record_label()
if not self.env.context.get("reload_wizard_action", False):
# If we want to keep the wizard open for multiple weighing, we do not
# need to close the wizard after printing a label.
action["close_on_report_download"] = True
return action
clean_action(action, self.env)
action_list.append(action)

Check warning on line 142 in stock_weighing/wizards/weighing_wizard.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/wizards/weighing_wizard.py#L141-L142

Added lines #L141 - L142 were not covered by tests
if self.env.context.get("reload_wizard_action", False):
return self.reload_action_wizard()
other_action = self.reload_action_wizard()
clean_action(other_action, self.env)
return self._actions_after_record_weight(action_list, other_action=other_action)

Check warning on line 146 in stock_weighing/wizards/weighing_wizard.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/wizards/weighing_wizard.py#L144-L146

Added lines #L144 - L146 were not covered by tests

@api.model
def _actions_after_record_weight(self, actions, other_action=False):
"""Print and return action window and no break workflow allowing print with
multi-thread option"""
action_list = []

Check warning on line 152 in stock_weighing/wizards/weighing_wizard.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/wizards/weighing_wizard.py#L152

Added line #L152 was not covered by tests
if other_action:
action_list = actions + [other_action]

Check warning on line 154 in stock_weighing/wizards/weighing_wizard.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/wizards/weighing_wizard.py#L154

Added line #L154 was not covered by tests
else:
action_list = actions + [

Check warning on line 156 in stock_weighing/wizards/weighing_wizard.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/wizards/weighing_wizard.py#L156

Added line #L156 was not covered by tests
{"type": "ir.actions.act_window_close"},
]
return {"type": "ir.actions.act_multi", "actions": action_list}

Check warning on line 159 in stock_weighing/wizards/weighing_wizard.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/wizards/weighing_wizard.py#L159

Added line #L159 was not covered by tests

def action_close(self):
"""Close but unlock the operation"""
Expand Down

0 comments on commit 922c2a5

Please sign in to comment.