65
66
wf_service = netsvc.LocalService("workflow")
66
67
wf_service.trg_validate(uid, 'l10n.es.aeat.mod347.report', ids and ids[0], 'calculate', cr)
71
dec_year =mod340.fiscalyear_id.date_start.split('-')[0]
75
if mod >= '01' and mod <= '12':
76
fecha_ini = datetime.strptime('%s-%s-01' % (dec_year, mod), '%Y-%m-%d')
77
fecha_fin = fecha_ini + relativedelta(months=+1, days=-1)
79
if mod in ('1T', '2T', '3T', '4T'):
80
month = ( ( int(mod[0])-1 ) * 3 ) + 1
81
fecha_ini = datetime.strptime('%s-%s-01' % (dec_year, month), '%Y-%m-%d')
82
fecha_fin = fecha_ini + relativedelta(months=+3, days=-1)
85
code = '340'+dec_year+''+mod+'0001'
87
account_period_id = self.pool.get('account.period').search(cr,uid,[('date_start','=',fecha_ini),('date_stop','=',fecha_fin)])
89
if not account_period_id:
90
raise osv.except_osv(_('El periodo seleccionado no coincide con los periodos del año fiscal:'), dec_year)
69
code = '340'+mod340.fiscalyear_id.code+''+mod340.period_to.date_stop[5:7]+'0001'
71
account_period_ids = period_obj.build_ctx_periods(cr, uid, mod340.period_from.id, mod340.period_to.id)
73
if len(account_period_ids) == 0:
74
raise osv.except_osv(_('Error'), _("The periods selected don't belong to the fiscal year %s") % (mod340.fiscalyear_id.name))
111
94
invoices340_rec.unlink(cr, uid, del_ids, context=context)
113
domain = [('period_id', '=',account_period_id[0]),
96
domain = [('period_id', 'in',account_period_ids),
114
97
('state', 'in', ('open', 'paid'))]
116
99
invoice_ids = self.pool.get('account.invoice').search(cr, uid, domain, context=context)
117
100
for invoice in self.pool.get('account.invoice').browse(cr, uid, invoice_ids, context):
118
if invoice.partner_id.vat_type == 1:
119
if not invoice.partner_id.vat:
120
raise osv.except_osv(_('La siguiente empresa no tiene asignado nif:'), invoice.partner_id.name)
122
nif = invoice.partner_id.vat and re.match(r"([A-Z]{0,2})(.*)", invoice.partner_id.vat).groups()[1]
123
country_code = invoice.address_invoice_id.country_id.code
126
'mod340_id': mod340.id,
127
'partner_id':invoice.partner_id.id,
129
'representative_vat': '',
130
'partner_country_code' : country_code,
131
'invoice_id':invoice.id,
132
'base_tax':invoice.amount_untaxed,
133
'amount_tax':invoice.amount_tax,
134
'total':invoice.amount_total
136
if invoice.type in ( 'out_refund','in_refund'):
137
values['base_tax'] *=-1
138
values['amount_tax'] *=-1
142
if invoice.type=="out_invoice" or invoice.type=="out_refund":
143
invoice_created = invoices340.create(cr,uid,values)
145
if invoice.type=="in_invoice" or invoice.type=="in_refund":
146
invoice_created = invoices340_rec.create(cr,uid,values)
152
# Add the invoices detail to the partner record
153
102
for tax_line in invoice.tax_line:
154
if tax_line.name.find('IRPF') == -1: # Remove IRPF from Mod340
155
tax_description = tax_line.name.split(' - ')
156
if len(tax_description) == 2: name = tax_description[1]
157
if len(tax_description) == 1: name = tax_description[0]
158
account_tax = self.pool.get('account.tax').browse(cr, uid, self.pool.get('account.tax').search(cr, uid, [('name','=',name)], context=context))
159
if account_tax[0].amount < 0:
164
'tax_percentage': account_tax[0].amount,
165
'tax_amount': tax_line.tax_amount,
166
'base_amount': tax_line.base_amount,
167
'invoice_record_id': invoice_created,
169
if invoice.type=="out_invoice" or invoice.type=="out_refund":
170
self.pool.get('l10n.es.aeat.mod340.tax_line_issued').create(cr, uid, values)
171
if invoice.type=="in_invoice" or invoice.type=="in_refund":
172
self.pool.get('l10n.es.aeat.mod340.tax_line_received').create(cr, uid, values)
173
tot_tax_invoice += tax_line.tax_amount
175
check_tax += tax_line.tax_amount
176
check_base += tax_line.base_amount
178
tot_base += invoice.amount_untaxed
179
tot_amount += tot_tax_invoice
180
tot_tot += invoice.amount_untaxed + tot_tax_invoice
182
if invoice.type=="out_invoice" or invoice.type=="out_refund":
183
invoices340.write(cr,uid,invoice_created,{'amount_tax':tot_tax_invoice})
184
if invoice.type=="in_invoice" or invoice.type=="in_refund":
185
invoices340_rec.write(cr,uid,invoice_created,{'amount_tax':tot_tax_invoice})
188
if invoice.type in ( 'out_refund','in_refund' ):
191
if str(invoice.amount_untaxed*sign) != str(check_base):
192
print "id:", invoice.id, "base: %.5f"%invoice.amount_untaxed , "taxlibe base: %.5f"%check_base, "number:",invoice.number
193
raise osv.except_osv( "REVIEW INVOICE", _('Invoice %s, Amount untaxed Lines %.2f do not correspond to AmountUntaxed on Invoice %.2f' )%(invoice.number, check_base, invoice.amount_untaxed*sign) )
103
if tax_line.base_code_id:
104
if tax_line.base_code_id.mod340 == True:
107
if invoice.partner_id.vat_type == 1:
108
if not invoice.partner_id.vat:
109
raise osv.except_osv(_('La siguiente empresa no tiene asignado nif:'), invoice.partner_id.name)
111
nif = invoice.partner_id.vat and re.match(r"([A-Z]{0,2})(.*)", invoice.partner_id.vat).groups()[1]
112
country_code = invoice.address_invoice_id.country_id.code
115
'mod340_id': mod340.id,
116
'partner_id':invoice.partner_id.id,
118
'representative_vat': '',
119
'partner_country_code' : country_code,
120
'invoice_id':invoice.id,
121
'base_tax':invoice.amount_untaxed,
122
'amount_tax':invoice.amount_tax,
123
'total':invoice.amount_total
125
if invoice.type in ( 'out_refund','in_refund'):
126
values['base_tax'] *=-1
127
values['amount_tax'] *=-1
131
if invoice.type=="out_invoice" or invoice.type=="out_refund":
132
invoice_created = invoices340.create(cr,uid,values)
134
if invoice.type=="in_invoice" or invoice.type=="in_refund":
135
invoice_created = invoices340_rec.create(cr,uid,values)
141
# Add the invoices detail to the partner record
142
for tax_line in invoice.tax_line:
143
if tax_line.base_code_id:
144
if tax_line.base_code_id.mod340 == True:
145
tax_percentage = tax_line.amount/tax_line.base
148
'name': tax_line.name,
149
'tax_percentage': tax_percentage,
150
'tax_amount': tax_line.tax_amount,
151
'base_amount': tax_line.base_amount,
152
'invoice_record_id': invoice_created,
154
if invoice.type=="out_invoice" or invoice.type=="out_refund":
155
self.pool.get('l10n.es.aeat.mod340.tax_line_issued').create(cr, uid, values)
156
if invoice.type=="in_invoice" or invoice.type=="in_refund":
157
self.pool.get('l10n.es.aeat.mod340.tax_line_received').create(cr, uid, values)
158
tot_tax_invoice += tax_line.tax_amount
160
check_tax += tax_line.tax_amount
161
check_base += tax_line.base_amount
163
tot_base += invoice.amount_untaxed
164
tot_amount += tot_tax_invoice
165
tot_tot += invoice.amount_untaxed + tot_tax_invoice
167
if invoice.type=="out_invoice" or invoice.type=="out_refund":
168
invoices340.write(cr,uid,invoice_created,{'amount_tax':tot_tax_invoice})
169
if invoice.type=="in_invoice" or invoice.type=="in_refund":
170
invoices340_rec.write(cr,uid,invoice_created,{'amount_tax':tot_tax_invoice})
173
if invoice.type in ( 'out_refund','in_refund' ):
176
if str(invoice.amount_untaxed*sign) != str(check_base):
177
print "id:", invoice.id, "base: %.5f"%invoice.amount_untaxed , "taxlibe base: %.5f"%check_base, "number:",invoice.number
178
raise osv.except_osv( "REVIEW INVOICE", _('Invoice %s, Amount untaxed Lines %.2f do not correspond to AmountUntaxed on Invoice %.2f' )%(invoice.number, check_base, invoice.amount_untaxed*sign) )
195
180
mod340.write({'total_taxable':tot_base,'total_sharetax':tot_amount,'number_records':tot_rec,'total':tot_tot,'number':code})