Skip to content

Commit

Permalink
[IMP] stock_weighing: use any operations flag as a general setting
Browse files Browse the repository at this point in the history
TT51720
  • Loading branch information
chienandalu committed Nov 13, 2024
1 parent cae7e1b commit 6ec499e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
11 changes: 10 additions & 1 deletion stock_weighing/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@ def action_weighing_operations(self):
action = self.env["ir.actions.actions"]._for_xml_id(
"stock_weighing.weighing_operation_action"
)
weight_moves = self.move_lines.filtered("has_weight")
any_operation_actions = (
self.env["ir.config_parameter"]
.sudo()
.get_param("stock_weighing.any_operation_actions")
)
weight_moves = (
self.move_lines
if any_operation_actions
else self.move_lines.filtered("has_weight")
)
action["name"] = _("Weighing operations for %(name)s", name=self.name)
action["domain"] = [("id", "in", weight_moves.ids)]
action["context"] = dict(
Expand Down
15 changes: 10 additions & 5 deletions stock_weighing/models/stock_picking_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ast

from odoo import _, api, fields, models
from odoo.osv import expression


class StockPickingType(models.Model):
Expand All @@ -25,13 +26,17 @@ class StockPickingType(models.Model):
to_do_weights = fields.Integer(compute="_compute_to_do_weights")

def _compute_weight_move_ids(self):
any_operation_actions = (
self.env["ir.config_parameter"]
.sudo()
.get_param("stock_weighing.any_operation_actions")
)
domain = [("state", "in", ("assigned", "confirmed", "waiting"))]
if any_operation_actions:
domain = expression.AND([domain, [("has_weight", "=", True)]])
for picking_type in self:
picking_type.weight_move_ids = self.env["stock.move"].search(
[
("picking_type_id", "=", picking_type.id),
("state", "in", ("assigned", "confirmed", "waiting")),
("has_weight", "=", True),
]
expression.AND([[("picking_type_id", "=", picking_type.id)], domain])
)

@api.depends("weight_move_ids")
Expand Down
30 changes: 10 additions & 20 deletions stock_weighing/wizards/weigh_operation_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,23 @@ def _get_weighing_start_screen_actions(self):
"title": _("Incoming (weighing)"),
"description": _("Incoming weighing operations"),
"icon": "fa-arrow-down text-success",
"method": "action_incoming_weighing_operations",
"method": (
"action_incoming_any_operations"
if any_operation_actions
else "action_incoming_weighing_operations"
),
}
)
if any_operation_actions:
actions.append(
{
"title": _("Incoming (any)"),
"description": _("Any incoming operation"),
"icon": "fa-arrow-down text-info",
"method": "action_incoming_any_operations",
}
)
actions.append(
{
"title": _("Outgoing (weighing)"),
"description": _("Outgoing weighing operations"),
"icon": "fa-arrow-right text-success",
"method": "action_outgoing_weighing_operations",
"method": (
"action_outgoing_any_operations"
if any_operation_actions
else "action_outgoing_weighing_operations"
),
}
)
if any_operation_actions:
actions.append(
{
"title": _("Outgoing (any)"),
"description": _("Any outgoing operation"),
"icon": "fa-arrow-right text-info",
"method": "action_outgoing_any_operations",
}
)
return actions

0 comments on commit 6ec499e

Please sign in to comment.