Merge lp:~elbati/openobject-italia/ref_l10n_it_withholding_tax into lp:~openobject-italia-core-devs/openobject-italia/italian-addons-6.1

Proposed by Lorenzo Battistini
Status: Merged
Merged at revision: 201
Proposed branch: lp:~elbati/openobject-italia/ref_l10n_it_withholding_tax
Merge into: lp:~openobject-italia-core-devs/openobject-italia/italian-addons-6.1
Diff against target: 276 lines (+174/-57)
3 files modified
l10n_it_withholding_tax/__openerp__.py (+19/-7)
l10n_it_withholding_tax/account.py (+104/-38)
l10n_it_withholding_tax/account_view.xml (+51/-12)
To merge this branch: bzr merge lp:~elbati/openobject-italia/ref_l10n_it_withholding_tax
Reviewer Review Type Date Requested Status
OpenERP Italia core devs Pending
Review via email: mp+116825@code.launchpad.net
To post a comment you must log in.
191. By Lorenzo Battistini

[FIX] l10n_it_withholding_tax
comment

192. By Lorenzo Battistini

[add] 'net pay' to invoice

193. By Lorenzo Battistini

[ref] entire workflow

194. By Lorenzo Battistini

[imp] description

195. By Lorenzo Battistini

[FIX] dont reconciled what reconciled yet

196. By Lorenzo Battistini

[fix] descr

197. By Lorenzo Battistini

[FIX] version

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'l10n_it_withholding_tax/__openerp__.py'
--- l10n_it_withholding_tax/__openerp__.py 2012-07-03 06:22:49 +0000
+++ l10n_it_withholding_tax/__openerp__.py 2012-08-09 13:32:07 +0000
@@ -23,20 +23,32 @@
23#23#
24##############################################################################24##############################################################################
25{25{
26 'name': "Italian Localisation - Ritenute d'acconto",26 'name': "Italian Localisation - Withholding tax",
27 'version': '0.1',27 'version': '0.2',
28 'category': 'Localisation/Italy',28 'category': 'Localisation/Italy',
29 'description': """29 'description': """
30 Modulo per le ritenute d'acconto sulle fatture fornitore30Ritenute d'acconto sulle fatture fornitore
31 31==========================================
32
33Per utilizzare il modulo bisogna configurare i campi associati alla company:
34 - Termine di pagamento della ritenuta
35 - Conto di debito per le ritenute da versare
36 - Sezionale che conterrà le registrazioni legate alla ritenuta
37
38Durante la compilazione di una fattura fornitore con ritenuta d'acconto, l'utente dovrà specificare l'importo della ritenuta.
39
40Requisiti
41---------
42http://wiki.openerp-italia.org/doku.php/area_utente/requisiti/ritenuta_d_acconto
43
44Howto
45-----
32http://planet.domsense.com/2012/06/come-registrare-in-openerp-le-fatture-fornitore-con-ritenuta-dacconto/46http://planet.domsense.com/2012/06/come-registrare-in-openerp-le-fatture-fornitore-con-ritenuta-dacconto/
33
34 http://wiki.openerp-italia.org/doku.php/area_utente/requisiti/ritenuta_d_acconto
35""",47""",
36 'author': 'OpenERP Italian Community',48 'author': 'OpenERP Italian Community',
37 'website': 'http://www.openerp-italia.org',49 'website': 'http://www.openerp-italia.org',
38 'license': 'AGPL-3',50 'license': 'AGPL-3',
39 "depends" : ['account_invoice_template'],51 "depends" : ['account_invoice_template', 'account_voucher_cash_basis'],
40 "init_xml" : [52 "init_xml" : [
41 'account_view.xml',53 'account_view.xml',
42 ],54 ],
4355
=== modified file 'l10n_it_withholding_tax/account.py'
--- l10n_it_withholding_tax/account.py 2012-06-12 15:40:54 +0000
+++ l10n_it_withholding_tax/account.py 2012-08-09 13:32:07 +0000
@@ -25,51 +25,117 @@
2525
26from osv import fields, osv26from osv import fields, osv
27from tools.translate import _27from tools.translate import _
28import decimal_precision as dp
2829
29class account_tax(osv.osv):30class res_company(osv.osv):
30 _inherit = 'account.tax'31 _inherit = 'res.company'
31 _columns = {32 _columns = {
32 'withholding_tax': fields.boolean('Withholding Tax'),33 'withholding_payment_term_id': fields.many2one('account.payment.term', 'Withholding tax Payment Term'),
33 'withholding_payment_term_id': fields.many2one('account.payment.term', 'Withholding Payment Term'),34 'withholding_account_id': fields.many2one('account.account','Withholding account', help='Payable account used for amount due to tax authority', domain=[('type', '=', 'payable')]),
35 'withholding_journal_id': fields.many2one('account.journal','Withholding journal', help="Journal used for registration of witholding amounts to be paid"),
34 }36 }
35account_tax()
3637
37class account_invoice(osv.osv):38class account_invoice(osv.osv):
39
40 def _net_pay(self, cr, uid, ids, field_name, arg, context=None):
41 res = {}
42 for invoice in self.browse(cr, uid, ids, context):
43 res[invoice.id] = invoice.amount_total - invoice.withholding_amount
44 return res
45
38 _inherit = "account.invoice"46 _inherit = "account.invoice"
39 47
40 def action_move_create(self, cr, uid, ids, context=None):48 _columns = {
41 res = super(account_invoice, self).action_move_create(cr, uid, ids, context=context)49 'withholding_amount': fields.float('Withholding amount', digits_compute=dp.get_precision('Account'), readonly=True, states={'draft':[('readonly',False)]}),
50 'has_withholding': fields.boolean('With withholding tax', readonly=True, states={'draft':[('readonly',False)]}),
51 'net_pay': fields.function(_net_pay, string="Net Pay"),
52 }
53
54class account_voucher(osv.osv):
55 _inherit = "account.voucher"
56
57 _columns = {
58 'withholding_move_ids': fields.many2many('account.move', 'voucher_withholding_move_rel', 'voucher_id', 'move_id', 'Withholding Tax Entries', readonly=True),
59 }
60
61 def reconcile_withholding_move(self, cr, uid, invoice, wh_move, context=None):
62 line_pool=self.pool.get('account.move.line')
63 rec_ids = []
64 for inv_move_line in invoice.move_id.line_id:
65 if inv_move_line.account_id.type == 'payable' and not inv_move_line.reconcile_id:
66 rec_ids.append(inv_move_line.id)
67 for wh_line in wh_move.line_id:
68 if wh_line.account_id.type == 'payable' and invoice.company_id.withholding_account_id and invoice.company_id.withholding_account_id.id != wh_line.account_id.id and not wh_line.reconcile_id:
69 rec_ids.append(wh_line.id)
70 return line_pool.reconcile_partial(cr, uid, rec_ids, type='auto', context=context)
71
72 def action_move_line_create(self, cr, uid, ids, context=None):
73 res = super(account_voucher,self).action_move_line_create(cr, uid, ids, context)
74 inv_pool = self.pool.get('account.invoice')
75 move_pool = self.pool.get('account.move')
42 tax_pool = self.pool.get('account.tax')76 tax_pool = self.pool.get('account.tax')
77 curr_pool = self.pool.get('res.currency')
43 term_pool = self.pool.get('account.payment.term')78 term_pool = self.pool.get('account.payment.term')
44 for inv in self.browse(cr, uid, ids, context=context):79 for voucher in self.browse(cr, uid, ids, context):
45 for move_line in inv.move_id.line_id:80 amounts_by_invoice = super(account_voucher,self).allocated_amounts_grouped_by_invoice(cr, uid,voucher, context)
46 if move_line.tax_code_id:81 for inv_id in amounts_by_invoice:
47 tax_ids = tax_pool.search(cr, uid, [('tax_code_id', '=', move_line.tax_code_id.id)])82 invoice = inv_pool.browse(cr, uid, inv_id, context)
48 is_withholding = False83 if invoice.withholding_amount:
49 for tax in tax_pool.browse(cr, uid, tax_ids):84 # only for supplier payments
50 if tax.withholding_tax:85 if voucher.type != 'payment':
51 is_withholding = True86 raise osv.except_osv(_('Error'), _('Can\'t handle withholding tax with voucher of type other than payment'))
52 if is_withholding:87 if not invoice.company_id.withholding_account_id:
53 if len(tax_ids) > 1:88 raise osv.except_osv(_('Error'), _('The company does not have an associated Withholding account') )
54 raise osv.except_osv(_('Error'),89 if not invoice.company_id.withholding_payment_term_id:
55 _('Too many taxes associated to tax.code %s') % move_line.tax_code_id.name)90 raise osv.except_osv(_('Error'), _('The company does not have an associated Withholding Payment Term') )
56 if not tax_ids:91 if not invoice.company_id.withholding_journal_id:
57 raise osv.except_osv(_('Error'),92 raise osv.except_osv(_('Error'), _('The company does not have an associated Withholding journal') )
58 _('No taxes associated to tax.code %s') % move_line.tax_code_id.name)93 # compute the new amount proportionally to paid amount
59 tax = tax_pool.browse(cr, uid, tax_ids[0])94 new_line_amount = curr_pool.round(cr, uid, voucher.company_id.currency_id, ((amounts_by_invoice[invoice.id]['allocated'] + amounts_by_invoice[invoice.id]['write-off']) / invoice.net_pay) * invoice.withholding_amount)
60 if tax.withholding_tax and tax.withholding_payment_term_id:95
61 due_list = term_pool.compute(96 # compute the due date
62 cr, uid, tax.withholding_payment_term_id.id, move_line.tax_amount,97 due_list = term_pool.compute(
63 date_ref=inv.date_invoice, context=context)98 cr, uid, invoice.company_id.withholding_payment_term_id.id, new_line_amount,
64 if len(due_list) > 1:99 date_ref=invoice.date_invoice, context=context)
65 raise osv.except_osv(_('Error'),100 if len(due_list) > 1:
66 _('The payment term %s has too many due dates')101 raise osv.except_osv(_('Error'),
67 % tax.withholding_payment_term_id.name)102 _('The payment term %s has too many due dates')
68 if len(due_list) == 0:103 % invoice.company_id.withholding_payment_term_id.name)
69 raise osv.except_osv(_('Error'),104 if len(due_list) == 0:
70 _('The payment term %s does not have due dates')105 raise osv.except_osv(_('Error'),
71 % tax.withholding_payment_term_id.name)106 _('The payment term %s does not have due dates')
72 move_line.write({'date_maturity': due_list[0][0]})107 % invoice.company_id.withholding_payment_term_id.name)
108
109 new_move = {
110 'journal_id': invoice.company_id.withholding_journal_id.id,
111 'line_id': [
112 (0,0,{
113 'name': invoice.number,
114 'account_id': invoice.account_id.id,
115 'debit': new_line_amount,
116 'credit': 0.0,
117 }),
118 (0,0,{
119 'name': _('Payable withholding - ') + invoice.number,
120 'account_id': invoice.company_id.withholding_account_id.id,
121 'debit': 0.0,
122 'credit': new_line_amount,
123 'date_maturity': due_list[0][0],
124 }),
125 ]
126 }
127 move_id = self.pool.get('account.move').create(cr, uid, new_move, context=context)
128 self.reconcile_withholding_move(cr, uid, invoice, move_pool.browse(cr, uid, move_id, context), context)
129 voucher.write({'withholding_move_ids': [(4, move_id)]})
73 return res130 return res
74131
75account_invoice()132 def cancel_voucher(self, cr, uid, ids, context=None):
133 res = super(account_voucher,self).cancel_voucher(cr, uid, ids, context)
134 reconcile_pool = self.pool.get('account.move.reconcile')
135 move_pool = self.pool.get('account.move')
136 for voucher in self.browse(cr, uid, ids, context=context):
137 recs = []
138 for move in voucher.withholding_move_ids:
139 move_pool.button_cancel(cr, uid, [move.id])
140 move_pool.unlink(cr, uid, [move.id])
141 return res
76142
=== modified file 'l10n_it_withholding_tax/account_view.xml'
--- l10n_it_withholding_tax/account_view.xml 2012-02-17 14:03:46 +0000
+++ l10n_it_withholding_tax/account_view.xml 2012-08-09 13:32:07 +0000
@@ -2,17 +2,56 @@
2<openerp>2<openerp>
3 <data>3 <data>
44
5 <record id="view_tax_form" model="ir.ui.view">5<!-- company -->
6 <field name="name">account.tax.form</field>6
7 <field name="model">account.tax</field>7 <record model="ir.ui.view" id="view_company_inherit_form">
8 <field name="type">form</field>8 <field name="name">res.company.form.inherit</field>
9 <field name="inherit_id" ref="account.view_tax_form"></field>9 <field name="inherit_id" ref="account.view_company_inherit_form"/>
10 <field name="arch" type="xml">10 <field name="model">res.company</field>
11 <field name="active" position="after">11 <field name="type">form</field>
12 <field name="withholding_tax"/>12 <field name="arch" type="xml">
13 <field name="withholding_payment_term_id" attrs="{'readonly':[('withholding_tax','=',False)]}"/>13 <field name="paypal_account" position="after">
14 </field>14 <separator colspan="4"></separator>
15 </field>15 <field name="withholding_payment_term_id"/>
16 </record>16 <field name="withholding_account_id"/>
17 <field name="withholding_journal_id" />
18 <separator colspan="4"></separator>
19 </field>
20 </field>
21 </record>
22
23 <!-- invoice -->
24
25 <record id="invoice_supplier_form" model="ir.ui.view">
26 <field name="name">account.invoice.supplier.form</field>
27 <field name="model">account.invoice</field>
28 <field name="type">form</field>
29 <field name="inherit_id" ref="account.invoice_supplier_form"/>
30 <field name="arch" type="xml">
31 <field name="date_due" position="after">
32 <field name="has_withholding"/>
33 </field>
34 <field name="amount_total" position="after">
35 <field name="withholding_amount" attrs="{'invisible': [('has_withholding', '=', False)]}"/>
36 <field name="net_pay" attrs="{'invisible': [('has_withholding', '=', False)]}"/>
37 </field>
38 </field>
39 </record>
40
41 <!-- voucher -->
42
43 <record id="view_vendor_payment_form_wh_move" model="ir.ui.view">
44 <field name="name">account.voucher.payment.form.wh.move</field>
45 <field name="model">account.voucher</field>
46 <field name="type">form</field>
47 <field name="inherit_id" ref="account_voucher.view_vendor_payment_form"/>
48 <field name="arch" type="xml">
49 <field name="move_ids" position="after">
50 <separator string="Withholding tax entries" colspan="4"></separator>
51 <field name="withholding_move_ids" colspan="4" nolabel="1"/>
52 </field>
53 </field>
54 </record>
55
17 </data>56 </data>
18</openerp>57</openerp>

Subscribers

People subscribed via source and target branches