Files
stock-logistics-warehouse/stock_request_mrp/models/stock_request_order.py
hveficent d3d11b12fe [13.0][ADD] stock_request_mrp
[UPD] Update stock_request_mrp.pot

[UPD] README.rst
2023-01-13 12:46:50 +01:00

43 lines
1.5 KiB
Python

# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models
class StockRequestOrder(models.Model):
_inherit = "stock.request.order"
production_ids = fields.One2many(
"mrp.production",
compute="_compute_production_ids",
string="Manufacturing Orders",
readonly=True,
)
production_count = fields.Integer(
string="Manufacturing Orders count",
compute="_compute_production_ids",
readonly=True,
)
@api.depends("stock_request_ids")
def _compute_production_ids(self):
for req in self:
req.production_ids = req.stock_request_ids.mapped("production_ids")
req.production_count = len(req.production_ids)
def action_view_mrp_production(self):
action = self.env.ref("mrp.mrp_production_action").read()[0]
productions = self.mapped("production_ids")
if len(productions) > 1:
action["domain"] = [("id", "in", productions.ids)]
action["views"] = [
(self.env.ref("mrp.mrp_production_tree_view").id, "tree"),
(self.env.ref("mrp.mrp_production_form_view").id, "form"),
]
elif productions:
action["views"] = [
(self.env.ref("mrp.mrp_production_form_view").id, "form")
]
action["res_id"] = productions.id
return action