28
28
from report import report_sxw
31
from amount_to_text_es import amount_to_text as amount_to_text_class
31
#from amount_to_text_es import amount_to_text as amount_to_text_class
33
amount_to_text_obj = amount_to_text_class()
33
#amount_to_text_obj = amount_to_text_class()
34
34
#amount_to_text = amount_to_text_obj.amount_to_text
35
amount_to_text = amount_to_text_obj.amount_to_text_cheque
35
#amount_to_text = amount_to_text_obj.amount_to_text_cheque
37
37
###sql_delete_report = "DELETE FROM ir_act_report_xml WHERE report_name = 'account.invoice.facturae.pdf'"--Si no toma la actualizacion del reporte xml, borrarlo directamente desde la base de datos, con este script.
42
42
self.localcontext.update({
43
43
'set_global_data': self._set_global_data,
44
44
'facturae_data_dict': self._facturae_data_dict,
45
'amount_to_text': self._get_amount_to_text,
45
#'amount_to_text': self._get_amount_to_text,
46
46
'split_string': self._split_string,
47
47
'company_address': self._company_address,
48
48
'subcompany_address': self._subcompany_address,
51
51
'get_taxes': self._get_taxes,
52
52
'get_taxes_ret': self._get_taxes_ret,
54
'exists_key': self._exists_key,
58
def _exists_key(self, key):
59
return self.invoice._columns.has_key(key)
62
str= 'self.invoice.'+key
57
69
def _set_global_data(self, o):
59
71
self.setLang(o.partner_id.lang)
79
91
return self.sequence
81
93
def _set_invoice_sequence_and_approval(self, invoice_id):
82
#TinyERP Compatibility
84
95
pool = pooler.get_pool(self.cr.dbname)
85
96
invoice_obj = pool.get('account.invoice')
86
97
sequence_obj = pool.get('ir.sequence')
87
approval_obj = pool.get('ir.sequence.approval')
88
#invoice = invoice_obj.browse(self.cr, self.uid, invoice_id)
89
sequence_id = invoice_obj._get_invoice_sequence(self.cr, self.uid, [invoice_id])[invoice_id]
90
sequence = sequence_obj.browse(self.cr, self.uid, [sequence_id])[0]
98
#approval_obj = pool.get('ir.sequence.approval')
99
invoice = invoice_obj.browse(self.cr, self.uid, [invoice_id], context=context)[0]
100
context.update({'number_work': invoice.number})
101
sequence = invoice.invoice_sequence_id or False
102
sequence_id = sequence and sequence.id or False
103
#invoice_obj._get_invoice_sequence(self.cr, self.uid, [invoice_id])[invoice_id]
104
#sequence_obj.browse(self.cr, self.uid, [sequence_id])[0]
91
105
self.sequence = sequence
93
invoice = invoice_obj.browse(self.cr, self.uid, [invoice_id])[0]
94
context.update({'number_work': invoice.number})
95
approval_id = sequence_obj._get_current_approval(self.cr, self.uid, [sequence_id], context=context)[sequence_id]
96
approval = approval_obj.browse(self.cr, self.uid, [approval_id])[0]
107
#invoice = invoice_obj.browse(self.cr, self.uid, [invoice_id])[0]
108
approval = sequence and sequence.approval_id or False
109
approval_id = approval and approval.id or False
110
#approval_id = sequence_obj._get_current_approval(self.cr, self.uid, [sequence_id], context=context)[sequence_id]
111
#approval = approval_obj.browse(self.cr, self.uid, [approval_id])[0]
97
112
self.approval = approval
98
113
return sequence, approval
126
def _set_taxes(self, invoice_id):
128
pool = pooler.get_pool(self.cr.dbname)
129
invoice_obj = pool.get('account.invoice')
130
invoice = invoice_obj.browse(self.cr, self.uid, [invoice_id])[0]
132
for line_tax_id in invoice.tax_line:
133
tax_name = line_tax_id.name.lower().replace('.','').replace('-','').replace(' ', '')
134
if tax_name in ['iva']:
136
elif 'isr' in tax_name:
138
elif 'ieps' in tax_name:
140
tax_names.append( tax_name )
143
'rate': "%.2f"%( round( line_tax_id.amount/(invoice.amount_total-line_tax_id.amount)*100, 0) ),
144
'amount': "%.2f"%( line_tax_id.amount or 0.0),
147
self.taxes = self.invoice_data_dict['Comprobante']['Impuestos']['Traslados']
110
152
def _split_string(self, string, length=100):
112
154
for i in range(0, len(string), length):
113
155
string = string[:i] + ' ' + string[i:]
116
158
def _get_amount_to_text(self, amount, lang, currency=""):
117
159
if currency.upper() in ('MXP', 'MXN', 'PESOS', 'PESOS MEXICANOS'):
131
173
address_obj = pool.get('res.partner.address')
132
174
invoice = invoice_obj.browse(self.cr, self.uid, invoice_id)
133
175
partner_id = invoice.company_id.parent_id and invoice.company_id.parent_id.partner_id.id or invoice.company_id.partner_id.id
176
self.invoice = invoice
177
#print "partner_id",partner_id
178
#invoice = partner_obj.browse(cr, uid, invoice_id)
134
179
address_id = partner_obj.address_get(self.cr, self.uid, [partner_id], ['invoice'])['invoice']
135
180
self.company_address_invoice = address_obj.browse(self.cr, self.uid, address_id)
141
186
subaddress_id = partner_obj.address_get(self.cr, self.uid, [subpartner_id], ['invoice'])['invoice']
142
187
self.subcompany_address_invoice = address_obj.browse(self.cr, self.uid, subaddress_id)
188
#print "self.company_address_invoice",self.company_address_invoice
189
#print "self.company_address_invoice[0]",self.company_address_invoice[0]
190
#self.company_address_invoice = self.company_address_invoice and self.company_address_invoice[0] or False
191
#print "self.company_address_invoice",self.company_address_invoice
192
#return [self.company_address_invoice]
145
195
def _company_address(self):
196
#print "self.company_address_invoice",self.company_address_invoice
146
197
return self.company_address_invoice
148
199
def _subcompany_address(self):
149
200
return self.subcompany_address_invoice
151
202
def _facturae_data_dict(self):
203
#print "self.invoice_data_dict",self.invoice_data_dict
152
204
return self.invoice_data_dict
154
def _get_facturae_data_dict(self, invoice_id):
206
def _get_facturae_data_dict(self, invoice):
207
self._set_invoice_sequence_and_approval( invoice.id )
208
#invoice_obj = pool.get('account.invoice')
209
self.taxes = [tax for tax in invoice.tax_line if tax.tax_percent > 0.01]
210
self.taxes_ret = [tax for tax in invoice.tax_line if tax.tax_percent <= 0.01]
155
213
pool = pooler.get_pool(self.cr.dbname)
156
214
invoice_obj = pool.get('account.invoice')
157
invoice_tax_obj = pool.get('account.invoice.tax')
215
self.invoice_data_dict = invoice_obj._get_facturae_invoice_xml_data(self.cr, self.uid, [invoice_id], context={'type_data': 'dict'})
216
#print "self.invoice_data_dict['Comprobante']['Impuestos']['Traslados']",self.invoice_data_dict['Comprobante']['Impuestos']['Traslados']
159
self._set_invoice_sequence_and_approval( invoice_id )
161
print "report error: self._set_invoice_sequence_and_approval( invoice_id )"
218
self.taxes = [ traslado['Traslado'] for traslado in self.invoice_data_dict['Comprobante']['Impuestos']['Traslados'] if float( traslado['Traslado']['tasa'] ) >0.01 ]
219
#self.taxes = [tax for tax in invoice.account_invoice_tax if tax.tax_percent > 0.01]
220
#self.taxes.extend( self.taxes_ret )
222
print "exception: %s"%( e )
163
invoice = invoice_obj.browse(self.cr, self.uid, [invoice_id])[0]
164
tax_line_ids = [tax_line.id for tax_line in invoice.tax_line]
165
tax_datas = invoice_tax_obj._get_tax_data(self.cr, self.uid, tax_line_ids)
166
self.taxes = tax_datas.values()
226
for retencion in self.invoice_data_dict['Comprobante']['Impuestos'].get('Retenciones', []):
227
amount_untaxed = float( self.invoice_data_dict['Comprobante']['subTotal'] )
228
tax_ret_amount = float( retencion['Retencion']['importe'] )
229
tasa = tax_ret_amount and amount_untaxed and tax_ret_amount * 100 / amount_untaxed or 0.0
230
retencion['Retencion'].update({'tasa': tasa})
231
self.taxes_ret.append( retencion['Retencion'] )
169
235
report_sxw.report_sxw(
170
236
'report.account.invoice.facturae.pdf2',