From 6ec5d101178261d90d0e74e9d7c6eb3f79ac9fea Mon Sep 17 00:00:00 2001
From: federico <federico.cruz@openpyme.mx>
Date: Mon, 6 Apr 2015 14:23:23 -0500
Subject: [PATCH] There was not implemented a  validation for differents vat in
 the partner and the receiver in the xml file

This line was erased in the last commit by a error

This line was erased by error

En el primer commit se tomo al reves el RFC del emisor y el RFC del receptor

SE agrego la validacion de del RFC del proveedor en las facturas de compra, pero con esto se elimino la validacion del RFC de nuestra empresa, todo esto cuando existe un archivo xml

Se cambio el mensaje en vez de desplegar de error

Se movieron las variables objetos hasta el principio de la funcion por convencion

Set the correct indent
---
 l10n_mx_facturae_validate_cfdi/invoice.py | 26 +++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/l10n_mx_facturae_validate_cfdi/invoice.py b/l10n_mx_facturae_validate_cfdi/invoice.py
index abeeae3a..b62390fc 100644
--- a/l10n_mx_facturae_validate_cfdi/invoice.py
+++ b/l10n_mx_facturae_validate_cfdi/invoice.py
@@ -51,6 +51,9 @@ class AccountInvoice(orm.Model):
     ]
 
     def invoice_validate(self, cr, uid, ids, context=None):
+        att_obj = self.pool.get('ir.attachment')
+        partner_obj = self.pool.get('res.partner')
+        
         def validate_cfdi_folio_fiscal(data):
             """ Validate an UUID on SAT servers"""
             # Validates if "data" exists
@@ -80,14 +83,12 @@ class AccountInvoice(orm.Model):
                     _('Error'),
                     _('The CFDI provided did not passed the SAT validation\n'
                       'The UUID sate on SAT servers is %s') % result)
-
             # If CFDI is valid:
             return True
 
         # Main function
         if context is None:
             context = {}
-
         for invoice in self.browse(cr, uid, ids, context=context):
             # If the user provides the field "cfdi_folio_fiscal" then
             # validates the info of the invoice, not the xml file
@@ -107,11 +108,9 @@ class AccountInvoice(orm.Model):
                 # "validate_sat" option
                 validate_cfdi_folio_fiscal(data)
                 continue
-
             # Validates the XML info if the journal has enabled the
             # "validate_xml" option
             if invoice.journal_id.validate_xml:
-                att_obj = self.pool.get('ir.attachment')
                 att_ids = att_obj.search(
                     cr, uid,
                     [('res_id', '=', invoice.id),
@@ -120,7 +119,6 @@ class AccountInvoice(orm.Model):
                      ('file_type', '=', 'application/xml'),
                      ('file_type', '=', 'text/plain')],
                     context=context)
-
                 # Process and stores the info of the attachments
                 count = 0
                 for att in att_obj.browse(cr, uid, att_ids, context=context):
@@ -134,7 +132,6 @@ class AccountInvoice(orm.Model):
                     except:
                         # Skip file if any error
                         continue
-
                     complemento = dict_data.get('cfdi:Complemento', {})
                     emitter = dict_data.get('cfdi:Emisor', {})
                     receiver = dict_data.get('cfdi:Receptor', {})
@@ -169,6 +166,23 @@ class AccountInvoice(orm.Model):
                 if invoice.type in ['in_invoice', 'in_refund']:
                     actor = _('Receiver')
                     vat = data['vat_receiver']
+                    if invoice.partner_id.vat_split:
+                        if data['vat_emitter'] != invoice.partner_id.vat_split:
+                            raise orm.except_orm(
+                                _("Error"),
+                                _("The Supplier's vat (%s) is different " 
+                                "to the Supplier's vat " 
+                                "in the xml file (%s)"
+                                %(invoice.partner_id.vat_split, 
+                                data['vat_emitter']))
+                            )
+                    else:
+                        vat_emitter = 'MX' + data['vat_emitter']
+                        partner_obj.write(
+                        cr, uid, invoice.partner_id.id,
+                        {'vat': vat_emitter},
+                        context=context
+                    )
                 else:
                     actor = _('Emitter')
                     vat = data['vat_emitter']
-- 
GitLab