~vauxoo/addons-vauxoo/7.0_test_hr_expense_dev_jorge

« back to all changes in this revision

Viewing changes to mrp_account_variation_cancel/account_variation_cancel.py

[MERGE] Add mrp_account_variation_cancel

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: 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: julio (julio@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 osv,fields
 
27
import decimal_precision as dp
 
28
 
 
29
class mrp_production(osv.osv):
 
30
    _inherit='mrp.production'
 
31
        
 
32
    def _create_account_variation_move_line(self, cr, uid, prod_variation, src_account_id, dest_account_id, reference_amount, context=None):
 
33
        res = super(mrp_production, self)._create_account_variation_move_line(cr, uid, prod_variation, src_account_id, dest_account_id, reference_amount, context=context)
 
34
        for lin in res:
 
35
            lin[2]['production_id'] = prod_variation.production_id and prod_variation.production_id.id or False
 
36
        return res
 
37
    
 
38
    def action_cancel(self, cr, uid, ids, context=None):
 
39
        account_move_line = self.pool.get('account.move.line')
 
40
        account_move = self.pool.get('account.move')
 
41
        
 
42
        if context is None:
 
43
            context = {}
 
44
            
 
45
        move_obj = self.pool.get('stock.move')
 
46
        result= {}
 
47
        for production in self.browse(cr, uid, ids, context=context):
 
48
            account_move_line_id = account_move_line.search(cr,uid,[('production_id','=',production.id)])
 
49
            for move_line in account_move_line.browse(cr, uid, account_move_line_id, context=context):
 
50
                result.setdefault(move_line.move_id.id, production.id)
 
51
        for lin in result.items():
 
52
            try:
 
53
                account_move.button_cancel(cr, uid, [lin[0]], context=context)
 
54
            except:
 
55
                pass
 
56
            account_move.unlink(cr, uid, [lin[0]])
 
57
        return super(mrp_production, self).action_cancel(cr, uid, ids, context=context)
 
58
    
 
59
mrp_production()
 
 
b'\\ No newline at end of file'