[IMP] stock_location_orderpoint: Add access to orderpoints from location form

This commit is contained in:
Denis Roussel
2023-04-17 12:29:08 +02:00
committed by Michael Tietz
parent a83a92afac
commit 3bc8426f1e
5 changed files with 82 additions and 0 deletions

View File

@@ -14,6 +14,7 @@
"data/queue_job_channel.xml",
"data/queue_job_function.xml",
"views/stock_location_orderpoint_views.xml",
"views/stock_location.xml",
"views/menu.xml",
],
"depends": [

View File

@@ -1,3 +1,4 @@
from . import stock_location_orderpoint
from . import stock_rule
from . import stock_move
from . import stock_location

View File

@@ -0,0 +1,42 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
from odoo.tools.safe_eval import safe_eval
class StockLocation(models.Model):
_inherit = "stock.location"
location_orderpoint_ids = fields.One2many(
comodel_name="stock.location.orderpoint",
inverse_name="location_id",
string="Location Orderpoints",
help="Location Orderpoints. Rules that allows this location to be replenished.",
)
location_orderpoint_count = fields.Integer(
compute="_compute_location_orderpoint_count",
)
def _compute_location_orderpoint_count(self):
groups = self.env["stock.location.orderpoint"].read_group(
[("location_id", "in", self.ids)], ["location_id"], ["location_id"]
)
result = {
data["location_id"][0]: (data["location_id_count"]) for data in groups
}
for location in self:
location.location_orderpoint_count = result.get(location.id, 0)
def action_open_location_orderpoints(self):
action = self.env["ir.actions.act_window"]._for_xml_id(
"stock_location_orderpoint.action_stock_location_orderpoint"
)
action["domain"] = [("location_id", "in", self.ids)]
if len(self.ids) == 1:
if "context" in action:
context = safe_eval(action["context"])
context.update({"default_location_id": self.id})
action["context"] = str(context)
else:
action["context"] = str({"default_location_id": self.id})
return action

View File

@@ -154,3 +154,13 @@ class TestLocationOrderpoint(TestLocationOrderpointCommon):
replenish_move_new = self._get_replenishment_move(orderpoint)
self.assertEqual(replenish_move, replenish_move_new)
self._check_replenishment_move(replenish_move, move_qty * 2, orderpoint)
def test_orderpoint_count(self):
"""
One orderpoint has already been created in demo data.
Check after each creation that count is increasing.
"""
_, _ = self._create_orderpoint_complete("Stock2", trigger="cron")
self.assertEqual(1, self.location_dest.location_orderpoint_count)
_, _ = self._create_orderpoint_complete("Stock3", trigger="cron")
self.assertEqual(2, self.location_dest.location_orderpoint_count)

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 ACSONE SA/NV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="view_location_form" model="ir.ui.view">
<field name="name">stock.location.form (in stock_location_orderpoint)</field>
<field name="model">stock.location</field>
<field name="inherit_id" ref="stock.view_location_form" />
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button
string=""
class="oe_stat_button"
icon="fa-refresh"
name="action_open_location_orderpoints"
type="object"
groups="stock.group_stock_multi_locations"
>
<field
name="location_orderpoint_count"
string="Orderpoints"
widget="statinfo"
/>
</button>
</div>
</field>
</record>
</odoo>