1
# -*- coding: utf-8 -*-
2
###########################################################################
3
# Module Writen to OpenERP, Open Source Management Solution
5
# Copyright (c) 2012 Vauxoo - http://www.vauxoo.com
8
############################################################################
9
# Coded by: Luis Torres (luis_t@vauxoo.com),Rodo (rodo@vauxoo.com)
10
############################################################################
12
# This program is free software: you can redistribute it and/or modify
13
# it under the terms of the GNU Affero General Public License as
14
# published by the Free Software Foundation, either version 3 of the
15
# License, or (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU Affero General Public License for more details.
22
# You should have received a copy of the GNU Affero General Public License
23
# along with this program. If not, see <http://www.gnu.org/licenses/>.
25
##############################################################################
26
from osv import fields, osv
28
class mrp_production(osv.osv):
29
_inherit= "mrp.production"
31
def product_id_change(self, cr, uid, ids, product_id, context=None):
32
bom_obj=self.pool.get('mrp.bom')
33
res=super(mrp_production, self).product_id_change(cr, uid, ids,product_id,context=context)
35
res['value']['analytic_acc_rm']=False
36
res['value']['analytic_acc_fg']=False
37
if res['value']['bom_id']:
38
bom=bom_obj.browse(cr,uid,[res['value']['bom_id']],context=context)
39
res['value']['analytic_acc_rm']=bom and bom[0].analytic_acc_rm.id or False
40
res['value']['analytic_acc_fg']=bom and bom[0].analytic_acc_fg.id or False
43
def bom_id_change(self, cr, uid, ids, bom_id, context=None):
44
bom_obj=self.pool.get('mrp.bom')
45
res=super(mrp_production, self).bom_id_change(cr, uid, ids, bom_id, context=context)
47
bom=bom_obj.browse(cr,uid,[bom_id],context=context)
48
res['value']['analytic_acc_rm']=bom and bom[0].analytic_acc_rm.id or False
49
res['value']['analytic_acc_fg']=bom and bom[0].analytic_acc_fg.id or False
51
res['value']['analytic_acc_rm']= False
52
res['value']['analytic_acc_fg']= False
56
def _make_production_internal_shipment_line(self, cr, uid, production_line, shipment_id, parent_move_id, destination_location_id=False, context=None):
57
stock_move = self.pool.get('stock.move')
58
production = production_line.production_id
59
res=super(mrp_production, self)._make_production_internal_shipment_line(cr, uid, production_line, shipment_id, parent_move_id, destination_location_id=destination_location_id, context=context)
61
if parent_move_id and production.analytic_acc_rm:
62
stock_move.write(cr,uid,[parent_move_id],{'analytic_acc':production.analytic_acc_rm.id},context=context)
63
if res and production.analytic_acc_rm:
64
stock_move.write(cr,uid,[res],{'analytic_acc':production.analytic_acc_rm.id},context=context)
67
def _make_production_produce_line(self, cr, uid, production, context=None):
68
stock_move = self.pool.get('stock.move')
69
res=super(mrp_production, self)._make_production_produce_line(cr, uid, production, context=context)
70
if production.analytic_acc_fg:
71
stock_move.write(cr,uid,[res],{'analytic_acc':production.analytic_acc_fg.id},context=context)
75
def _make_production_consume_line(self, cr, uid, production_line, parent_move_id, source_location_id=False, context=None):
76
stock_move = self.pool.get('stock.move')
77
production = production_line.production_id
78
res=super(mrp_production, self)._make_production_consume_line(cr, uid, production_line, parent_move_id, source_location_id=False, context=context)
79
if production.analytic_acc_rm.id:
80
stock_move.write(cr,uid,[res],{'analytic_acc':production.analytic_acc_rm.id},context=context)
85
'analytic_acc_rm': fields.many2one('account.analytic.account','Analytic Account RM', readonly=True, states={'draft':[('readonly',False)]}),
86
'analytic_acc_fg': fields.many2one('account.analytic.account','Analytic Account FG', readonly=True, states={'draft':[('readonly',False)]})
90
class mrp_bom(osv.osv):
96
'analytic_acc_rm': fields.many2one('account.analytic.account','Analytic Account RM',),
97
'analytic_acc_fg': fields.many2one('account.analytic.account','Analytic Account FG',)