@@ -637,18 +637,18 @@ def l10n_uy_complete_invoice_with_xml(self, company, root, invoice):
637
637
error = False
638
638
invoice_date_due = False
639
639
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 )
642
642
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
645
645
if fecha_vto :
646
646
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
648
648
if fma_pago and fma_pago == '2' :
649
649
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
652
652
partner_id = self .env ['res.partner' ].search ([('commercial_partner_id.vat' , '=' , partner_vat_RUC )], limit = 1 )
653
653
# Si no existe el partner lo creamos
654
654
if not partner_id :
@@ -668,6 +668,7 @@ def l10n_uy_complete_invoice_with_xml(self, company, root, invoice):
668
668
# Process Invoice Lines. To iterate is used findall.
669
669
invoice_line_ids = root .findall ('.//Item' )
670
670
line_ids = self .l10n_uy_vendor_prepare_lines (company , invoice_line_ids , invoice )
671
+ import pdb ; pdb .set_trace ()
671
672
invoice .line_ids = line_ids
672
673
if len (invoice .invoice_line_ids ) != int (cant_lineas ):
673
674
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):
677
678
invoice .l10n_latam_document_number = l10n_latam_document_number
678
679
self .env .cr .commit ()
679
680
invoice_amount_total = invoice .amount_total
680
- xml_amount_total = float (root .findtext ('.//MntPagar' ))
681
+ xml_amount_total = float (root .find ('.//{*} MntPagar' ). text )
681
682
if float_compare (invoice_amount_total , xml_amount_total , precision_digits = invoice .currency_id .decimal_places ):
682
683
invoice .message_post (
683
684
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
716
717
'l10n_uy_ucfe_msg' : response_610 .Resp .MensajeRta ,
717
718
})
718
719
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
722
723
723
724
req_data_pdf = {'rut' : company .vat ,
724
725
'rutRecibido' : partner_vat_RUC ,
@@ -766,7 +767,7 @@ def l10n_uy_create_pdf_vendor_bill(self, company, invoice, req_data_pdf):
766
767
767
768
def l10n_uy_get_cfe_document_type (self , root ):
768
769
""" :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
770
771
return self .env ['l10n_latam.document.type' ].search ([('code' , '=' , l10n_latam_document_type_id ), ('country_id.code' , '=' , 'UY' )])
771
772
772
773
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):
805
806
xml_string = response_610 .Resp .XmlCfeFirmado
806
807
if not xml_string :
807
808
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
809
810
810
811
def _l10n_uy_get_tax_not_implemented_description (self , ind_fact ):
811
812
""" 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):
889
890
root = ET .fromstring (xml_string )
890
891
return root
891
892
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
-
898
893
def l10n_uy_vendor_prepare_lines (self , company , invoice_line_ids , invoice ):
899
894
""" Here are prepared the lines of vendor bills that are synchronized through the Uruware notification request. """
900
895
line_ids = []
901
896
for value in invoice_line_ids :
902
897
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
904
900
if ind_fact == '1' :
905
901
# Exento de IVA
906
902
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):
910
906
elif ind_fact == '3' :
911
907
# Gravado a Tasa Básica
912
908
domain_tax += [('tax_group_id.l10n_uy_vat_code' , '=' , 'vat_22' )]
913
- price_unit = value .findtext ( " .//PrecioUnitario" )
909
+ price_unit = value .find ( ' .//{*} PrecioUnitario' ). text
914
910
tax_item = self .env ['account.tax' ].search (domain_tax , limit = 1 )
915
911
line_vals = {'move_type' : invoice .l10n_latam_document_type_id ._get_move_type (),
916
912
# 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 ),
919
915
'price_unit' : float (price_unit ) if ind_fact != '7' else - 1 * float (price_unit ),
920
916
'tax_ids' : [(6 , 0 , tax_item .ids )] if ind_fact in ['1' , '2' , '3' ] else []}
921
917
line_ids .append ((0 , 0 , line_vals ))
0 commit comments