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 openerp.osv import osv, fields
29
class mrp_production(osv.Model):
30
_inherit = "mrp.production"
32
def product_id_change(self, cr, uid, ids, product_id, context=None):
33
bom_obj = self.pool.get('mrp.bom')
34
res = super(mrp_production, self).product_id_change(
35
cr, uid, ids, product_id, context=context)
37
res['value']['analytic_acc_rm'] = False
38
res['value']['analytic_acc_fg'] = False
39
if res['value']['bom_id']:
40
bom = bom_obj.browse(cr, uid, [res[
41
'value']['bom_id']], context=context)
42
res['value']['analytic_acc_rm'] = bom and bom[
43
0].analytic_acc_rm.id or False
44
res['value']['analytic_acc_fg'] = bom and bom[
45
0].analytic_acc_fg.id or False
48
def bom_id_change(self, cr, uid, ids, bom_id, context=None):
49
bom_obj = self.pool.get('mrp.bom')
50
res = super(mrp_production, self).bom_id_change(
51
cr, uid, ids, bom_id, context=context)
53
bom = bom_obj.browse(cr, uid, [bom_id], context=context)
54
res['value']['analytic_acc_rm'] = bom and bom[
55
0].analytic_acc_rm.id or False
56
res['value']['analytic_acc_fg'] = bom and bom[
57
0].analytic_acc_fg.id or False
59
res['value']['analytic_acc_rm'] = False
60
res['value']['analytic_acc_fg'] = False
63
def _make_production_internal_shipment_line(self, cr, uid, production_line,
64
shipment_id, parent_move_id,
65
destination_location_id=False,
67
stock_move = self.pool.get('stock.move')
68
production = production_line.production_id
70
mrp_production, self)._make_production_internal_shipment_line(cr,
71
uid, production_line, shipment_id,
73
destination_location_id=destination_location_id,
76
if parent_move_id and production.analytic_acc_rm:
77
stock_move.write(cr, uid, [parent_move_id], {
78
'analytic_acc': production.analytic_acc_rm.id},
80
if res and production.analytic_acc_rm:
81
stock_move.write(cr, uid, [res], {
82
'analytic_acc': production.analytic_acc_rm.id},
86
def _make_production_produce_line(self, cr, uid, production, context=None):
87
stock_move = self.pool.get('stock.move')
88
res = super(mrp_production, self)._make_production_produce_line(
89
cr, uid, production, context=context)
90
if production.analytic_acc_fg:
91
stock_move.write(cr, uid, [res], {
92
'analytic_acc': production.analytic_acc_fg.id},
96
def _make_production_consume_line(self, cr, uid, production_line,
97
parent_move_id, source_location_id=False, context=None):
98
stock_move = self.pool.get('stock.move')
99
production = production_line.production_id
100
res = super(mrp_production, self)._make_production_consume_line(
101
cr, uid, production_line, parent_move_id,
102
source_location_id=False, context=context)
103
if production.analytic_acc_rm.id:
104
stock_move.write(cr, uid, [res], {
105
'analytic_acc': production.analytic_acc_rm.id},
110
'analytic_acc_rm': fields.many2one('account.analytic.account',
111
'Analytic Account RM', readonly=True,
112
states={'draft': [('readonly', False)]}),
113
'analytic_acc_fg': fields.many2one('account.analytic.account',
114
'Analytic Account FG', readonly=True,
115
states={'draft': [('readonly', False)]})
119
class mrp_bom(osv.Model):
123
'analytic_acc_rm': fields.many2one('account.analytic.account',
124
'Analytic Account RM',),
125
'analytic_acc_fg': fields.many2one('account.analytic.account',
126
'Analytic Account FG',)