~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to mrp_production_analytic_acc/mrp.py

  • Committer: Gabriela (Vauxoo)
  • Date: 2012-01-03 00:42:58 UTC
  • Revision ID: gabrielaquilarque97@gmail.com-20120103004258-w881e8vj51secs2q

[IMP] Changed name of modules.

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 openerp.osv import osv, fields
27
 
 
28
 
 
29
 
class mrp_production(osv.Model):
30
 
    _inherit = "mrp.production"
31
 
 
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)
36
 
        if not product_id:
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
46
 
        return res
47
 
 
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)
52
 
        if bom_id:
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
58
 
        else:
59
 
            res['value']['analytic_acc_rm'] = False
60
 
            res['value']['analytic_acc_fg'] = False
61
 
        return res
62
 
 
63
 
    def _make_production_internal_shipment_line(self, cr, uid, production_line,
64
 
                                                shipment_id, parent_move_id,
65
 
                                                destination_location_id=False,
66
 
                                                context=None):
67
 
        stock_move = self.pool.get('stock.move')
68
 
        production = production_line.production_id
69
 
        res = super(
70
 
            mrp_production, self)._make_production_internal_shipment_line(cr,
71
 
                        uid, production_line, shipment_id,
72
 
                        parent_move_id,
73
 
                        destination_location_id=destination_location_id,
74
 
                        context=context)
75
 
        print res
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},
79
 
                                            context=context)
80
 
        if res and production.analytic_acc_rm:
81
 
            stock_move.write(cr, uid, [res], {
82
 
                             'analytic_acc': production.analytic_acc_rm.id},
83
 
                                            context=context)
84
 
        return res
85
 
 
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},
93
 
                                            context=context)
94
 
        return res
95
 
 
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},
106
 
                                            context=context)
107
 
            return res
108
 
 
109
 
    _columns = {
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)]})
116
 
    }
117
 
 
118
 
 
119
 
class mrp_bom(osv.Model):
120
 
    _inherit = "mrp.bom"
121
 
 
122
 
    _columns = {
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',)
127
 
    }