mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
14 add link between sale order line and mrp production
This commit is contained in:
@@ -4,3 +4,4 @@ from . import mrp_production
|
||||
from . import mrp_workorder
|
||||
from . import stock_rule
|
||||
from . import sale_order
|
||||
from . import sale_order_line
|
||||
|
||||
@@ -32,3 +32,10 @@ class MrpProduction(models.Model):
|
||||
client_order_ref = fields.Char(
|
||||
related="sale_id.client_order_ref", string="Customer Reference", store=True
|
||||
)
|
||||
sale_line_ids = fields.Many2many(
|
||||
comodel_name="sale.order.line",
|
||||
relation="sale_line_production_rel",
|
||||
column1="production_id",
|
||||
column2="line_id",
|
||||
string="Sale order line",
|
||||
)
|
||||
|
||||
17
mrp_sale_info/models/sale_order_line.py
Normal file
17
mrp_sale_info/models/sale_order_line.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# Copyright 2021 Akretion (http://www.akretion.com).
|
||||
# @author Benoît GUILLOT <benoit.guillot@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class SaleOrderLine(models.Model):
|
||||
_inherit = "sale.order.line"
|
||||
|
||||
production_ids = fields.Many2many(
|
||||
comodel_name="mrp.production",
|
||||
relation="sale_line_production_rel",
|
||||
column1="line_id",
|
||||
column2="production_id",
|
||||
string="Manufacturing orders",
|
||||
)
|
||||
@@ -34,4 +34,10 @@ class StockRule(models.Model):
|
||||
res["source_procurement_group_id"] = (
|
||||
values.get("group_id").id if values.get("group_id", False) else False
|
||||
)
|
||||
moves = values.get("move_dest_ids")
|
||||
line_ids = moves.sale_line_id
|
||||
while moves.move_dest_ids:
|
||||
moves = moves.move_dest_ids
|
||||
line_ids |= moves.sale_line_id
|
||||
res["sale_line_ids"] = line_ids and [(4, x.id) for x in line_ids] or False
|
||||
return res
|
||||
|
||||
@@ -49,6 +49,7 @@ class TestMrpSaleInfo(common.SavepointCase):
|
||||
prev_productions = self.env["mrp.production"].search([])
|
||||
self.sale_order.action_confirm()
|
||||
production = self.env["mrp.production"].search([]) - prev_productions
|
||||
self.assertEqual(production.sale_line_ids, self.sale_order.order_line)
|
||||
self.assertEqual(production.sale_id, self.sale_order)
|
||||
self.assertEqual(production.partner_id, self.partner)
|
||||
self.assertEqual(production.client_order_ref, self.sale_order.client_order_ref)
|
||||
|
||||
Reference in New Issue
Block a user