mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[IMP] mrp_multi_level: add MRP Area smart button on stock locations
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# Copyright 2016-19 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||
# - Jordi Ballester Alomar <jordi.ballester@forgeflow.com>
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
import ast
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
@@ -9,9 +10,32 @@ from odoo import fields, models
|
||||
class StockLocation(models.Model):
|
||||
_inherit = "stock.location"
|
||||
|
||||
mrp_area_id = fields.Many2one(
|
||||
comodel_name="mrp.area",
|
||||
string="MRP Area",
|
||||
help="Requirements for a particular MRP area are combined for the "
|
||||
"purposes of procurement by the MRP.",
|
||||
mrp_area_count = fields.Integer(
|
||||
string="MRP Area Parameter Count",
|
||||
readonly=True,
|
||||
compute="_compute_mrp_area_count",
|
||||
)
|
||||
|
||||
def _compute_mrp_area_count(self):
|
||||
for rec in self:
|
||||
areas = self.env["mrp.area"].search([("location_id", "=", rec.id)])
|
||||
rec.mrp_area_count = len(areas)
|
||||
|
||||
def action_view_mrp_area_location(self):
|
||||
self.ensure_one()
|
||||
result = self.env["ir.actions.actions"]._for_xml_id(
|
||||
"mrp_multi_level.mrp_area_action"
|
||||
)
|
||||
ctx = ast.literal_eval(result.get("context"))
|
||||
if not ctx:
|
||||
ctx = {}
|
||||
mrp_areas = self.env["mrp.area"].search([("location_id", "=", self.id)])
|
||||
if self.mrp_area_count != 1:
|
||||
result["domain"] = [("id", "in", mrp_areas.ids)]
|
||||
else:
|
||||
ctx.update({"default_mrp_area_id": mrp_areas[0].id})
|
||||
res = self.env.ref("mrp_multi_level.mrp_area_form", False)
|
||||
result["views"] = [(res and res.id or False, "form")]
|
||||
result["res_id"] = mrp_areas[0].id
|
||||
result["context"] = ctx
|
||||
return result
|
||||
|
||||
@@ -5,29 +5,16 @@
|
||||
<field name="model">stock.location</field>
|
||||
<field name="inherit_id" ref="stock.view_location_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="company_id" position="before">
|
||||
<field name="mrp_area_id" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_location_search" model="ir.ui.view">
|
||||
<field name="name">stock.location.search</field>
|
||||
<field name="model">stock.location</field>
|
||||
<field name="inherit_id" ref="stock.view_location_search" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="location_id" position="after">
|
||||
<field name="mrp_area_id" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_location_tree2" model="ir.ui.view">
|
||||
<field name="name">stock.location.tree</field>
|
||||
<field name="model">stock.location</field>
|
||||
<field name="inherit_id" ref="stock.view_location_tree2" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="company_id" position="before">
|
||||
<field name="mrp_area_id" />
|
||||
</field>
|
||||
<xpath expr="//button" position="before">
|
||||
<button
|
||||
type="object"
|
||||
name="action_view_mrp_area_location"
|
||||
class="oe_stat_button"
|
||||
icon="fa-eject"
|
||||
>
|
||||
<field name="mrp_area_count" widget="statinfo" string="MRP Areas" />
|
||||
</button>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user