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_weighing: use any operations flag as a general setting #22

Merged
Merged
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
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
Loading