From 4022a47de2e31c319650daa20a13a1df0eca1bc5 Mon Sep 17 00:00:00 2001 From: Foram Shah Date: Fri, 8 Jul 2016 17:38:38 +0530 Subject: [PATCH] [IMP] mrp,sale_mrp: add origin of MO in chatter Set sale order and production order link on Mo. override make_mo method in sale_mrp module to set sale order reference in mo. .and to find final destination move, i created one common private method to get parent move. MESSAGES TO DISPLAY: -Set a Reordering Rule (stock.warehouse.orderpoint) that creates a manufacturing order: "This manufacturing order has been created from: OP/00001" -Create new Sales order of manufactured product , there will be a Source Document with procurement of that Sale Order "This manufacturing order has been created from: SO001" -create MO for BoM items of the product, there will be a Source Document with procurement of that Manufacturing Order "This manufacturing order has been created from: MO/00001" --- addons/mrp/models/procurement.py | 12 +++++++++++- addons/sale_mrp/__init__.py | 1 + addons/sale_mrp/models/__init__.py | 4 ++++ addons/sale_mrp/models/procurement.py | 23 +++++++++++++++++++++++ addons/sale_mrp/sale_mrp.py | 11 ++++++----- 5 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 addons/sale_mrp/models/__init__.py create mode 100644 addons/sale_mrp/models/procurement.py diff --git a/addons/mrp/models/procurement.py b/addons/mrp/models/procurement.py index 1cfb047d856..ba11ffc9e81 100644 --- a/addons/mrp/models/procurement.py +++ b/addons/mrp/models/procurement.py @@ -83,8 +83,18 @@ class ProcurementOrder(models.Model): if bom: # create the MO as SUPERUSER because the current user may not have the rights to do it (mto product launched by a sale for example) production = ProductionSudo.create(procurement._prepare_mo_vals(bom)) + origin_production = procurement.move_dest_id.raw_material_production_id + orderpoint = procurement.orderpoint_id + if orderpoint: + production.message_post_with_view('mail.message_origin_link', + values={'self': production, 'origin': orderpoint}, + subtype_id=self.env.ref('mail.mt_note').id) + if origin_production: + production.message_post_with_view('mail.message_origin_link', + values={'self': production, 'origin': origin_production}, + subtype_id=self.env.ref('mail.mt_note').id) + res[procurement.id] = production.id - procurement.message_post(body=_("Manufacturing Order %s created.") % (production.name)) else: res[procurement.id] = False procurement.message_post(body=_("No BoM exists for this product!")) diff --git a/addons/sale_mrp/__init__.py b/addons/sale_mrp/__init__.py index a3a87f0de22..adc1a9aee5e 100644 --- a/addons/sale_mrp/__init__.py +++ b/addons/sale_mrp/__init__.py @@ -2,3 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. import sale_mrp +import models diff --git a/addons/sale_mrp/models/__init__.py b/addons/sale_mrp/models/__init__.py new file mode 100644 index 00000000000..b0f44e7d511 --- /dev/null +++ b/addons/sale_mrp/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import procurement \ No newline at end of file diff --git a/addons/sale_mrp/models/procurement.py b/addons/sale_mrp/models/procurement.py new file mode 100644 index 00000000000..a00176ddfef --- /dev/null +++ b/addons/sale_mrp/models/procurement.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models + + +class ProcurementOrder(models.Model): + _inherit = 'procurement.order' + + @api.multi + def make_mo(self): + """ override method to set link in production created from sale order.""" + res = super(ProcurementOrder, self).make_mo() + for procurement_id, production_id in res.items(): + if production_id: + production = self.env['mrp.production'].browse(production_id) + move = production._get_parent_move(production.move_finished_ids[0]) + sale_order = move.procurement_id.sale_line_id.order_id + if sale_order: + production.message_post_with_view('mail.message_origin_link', + values={'self': production, 'origin': sale_order}, + subtype_id=self.env.ref('mail.mt_note').id) + return res diff --git a/addons/sale_mrp/sale_mrp.py b/addons/sale_mrp/sale_mrp.py index fce9f550395..1c08cef7feb 100644 --- a/addons/sale_mrp/sale_mrp.py +++ b/addons/sale_mrp/sale_mrp.py @@ -11,14 +11,15 @@ class MrpProduction(models.Model): sale_name = fields.Char(compute='_compute_sale_name_sale_ref', string='Sale Name', help='Indicate the name of sales order.') sale_ref = fields.Char(compute='_compute_sale_name_sale_ref', string='Sale Reference', help='Indicate the Customer Reference from sales order.') + def _get_parent_move(self, move): + if move.move_dest_id: + return self._get_parent_move(move.move_dest_id) + return move + @api.multi def _compute_sale_name_sale_ref(self): - def get_parent_move(move): - if move.move_dest_id: - return get_parent_move(move.move_dest_id) - return move for production in self: - move = get_parent_move(production.move_finished_ids[0]) + move = production._get_parent_move(production.move_finished_ids[0]) production.sale_name = move.procurement_id and move.procurement_id.sale_line_id and move.procurement_id.sale_line_id.order_id.name or False production.sale_ref = move.procurement_id and move.procurement_id.sale_line_id and move.procurement_id.sale_line_id.order_id.client_order_ref or False