[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"
This commit is contained in:
committed by
Denis Vermylen (dve)
parent
81acd4dee2
commit
4022a47de2
@@ -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 <em>%s</em> created.") % (production.name))
|
||||
else:
|
||||
res[procurement.id] = False
|
||||
procurement.message_post(body=_("No BoM exists for this product!"))
|
||||
|
||||
@@ -2,3 +2,4 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import sale_mrp
|
||||
import models
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import procurement
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user