Files
stock-logistics-warehouse/stock_request_mrp/models/mrp_production.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

70 lines
2.1 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 MrpProduction(models.Model):
_inherit = "mrp.production"
stock_request_ids = fields.Many2many(
"stock.request",
"mrp_production_stock_request_rel",
"mrp_production_id",
"stock_request_id",
string="Stock Requests",
)
stock_request_count = fields.Integer(
"Stock Request #", compute="_compute_stock_request_ids"
)
@api.depends("stock_request_ids")
def _compute_stock_request_ids(self):
for rec in self:
rec.stock_request_count = len(rec.stock_request_ids)
def action_view_stock_request(self):
"""
:return dict: dictionary value for created view
"""
action = self.env.ref("stock_request.action_stock_request_form").read()[0]
requests = self.mapped("stock_request_ids")
if len(requests) > 1:
action["domain"] = [("id", "in", requests.ids)]
elif requests:
action["views"] = [
(self.env.ref("stock_request.view_stock_request_form").id, "form")
]
action["res_id"] = requests.id
return action
def _get_finished_move_value(
self,
product_id,
product_uom_qty,
product_uom,
operation_id=False,
byproduct_id=False,
):
res = super()._get_finished_move_value(
product_id,
product_uom_qty,
product_uom,
operation_id=operation_id,
byproduct_id=byproduct_id,
)
if self.stock_request_ids:
res["allocation_ids"] = [
(
0,
0,
{
"stock_request_id": request.id,
"requested_product_uom_qty": request.product_qty,
},
)
for request in self.stock_request_ids
]
return res