Merge lp:~elbati/openobject-italia/ref_l10n_it_withholding_tax into lp:~openobject-italia-core-devs/openobject-italia/italian-addons-6.1
- ref_l10n_it_withholding_tax
- Merge into 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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
OpenERP Italia core devs | Pending | ||
Review via email: mp+116825@code.launchpad.net |
Commit message
Description of the change
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
1 | === modified file 'l10n_it_withholding_tax/__openerp__.py' | |||
2 | --- l10n_it_withholding_tax/__openerp__.py 2012-07-03 06:22:49 +0000 | |||
3 | +++ l10n_it_withholding_tax/__openerp__.py 2012-08-09 13:32:07 +0000 | |||
4 | @@ -23,20 +23,32 @@ | |||
5 | 23 | # | 23 | # |
6 | 24 | ############################################################################## | 24 | ############################################################################## |
7 | 25 | { | 25 | { |
10 | 26 | 'name': "Italian Localisation - Ritenute d'acconto", | 26 | 'name': "Italian Localisation - Withholding tax", |
11 | 27 | 'version': '0.1', | 27 | 'version': '0.2', |
12 | 28 | 'category': 'Localisation/Italy', | 28 | 'category': 'Localisation/Italy', |
13 | 29 | 'description': """ | 29 | 'description': """ |
16 | 30 | Modulo per le ritenute d'acconto sulle fatture fornitore | 30 | Ritenute d'acconto sulle fatture fornitore |
17 | 31 | 31 | ========================================== | |
18 | 32 | |||
19 | 33 | Per utilizzare il modulo bisogna configurare i campi associati alla company: | ||
20 | 34 | - Termine di pagamento della ritenuta | ||
21 | 35 | - Conto di debito per le ritenute da versare | ||
22 | 36 | - Sezionale che conterrà le registrazioni legate alla ritenuta | ||
23 | 37 | |||
24 | 38 | Durante la compilazione di una fattura fornitore con ritenuta d'acconto, l'utente dovrà specificare l'importo della ritenuta. | ||
25 | 39 | |||
26 | 40 | Requisiti | ||
27 | 41 | --------- | ||
28 | 42 | http://wiki.openerp-italia.org/doku.php/area_utente/requisiti/ritenuta_d_acconto | ||
29 | 43 | |||
30 | 44 | Howto | ||
31 | 45 | ----- | ||
32 | 32 | http://planet.domsense.com/2012/06/come-registrare-in-openerp-le-fatture-fornitore-con-ritenuta-dacconto/ | 46 | http://planet.domsense.com/2012/06/come-registrare-in-openerp-le-fatture-fornitore-con-ritenuta-dacconto/ |
33 | 33 | |||
34 | 34 | http://wiki.openerp-italia.org/doku.php/area_utente/requisiti/ritenuta_d_acconto | ||
35 | 35 | """, | 47 | """, |
36 | 36 | 'author': 'OpenERP Italian Community', | 48 | 'author': 'OpenERP Italian Community', |
37 | 37 | 'website': 'http://www.openerp-italia.org', | 49 | 'website': 'http://www.openerp-italia.org', |
38 | 38 | 'license': 'AGPL-3', | 50 | 'license': 'AGPL-3', |
40 | 39 | "depends" : ['account_invoice_template'], | 51 | "depends" : ['account_invoice_template', 'account_voucher_cash_basis'], |
41 | 40 | "init_xml" : [ | 52 | "init_xml" : [ |
42 | 41 | 'account_view.xml', | 53 | 'account_view.xml', |
43 | 42 | ], | 54 | ], |
44 | 43 | 55 | ||
45 | === modified file 'l10n_it_withholding_tax/account.py' | |||
46 | --- l10n_it_withholding_tax/account.py 2012-06-12 15:40:54 +0000 | |||
47 | +++ l10n_it_withholding_tax/account.py 2012-08-09 13:32:07 +0000 | |||
48 | @@ -25,51 +25,117 @@ | |||
49 | 25 | 25 | ||
50 | 26 | from osv import fields, osv | 26 | from osv import fields, osv |
51 | 27 | from tools.translate import _ | 27 | from tools.translate import _ |
52 | 28 | import decimal_precision as dp | ||
53 | 28 | 29 | ||
56 | 29 | class account_tax(osv.osv): | 30 | class res_company(osv.osv): |
57 | 30 | _inherit = 'account.tax' | 31 | _inherit = 'res.company' |
58 | 31 | _columns = { | 32 | _columns = { |
61 | 32 | 'withholding_tax': fields.boolean('Withholding Tax'), | 33 | 'withholding_payment_term_id': fields.many2one('account.payment.term', 'Withholding tax Payment Term'), |
62 | 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')]), |
63 | 35 | 'withholding_journal_id': fields.many2one('account.journal','Withholding journal', help="Journal used for registration of witholding amounts to be paid"), | ||
64 | 34 | } | 36 | } |
65 | 35 | account_tax() | ||
66 | 36 | 37 | ||
67 | 37 | class account_invoice(osv.osv): | 38 | class account_invoice(osv.osv): |
68 | 39 | |||
69 | 40 | def _net_pay(self, cr, uid, ids, field_name, arg, context=None): | ||
70 | 41 | res = {} | ||
71 | 42 | for invoice in self.browse(cr, uid, ids, context): | ||
72 | 43 | res[invoice.id] = invoice.amount_total - invoice.withholding_amount | ||
73 | 44 | return res | ||
74 | 45 | |||
75 | 38 | _inherit = "account.invoice" | 46 | _inherit = "account.invoice" |
79 | 39 | 47 | ||
80 | 40 | def action_move_create(self, cr, uid, ids, context=None): | 48 | _columns = { |
81 | 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)]}), |
82 | 50 | 'has_withholding': fields.boolean('With withholding tax', readonly=True, states={'draft':[('readonly',False)]}), | ||
83 | 51 | 'net_pay': fields.function(_net_pay, string="Net Pay"), | ||
84 | 52 | } | ||
85 | 53 | |||
86 | 54 | class account_voucher(osv.osv): | ||
87 | 55 | _inherit = "account.voucher" | ||
88 | 56 | |||
89 | 57 | _columns = { | ||
90 | 58 | 'withholding_move_ids': fields.many2many('account.move', 'voucher_withholding_move_rel', 'voucher_id', 'move_id', 'Withholding Tax Entries', readonly=True), | ||
91 | 59 | } | ||
92 | 60 | |||
93 | 61 | def reconcile_withholding_move(self, cr, uid, invoice, wh_move, context=None): | ||
94 | 62 | line_pool=self.pool.get('account.move.line') | ||
95 | 63 | rec_ids = [] | ||
96 | 64 | for inv_move_line in invoice.move_id.line_id: | ||
97 | 65 | if inv_move_line.account_id.type == 'payable' and not inv_move_line.reconcile_id: | ||
98 | 66 | rec_ids.append(inv_move_line.id) | ||
99 | 67 | for wh_line in wh_move.line_id: | ||
100 | 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: | ||
101 | 69 | rec_ids.append(wh_line.id) | ||
102 | 70 | return line_pool.reconcile_partial(cr, uid, rec_ids, type='auto', context=context) | ||
103 | 71 | |||
104 | 72 | def action_move_line_create(self, cr, uid, ids, context=None): | ||
105 | 73 | res = super(account_voucher,self).action_move_line_create(cr, uid, ids, context) | ||
106 | 74 | inv_pool = self.pool.get('account.invoice') | ||
107 | 75 | move_pool = self.pool.get('account.move') | ||
108 | 42 | tax_pool = self.pool.get('account.tax') | 76 | tax_pool = self.pool.get('account.tax') |
109 | 77 | curr_pool = self.pool.get('res.currency') | ||
110 | 43 | term_pool = self.pool.get('account.payment.term') | 78 | term_pool = self.pool.get('account.payment.term') |
140 | 44 | for inv in self.browse(cr, uid, ids, context=context): | 79 | for voucher in self.browse(cr, uid, ids, context): |
141 | 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) |
142 | 46 | if move_line.tax_code_id: | 81 | for inv_id in amounts_by_invoice: |
143 | 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) |
144 | 48 | is_withholding = False | 83 | if invoice.withholding_amount: |
145 | 49 | for tax in tax_pool.browse(cr, uid, tax_ids): | 84 | # only for supplier payments |
146 | 50 | if tax.withholding_tax: | 85 | if voucher.type != 'payment': |
147 | 51 | is_withholding = True | 86 | raise osv.except_osv(_('Error'), _('Can\'t handle withholding tax with voucher of type other than payment')) |
148 | 52 | if is_withholding: | 87 | if not invoice.company_id.withholding_account_id: |
149 | 53 | if len(tax_ids) > 1: | 88 | raise osv.except_osv(_('Error'), _('The company does not have an associated Withholding account') ) |
150 | 54 | raise osv.except_osv(_('Error'), | 89 | if not invoice.company_id.withholding_payment_term_id: |
151 | 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') ) |
152 | 56 | if not tax_ids: | 91 | if not invoice.company_id.withholding_journal_id: |
153 | 57 | raise osv.except_osv(_('Error'), | 92 | raise osv.except_osv(_('Error'), _('The company does not have an associated Withholding journal') ) |
154 | 58 | _('No taxes associated to tax.code %s') % move_line.tax_code_id.name) | 93 | # compute the new amount proportionally to paid amount |
155 | 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) |
156 | 60 | if tax.withholding_tax and tax.withholding_payment_term_id: | 95 | |
157 | 61 | due_list = term_pool.compute( | 96 | # compute the due date |
158 | 62 | cr, uid, tax.withholding_payment_term_id.id, move_line.tax_amount, | 97 | due_list = term_pool.compute( |
159 | 63 | date_ref=inv.date_invoice, context=context) | 98 | cr, uid, invoice.company_id.withholding_payment_term_id.id, new_line_amount, |
160 | 64 | if len(due_list) > 1: | 99 | date_ref=invoice.date_invoice, context=context) |
161 | 65 | raise osv.except_osv(_('Error'), | 100 | if len(due_list) > 1: |
162 | 66 | _('The payment term %s has too many due dates') | 101 | raise osv.except_osv(_('Error'), |
163 | 67 | % tax.withholding_payment_term_id.name) | 102 | _('The payment term %s has too many due dates') |
164 | 68 | if len(due_list) == 0: | 103 | % invoice.company_id.withholding_payment_term_id.name) |
165 | 69 | raise osv.except_osv(_('Error'), | 104 | if len(due_list) == 0: |
166 | 70 | _('The payment term %s does not have due dates') | 105 | raise osv.except_osv(_('Error'), |
167 | 71 | % tax.withholding_payment_term_id.name) | 106 | _('The payment term %s does not have due dates') |
168 | 72 | move_line.write({'date_maturity': due_list[0][0]}) | 107 | % invoice.company_id.withholding_payment_term_id.name) |
169 | 108 | |||
170 | 109 | new_move = { | ||
171 | 110 | 'journal_id': invoice.company_id.withholding_journal_id.id, | ||
172 | 111 | 'line_id': [ | ||
173 | 112 | (0,0,{ | ||
174 | 113 | 'name': invoice.number, | ||
175 | 114 | 'account_id': invoice.account_id.id, | ||
176 | 115 | 'debit': new_line_amount, | ||
177 | 116 | 'credit': 0.0, | ||
178 | 117 | }), | ||
179 | 118 | (0,0,{ | ||
180 | 119 | 'name': _('Payable withholding - ') + invoice.number, | ||
181 | 120 | 'account_id': invoice.company_id.withholding_account_id.id, | ||
182 | 121 | 'debit': 0.0, | ||
183 | 122 | 'credit': new_line_amount, | ||
184 | 123 | 'date_maturity': due_list[0][0], | ||
185 | 124 | }), | ||
186 | 125 | ] | ||
187 | 126 | } | ||
188 | 127 | move_id = self.pool.get('account.move').create(cr, uid, new_move, context=context) | ||
189 | 128 | self.reconcile_withholding_move(cr, uid, invoice, move_pool.browse(cr, uid, move_id, context), context) | ||
190 | 129 | voucher.write({'withholding_move_ids': [(4, move_id)]}) | ||
191 | 73 | return res | 130 | return res |
192 | 74 | 131 | ||
194 | 75 | account_invoice() | 132 | def cancel_voucher(self, cr, uid, ids, context=None): |
195 | 133 | res = super(account_voucher,self).cancel_voucher(cr, uid, ids, context) | ||
196 | 134 | reconcile_pool = self.pool.get('account.move.reconcile') | ||
197 | 135 | move_pool = self.pool.get('account.move') | ||
198 | 136 | for voucher in self.browse(cr, uid, ids, context=context): | ||
199 | 137 | recs = [] | ||
200 | 138 | for move in voucher.withholding_move_ids: | ||
201 | 139 | move_pool.button_cancel(cr, uid, [move.id]) | ||
202 | 140 | move_pool.unlink(cr, uid, [move.id]) | ||
203 | 141 | return res | ||
204 | 76 | 142 | ||
205 | === modified file 'l10n_it_withholding_tax/account_view.xml' | |||
206 | --- l10n_it_withholding_tax/account_view.xml 2012-02-17 14:03:46 +0000 | |||
207 | +++ l10n_it_withholding_tax/account_view.xml 2012-08-09 13:32:07 +0000 | |||
208 | @@ -2,17 +2,56 @@ | |||
209 | 2 | <openerp> | 2 | <openerp> |
210 | 3 | <data> | 3 | <data> |
211 | 4 | 4 | ||
224 | 5 | <record id="view_tax_form" model="ir.ui.view"> | 5 | <!-- company --> |
225 | 6 | <field name="name">account.tax.form</field> | 6 | |
226 | 7 | <field name="model">account.tax</field> | 7 | <record model="ir.ui.view" id="view_company_inherit_form"> |
227 | 8 | <field name="type">form</field> | 8 | <field name="name">res.company.form.inherit</field> |
228 | 9 | <field name="inherit_id" ref="account.view_tax_form"></field> | 9 | <field name="inherit_id" ref="account.view_company_inherit_form"/> |
229 | 10 | <field name="arch" type="xml"> | 10 | <field name="model">res.company</field> |
230 | 11 | <field name="active" position="after"> | 11 | <field name="type">form</field> |
231 | 12 | <field name="withholding_tax"/> | 12 | <field name="arch" type="xml"> |
232 | 13 | <field name="withholding_payment_term_id" attrs="{'readonly':[('withholding_tax','=',False)]}"/> | 13 | <field name="paypal_account" position="after"> |
233 | 14 | </field> | 14 | <separator colspan="4"></separator> |
234 | 15 | </field> | 15 | <field name="withholding_payment_term_id"/> |
235 | 16 | </record> | 16 | <field name="withholding_account_id"/> |
236 | 17 | <field name="withholding_journal_id" /> | ||
237 | 18 | <separator colspan="4"></separator> | ||
238 | 19 | </field> | ||
239 | 20 | </field> | ||
240 | 21 | </record> | ||
241 | 22 | |||
242 | 23 | <!-- invoice --> | ||
243 | 24 | |||
244 | 25 | <record id="invoice_supplier_form" model="ir.ui.view"> | ||
245 | 26 | <field name="name">account.invoice.supplier.form</field> | ||
246 | 27 | <field name="model">account.invoice</field> | ||
247 | 28 | <field name="type">form</field> | ||
248 | 29 | <field name="inherit_id" ref="account.invoice_supplier_form"/> | ||
249 | 30 | <field name="arch" type="xml"> | ||
250 | 31 | <field name="date_due" position="after"> | ||
251 | 32 | <field name="has_withholding"/> | ||
252 | 33 | </field> | ||
253 | 34 | <field name="amount_total" position="after"> | ||
254 | 35 | <field name="withholding_amount" attrs="{'invisible': [('has_withholding', '=', False)]}"/> | ||
255 | 36 | <field name="net_pay" attrs="{'invisible': [('has_withholding', '=', False)]}"/> | ||
256 | 37 | </field> | ||
257 | 38 | </field> | ||
258 | 39 | </record> | ||
259 | 40 | |||
260 | 41 | <!-- voucher --> | ||
261 | 42 | |||
262 | 43 | <record id="view_vendor_payment_form_wh_move" model="ir.ui.view"> | ||
263 | 44 | <field name="name">account.voucher.payment.form.wh.move</field> | ||
264 | 45 | <field name="model">account.voucher</field> | ||
265 | 46 | <field name="type">form</field> | ||
266 | 47 | <field name="inherit_id" ref="account_voucher.view_vendor_payment_form"/> | ||
267 | 48 | <field name="arch" type="xml"> | ||
268 | 49 | <field name="move_ids" position="after"> | ||
269 | 50 | <separator string="Withholding tax entries" colspan="4"></separator> | ||
270 | 51 | <field name="withholding_move_ids" colspan="4" nolabel="1"/> | ||
271 | 52 | </field> | ||
272 | 53 | </field> | ||
273 | 54 | </record> | ||
274 | 55 | |||
275 | 17 | </data> | 56 | </data> |
276 | 18 | </openerp> | 57 | </openerp> |