...
 
Commits (7)
<a name="2.5.0"></a>
## 2.5.0 (2019-09-23)
#### Feature
* **base.cfdi:** agrega campo cfdi_adenda_id en ir.attachment.facturae y lo copia desde el cfdi.base ([847a08ca](847a08ca))
* **ir.attachment.facturae.mx:**
* agrega posibilidad de manejar complementos en generacion de addendas ([06bce156](06bce156))
* agrega funcion de renderizado del reporte asociado a la Addenda ([06f94a47](06f94a47))
<a name="2.4.1"></a>
## 2.4.1 (2019-08-21)
......
......@@ -2,7 +2,7 @@
{
"name": "CFDI",
"version": "2.5.0",
"version": "2.6.0",
"author": "OpenPyme",
"category": "Localization/Mexico",
"website": "http://www.openpyme.mx/",
......
......@@ -87,6 +87,13 @@ class BaseCfdi(models.AbstractModel):
copy=False,
help="Original CFDI to which this CFDI is referred to",
)
cfdi_adenda_id = fields.Many2one(
"cfdi.adenda",
"Addendum",
readonly=True,
states={"draft": [("readonly", False)]},
help="Select addendum node to use on this CFDI."
)
@api.one
def create_cfdi(self):
......@@ -98,6 +105,7 @@ class BaseCfdi(models.AbstractModel):
"res_id": self.id,
"type_attachment": self._name,
"company_id": self.company_id.id,
"cfdi_adenda_id": self.cfdi_adenda_id.id or None,
}
)
self.cfdi_id.action_validate()
......
......@@ -11,6 +11,7 @@ from lxml import etree as ET # noqa
from pytz import timezone, utc
from requests import Request, Session
from requests.exceptions import HTTPError
from xml.dom import minidom
from xml.sax.saxutils import escape
import M2Crypto as m2
......@@ -237,6 +238,13 @@ class IrAttachmentFacturaeMx(models.Model):
rfc_receptor = fields.Char(compute="_compute_vat_numbers")
total = fields.Float(compute="_compute_total")
version_timbre = fields.Char(compute="_compute_version_timbre")
cfdi_adenda_id = fields.Many2one(
"cfdi.adenda",
"Addendum",
readonly=True,
states={"draft": [("readonly", False)]},
help="Addenda used for this cfdi."
)
@api.one
@api.depends("cfdi_type", "type_attachment")
......@@ -771,16 +779,61 @@ class IrAttachmentFacturaeMx(models.Model):
)
return result
@api.multi
def create_report_adenda(self):
""" Create Addenda for XML """
self.ensure_one()
record = self.env[self.type_attachment].browse(self.res_id)
adenda = self.cfdi_adenda_id
result = ""
if adenda:
report_name = adenda.report_id.report_name
result = self.create_report(record.id, report_name, record._name)
_logger.debug("Addenda before attach to XML: %s", result.decode("UTF-8"))
return result
@api.multi
def create_report_xml(self):
""" Create XML report and sign with company certificates"""
self.ensure_one()
config = self.config_id
record = self.env[self.type_attachment].browse(self.res_id)
# Render XML into string
result = self.create_report(record.id, config.template_xml_sign, record._name)
# Convert string to XML
# Adjunta Addenda al XML
if self.cfdi_adenda_id:
adenda = self.cfdi_adenda_id
result_adenda = self.create_report_adenda()
document = minidom.parseString(result)
node_comprobante = document.documentElement
a_document = minidom.parseString(result_adenda.strip())
adenda_content = a_document.documentElement
if adenda.xml_prefix and adenda.xml_ns and adenda.xml_xsd:
# Si estan definidos los campos de Namespace,
# entonces es un cfdi:Complemento
node_name = "cfdi:Complemento"
xsi_schemans = "http://www.w3.org/2001/XMLSchema-instance"
ns_xmlns = "http://www.w3.org/2000/xmlns/"
ns_xsd_sat = node_comprobante.getAttribute("xsi:schemaLocation")
# Se agregan los Namespaces
node_comprobante.setAttributeNS(
xsi_schemans,
"xsi:schemaLocation",
"%s %s %s" % (ns_xsd_sat, adenda.xml_ns, adenda.xml_xsd)
)
node_comprobante.setAttributeNS(
ns_xmlns, adenda.xml_prefix, adenda.xml_ns
)
else:
# Caso contrario, entonces es una cfdi:Addenda
node_name = "cfdi:Addenda"
node_adenda = document.createElement(node_name)
node_adenda.appendChild(adenda_content)
node_comprobante.appendChild(node_adenda)
result = document.toxml(encoding="UTF-8")
xml_data = parse_xml_string(result.strip())
xml_data = self.sign_xml(xml_data=xml_data)
# Create XML attachment
......
......@@ -36,6 +36,7 @@
<field name="company_id"/>
<field name="file_xml_sign"/>
<field name="file_pdf"/>
<field name="cfdi_adenda_id"/>
</group>
</sheet>
<div class="oe_chatter">
......