~jo0thlt/sfsoluciones/mtf

« back to all changes in this revision

Viewing changes to sfs_product_qty_available/account_move_line.py

  • Committer: contact at zbeanztech
  • Date: 2014-11-07 18:54:14 UTC
  • Revision ID: contact@zbeanztech.com-20141107185414-tzybvn7293tju4ce
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    Copyright (c) 2014 SF Soluciones.
 
5
#    (http://www.sfsoluciones.com)
 
6
#    contacto@sfsoluciones.com
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
from openerp.osv import fields, osv, orm
 
24
import openerp.addons.decimal_precision as dp
 
25
 
 
26
class account_move_line(osv.osv):
 
27
    _inherit = "account.move.line"
 
28
    
 
29
    def _compute_balance(self, cr, uid, ids, name, args, context=None):
 
30
        res = {}
 
31
        
 
32
        for line in self.browse(cr, uid, ids, context=context):
 
33
            balance = 0.00
 
34
            if line.reconcile_id:
 
35
                for payment_line in line.reconcile_id.line_id:
 
36
                    balance += (payment_line.debit - payment_line.credit)
 
37
            elif line.reconcile_partial_id:
 
38
                for payment_line in line.reconcile_partial_id.line_partial_ids:
 
39
                    balance += (payment_line.debit - payment_line.credit)
 
40
            res[line.id] = balance
 
41
        return res
 
42
    
 
43
    def _get_line_from_reconcile(self, cr, uid, ids, context=None):
 
44
        result = {}
 
45
        for r in self.pool.get('account.move.reconcile').browse(cr, uid, ids, context=context):
 
46
            for line in r.line_partial_ids:
 
47
                result[line.id] = True
 
48
            for line in r.line_id:
 
49
                result[line.id] = True
 
50
        return result.keys()
 
51
    
 
52
    _columns = {
 
53
        'tot_balance':fields.function(_compute_balance, digits_compute=dp.get_precision('Account'), string='Balance',
 
54
                                   type='float', store={
 
55
                'account.move.line': (lambda self, cr, uid, ids, c={}: ids, ['debit','credit','reconcile_id','reconcile_partial_id'], 20),
 
56
                'account.move.reconcile': (_get_line_from_reconcile, None, 20),
 
57
                
 
58
            },
 
59
            ),
 
60
                
 
61
    }
 
62
account_move_line()
 
63
 
 
64
 
 
65
 
 
66
 
 
67
 
 
68
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: