Commit 6ec5d101 authored by fedexin40's avatar fedexin40 Committed by agb80

There was not implemented a validation for differents vat in the partner and...

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
parent 46bc5fc5
...@@ -51,6 +51,9 @@ class AccountInvoice(orm.Model): ...@@ -51,6 +51,9 @@ class AccountInvoice(orm.Model):
] ]
def invoice_validate(self, cr, uid, ids, context=None): 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): def validate_cfdi_folio_fiscal(data):
""" Validate an UUID on SAT servers""" """ Validate an UUID on SAT servers"""
# Validates if "data" exists # Validates if "data" exists
...@@ -80,14 +83,12 @@ class AccountInvoice(orm.Model): ...@@ -80,14 +83,12 @@ class AccountInvoice(orm.Model):
_('Error'), _('Error'),
_('The CFDI provided did not passed the SAT validation\n' _('The CFDI provided did not passed the SAT validation\n'
'The UUID sate on SAT servers is %s') % result) 'The UUID sate on SAT servers is %s') % result)
# If CFDI is valid: # If CFDI is valid:
return True return True
# Main function # Main function
if context is None: if context is None:
context = {} context = {}
for invoice in self.browse(cr, uid, ids, context=context): for invoice in self.browse(cr, uid, ids, context=context):
# If the user provides the field "cfdi_folio_fiscal" then # If the user provides the field "cfdi_folio_fiscal" then
# validates the info of the invoice, not the xml file # validates the info of the invoice, not the xml file
...@@ -107,11 +108,9 @@ class AccountInvoice(orm.Model): ...@@ -107,11 +108,9 @@ class AccountInvoice(orm.Model):
# "validate_sat" option # "validate_sat" option
validate_cfdi_folio_fiscal(data) validate_cfdi_folio_fiscal(data)
continue continue
# Validates the XML info if the journal has enabled the # Validates the XML info if the journal has enabled the
# "validate_xml" option # "validate_xml" option
if invoice.journal_id.validate_xml: if invoice.journal_id.validate_xml:
att_obj = self.pool.get('ir.attachment')
att_ids = att_obj.search( att_ids = att_obj.search(
cr, uid, cr, uid,
[('res_id', '=', invoice.id), [('res_id', '=', invoice.id),
...@@ -120,7 +119,6 @@ class AccountInvoice(orm.Model): ...@@ -120,7 +119,6 @@ class AccountInvoice(orm.Model):
('file_type', '=', 'application/xml'), ('file_type', '=', 'application/xml'),
('file_type', '=', 'text/plain')], ('file_type', '=', 'text/plain')],
context=context) context=context)
# Process and stores the info of the attachments # Process and stores the info of the attachments
count = 0 count = 0
for att in att_obj.browse(cr, uid, att_ids, context=context): for att in att_obj.browse(cr, uid, att_ids, context=context):
...@@ -134,7 +132,6 @@ class AccountInvoice(orm.Model): ...@@ -134,7 +132,6 @@ class AccountInvoice(orm.Model):
except: except:
# Skip file if any error # Skip file if any error
continue continue
complemento = dict_data.get('cfdi:Complemento', {}) complemento = dict_data.get('cfdi:Complemento', {})
emitter = dict_data.get('cfdi:Emisor', {}) emitter = dict_data.get('cfdi:Emisor', {})
receiver = dict_data.get('cfdi:Receptor', {}) receiver = dict_data.get('cfdi:Receptor', {})
...@@ -169,6 +166,23 @@ class AccountInvoice(orm.Model): ...@@ -169,6 +166,23 @@ class AccountInvoice(orm.Model):
if invoice.type in ['in_invoice', 'in_refund']: if invoice.type in ['in_invoice', 'in_refund']:
actor = _('Receiver') actor = _('Receiver')
vat = data['vat_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: else:
actor = _('Emitter') actor = _('Emitter')
vat = data['vat_emitter'] vat = data['vat_emitter']
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment