~domsense/domsense-agilebg-addons/trunk

« back to all changes in this revision

Viewing changes to tax_stamp/invoice.py

  • Committer: Lorenzo Battistini
  • Date: 2012-10-27 10:52:42 UTC
  • Revision ID: lorenzo.battistini@agilebg.com-20121027105242-skkt1bsl4ed7unxe
[DEL] every module, as they are developed for 6.1.
As soon as we port a module to 7.0, before 7.0 was released,
we'll put it here

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from osv import osv, fields
2
 
from tools import config
3
 
 
4
 
class invoice_line(osv.osv):
5
 
    _inherit = 'account.invoice.line'
6
 
    _columns = {
7
 
        'tax_stamp': fields.boolean('Tax stamp', help='Specify whether this line should be used for comuting the taxable amount'),
8
 
        }
9
 
invoice_line()
10
 
 
11
 
class account_invoice(osv.osv):
12
 
    _inherit = 'account.invoice'
13
 
 
14
 
    def _amount_all(self, cr, uid, ids, name, args, context=None):
15
 
#        import pdb; pdb.set_trace()
16
 
        res = {}
17
 
        for invoice in self.browse(cr,uid,ids, context=context):
18
 
            res[invoice.id] = {
19
 
                'amount_untaxed': 0.0,
20
 
                'amount_tax': 0.0,
21
 
                'amount_total': 0.0
22
 
            }
23
 
            for line in invoice.invoice_line:
24
 
                if(line.tax_stamp):
25
 
                    res[invoice.id]['amount_tax'] += line.price_subtotal
26
 
                else:
27
 
                    res[invoice.id]['amount_untaxed'] += line.price_subtotal
28
 
            for line in invoice.tax_line:
29
 
                res[invoice.id]['amount_tax'] += line.amount
30
 
            res[invoice.id]['amount_total'] = res[invoice.id]['amount_tax'] + res[invoice.id]['amount_untaxed']
31
 
        return res
32
 
 
33
 
    def _get_invoice_tax(self, cr, uid, ids, context=None):
34
 
        return super(account_invoice, self)._get_invoice_tax(self, cr, uid, ids, context)
35
 
 
36
 
    def _get_invoice_line(self, cr, uid, ids, context=None):
37
 
        return super(account_invoice, self)._get_invoice_line(self, cr, uid, ids, context)
38
 
 
39
 
    _columns = {
40
 
        'amount_untaxed': fields.function(_amount_all, method=True, digits=(16, int(config['price_accuracy'])),string='Untaxed',
41
 
            store={
42
 
                'account.invoice': (lambda self, cr, uid, ids, c={}: ids, ['invoice_line'], 20),
43
 
                'account.invoice.tax': (_get_invoice_tax, None, 20),
44
 
                'account.invoice.line': (_get_invoice_line, ['price_unit','invoice_line_tax_id','quantity','discount'], 20),
45
 
            },
46
 
            multi='all'),
47
 
        'amount_tax': fields.function(_amount_all, method=True, digits=(16, int(config['price_accuracy'])), string='Tax',
48
 
            store={
49
 
                'account.invoice': (lambda self, cr, uid, ids, c={}: ids, ['invoice_line'], 20),
50
 
                'account.invoice.tax': (_get_invoice_tax, None, 20),
51
 
                'account.invoice.line': (_get_invoice_line, ['price_unit','invoice_line_tax_id','quantity','discount'], 20),
52
 
            },
53
 
            multi='all'),
54
 
        'amount_total': fields.function(_amount_all, method=True, digits=(16, int(config['price_accuracy'])), string='Total',
55
 
            store={
56
 
                'account.invoice': (lambda self, cr, uid, ids, c={}: ids, ['invoice_line'], 20),
57
 
                'account.invoice.tax': (_get_invoice_tax, None, 20),
58
 
                'account.invoice.line': (_get_invoice_line, ['price_unit','invoice_line_tax_id','quantity','discount'], 20),
59
 
            },
60
 
            multi='all'),
61
 
        }
62
 
 
63
 
account_invoice()