Skip to content

Commit

Permalink
[18.0][MIG] stock_picking_show_linked: Migration to 18.0, suggested i…
Browse files Browse the repository at this point in the history
…mprovements
  • Loading branch information
fd-oerp committed Dec 12, 2024
1 parent c2bc7fe commit a1babfa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions stock_picking_show_linked/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2022 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
{
"name": "Stock Picking Show Linked",
"summary": """
Expand Down
23 changes: 14 additions & 9 deletions stock_picking_show_linked/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2022 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from odoo import api, fields, models

Expand All @@ -9,22 +10,26 @@ class StockPicking(models.Model):
dest_picking_count = fields.Integer(compute="_compute_picking_count")
origin_picking_count = fields.Integer(compute="_compute_picking_count")

@api.depends("move_ids")
@api.depends("move_ids.move_orig_ids", "move_ids.move_dest_ids")
def _compute_picking_count(self):
for record in self:
origin_pickings = record.mapped("move_ids.move_orig_ids.picking_id")
dest_pickings = record.mapped("move_ids.move_dest_ids.picking_id")
record.origin_picking_count = len(origin_pickings)
record.dest_picking_count = len(dest_pickings)

def _get_action_link(self, pickings):
record.update(
{
"origin_picking_count": len(origin_pickings),
"dest_picking_count": len(dest_pickings),
}
)

def _get_action_link(self, picking_ids):
result = self.env["ir.actions.actions"]._for_xml_id(
"stock.action_picking_tree_all"
)
# choose the view_mode accordingly
if not pickings or len(pickings) > 1:
result["domain"] = f"[('id','in',{pickings})]"
elif len(pickings) == 1:
if not picking_ids or len(picking_ids) > 1:
result["domain"] = f"[('id','in',{picking_ids})]"
elif len(picking_ids) == 1:
res = self.env.ref("stock.view_picking_form", False)
form_view = [(res and res.id or False, "form")]
if "views" in result:
Expand All @@ -33,7 +38,7 @@ def _get_action_link(self, pickings):
]
else:
result["views"] = form_view
result["res_id"] = pickings[0]
result["res_id"] = picking_ids[0]
return result

def action_stock_picking_origin(self):
Expand Down
2 changes: 2 additions & 0 deletions stock_picking_show_linked/views/stock_picking.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--Copyright 2022 ForgeFlow S.L. (https://www.forgeflow.com)
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)-->
<odoo>
<record id="stock_picking_show_linked_form_inherit" model="ir.ui.view">
<field name="name">stock_picking_show_linked.form</field>
Expand Down

0 comments on commit a1babfa

Please sign in to comment.