~vauxoo/addons-vauxoo/8.0-import_tax_tariff-dev-yani-rev-2

« back to all changes in this revision

Viewing changes to mrp_production_analytic_acc/mrp.py

  • Committer: jose at vauxoo
  • Date: 2012-10-30 22:29:46 UTC
  • mfrom: (501.1.58 6.1)
  • Revision ID: jose@vauxoo.com-20121030222946-gjtl9xw24t27xrrw
  
[MERGE] Merge to 6.1 branch to added new features 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
###########################################################################
 
3
#    Module Writen to OpenERP, Open Source Management Solution
 
4
#
 
5
#    Copyright (c) 2012 Vauxoo - http://www.vauxoo.com
 
6
#    All Rights Reserved.
 
7
#    info@vauxoo.com
 
8
############################################################################
 
9
#    Coded by: Luis Torres (luis_t@vauxoo.com),Rodo (rodo@vauxoo.com)
 
10
############################################################################
 
11
#
 
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.
 
16
#
 
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.
 
21
#
 
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/>.
 
24
#
 
25
##############################################################################
 
26
from osv import fields, osv
 
27
 
 
28
class mrp_production(osv.osv):
 
29
    _inherit= "mrp.production"
 
30
    
 
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)
 
34
        if not product_id:
 
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
 
41
        return res
 
42
        
 
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)
 
46
        if bom_id:
 
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
 
50
        else:
 
51
            res['value']['analytic_acc_rm']= False
 
52
            res['value']['analytic_acc_fg']= False
 
53
        return res
 
54
        
 
55
        
 
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)
 
60
        print res
 
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)
 
65
        return res
 
66
        
 
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)
 
72
        return res
 
73
        
 
74
        
 
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)
 
81
            return res
 
82
        
 
83
                
 
84
    _columns={
 
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)]})
 
87
    }
 
88
 
 
89
        
 
90
class mrp_bom(osv.osv):
 
91
    _inherit= "mrp.bom"
 
92
    
 
93
 
 
94
    
 
95
    _columns={
 
96
        'analytic_acc_rm': fields.many2one('account.analytic.account','Analytic Account RM',),
 
97
        'analytic_acc_fg': fields.many2one('account.analytic.account','Analytic Account FG',)
 
98
    }
 
99
 
 
100