...
 
Commits (9)
<a name="4.1.1"></a>
## 4.1.1 (2018-09-26)
#### Bug Fixes
* **ir.attachment.facturae.mx:**
* homogenizo el comportamiento de la funcion _compute_fecha() con el d ([83437d0c](83437d0c))
* se corrige el calculo de la hora UTC del campo cfdi_fecha_timbrado ([0f57526f](0f57526f))
* se corrige el calculo de la hora UTC del campo fecha ([cd7ce809](cd7ce809))
* **ir.attachment.facturea.mx:** se crea funcion _parser_to_date_from_xml() ([b095996b](b095996b))
<a name="4.1.0"></a>
## 4.1.0 (2018-09-20)
......
......@@ -2,7 +2,7 @@
{
'name': 'CFDI',
'version': '2.1.0',
'version': '2.1.1',
'author': 'OpenPyme',
'category': 'Localization/Mexico',
'website': 'http://www.openpyme.mx/',
......
......@@ -68,6 +68,15 @@ class BaseCfdi(models.AbstractModel):
help='CFDI realed to the selected record.',
)
cfdi_state = fields.Selection(related='cfdi_id.state')
cfdi_relation_type = fields.Many2one(
'cfdi.relation.type', 'CFDI Relation type', copy=False,
)
related_cfdi_ids = fields.Many2many(
'ir.attachment.facturae.mx', 'cfdis_related_rel',
'related_cfdi_id', 'original_cfdi_id', 'Refund invoices',
readonly=True, copy=False,
help='Original CFDI to which this CFDI is referred to',
)
@api.one
def create_cfdi(self):
......@@ -79,3 +88,10 @@ class BaseCfdi(models.AbstractModel):
'company_id': self.company_id.id,
})
self.cfdi_id.action_validate()
@api.one
def cancel_cfdi(self):
"""Cancels the cfdi related with current record and delete relation"""
if self.cfdi_id and self.cfdi_id.state in ['signed', 'done']:
self.cfdi_id.action_cancel()
self.cfdi_id = False
......@@ -6,7 +6,6 @@ import logging
import pkg_resources
import re
import six
from datetime import datetime
from dateutil.parser import parse
from lxml import etree as ET # noqa
from pytz import timezone, utc
......@@ -215,7 +214,8 @@ class IrAttachmentFacturaeMx(models.Model):
help='Company to which it belongs this attachment',
)
uuid = fields.Char(
compute='_compute_uuid', store=True, track_visibility='onchange',
compute='_compute_uuid',
store=True, track_visibility='onchange',
)
cfdi_cadena_original = fields.Text(
'CFD-I Original String', copy=False,
......@@ -269,10 +269,7 @@ class IrAttachmentFacturaeMx(models.Model):
@api.depends('file_xml_sign')
def _compute_cfdi_fecha_timbrado(self):
"""Get FechaTimbrado field from XML file"""
fecha = self._parse_xml('FechaTimbrado')
if fecha:
fecha = datetime.strptime(fecha, '%Y-%m-%dT%H:%M:%S')
self.cfdi_fecha_timbrado = fecha.strftime('%Y-%m-%d %H:%M:%S')
self.cfdi_fecha_timbrado = self._parser_to_date_from_xml('FechaTimbrado')
@api.one
@api.depends('file_xml_sign', 'version')
......@@ -324,12 +321,7 @@ class IrAttachmentFacturaeMx(models.Model):
@api.depends('file_xml_sign', 'version')
def _compute_fecha(self):
"""Get issuing date from XML file"""
if not self.file_xml_sign.exists():
return
date = parse(self._parse_xml(NAMES[self.version]['date']))
# Set default timezone to Mexico/General if not set
date = date.replace(tzinfo=date.tzinfo or timezone('Mexico/General'))
self.fecha = fields.Datetime.to_string(date.astimezone(utc))
self.fecha = self._parser_to_date_from_xml(NAMES[self.version]['date'])
@api.one
@api.depends('file_xml_sign', 'version')
......@@ -352,6 +344,31 @@ class IrAttachmentFacturaeMx(models.Model):
),
)
@api.model
def _parser_to_date_from_xml(self, tag):
'''Get a datime value from a value in a xml
Get a datime value parsing an xml file looking the element with 'tag', try to
parse the value found if any, and if not throw an exception, catch it and
return None
:param tag: tag to look for a value in xml file
:return fecha: datetime value of tag found
:rtype fecha: Datetime
'''
if not self.env.user.partner_id.tz:
raise UserError(_('Set your time zone'))
try:
fecha = parse(self._parse_xml(tag))
except AttributeError as e:
_logger.debug(e)
fecha = None
if fecha:
user_tz = timezone(self.env.user.partner_id.tz)
fecha = user_tz.localize(fecha)
fecha = fecha.astimezone(utc)
return fields.Datetime.to_string(fecha)
@property
def hash_type(self):
"""Easy way to select the kind of hash to use for get sello
......