From b1413010cb8c02ceca16ae2bcd147250cc27d178 Mon Sep 17 00:00:00 2001 From: bima Date: Sat, 17 Jun 2017 10:20:18 +0700 Subject: [PATCH] user store field sale info not fulfill correctly MO always empty. Save sale info from create MO from procurement --- mrp_sale_info/models/__init__.py | 1 + mrp_sale_info/models/mrp_production.py | 30 ++++--------------------- mrp_sale_info/models/procurement.py | 31 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 26 deletions(-) create mode 100644 mrp_sale_info/models/procurement.py diff --git a/mrp_sale_info/models/__init__.py b/mrp_sale_info/models/__init__.py index 2a095e3da..26f28b9bb 100644 --- a/mrp_sale_info/models/__init__.py +++ b/mrp_sale_info/models/__init__.py @@ -4,3 +4,4 @@ from . import mrp_production from . import mrp_workorder +from . import procurement diff --git a/mrp_sale_info/models/mrp_production.py b/mrp_sale_info/models/mrp_production.py index c482a0aa7..6e0492dec 100644 --- a/mrp_sale_info/models/mrp_production.py +++ b/mrp_sale_info/models/mrp_production.py @@ -10,32 +10,10 @@ class MrpProduction(models.Model): sale_id = fields.Many2one( 'sale.order', - compute='_compute_sale_info', string='Sale order', - readonly=True, - store=True) + readonly=True) partner_id = fields.Many2one( 'res.partner', - compute='_compute_sale_info', - string='Customer', - store=True) - commitment_date = fields.Datetime(compute='_compute_sale_info', - string='Commitment Date') - - @api.multi - def _compute_sale_info(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) - proc = move.procurement_id - production.sale_id = proc and proc.sale_line_id and \ - proc.sale_line_id.order_id.id or False - production.partner_id = production.sale_id and \ - production.sale_id.partner_id and \ - production.sale_id.partner_id.id or False - production.commitment_date = production.sale_id and \ - production.sale_id.commitment_date or '' + readonly=True, + string='Customer') + commitment_date = fields.Datetime(string='Commitment Date') diff --git a/mrp_sale_info/models/procurement.py b/mrp_sale_info/models/procurement.py new file mode 100644 index 000000000..8bca95a0f --- /dev/null +++ b/mrp_sale_info/models/procurement.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models, _ + + +class ProcurementOrder(models.Model): + _inherit = 'procurement.order' + + @api.multi + def make_mo(self): + def get_parent_move(move): + if move.move_dest_id: + return get_parent_move(move.move_dest_id) + return move + + res = super(ProcurementOrder, self).make_mo() + for prod_id in res: + production = self.env['mrp.production'].browse([res[prod_id]]) + move = get_parent_move(production.move_finished_ids) + proc = move.procurement_id + + production.sale_id = \ + proc and proc.sale_line_id and \ + proc.sale_line_id.order_id.id or False + production.partner_id = \ + production.sale_id and production.sale_id.partner_id and \ + production.sale_id.partner_id.id or False + production.commitment_date = \ + production.sale_id and production.sale_id.commitment_date or '' + return res