~valix/openobject-italia/rivalsa_inps

« back to all changes in this revision

Viewing changes to l10n_it_withholding_tax/account.py

  • Committer: Lorenzo Battistini
  • Date: 2012-07-17 14:51:47 UTC
  • Revision ID: lorenzo.battistini@agilebg.com-20120717145147-wpfd57jfdv6az0f6
[REM] l10n_it_withholding_tax

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
##############################################################################
3
 
#    
4
 
#    Copyright (C) 2012 Associazione OpenERP Italia
5
 
#    (<http://www.openerp-italia.org>). 
6
 
#    All Rights Reserved
7
 
#    Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
8
 
#    Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
9
 
#    All Rights Reserved
10
 
#
11
 
#    This program is free software: you can redistribute it and/or modify
12
 
#    it under the terms of the GNU Affero General Public License as published by
13
 
#    the Free Software Foundation, either version 3 of the License, or
14
 
#    (at your option) any later version.
15
 
#
16
 
#    This program is distributed in the hope that it will be useful,
17
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 
#    GNU Affero General Public License for more details.
20
 
#
21
 
#    You should have received a copy of the GNU Affero General Public License
22
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 
#
24
 
##############################################################################
25
 
 
26
 
from osv import fields, osv
27
 
from tools.translate import _
28
 
 
29
 
class account_tax(osv.osv):
30
 
    _inherit = 'account.tax'
31
 
    _columns = {
32
 
        'withholding_tax': fields.boolean('Withholding Tax'),
33
 
        'withholding_payment_term_id': fields.many2one('account.payment.term', 'Withholding Payment Term'),
34
 
        }
35
 
account_tax()
36
 
 
37
 
class account_invoice(osv.osv):
38
 
    _inherit = "account.invoice"
39
 
    
40
 
    def action_move_create(self, cr, uid, ids, context=None):
41
 
        res = super(account_invoice, self).action_move_create(cr, uid, ids, context=context)
42
 
        tax_pool = self.pool.get('account.tax')
43
 
        term_pool = self.pool.get('account.payment.term')
44
 
        for inv in self.browse(cr, uid, ids, context=context):
45
 
            for move_line in inv.move_id.line_id:
46
 
                if move_line.tax_code_id:
47
 
                    tax_ids = tax_pool.search(cr, uid, [('tax_code_id', '=', move_line.tax_code_id.id)])
48
 
                    is_withholding = False
49
 
                    for tax in tax_pool.browse(cr, uid, tax_ids):
50
 
                        if tax.withholding_tax:
51
 
                            is_withholding = True
52
 
                    if is_withholding:
53
 
                        if len(tax_ids) > 1:
54
 
                            raise osv.except_osv(_('Error'),
55
 
                                _('Too many taxes associated to tax.code %s') % move_line.tax_code_id.name)
56
 
                        if not tax_ids:
57
 
                            raise osv.except_osv(_('Error'),
58
 
                                _('No taxes associated to tax.code %s') % move_line.tax_code_id.name)
59
 
                        tax = tax_pool.browse(cr, uid, tax_ids[0])
60
 
                        if tax.withholding_tax and tax.withholding_payment_term_id:
61
 
                            due_list = term_pool.compute(
62
 
                                cr, uid, tax.withholding_payment_term_id.id, move_line.tax_amount,
63
 
                                date_ref=inv.date_invoice, context=context)
64
 
                            if len(due_list) > 1:
65
 
                                raise osv.except_osv(_('Error'),
66
 
                                    _('The payment term %s has too many due dates')
67
 
                                    % tax.withholding_payment_term_id.name)
68
 
                            if len(due_list) == 0:
69
 
                                raise osv.except_osv(_('Error'),
70
 
                                    _('The payment term %s does not have due dates')
71
 
                                    % tax.withholding_payment_term_id.name)
72
 
                            move_line.write({'date_maturity': due_list[0][0]})
73
 
        return res
74
 
 
75
 
account_invoice()