Merge PR #985 into 14.0

Signed-off-by LoisRForgeFlow
This commit is contained in:
OCA-git-bot
2023-03-01 09:15:54 +00:00
8 changed files with 59 additions and 10 deletions

View File

@@ -1,7 +1,7 @@
# Copyright 2020 Quartile Limited
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
{
"name": "Link Purchase Order to Subcontract Productions",
"name": "Link Purchase Order Line to Subcontract Productions",
"version": "14.0.1.0.1",
"category": "Manufacturing",
"license": "LGPL-3",

View File

@@ -0,0 +1,38 @@
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 migrate(cr, version=None):
if not version:
return
update_po_line_in_mrp_production(cr)

View File

@@ -8,5 +8,13 @@ class MrpProduction(models.Model):
_inherit = "mrp.production"
purchase_order_id = fields.Many2one(
"purchase.order", "Subcontract Purchase Order", readonly=True
"purchase.order",
"Subcontract Purchase Order",
readonly=True,
related="purchase_line_id.order_id",
store=True,
)
purchase_line_id = fields.Many2one(
"purchase.order.line", "Subcontract Purchase Order Line", readonly=True
)

View File

@@ -7,15 +7,16 @@ from odoo import fields, models
class PurchaseOrder(models.Model):
_inherit = "purchase.order"
subcontract_production_count = fields.Integer(
compute="_compute_subcontract_production_count"
)
subcontract_production_ids = fields.One2many(
"mrp.production",
"purchase_order_id",
"Subcontract Production Orders",
readonly=True,
)
subcontract_production_count = fields.Integer(
compute="_compute_subcontract_production_count"
)
def action_view_mrp(self):
productions = self.subcontract_production_ids

View File

@@ -10,5 +10,5 @@ class StockPicking(models.Model):
def _prepare_subcontract_mo_vals(self, subcontract_move, bom):
vals = super()._prepare_subcontract_mo_vals(subcontract_move, bom)
if subcontract_move.purchase_line_id:
vals["purchase_order_id"] = subcontract_move.purchase_line_id.order_id.id
vals["purchase_line_id"] = subcontract_move.purchase_line_id.id
return vals

View File

@@ -1,4 +1,4 @@
This module does the following:
- Extends _prepare_subcontract_mo_vals() and adds the purchase order reference to the subcontracted manufacturing orders.
- Extends _prepare_subcontract_mo_vals() and adds the purchase order line reference to the subcontracted manufacturing orders.
- Adds an action button in the purchase order form view to open related subcontracted manufacturing orders.

View File

@@ -44,8 +44,8 @@ class TestMrpSubcontractingPurchaseLink(TestMrpSubcontractingCommon):
self.assertEqual(
picking._prepare_subcontract_mo_vals(
move, move._get_subcontract_bom()
)["purchase_order_id"],
purchase_order.id,
)["purchase_line_id"],
purchase_order.order_line.id,
)
def test_02_compute_subcontract_production_count(self):
@@ -62,7 +62,8 @@ class TestMrpSubcontractingPurchaseLink(TestMrpSubcontractingCommon):
action["views"], [(self.env.ref("mrp.mrp_production_form_view").id, "form")]
)
self.assertEqual(
action["res_id"], purchase_order1.subcontract_production_ids[0].id
action["res_id"],
purchase_order1.subcontract_production_ids[0].id,
)
action = purchase_order2.action_view_mrp()
self.assertEqual(

View File

@@ -7,6 +7,7 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='company_id']" position="after">
<field name="purchase_order_id" groups="purchase.group_purchase_user" />
<field name="purchase_line_id" groups="purchase.group_purchase_user" />
</xpath>
</field>
</record>