Files
manufacture/purchase_mrp_distribution/models/purchase.py
Carlos Roca 0ea4e392c8 [ADD] purchase_mrp_distribution: New module to distribute qty of move in diferent products
This module aims to address the need to receive a
generic product, but until the moment of reception,
we do not know the quantity that we might receive
of its specific products.

Using kits was not suitable for us, because to
account for a unit of the kit product, the quantity
specified in the BoM must be received. Therefore,
we opted to define a new type of BoM called
distribution.

In this way, upon receiving a unit of any product
added to the BoM, it will be accounted for as a
unit of the generic product and will be reflected
in the svls as separate products, but they will be
accounted for in the purchase line as part of the
product.
2024-11-11 08:35:57 +01:00

40 lines
1.1 KiB
Python

# Copyright 2024 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import models
class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"
def _prepare_stock_move_vals(
self, picking, price_unit, product_uom_qty, product_uom
):
res = super()._prepare_stock_move_vals(
picking, price_unit, product_uom_qty, product_uom
)
bom = (
self.env["mrp.bom"]
.sudo()
._bom_find(
self.product_id, company_id=self.company_id.id, bom_type="distribution"
)[self.product_id]
)
if bom:
res["distribution_bom_id"] = bom.id
return res
def _get_po_line_moves(self):
res = super()._get_po_line_moves()
bom = (
self.env["mrp.bom"]
.sudo()
._bom_find(
self.product_id, company_id=self.company_id.id, bom_type="distribution"
)[self.product_id]
)
res |= self.move_ids.filtered(
lambda m: m.product_id in bom.bom_line_ids.product_id
)
return res