2010-05-27 13:26:15 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
2010-07-02 14:00:32 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
2010-05-27 13:26:15 +00:00
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). All Rights Reserved
|
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2010-10-28 06:54:18 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
2010-05-27 13:26:15 +00:00
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-10-28 06:54:18 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2010-05-27 13:26:15 +00:00
|
|
|
#
|
2010-10-28 06:54:18 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2010-05-27 13:26:15 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2012-12-06 14:56:32 +00:00
|
|
|
from openerp.osv import fields, osv
|
2010-05-27 13:26:15 +00:00
|
|
|
|
|
|
|
class mrp_production(osv.osv):
|
|
|
|
_inherit = 'mrp.production'
|
2010-07-02 14:00:32 +00:00
|
|
|
|
2010-07-07 14:38:23 +00:00
|
|
|
def _ref_calc(self, cr, uid, ids, field_names=None, arg=False, context=None):
|
2010-12-13 06:07:23 +00:00
|
|
|
""" Finds reference of sales order for production order.
|
2010-05-27 13:26:15 +00:00
|
|
|
@param field_names: Names of fields.
|
|
|
|
@param arg: User defined arguments
|
|
|
|
@return: Dictionary of values.
|
|
|
|
"""
|
2010-07-07 14:38:23 +00:00
|
|
|
res = {}
|
2010-05-27 13:26:15 +00:00
|
|
|
if not field_names:
|
2010-07-02 14:00:32 +00:00
|
|
|
field_names = []
|
2010-05-27 13:26:15 +00:00
|
|
|
for id in ids:
|
|
|
|
res[id] = {}.fromkeys(field_names, False)
|
2010-07-02 14:00:32 +00:00
|
|
|
for f in field_names:
|
|
|
|
field_name = False
|
|
|
|
if f == 'sale_name':
|
2010-05-27 13:26:15 +00:00
|
|
|
field_name = 'name'
|
2010-07-07 14:38:23 +00:00
|
|
|
if f == 'sale_ref':
|
2010-07-02 14:00:32 +00:00
|
|
|
field_name = 'client_order_ref'
|
2010-05-27 13:26:15 +00:00
|
|
|
for key, value in self._get_sale_ref(cr, uid, ids, field_name).items():
|
|
|
|
res[key][f] = value
|
|
|
|
return res
|
2010-07-02 14:00:32 +00:00
|
|
|
|
2010-05-27 13:26:15 +00:00
|
|
|
def _get_sale_ref(self, cr, uid, ids, field_name=False):
|
2010-07-07 14:38:23 +00:00
|
|
|
move_obj = self.pool.get('stock.move')
|
2010-07-02 14:00:32 +00:00
|
|
|
|
2010-05-27 13:26:15 +00:00
|
|
|
def get_parent_move(move_id):
|
|
|
|
move = move_obj.browse(cr, uid, move_id)
|
|
|
|
if move.move_dest_id:
|
|
|
|
return get_parent_move(move.move_dest_id.id)
|
|
|
|
return move_id
|
2010-07-02 14:00:32 +00:00
|
|
|
|
2010-07-07 14:38:23 +00:00
|
|
|
res = {}
|
2010-09-28 12:28:07 +00:00
|
|
|
productions = self.browse(cr, uid, ids)
|
2010-05-27 13:26:15 +00:00
|
|
|
for production in productions:
|
2010-09-28 12:28:07 +00:00
|
|
|
res[production.id] = False
|
|
|
|
if production.move_prod_id:
|
2010-10-22 09:39:03 +00:00
|
|
|
parent_move_line = get_parent_move(production.move_prod_id.id)
|
2010-05-27 13:26:15 +00:00
|
|
|
if parent_move_line:
|
2010-10-22 07:23:46 +00:00
|
|
|
move = move_obj.browse(cr, uid, parent_move_line)
|
2010-05-27 13:26:15 +00:00
|
|
|
if field_name == 'name':
|
2013-09-09 11:55:15 +00:00
|
|
|
res[production.id] = move.procurement_id and move.procurement_id.sale_line_id and move.procurement_id.sale_line_id.order_id.name or False
|
2010-07-07 14:38:23 +00:00
|
|
|
if field_name == 'client_order_ref':
|
2013-09-09 11:55:15 +00:00
|
|
|
res[production.id] = move.procurement_id and move.procurement_id.sale_line_id and move.procurement_id.sale_line_id.order_id.client_order_ref or False
|
2010-05-27 13:26:15 +00:00
|
|
|
return res
|
2010-07-02 14:00:32 +00:00
|
|
|
|
2013-09-18 07:33:33 +00:00
|
|
|
def _hook_create_post_procurement(self, cr, uid, production, procurement_id, context=None):
|
|
|
|
def get_parent_move(move):
|
|
|
|
if move.move_dest_id:
|
|
|
|
return get_parent_move(move.move_dest_id)
|
|
|
|
return move
|
|
|
|
|
|
|
|
res = super(mrp_production, self)._hook_create_post_procurement(cr, uid, production, procurement_id, context)
|
|
|
|
if production.move_prod_id:
|
|
|
|
parent_move_line = get_parent_move(production.move_prod_id)
|
|
|
|
if parent_move_line and parent_move_line.sale_line_id:
|
|
|
|
self.pool.get('procurement.order').write(cr, uid, procurement_id, {'sale_line_id': parent_move_line.sale_line_id.id})
|
|
|
|
return res
|
|
|
|
|
2010-05-27 13:26:15 +00:00
|
|
|
_columns = {
|
2012-06-22 12:03:53 +00:00
|
|
|
'sale_name': fields.function(_ref_calc, multi='sale_name', type='char', string='Sale Name', help='Indicate the name of sales order.'),
|
|
|
|
'sale_ref': fields.function(_ref_calc, multi='sale_name', type='char', string='Sale Reference', help='Indicate the Customer Reference from sales order.'),
|
2010-05-27 13:26:15 +00:00
|
|
|
}
|
2010-07-02 14:00:32 +00:00
|
|
|
|
2010-05-27 13:26:15 +00:00
|
|
|
|
2010-09-28 12:28:07 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|