~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to reverse_bom/wizard/mrp_bom_reverted.py

  • Committer: nel at tinyerp
  • Date: 2010-06-11 07:33:35 UTC
  • Revision ID: nel@tinyerp.com-20100611073335-vnxjsybi3ad1gx3k
[ADD] Reverse bom

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#    
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU Affero General Public License as
 
9
#    published by the Free Software Foundation, either version 3 of the
 
10
#    License, or (at your option) any later version.
 
11
#
 
12
#    This program is distributed in the hope that it will be useful,
 
13
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#    GNU Affero General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU Affero General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
 
19
#
 
20
##############################################################################
 
21
 
 
22
from osv import fields, osv
 
23
 
 
24
class mrp_reversed_bom(osv.osv_memory):
 
25
    _name = "mrp.reversed.bom"
 
26
    _description = "Reversed Bom"
 
27
    
 
28
    _columns = {
 
29
    }
 
30
 
 
31
    def do_reverse(self, cr, uid, ids, context={}):
 
32
        """ To check the product type
 
33
        @param self: The object pointer.
 
34
        @param cr: A database cursor
 
35
        @param uid: ID of the user currently logged in
 
36
        @param ids: the ID or list of IDs if we want more than one 
 
37
        @param context: A standard dictionary
 
38
        @return:  
 
39
        """               
 
40
        bom_obj = self.pool.get('mrp.bom')
 
41
        bom_ids = context['active_ids']
 
42
        bom_ids = bom_obj.browse(cr, uid, context['active_ids'])
 
43
        for bom_id in bom_ids:
 
44
            new_bom_id = bom_obj.copy(cr, uid, bom_id.id, {'name': 'Reversed ' + bom_id.name,
 
45
                                                        'product_qty':(-1)*bom_id.product_qty,
 
46
                                                        'bom_lines' : [],
 
47
                                                        'product_uos_qty':(-1)*bom_id.product_uos_qty
 
48
            })
 
49
            for b in bom_id.bom_lines:
 
50
                print b
 
51
                bom_obj.copy(cr, uid, b.id, {'name': 'reversed' + b.name, 
 
52
                                            'bom_id':new_bom_id ,
 
53
                                            'product_qty':(-1)*b.product_qty,
 
54
                                            'product_uos_qty':(-1)*b.product_uos_qty
 
55
                    })
 
56
        return {}
 
57
 
 
58
mrp_reversed_bom()
 
59
 
 
60