Skip to content

Commit 80a7e17

Browse files
[WIP] l10n_uy_edi: Mejora tecnica modulo factura de proveedor Uy
Tarea: 41024
1 parent cb3a929 commit 80a7e17

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

l10n_uy_edi/models/l10n_uy_cfe.py

+19-23
Original file line numberDiff line numberDiff line change
@@ -637,18 +637,18 @@ def l10n_uy_complete_invoice_with_xml(self, company, root, invoice):
637637
error = False
638638
invoice_date_due = False
639639
try:
640-
partner_vat_RUC = root.findtext('.//RUCEmisor')
641-
l10n_latam_document_number = root.findtext('.//Serie') + root.findtext('.//Nro').zfill(7)
640+
partner_vat_RUC = root.find('.//{*}RUCEmisor').text
641+
l10n_latam_document_number = root.find('.//{*}Serie').text + root.find('.//{*}Nro').text.zfill(7)
642642
date_format = '%Y-%m-%d'
643-
invoice_date = datetime.strptime(root.findtext('.//FchEmis'), date_format).date()
644-
fecha_vto = root.findtext('.//FchVenc')
643+
invoice_date = datetime.strptime(root.find('.//{*}FchEmis').text, date_format).date()
644+
fecha_vto = root.find('.//{*}FchVenc').text if root.find('.//{*}FchVenc') else False
645645
if fecha_vto:
646646
invoice_date_due = datetime.strptime(fecha_vto, date_format).date()
647-
fma_pago = root.findtext('.//FmaPago')
647+
fma_pago = root.find('.//{*}FmaPago').text if root.find('.//{*}FmaPago') else False
648648
if fma_pago and fma_pago == '2':
649649
invoice.l10n_uy_payment_type = 'credit'
650-
invoice_currency = root.findtext('.//TpoMoneda')
651-
cant_lineas = root.findtext('.//CantLinDet')
650+
invoice_currency = root.find('.//{*}TpoMoneda').text
651+
cant_lineas = root.find('.//{*}CantLinDet').text
652652
partner_id = self.env['res.partner'].search([('commercial_partner_id.vat', '=', partner_vat_RUC)], limit=1)
653653
# Si no existe el partner lo creamos
654654
if not partner_id:
@@ -668,6 +668,7 @@ def l10n_uy_complete_invoice_with_xml(self, company, root, invoice):
668668
# Process Invoice Lines. To iterate is used findall.
669669
invoice_line_ids = root.findall('.//Item')
670670
line_ids = self.l10n_uy_vendor_prepare_lines(company, invoice_line_ids, invoice)
671+
import pdb; pdb.set_trace()
671672
invoice.line_ids = line_ids
672673
if len(invoice.invoice_line_ids) != int(cant_lineas):
673674
error = _('The number of invoice lines %s (id:%d) is invalid') % (invoice.name, invoice.id)
@@ -677,7 +678,7 @@ def l10n_uy_complete_invoice_with_xml(self, company, root, invoice):
677678
invoice.l10n_latam_document_number = l10n_latam_document_number
678679
self.env.cr.commit()
679680
invoice_amount_total = invoice.amount_total
680-
xml_amount_total = float(root.findtext('.//MntPagar'))
681+
xml_amount_total = float(root.find('.//{*}MntPagar').text)
681682
if float_compare(invoice_amount_total, xml_amount_total, precision_digits=invoice.currency_id.decimal_places):
682683
invoice.message_post(
683684
body=_('There is a difference between the invoice total amount in Odoo and the invoice XML. '
@@ -716,9 +717,9 @@ def l10n_uy_create_cfe_from_xml(self, company, root, transport, l10n_uy_idreq, r
716717
'l10n_uy_ucfe_msg': response_610.Resp.MensajeRta,
717718
})
718719
invoice._update_l10n_uy_cfe_state()
719-
partner_vat_RUC = root.findtext('.//RUCEmisor')
720-
serieCfe = root.findtext('.//Serie')
721-
l10n_latam_document_number = root.findtext('.//Nro')
720+
partner_vat_RUC = root.find('.//{*}RUCEmisor').text
721+
serieCfe = root.find('.//{*}Serie').text
722+
l10n_latam_document_number = root.find('.//{*}Nro').text
722723

723724
req_data_pdf = {'rut': company.vat,
724725
'rutRecibido': partner_vat_RUC,
@@ -766,7 +767,7 @@ def l10n_uy_create_pdf_vendor_bill(self, company, invoice, req_data_pdf):
766767

767768
def l10n_uy_get_cfe_document_type(self, root):
768769
""" :return: latam document type in Odoo that represented the XML CFE. """
769-
l10n_latam_document_type_id = root.findtext('.//TipoCFE')
770+
l10n_latam_document_type_id = root.find('.//{*}TipoCFE').text
770771
return self.env['l10n_latam.document.type'].search([('code', '=', l10n_latam_document_type_id), ('country_id.code', '=', 'UY')])
771772

772773
def l10n_uy_get_l10n_uy_received_bills(self):
@@ -805,7 +806,7 @@ def l10n_uy_get_parsed_xml_cfe(self, response_610, l10n_uy_idreq):
805806
xml_string = response_610.Resp.XmlCfeFirmado
806807
if not xml_string:
807808
raise UserError(_('There is no information to create the vendor bill in the notification %d consulted') % (l10n_uy_idreq))
808-
return self.l10n_uy_vendor_prepare_cfe_xml(xml_string)
809+
return xml_string
809810

810811
def _l10n_uy_get_tax_not_implemented_description(self, ind_fact):
811812
""" There are some taxes no implemented for Uruguay, so when move lines are created and if those ones don`t have ind_fact (Indicador de facturación) 1, 2 or 3 then is concatenated the name of the tax not implemented with the name of the line. """
@@ -889,18 +890,13 @@ def l10n_uy_vendor_create_xml_root(self, response_610, l10n_uy_idreq):
889890
root = ET.fromstring(xml_string)
890891
return root
891892

892-
def l10n_uy_vendor_prepare_cfe_xml(self, xml_string):
893-
""" Parse cfe xml so enable to create vendor bills. We don´t know which format of xml is received, so it is needed to clean the tags of the xml to make it readable by the library xml.etree.ElementTree . """
894-
xml_string = re.sub(r'\bns[A-Za-z0-9]*:', '', xml_string)
895-
xml_string = re.sub(r'<eFact[^>]*>', '<eFact>', xml_string)
896-
return re.sub(r'<CFE[^>]*>', '<CFE>', xml_string)
897-
898893
def l10n_uy_vendor_prepare_lines(self, company, invoice_line_ids, invoice):
899894
""" Here are prepared the lines of vendor bills that are synchronized through the Uruware notification request. """
900895
line_ids = []
901896
for value in invoice_line_ids:
902897
domain_tax = [('country_code', '=', 'UY'), ('company_id', '=', company.id), ('type_tax_use', '=', 'purchase')]
903-
ind_fact = value.findtext(".//IndFact")
898+
import pdb; pdb.set_trace()
899+
ind_fact = value.find('.//{*}IndFact').text
904900
if ind_fact == '1':
905901
# Exento de IVA
906902
domain_tax += [('tax_group_id.l10n_uy_vat_code', '=', 'vat_exempt')]
@@ -910,12 +906,12 @@ def l10n_uy_vendor_prepare_lines(self, company, invoice_line_ids, invoice):
910906
elif ind_fact == '3':
911907
# Gravado a Tasa Básica
912908
domain_tax += [('tax_group_id.l10n_uy_vat_code', '=', 'vat_22')]
913-
price_unit = value.findtext(".//PrecioUnitario")
909+
price_unit = value.find('.//{*}PrecioUnitario').text
914910
tax_item = self.env['account.tax'].search(domain_tax, limit=1)
915911
line_vals = {'move_type': invoice.l10n_latam_document_type_id._get_move_type(),
916912
# There are some taxes no implemented for Uruguay, so when move lines are created and if those ones have ind_fact not in 1, 2 or 3 then is concatenated the name of the tax not implemented with the name of the line.
917-
'name': value.findtext(".//NomItem") + (" (*%s)" % self._l10n_uy_get_tax_not_implemented_description(ind_fact) if ind_fact not in ['1', '2', '3'] else ""),
918-
'quantity': float(value.findtext(".//Cantidad")),
913+
'name': value.find('.//{*}NomItem').text + (" (*%s)" % self._l10n_uy_get_tax_not_implemented_description(ind_fact) if ind_fact not in ['1', '2', '3'] else ""),
914+
'quantity': float(value.find('.//{*}Cantidad').text),
919915
'price_unit': float(price_unit) if ind_fact != '7' else -1*float(price_unit),
920916
'tax_ids': [(6, 0, tax_item.ids)] if ind_fact in ['1', '2', '3'] else []}
921917
line_ids.append((0, 0, line_vals))

0 commit comments

Comments
 (0)