[IMP] mrp_subcontracting_purchase_link: add post init hook to populate the PO line on previous manufacturing orders

This commit is contained in:
Jordi Ballester Alomar
2023-03-14 20:16:01 +01:00
parent 689c185c0f
commit 257190d489
5 changed files with 49 additions and 1 deletions

View File

@@ -1 +1,2 @@
from . import models from . import models
from .hooks import post_init_hook

View File

@@ -5,9 +5,10 @@
"version": "14.0.2.0.0", "version": "14.0.2.0.0",
"category": "Manufacturing", "category": "Manufacturing",
"license": "LGPL-3", "license": "LGPL-3",
"author": "Quartile Limited, Odoo Community Association (OCA)", "author": "Quartile Limited, ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/manufacture", "website": "https://github.com/OCA/manufacture",
"depends": ["purchase", "mrp_subcontracting"], "depends": ["purchase", "mrp_subcontracting"],
"data": ["views/purchase_order_views.xml", "views/mrp_production_views.xml"], "data": ["views/purchase_order_views.xml", "views/mrp_production_views.xml"],
"post_init_hook": "post_init_hook",
"installable": True, "installable": True,
} }

View File

@@ -0,0 +1,39 @@
# Copyright 2023 ForgeFlow, S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
import logging
_logger = logging.getLogger(__name__)
def update_po_line_in_mrp_production(cr):
""" """
_logger.info("Updating PO line in MRP production")
cr.execute(
"""
UPDATE mrp_production
SET
purchase_line_id = Q.purchase_line_id,
purchase_order_id = Q.purchase_id
FROM (
SELECT po_sm.purchase_line_id, mo_sm.production_id, po.id as purchase_id
FROM stock_move as po_sm
INNER JOIN stock_move_move_rel as rel
ON rel.move_dest_id = po_sm.id
INNER JOIN stock_move as mo_sm
ON mo_sm.id = rel.move_orig_id
INNER JOIN purchase_order_line as pol
ON pol.id = po_sm.purchase_line_id
INNER JOIN purchase_order as po
ON po.id = pol.order_id
where po_sm.is_subcontract = true
AND po_sm.purchase_line_id is not null
AND mo_sm.production_id is not null
) AS Q
WHERE mrp_production.id = Q.production_id
"""
)
def post_init_hook(cr, registry):
update_po_line_in_mrp_production(cr)

View File

@@ -1,3 +1,5 @@
# Copyright 2023 ForgeFlow, S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
import logging import logging
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)

View File

@@ -2,3 +2,8 @@
* Yoshi Tashiro <tashiro@quartile.co> * Yoshi Tashiro <tashiro@quartile.co>
* Tim Lai <tl@quartile.com> * Tim Lai <tl@quartile.com>
* `ForgeFlow <https://www.forgeflow.com>`__:
* Thiago Mulero <thuago.mulero@forgeflow.com>
* Jordi Ballester <jordi.ballester@forgeflow.com>