[14.0][FIX] mrp_subcontracting_purchase_link: link to PO line, not PO

This commit is contained in:
ThiagoMForgeFlow
2023-02-23 12:29:32 +01:00
committed by Meritxell Abellan
parent 0012430f55
commit f4165cde63
7 changed files with 21 additions and 10 deletions

View File

@@ -1,7 +1,7 @@
# Copyright 2020 Quartile Limited # Copyright 2020 Quartile Limited
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). # 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", "version": "14.0.1.0.1",
"category": "Manufacturing", "category": "Manufacturing",
"license": "LGPL-3", "license": "LGPL-3",

View File

@@ -8,5 +8,13 @@ class MrpProduction(models.Model):
_inherit = "mrp.production" _inherit = "mrp.production"
purchase_order_id = fields.Many2one( 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): class PurchaseOrder(models.Model):
_inherit = "purchase.order" _inherit = "purchase.order"
subcontract_production_count = fields.Integer(
compute="_compute_subcontract_production_count"
)
subcontract_production_ids = fields.One2many( subcontract_production_ids = fields.One2many(
"mrp.production", "mrp.production",
"purchase_order_id", "purchase_order_id",
"Subcontract Production Orders", "Subcontract Production Orders",
readonly=True, readonly=True,
) )
subcontract_production_count = fields.Integer(
compute="_compute_subcontract_production_count"
)
def action_view_mrp(self): def action_view_mrp(self):
productions = self.subcontract_production_ids productions = self.subcontract_production_ids

View File

@@ -10,5 +10,5 @@ class StockPicking(models.Model):
def _prepare_subcontract_mo_vals(self, subcontract_move, bom): def _prepare_subcontract_mo_vals(self, subcontract_move, bom):
vals = super()._prepare_subcontract_mo_vals(subcontract_move, bom) vals = super()._prepare_subcontract_mo_vals(subcontract_move, bom)
if subcontract_move.purchase_line_id: 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 return vals

View File

@@ -1,4 +1,4 @@
This module does the following: 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. - 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( self.assertEqual(
picking._prepare_subcontract_mo_vals( picking._prepare_subcontract_mo_vals(
move, move._get_subcontract_bom() move, move._get_subcontract_bom()
)["purchase_order_id"], )["purchase_line_id"],
purchase_order.id, purchase_order.order_line.id,
) )
def test_02_compute_subcontract_production_count(self): 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")] action["views"], [(self.env.ref("mrp.mrp_production_form_view").id, "form")]
) )
self.assertEqual( 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() action = purchase_order2.action_view_mrp()
self.assertEqual( self.assertEqual(

View File

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