From 6ec499ee5029e8d1fe1d72198f5b17d6c3ad2e1d Mon Sep 17 00:00:00 2001 From: David Date: Wed, 13 Nov 2024 17:39:21 +0100 Subject: [PATCH] [IMP] stock_weighing: use any operations flag as a general setting TT51720 --- stock_weighing/models/stock_picking.py | 11 ++++++- stock_weighing/models/stock_picking_type.py | 15 ++++++---- .../wizards/weigh_operation_selection.py | 30 +++++++------------ 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/stock_weighing/models/stock_picking.py b/stock_weighing/models/stock_picking.py index 99d93cde..a5e32ef7 100644 --- a/stock_weighing/models/stock_picking.py +++ b/stock_weighing/models/stock_picking.py @@ -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( diff --git a/stock_weighing/models/stock_picking_type.py b/stock_weighing/models/stock_picking_type.py index 046af28d..f183de6c 100644 --- a/stock_weighing/models/stock_picking_type.py +++ b/stock_weighing/models/stock_picking_type.py @@ -3,6 +3,7 @@ import ast from odoo import _, api, fields, models +from odoo.osv import expression class StockPickingType(models.Model): @@ -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") diff --git a/stock_weighing/wizards/weigh_operation_selection.py b/stock_weighing/wizards/weigh_operation_selection.py index 367dde16..34844b97 100644 --- a/stock_weighing/wizards/weigh_operation_selection.py +++ b/stock_weighing/wizards/weigh_operation_selection.py @@ -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