Merge lp:~lambdasoftware/openerp-spain/6.1 into lp:~openerp-spain-team/openerp-spain/6.1

Proposed by lambdasoftware
Status: Rejected
Rejected by: Pedro Manuel Baeza
Proposed branch: lp:~lambdasoftware/openerp-spain/6.1
Merge into: lp:~openerp-spain-team/openerp-spain/6.1
Diff against target: 710 lines (+360/-113)
4 files modified
l10n_es_aeat_mod340/__openerp__.py (+1/-1)
l10n_es_aeat_mod340/mod340.py (+86/-64)
l10n_es_aeat_mod340/wizard/calculate_mod340_records.py (+185/-9)
l10n_es_aeat_mod340/wizard/export_mod340_to_boe.py (+88/-39)
To merge this branch: bzr merge lp:~lambdasoftware/openerp-spain/6.1
Reviewer Review Type Date Requested Status
Pedro Manuel Baeza Needs Resubmitting
Review via email: mp+224974@code.launchpad.net

Description of the change

Se han añadido los tipos de facturas intracomunitarios e inversión de sujeto pasivo.
Se modifica la funcionalidad del botón recalcular para que haga el recalculo solo sobre las facturas de las pestañas "Facturas emitidas" y "Facturas recibidas" pudiendolas añadir o eliminar manualmente.

¡¡¡revisadlo!!! Nuestro cliente aun no lo ha hecho y se ha hecho el mp por no duplicar trabajo con algún miembro de la comunidad

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

El proyecto está hospedado ahora en https://github.com/OCA/l10n-spain.

Mueve por favor tu propuesta allí. Esta guía puede ayudarte: https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub

Un saludo.

review: Needs Resubmitting

Unmerged revisions

398. By LambdaSoftware Development Team <email address hidden>

[ADD] Facturas intracomunitarias e inversion de sujeto pasivo

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'l10n_es_aeat_mod340/__openerp__.py' (properties changed: -x to +x)
2--- l10n_es_aeat_mod340/__openerp__.py 2014-02-13 11:45:56 +0000
3+++ l10n_es_aeat_mod340/__openerp__.py 2014-06-30 10:24:12 +0000
4@@ -41,11 +41,11 @@
5 Facturas rectificativas.
6 Facturas resumen de tiques.
7 Permite imprimir el libro de IVA, basado en la misma legislación.
8+Facturas intracomunitarias. Operaciones a las que hace referencia el artículo 66 del RIVA.
9
10 --- COSAS PENDIENTES (TODO LIST) ----------------------------------------------
11
12 Facturas bienes de inversión
13-Facturas intracomunitarias. Operaciones a las que hace referencia el artículo 66 del RIVA.
14 Asientos contables de resumen de tiques
15 Exportación de asientos resumen de facturas
16 ''',
17
18=== modified file 'l10n_es_aeat_mod340/mod340.py' (properties changed: -x to +x)
19--- l10n_es_aeat_mod340/mod340.py 2014-02-09 16:45:39 +0000
20+++ l10n_es_aeat_mod340/mod340.py 2014-06-30 10:24:12 +0000
21@@ -45,18 +45,21 @@
22 calculate_obj._wkf_calculate_records(cr, uid, ids, context)
23
24 return True
25-
26+
27+
28+ #LBD: FUNCION RECALCULAR TENIENDO EN CUENTA LAS FACTURAS INSERTADAS Y/O ELIMINADAS MANUALMENTE
29 def button_recalculate(self, cr, uid, ids, context=None):
30 if context is None:
31 context = {}
32
33- calculate_obj = self. pool.get('l10n.es.aeat.mod340.calculate_records')
34- calculate_obj._calculate_records(cr, uid, ids, context)
35+ calculate_obj = self.pool.get('l10n.es.aeat.mod340.calculate_records')
36+ calculate_obj._wkf_recalculate_records(cr, uid, ids, context)
37
38 return True
39
40+
41 def button_export(self, cr, uid, ids, context=None):
42-
43+
44 if context is None:
45 context = {}
46
47@@ -65,7 +68,7 @@
48 export_obj._export_boe_file(cr, uid, ids, report)
49
50 return True
51-
52+
53 def _name_get(self, cr, uid, ids, field_name, arg, context={}):
54 """
55 Returns the report name
56@@ -74,28 +77,28 @@
57 for report in self.browse(cr, uid, ids, context):
58 result[report.id] = report.number
59 return result
60-
61- def _get_number_records( self, cr, uid,ids, field_name, args,context ):
62-
63- result = {}
64+
65+ def _get_number_records(self, cr, uid, ids, field_name, args, context):
66+
67+ result = {}
68 for id in ids:
69 result[id] = {}.fromkeys(
70- ['number_records','total_taxable','total_sharetax','total'],
71- 0.0)
72-
73- for model in self.browse(cr, uid, ids,context):
74+ ['number_records', 'total_taxable', 'total_sharetax', 'total'],
75+ 0.0)
76+
77+ for model in self.browse(cr, uid, ids, context):
78
79 for issue in model.issued:
80- result[model.id]['number_records'] += len( issue.tax_line_ids )
81- result[model.id]['total_taxable'] +=issue.base_tax
82- result[model.id]['total_sharetax'] +=issue.amount_tax
83- result[model.id]['total'] +=issue.base_tax + issue.amount_tax
84+ result[model.id]['number_records'] += len(issue.tax_line_ids)
85+ result[model.id]['total_taxable'] += issue.base_tax
86+ result[model.id]['total_sharetax'] += issue.amount_tax
87+ result[model.id]['total'] += issue.base_tax + issue.amount_tax
88
89 for issue in model.received:
90- result[model.id]['number_records'] += len( issue.tax_line_ids )
91- result[model.id]['total_taxable'] +=issue.base_tax
92- result[model.id]['total_sharetax'] +=issue.amount_tax
93- result[model.id]['total'] +=issue.base_tax + issue.amount_tax
94+ result[model.id]['number_records'] += len(issue.tax_line_ids)
95+ result[model.id]['total_taxable'] += issue.base_tax
96+ result[model.id]['total_sharetax'] += issue.amount_tax
97+ result[model.id]['total'] += issue.base_tax + issue.amount_tax
98
99 return result
100
101@@ -103,54 +106,54 @@
102 _name = 'l10n.es.aeat.mod340'
103 _description = 'Model 340'
104 _columns = {
105- 'name': fields.function(_name_get, method=True, type="char",
106+ 'name': fields.function(_name_get, method=True, type="char",
107 size="64", string="Name"),
108 'contact_phone': fields.char("Phone", size=9),
109- 'phone_contact' : fields.char('Phone Contact',size=9),
110- 'name_contact' : fields.char('Name And Surname Contact',size=40),
111+ 'phone_contact': fields.char('Phone Contact', size=9),
112+ 'name_contact': fields.char('Name And Surname Contact', size=40),
113 'period_from': fields.many2one('account.period', 'Start period',
114 states={'done': [('readonly', True)]}),
115 'period_to': fields.many2one('account.period', 'End period',
116 states={'done': [('readonly', True)]}),
117- 'issued': fields.one2many('l10n.es.aeat.mod340.issued','mod340_id',
118+ 'issued': fields.one2many('l10n.es.aeat.mod340.issued', 'mod340_id',
119 'Invoices Issued',
120 states={'done': [('readonly', True)]}),
121 'received': fields.one2many('l10n.es.aeat.mod340.received',
122- 'mod340_id','Invoices Received',
123+ 'mod340_id', 'Invoices Received',
124 states={'done': [('readonly', True)]}),
125 'investment': fields.one2many('l10n.es.aeat.mod340.investment',
126- 'mod340_id','Property Investment'),
127+ 'mod340_id', 'Property Investment'),
128 'intracomunitarias': fields.one2many(
129- 'l10n.es.aeat.mod340.intracomunitarias',
130- 'mod340_id','Operations Intracomunitarias'),
131-
132+ 'l10n.es.aeat.mod340.intracomunitarias',
133+ 'mod340_id', 'Operations Intracomunitarias'),
134+
135 'ean13': fields.char('Electronic Code VAT reverse charge', size=16),
136
137- 'total_taxable': fields.function(_get_number_records, method=True,
138- type='float', string='Total Taxable', multi='recalc',
139- help="""The declaration will include partners with the total
140+ 'total_taxable': fields.function(_get_number_records, method=True,
141+ type='float', string='Total Taxable', multi='recalc',
142+ help="""The declaration will include partners with the total
143 of operations over this limit"""),
144 'total_sharetax': fields.function(_get_number_records, method=True,
145- type='float', string='Total Share Tax', multi='recalc',
146- help="""The declaration will include partners with the total
147+ type='float', string='Total Share Tax', multi='recalc',
148+ help="""The declaration will include partners with the total
149 of operations over this limit"""),
150 'number_records': fields.function(_get_number_records, method=True,
151- type='integer', string='Records', multi='recalc',
152- help="""The declaration will include partners with the total
153+ type='integer', string='Records', multi='recalc',
154+ help="""The declaration will include partners with the total
155 of operations over this limit"""),
156 'total': fields.function(_get_number_records, method=True,
157- type='float', string="Total", multi='recalc',
158- help="""The declaration will include partners with the total
159+ type='float', string="Total", multi='recalc',
160+ help="""The declaration will include partners with the total
161 of operations over this limit"""),
162 'calculation_date': fields.date('Calculation date', readonly=True),
163 }
164 _defaults = {
165- 'number' : lambda *a: '340',
166- }
167+ 'number': lambda *a: '340',
168+ }
169
170 def set_done(self, cr, uid, id, *args):
171- self.write(cr,uid,id,{'calculation_date': time.strftime('%Y-%m-%d'),
172- 'state': 'done',})
173+ self.write(cr, uid, id, {'calculation_date': time.strftime('%Y-%m-%d'),
174+ 'state': 'done', })
175 wf_service = netsvc.LocalService("workflow")
176 wf_service.trg_validate(uid, 'l10n.es.aeat.mod340', id, 'done', cr)
177 return True
178@@ -177,75 +180,94 @@
179 self.write(cr, uid, ids, {'state': 'canceled'})
180
181 return True
182-
183+
184+
185 l10n_es_aeat_mod340()
186
187+
188 class l10n_es_aeat_mod340_issued(osv.osv):
189 _name = 'l10n.es.aeat.mod340.issued'
190 _description = 'Invoices invoice'
191- _columns = {
192- 'mod340_id': fields.many2one('l10n.es.aeat.mod340','Model 340',
193- ondelete="cascade"),
194- 'partner_id':fields.many2one('res.partner','Partner',
195- ondelete="cascade"),
196- 'partner_vat':fields.char('Company CIF/NIF',size=12),
197+ _columns = {
198+ 'mod340_id': fields.many2one('l10n.es.aeat.mod340', 'Model 340',
199+ ondelete="cascade"),
200+ 'partner_id': fields.many2one('res.partner', 'Partner',
201+ ondelete="cascade"),
202+ 'partner_vat': fields.char('Company CIF/NIF', size=12),
203 'representative_vat': fields.char('L.R. VAT number', size=9,
204- help="Legal Representative VAT number"),
205+ help="Legal Representative VAT number"),
206 'partner_country_code': fields.char('Country Code', size=2),
207- 'invoice_id':fields.many2one('account.invoice','Invoice',
208- ondelete="cascade"),
209- 'base_tax':fields.float('Base tax bill',digits=(13,2)),
210- 'amount_tax':fields.float('Total tax',digits=(13,2)),
211- 'total':fields.float('Total',digits=(13,2)),
212+ 'invoice_id': fields.many2one('account.invoice', 'Invoice',
213+ ondelete="cascade"),
214+ 'base_tax': fields.float('Base tax bill', digits=(13, 2)),
215+ 'amount_tax': fields.float('Total tax', digits=(13, 2)),
216+ 'total': fields.float('Total', digits=(13, 2)),
217 'tax_line_ids': fields.one2many('l10n.es.aeat.mod340.tax_line_issued',
218 'invoice_record_id', 'Tax lines'),
219 'date_invoice': fields.date('Date Invoice', readonly=True),
220 }
221-
222+
223 _order = 'date_invoice asc, invoice_id asc'
224+
225+
226 l10n_es_aeat_mod340_issued()
227
228+
229 class l10n_es_aeat_mod340_received(osv.osv):
230 _name = 'l10n.es.aeat.mod340.received'
231 _description = 'Invoices Received'
232 _inherit = 'l10n.es.aeat.mod340.issued'
233 _columns = {
234- 'tax_line_ids':fields.one2many('l10n.es.aeat.mod340.tax_line_received',
235- 'invoice_record_id', 'Tax lines'),
236+ 'tax_line_ids': fields.one2many('l10n.es.aeat.mod340.tax_line_received',
237+ 'invoice_record_id', 'Tax lines'),
238 }
239+
240+
241 l10n_es_aeat_mod340_received()
242
243+
244 class l10n_es_aeat_mod340_investment(osv.osv):
245 _name = 'l10n.es.aeat.mod340.investment'
246 _description = 'Property Investment'
247 _inherit = 'l10n.es.aeat.mod340.issued'
248+
249+
250 l10n_es_aeat_mod340_investment()
251
252+
253 class l10n_es_aeat_mod340_intracomunitarias(osv.osv):
254 _name = 'l10n.es.aeat.mod340.intracomunitarias'
255 _description = 'Operations Intracomunitarias'
256 _inherit = 'l10n.es.aeat.mod340.issued'
257+
258+
259 l10n_es_aeat_mod340_intracomunitarias()
260
261+
262 class l10n_es_aeat_mod340_tax_line_issued(osv.osv):
263 _name = 'l10n.es.aeat.mod340.tax_line_issued'
264 _description = 'Mod340 vat lines issued'
265 _columns = {
266 'name': fields.char('Name', size=128, required=True, select=True),
267- 'tax_percentage': fields.float('Tax percentage',digits=(0,2)),
268- 'tax_amount': fields.float('Tax amount',digits=(13,2)),
269- 'base_amount': fields.float('Base tax bill',digits=(13,2)),
270+ 'tax_percentage': fields.float('Tax percentage', digits=(0, 2)),
271+ 'tax_amount': fields.float('Tax amount', digits=(13, 2)),
272+ 'base_amount': fields.float('Base tax bill', digits=(13, 2)),
273 'invoice_record_id': fields.many2one('l10n.es.aeat.mod340.issued',
274- 'Invoice issued', required=True, ondelete="cascade", select=1),
275+ 'Invoice issued', required=True, ondelete="cascade", select=1),
276 }
277+
278+
279 l10n_es_aeat_mod340_tax_line_issued()
280
281+
282 class l10n_es_aeat_mod340_tax_line_received(osv.osv):
283 _name = 'l10n.es.aeat.mod340.tax_line_received'
284 _description = 'Mod340 vat lines received'
285 _inherit = 'l10n.es.aeat.mod340.tax_line_issued'
286 _columns = {
287 'invoice_record_id': fields.many2one('l10n.es.aeat.mod340.received',
288- 'Invoice received', required=True, ondelete="cascade", select=1),
289+ 'Invoice received', required=True, ondelete="cascade", select=1),
290 }
291+
292+
293 l10n_es_aeat_mod340_tax_line_received()
294
295=== modified file 'l10n_es_aeat_mod340/wizard/calculate_mod340_records.py' (properties changed: -x to +x)
296--- l10n_es_aeat_mod340/wizard/calculate_mod340_records.py 2014-02-14 18:02:38 +0000
297+++ l10n_es_aeat_mod340/wizard/calculate_mod340_records.py 2014-06-30 10:24:12 +0000
298@@ -42,6 +42,15 @@
299 wf_service.trg_validate(uid, 'l10n.es.aeat.mod340', ids and ids[0],
300 'calculate', cr)
301
302+ def _wkf_recalculate_records(self, cr, uid, ids, context=None):
303+ if context is None:
304+ context = {}
305+
306+ self._recalculate_records(cr, uid, ids, context, recalculate=True)
307+ wf_service = netsvc.LocalService("workflow")
308+ wf_service.trg_validate(uid, 'l10n.es.aeat.mod340', ids and ids[0],
309+ 'calculate', cr)
310+
311
312
313 def _calculate_records(self, cr, uid, ids, context=None, recalculate=True):
314@@ -87,15 +96,14 @@
315
316
317 #Limpieza de las facturas calculadas anteriormente
318-
319 del_ids = invoices340.search(cr, uid, [
320- ('mod340_id', '=', mod340.id)])
321+ ('mod340_id', '=', mod340.id)])
322
323 if del_ids:
324 invoices340.unlink(cr, uid, del_ids, context=context)
325-
326+
327 del_ids = invoices340_rec.search(cr, uid, [
328- ('mod340_id', '=', mod340.id)])
329+ ('mod340_id', '=', mod340.id)])
330
331 if del_ids:
332 invoices340_rec.unlink(cr, uid, del_ids, context=context)
333@@ -104,7 +112,7 @@
334 ('state', 'in', ('open', 'paid'))]
335
336 invoice_obj=self.pool.get('account.invoice')
337- invoice_ids = invoice_obj.search(cr, uid,domain, context=context)
338+ invoice_ids = invoice_obj.search(cr,uid,domain,context=context)
339 for invoice in invoice_obj.browse(cr, uid, invoice_ids, context):
340 include = False
341 for tax_line in invoice.tax_line:
342@@ -155,12 +163,13 @@
343 if tax_line.base_code_id and tax_line.base:
344 if tax_line.base_code_id.mod340 == True:
345 tax_percentage = tax_line.amount/tax_line.base
346-
347+
348 values = {
349 'name': tax_line.name,
350 'tax_percentage': tax_percentage,
351- 'tax_amount': tax_line.tax_amount,
352- 'base_amount': tax_line.base_amount,
353+ 'tax_amount': tax_line.amount,#tax_line.tax_amount,
354+ 'base_amount': tax_line.base, #tax_line.base_amount,
355+ 'base_amount': tax_line.base, #tax_line.base_amount,
356 'invoice_record_id': invoice_created,
357 }
358 if invoice.type=="out_invoice" or invoice.type=="out_refund":
359@@ -169,7 +178,7 @@
360 if invoice.type=="in_invoice" or invoice.type=="in_refund":
361 received_obj=self.pool.get('l10n.es.aeat.mod340.tax_line_received')
362 received_obj.create(cr, uid, values)
363- tot_tax_invoice += tax_line.tax_amount
364+ tot_tax_invoice += tax_line.amount #tax_line.tax_amount
365 tot_rec += 1
366 check_tax += tax_line.tax_amount
367 if tax_percentage >= 0:
368@@ -211,6 +220,173 @@
369
370 return True
371
372+ #LBD: INSERTO FUNCION PARA RECALCULAR TENIENDO EN CUENTA LAS FACTURAS INSERTADAS Y/O ELIMINADAS MANUALMENTE
373+ def _recalculate_records(self, cr, uid, ids, context=None, recalculate=True):
374+ if context is None:
375+ context = {}
376+
377+ try:
378+ report_obj = self.pool.get('l10n.es.aeat.mod340')
379+ mod340 = report_obj.browse(cr, uid, ids)[0]
380+
381+ invoices340 = self.pool.get('l10n.es.aeat.mod340.issued')
382+ invoices340_rec = self.pool.get('l10n.es.aeat.mod340.received')
383+ period_obj = self.pool.get('account.period')
384+
385+ mod340.write({
386+ 'state' : 'calculated',
387+ 'calculation_date' : time.strftime('%Y-%m-%d %H:%M:%S')
388+ })
389+
390+ if not mod340.company_id.partner_id.vat:
391+ raise osv.except_osv(mod340.company_id.partner_id.name,
392+ _('This company dont have NIF'))
393+
394+ wf_service = netsvc.LocalService("workflow")
395+ wf_service.trg_validate(uid, 'l10n.es.aeat.mod347.report',
396+ ids and ids[0], 'calculate', cr)
397+
398+ code = '340'+mod340.fiscalyear_id.code+''
399+ code += mod340.period_to.date_stop[5:7]+'0001'
400+
401+ account_period_ids = period_obj.build_ctx_periods(cr, uid,
402+ mod340.period_from.id, mod340.period_to.id)
403+
404+ if len(account_period_ids) == 0:
405+ raise osv.except_osv(_('Error'),
406+ _("The periods selected don't belong to the fiscal year %s")
407+ % (mod340.fiscalyear_id.name))
408+
409+ tot_base = 0
410+ tot_amount = 0
411+ tot_tot = 0
412+ tot_rec = 0
413+
414+
415+ #Limpieza de las facturas calculadas anteriormente
416+
417+ invoices_ids = invoices340.search(cr, uid, [
418+ ('mod340_id', '=', mod340.id)])
419+
420+ #if del_ids:
421+ # invoices340.unlink(cr, uid, del_ids, context=context)
422+
423+ invoices_rec_ids = invoices340_rec.search(cr, uid, [
424+ ('mod340_id', '=', mod340.id)])
425+
426+ #if del_ids:
427+ # invoices340_rec.unlink(cr, uid, del_ids, context=context)
428+
429+ #domain = [('period_id', 'in',account_period_ids),
430+ # ('state', 'in', ('open', 'paid'))]
431+
432+ invoice_obj=self.pool.get('account.invoice')
433+ #invoice_ids = invoice_obj.search(cr, uid,domain, context=context)
434+
435+ for invoice in invoice_obj.browse(cr, uid, invoices_ids, context):
436+ include = False
437+ for tax_line in invoice.tax_line:
438+ if tax_line.base_code_id and tax_line.base:
439+ if tax_line.base_code_id.mod340 == True:
440+ include = True
441+ if include == True:
442+ if invoice.partner_id.vat_type == 1:
443+ if not invoice.partner_id.vat:
444+ raise osv.except_osv(
445+ _('La siguiente empresa no tiene asignado nif:'),
446+ invoice.partner_id.name)
447+
448+ nif = invoice.partner_id.vat and re.match(r"([A-Z]{0,2})(.*)",
449+ invoice.partner_id.vat).groups()[1]
450+ country_code = invoice.address_invoice_id.country_id.code
451+
452+ values = {
453+ 'mod340_id': mod340.id,
454+ 'partner_id':invoice.partner_id.id,
455+ 'partner_vat':nif,
456+ 'representative_vat': '',
457+ 'partner_country_code' : country_code,
458+ 'invoice_id':invoice.id,
459+ 'base_tax':invoice.amount_untaxed,
460+ 'amount_tax':invoice.amount_tax,
461+ 'total':invoice.amount_total,
462+ 'date_invoice':invoice.date_invoice,
463+ }
464+ if invoice.type in ( 'out_refund','in_refund'):
465+ values['base_tax'] *=-1
466+ values['amount_tax'] *=-1
467+ values['total'] *=-1
468+
469+
470+ if invoice.type=="out_invoice" or invoice.type=="out_refund":
471+ invoice_created = invoices340.create(cr,uid,values)
472+
473+ if invoice.type=="in_invoice" or invoice.type=="in_refund":
474+ invoice_created = invoices340_rec.create(cr,uid,values)
475+
476+ tot_tax_invoice = 0
477+ check_tax=0
478+ check_base=0
479+
480+ # Add the invoices detail to the partner record
481+ for tax_line in invoice.tax_line:
482+ if tax_line.base_code_id and tax_line.base:
483+ if tax_line.base_code_id.mod340 == True:
484+ tax_percentage = tax_line.amount/tax_line.base
485+
486+ values = {
487+ 'name': tax_line.name,
488+ 'tax_percentage': tax_percentage,
489+ 'tax_amount': tax_line.amount,#tax_line.tax_amount,
490+ 'base_amount': tax_line.base, #tax_line.base_amount,
491+ 'invoice_record_id': invoice_created,
492+ }
493+ if invoice.type=="out_invoice" or invoice.type=="out_refund":
494+ issued_obj = self.pool.get('l10n.es.aeat.mod340.tax_line_issued')
495+ issued_obj.create(cr, uid, values)
496+ if invoice.type=="in_invoice" or invoice.type=="in_refund":
497+ received_obj=self.pool.get('l10n.es.aeat.mod340.tax_line_received')
498+ received_obj.create(cr, uid, values)
499+ tot_tax_invoice += tax_line.amount #tax_line.tax_amount
500+ tot_rec += 1
501+ check_tax += tax_line.tax_amount
502+ if tax_percentage >= 0:
503+ check_base += tax_line.base_amount
504+
505+ tot_base += invoice.amount_untaxed
506+ tot_amount += tot_tax_invoice
507+ tot_tot += invoice.amount_untaxed + tot_tax_invoice
508+
509+ if invoice.type=="out_invoice" or invoice.type=="out_refund":
510+ invoices340.write(cr,uid,invoice_created,
511+ {'amount_tax':tot_tax_invoice})
512+ if invoice.type=="in_invoice" or invoice.type=="in_refund":
513+ invoices340_rec.write(cr,uid,invoice_created,
514+ {'amount_tax':tot_tax_invoice})
515+
516+ sign=1
517+ if invoice.type in ( 'out_refund','in_refund' ):
518+ sign = -1
519+
520+ if str(invoice.amount_untaxed*sign) != str(check_base):
521+ raise osv.except_osv( "REVIEW INVOICE",
522+ _('Invoice %s, Amount untaxed Lines %.2f do not correspond to AmountUntaxed on Invoice %.2f' )
523+ %(invoice.number, check_base, invoice.amount_untaxed*sign) )
524+
525+ mod340.write({'total_taxable':tot_base,'total_sharetax':tot_amount,
526+ 'number_records':tot_rec,'total':tot_tot,'number':code})
527+
528+ if recalculate:
529+ mod340.write({
530+ 'state' : 'calculated',
531+ 'calculation_date' : time.strftime('%Y-%m-%d %H:%M:%S')
532+ })
533+
534+ except Exception, ex:
535+ raise
536+
537+ return True
538+
539
540 def calculation_threading(self, cr, uid, ids, context=None):
541 if context is None:
542
543=== modified file 'l10n_es_aeat_mod340/wizard/export_mod340_to_boe.py'
544--- l10n_es_aeat_mod340/wizard/export_mod340_to_boe.py 2014-02-14 18:02:38 +0000
545+++ l10n_es_aeat_mod340/wizard/export_mod340_to_boe.py 2014-06-30 10:24:12 +0000
546@@ -82,11 +82,15 @@
547 # Número identificativo de la declaración
548 text += self._formatNumber(report.number, 13)
549 # Declaración complementaria
550- if (report.type == 'C'): text += 'C'
551- else: text += ' '
552+ if (report.type == 'C'):
553+ text += 'C'
554+ else:
555+ text += ' '
556 # Declaración substitutiva
557- if (report.type == 'S'): text += 'S'
558- else: text += ' '
559+ if (report.type == 'S'):
560+ text += 'S'
561+ else:
562+ text += ' '
563 # Número identificativo de la declaración anterior
564 text += self._formatNumber(report.previous_number, 13)
565 period_stop = report.period_to.date_stop[5:7]
566@@ -103,14 +107,14 @@
567 elif period_stop == '12':
568 period = '4T'
569 else:
570- raise osv.except_osv( "ERROR",
571- _("The period hasn't a valid Mod340 period" ))
572+ raise osv.except_osv("ERROR",
573+ _("The period hasn't a valid Mod340 period"))
574 # Periodo
575- text += self._formatString(period,2)
576+ text += self._formatString(period, 2)
577 # Número total de registros
578 text += self._formatNumber(report.number_records, 9)
579 # Importe total de la base imponible
580- text += self._formatNumber(report.total_taxable, 15, 2,True)
581+ text += self._formatNumber(report.total_taxable, 15, 2, True)
582 # Importe Total de la cuota del impuesto
583 text += self._formatNumber(report.total_sharetax, 15, 2,True)
584 # Importe total de las facturas
585@@ -215,18 +219,38 @@
586 # Clave tipo de libro. Constante 'E'.
587 text += 'E'
588 # Clave de operación
589- if invoice_issued.invoice_id.origin_invoices_ids:
590- text +='D'
591- elif len(invoice_issued.tax_line_ids) > 1: text += 'C'
592- elif invoice_issued.invoice_id.is_ticket_summary == 1: text += 'B'
593- else: text += ' '
594-
595- text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[0],4)
596- text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[1],2)
597- text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[2],2)
598- text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[0],4)
599- text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[1],2)
600- text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[2],2)
601+
602+ tipo_operacion = False
603+ if invoice_issued.tax_line_ids[0].name.find('sujeto pasivo') != -1 and not tipo_operacion:
604+ text += 'I'
605+ tipo_operacion = True
606+ elif invoice_issued.tax_line_ids[0].name.find('Intracomunitario') != -1 and not tipo_operacion:
607+ text += 'P'
608+ tipo_operacion = True
609+
610+ elif invoice_issued.invoice_id.origin_invoices_ids and not tipo_operacion:
611+ text += 'D'
612+ tipo_operacion = True
613+ elif len(invoice_issued.tax_line_ids) > 1 and not tipo_operacion:
614+ text += 'C'
615+ tipo_operacion = True
616+ elif invoice_issued.invoice_id.is_ticket_summary == 1 and not tipo_operacion:
617+ text += 'B'
618+ tipo_operacion = True
619+ elif not tipo_operacion:
620+ text += ' '
621+ # if invoice_issued.invoice_id.origin_invoices_ids:
622+ # text +='D'
623+ # elif len(invoice_issued.tax_line_ids) > 1: text += 'C'
624+ # elif invoice_issued.invoice_id.is_ticket_summary == 1: text += 'B'
625+ # else: text += ' '
626+
627+ text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[0], 4)
628+ text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[1], 2)
629+ text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[2], 2)
630+ text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[0], 4)
631+ text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[1], 2)
632+ text += self._formatNumber(invoice_issued.invoice_id.date_invoice.split('-')[2], 2)
633 #Tipo impositivo
634 text += self._formatNumber(tax_line.tax_percentage*100,3,2)
635 # Base imponible
636@@ -334,25 +358,49 @@
637 if invoice_received.partner_country_code != 'ES': # Número de identificación fiscal en el país de residencia.
638 text += self._formatString(invoice_received.partner_country_code, 2)
639 text += self._formatString(invoice_received.partner_vat, 15)
640- else: text += 17*' '
641- text += 3*' ' # Blancos
642- text += 'R' # Clave tipo de libro. Constante 'E'.
643-
644- if len(invoice_received.tax_line_ids) > 1: text += 'C' # Clave de operación
645- else: text += ' '
646-
647- text += self._formatNumber(invoice_received.invoice_id.date_invoice.split('-')[0],4)
648- text += self._formatNumber(invoice_received.invoice_id.date_invoice.split('-')[1],2)
649- text += self._formatNumber(invoice_received.invoice_id.date_invoice.split('-')[2],2) # Fecha de expedición
650- text += self._formatNumber(invoice_received.invoice_id.date_invoice.split('-')[0],4)
651- text += self._formatNumber(invoice_received.invoice_id.date_invoice.split('-')[1],2)
652- text += self._formatNumber(invoice_received.invoice_id.date_invoice.split('-')[2],2) # Fecha de operación
653-
654- text += self._formatNumber(tax_line.tax_percentage*100,3,2) #Tipo impositivo
655- text += self._formatNumber(tax_line.base_amount, 11,2,True) # Base imponible
656- text += self._formatNumber(tax_line.tax_amount, 11,2,True) # Cuota del impuesto
657- text += self._formatNumber(tax_line.tax_amount+tax_line.base_amount, 11,2,True) # Importe total de la factura
658- text += ' '+self._formatNumber(0, 11,2) # Base imponible a coste.
659+ else:
660+ text += 17 * ' '
661+ text += 3 * ' ' # Blancos
662+ text += 'R' # Clave tipo de libro. Constante 'R'.
663+
664+ tipo_operacionR = False
665+
666+ # Clave de operación
667+ print invoice_received.tax_line_ids[0].name
668+ if invoice_received.tax_line_ids[0].name.find('sujeto pasivo') != -1 and not tipo_operacionR:
669+ text += 'I'
670+ tipo_operacionR = True
671+ elif invoice_received.tax_line_ids[0].name.find('Intracomunitario') != -1 and not tipo_operacionR:
672+ text += 'P'
673+ tipo_operacionR = True
674+ elif not tipo_operacionR and len(invoice_received.tax_line_ids) > 1:
675+ text += 'C'
676+ elif not tipo_operacionR:
677+ text += ' '
678+
679+ # for tax in invoice_received.tax_line_ids:
680+ # if tax.name.find('sujeto pasivo') != -1 and not tipo_operacionR:
681+ # text += 'I'
682+ # tipo_operacionR = True
683+ # elif tax.name.find('Intracomunitario') != -1 and not tipo_operacionR:
684+ # text += 'P'
685+ # tipo_operacionR = True
686+
687+
688+
689+ text += self._formatNumber(invoice_received.invoice_id.date_invoice.split('-')[0], 4)
690+ text += self._formatNumber(invoice_received.invoice_id.date_invoice.split('-')[1], 2)
691+ text += self._formatNumber(invoice_received.invoice_id.date_invoice.split('-')[2], 2) # Fecha de expedición
692+ text += self._formatNumber(invoice_received.invoice_id.date_invoice.split('-')[0], 4)
693+ text += self._formatNumber(invoice_received.invoice_id.date_invoice.split('-')[1], 2)
694+ text += self._formatNumber(invoice_received.invoice_id.date_invoice.split('-')[2], 2) # Fecha de operación
695+
696+ text += self._formatNumber(tax_line.tax_percentage * 100, 3, 2) #Tipo impositivo
697+ text += self._formatNumber(tax_line.base_amount, 11, 2, True) # Base imponible
698+ text += self._formatNumber(tax_line.tax_amount, 11, 2, True) # Cuota del impuesto
699+ text += self._formatNumber(tax_line.tax_amount + tax_line.base_amount, 11, 2,
700+ True) # Importe total de la factura
701+ text += ' ' + self._formatNumber(0, 11, 2) # Base imponible a coste.
702 text += self._formatString(invoice_received.invoice_id.reference, 40) # Identificación de la factura
703 text += self._formatString(self.pool.get('ir.sequence').get(cr, uid, 'mod340'),18) # Número de registro
704 text += self._formatNumber(1, 18) # Número de facturas
705@@ -427,4 +475,5 @@
706
707 return True
708
709+
710 l10n_es_aeat_mod340_export_to_boe()