user store field sale info not fulfill correctly MO always empty.

Save sale info from create MO from procurement
This commit is contained in:
bima
2017-06-17 10:20:18 +07:00
parent 4e357d3766
commit b1413010cb
3 changed files with 36 additions and 26 deletions

View File

@@ -4,3 +4,4 @@
from . import mrp_production
from . import mrp_workorder
from . import procurement

View File

@@ -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')

View File

@@ -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