def _get_xml_file(self):
        if self.invoice_id.type == "out_invoice":
            xml_without_signature = global_functions.get_template_xml(
                self._get_invoice_values(),
                'Invoice')
        elif self.invoice_id.type == "out_refund" and self.invoice_id.refund_type == "credit":
            xml_without_signature = global_functions.get_template_xml(
                self._get_credit_note_values(),
                'CreditNote')
        elif self.invoice_id.type == "out_refund" and self.invoice_id.refund_type == "debit":
            xml_without_signature = global_functions.get_template_xml(
                self._get_debit_note_values(),
                'DebitNote')

        try:
            response = urlopen(self.company_id.signature_policy_url, timeout=2)

            if response.getcode() != 200:
                return False
        except:
            return False

        xml_with_signature = global_functions.get_xml_with_signature(
            xml_without_signature,
            self.company_id.signature_policy_url,
            self.company_id.signature_policy_description,
            self.company_id.certificate_file,
            self.company_id.certificate_password)

        return xml_with_signature
    def sent_zipped_file(self):
        if self.invoice_id.company_id.profile_execution_id == '1':
            SendBillAsync_values = self._get_SendBillAsync_values()
            xml_soap_with_signature = global_functions.get_xml_soap_with_signature(
                global_functions.get_template_xml(SendBillAsync_values,
                                                  'SendBillAsync'),
                SendBillAsync_values['Id'],
                self.invoice_id.company_id.certificate_file,
                self.invoice_id.company_id.certificate_password)
        elif self.invoice_id.company_id.profile_execution_id == '2':
            SendTestSetAsync_values = self._get_SendTestSetAsync_values()
            xml_soap_with_signature = global_functions.get_xml_soap_with_signature(
                global_functions.get_template_xml(SendTestSetAsync_values,
                                                  'SendTestSetAsync'),
                SendTestSetAsync_values['Id'],
                self.invoice_id.company_id.certificate_file,
                self.invoice_id.company_id.certificate_password)

        response = post(
            DIAN['wsdl'],
            headers={'content-type': 'application/soap+xml;charset=utf-8'},
            data=etree.tostring(xml_soap_with_signature))

        if response.status_code == 200:
            b = "http://schemas.datacontract.org/2004/07/UploadDocumentResponse"

            root = etree.fromstring(response.text)

            for element in root.iter("{%s}ZipKey" % b):
                self.write({'zip_key': element.text})
        else:
            raise ValidationError(response.status_code)
示例#3
0
    def action_SendBillAttachmentAsync(self):
        b = "http://schemas.datacontract.org/2004/07/UploadDocumentResponse"
        wsdl = DIAN['wsdl-hab']

        if self.company_id.profile_execution_id == '1':
            wsdl = DIAN['wsdl']

        SendBillAttachmentAsync_values = self._get_SendBillAttachmentAsync_values(
        )
        SendBillAttachmentAsync_values['To'] = wsdl.replace('?wsdl', '')
        xml_soap_with_signature = global_functions.get_xml_soap_with_signature(
            global_functions.get_template_xml(SendBillAttachmentAsync_values,
                                              'SendBillAttachmentAsync'),
            SendBillAttachmentAsync_values['Id'],
            self.company_id.certificate_file,
            self.company_id.certificate_password)

        response = post(
            wsdl,
            headers={'content-type': 'application/soap+xml;charset=utf-8'},
            data=etree.tostring(xml_soap_with_signature))

        if response.status_code == 200:
            root = etree.fromstring(response.text)

            #raise Warning(response.text)

        return True
示例#4
0
    def action_GetStatusZip(self):
        wsdl = DIAN['wsdl-hab']

        if self.company_id.profile_execution_id == '1':
            wsdl = DIAN['wsdl']

        GetStatusZip_values = self._get_GetStatusZip_values()
        GetStatusZip_values['To'] = wsdl.replace('?wsdl', '')
        xml_soap_with_signature = global_functions.get_xml_soap_with_signature(
            global_functions.get_template_xml(GetStatusZip_values,
                                              'GetStatusZip'),
            GetStatusZip_values['Id'], self.company_id.certificate_file,
            self.company_id.certificate_password)

        response = post(
            wsdl,
            headers={'content-type': 'application/soap+xml;charset=utf-8'},
            data=etree.tostring(xml_soap_with_signature))

        if response.status_code == 200:
            self._get_status_response(response)
        else:
            raise ValidationError(response.status_code)

        return True
    def _get_GetStatus(self, send_mail):
        msg1 = _("Unknown Error,\nStatus Code: %s,\nReason: %s"
                 "\n\nContact with your administrator.")
        msg2 = _("Unknown Error: %s\n\nContact with your administrator.")
        wsdl = DIAN['wsdl-hab']

        if self.company_id.profile_execution_id == '1':
            wsdl = DIAN['wsdl']

        GetStatus_values = self._get_GetStatus_values()
        GetStatus_values['To'] = wsdl.replace('?wsdl', '')
        xml_soap_with_signature = global_functions.get_xml_soap_with_signature(
            global_functions.get_template_xml(GetStatus_values, 'GetStatus'),
            GetStatus_values['Id'],
            self.company_id.certificate_file,
            self.company_id.certificate_password)

        try:
            response = post(
                wsdl,
                headers={'content-type': 'application/soap+xml;charset=utf-8'},
                data=etree.tostring(xml_soap_with_signature))

            if response.status_code == 200:
                return self._get_status_response(response, send_mail)
            else:
                raise ValidationError(msg1 % (response.status_code, response.reason))
        except exceptions.RequestException as e:
            raise ValidationError(msg2 % (e))
示例#6
0
    def _get_xml_file(self):
        if self.invoice_id.type == "out_invoice":
            xml_without_signature = global_functions.get_template_xml(
                self._get_invoice_values(), 'Invoice')
        elif self.invoice_id.type == "out_refund" and self.invoice_id.refund_type == "credit":
            xml_without_signature = global_functions.get_template_xml(
                self._get_credit_note_values(), 'CreditNote')
        elif self.invoice_id.type == "out_refund" and self.invoice_id.refund_type == "debit":
            xml_without_signature = global_functions.get_template_xml(
                self._get_debit_note_values(), 'DebitNote')

        xml_with_signature = global_functions.get_xml_with_signature(
            xml_without_signature, self.company_id.signature_policy_url,
            self.company_id.signature_policy_description,
            self.company_id.certificate_file,
            self.company_id.certificate_password)

        return xml_with_signature
    def _get_xml_file(self):
        xml_without_signature = global_functions.get_template_xml(
            self._get_xml_values(), 'generic_invoice')
        xml_with_signature = global_functions.get_xml_with_signature(
            xml_without_signature,
            self.invoice_id.company_id.signature_policy_url,
            self.invoice_id.company_id.signature_policy_description,
            self.invoice_id.company_id.certificate_file,
            self.invoice_id.company_id.certificate_password)

        return xml_with_signature
    def GetStatusZip(self):
        GetStatusZip_values = self._get_GetStatusZip_values()
        xml_soap_with_signature = global_functions.get_xml_soap_with_signature(
            global_functions.get_template_xml(GetStatusZip_values,
                                              'GetStatusZip'),
            GetStatusZip_values['Id'],
            self.invoice_id.company_id.certificate_file,
            self.invoice_id.company_id.certificate_password)

        response = post(
            DIAN['wsdl'],
            headers={'content-type': 'application/soap+xml;charset=utf-8'},
            data=etree.tostring(xml_soap_with_signature))

        if response.status_code == 200:
            self.write({'get_status_zip_response': response.text})
        else:
            raise ValidationError(response.status_code)
示例#9
0
    def action_GetNumberingRange(self):
        msg1 = _("Unknown Error,\nStatus Code: %s,\nReason: %s.")
        msg2 = _("Unknown Error: %s\n.")
        wsdl = 'https://vpfe.dian.gov.co/WcfDianCustomerServices.svc?wsdl'
        s = "http://www.w3.org/2003/05/soap-envelope"

        GetNumberingRange_values = self._get_GetNumberingRange_values()
        GetNumberingRange_values['To'] = wsdl.replace('?wsdl', '')
        xml_soap_with_signature = global_functions.get_xml_soap_with_signature(
            global_functions.get_template_xml(GetNumberingRange_values,
                                              'GetNumberingRange'),
            GetNumberingRange_values['Id'], self.certificate_file,
            self.certificate_password)

        try:
            response = post(
                wsdl,
                headers={'content-type': 'application/soap+xml;charset=utf-8'},
                data=etree.tostring(xml_soap_with_signature))

            if response.status_code == 200:
                root = etree.fromstring(response.text)
                response = ''

                for element in root.iter("{%s}Body" % s):
                    response = etree.tostring(element, pretty_print=True)

                if response == '':
                    response = etree.tostring(root, pretty_print=True)

                self.write({'get_numbering_range_response': response})
            else:
                raise ValidationError(msg1 %
                                      (response.status_code, response.reason))

        except exceptions.RequestException as e:
            raise ValidationError(msg2 % (e))

        return True
示例#10
0
    def action_sent_zipped_file(self):
        msg1 = _(
            "Unknown Error,\nStatus Code: %s,\nReason: %s,\n\nContact with your administrator "
            "or you can choose a journal with a Contingency Checkbook E-Invoicing sequence "
            "and change the Invoice Type to 'Factura por Contingencia Facturador'."
        )
        msg2 = _(
            "Unknown Error: %s\n\nContact with your administrator "
            "or you can choose a journal with a Contingency Checkbook E-Invoicing sequence "
            "and change the Invoice Type to 'Factura por Contingencia Facturador'."
        )
        b = "http://schemas.datacontract.org/2004/07/UploadDocumentResponse"
        wsdl = DIAN['wsdl-hab']

        if self.company_id.profile_execution_id == '1':
            wsdl = DIAN['wsdl']
            SendBillAsync_values = self._get_SendBillAsync_values()
            SendBillAsync_values['To'] = wsdl.replace('?wsdl', '')
            xml_soap_with_signature = global_functions.get_xml_soap_with_signature(
                global_functions.get_template_xml(SendBillAsync_values,
                                                  'SendBillSync'),
                SendBillAsync_values['Id'], self.company_id.certificate_file,
                self.company_id.certificate_password)
        else:
            SendTestSetAsync_values = self._get_SendTestSetAsync_values()
            SendTestSetAsync_values['To'] = wsdl.replace('?wsdl', '')
            xml_soap_with_signature = global_functions.get_xml_soap_with_signature(
                global_functions.get_template_xml(SendTestSetAsync_values,
                                                  'SendTestSetAsync'),
                SendTestSetAsync_values['Id'],
                self.company_id.certificate_file,
                self.company_id.certificate_password)

        try:
            response = post(
                wsdl,
                headers={'content-type': 'application/soap+xml;charset=utf-8'},
                data=etree.tostring(xml_soap_with_signature))

            if response.status_code == 200:
                if self.company_id.profile_execution_id == '1':
                    self._get_status_response(response)
                else:
                    root = etree.fromstring(response.text)

                    for element in root.iter("{%s}ZipKey" % b):
                        self.write({'zip_key': element.text, 'state': 'sent'})
                        self.action_GetStatusZip()
            elif response.status_code in (500, 503, 507):
                dian_document_line_obj = self.env[
                    'account.invoice.dian.document.line']
                dian_document_line_obj.create({
                    'dian_document_id':
                    self.id,
                    'send_async_status_code':
                    response.status_code,
                    'send_async_reason':
                    response.reason,
                    'send_async_response':
                    response.text
                })
            else:
                raise ValidationError(msg1 %
                                      (response.status_code, response.reason))
        except exceptions.RequestException as e:
            raise ValidationError(msg2 % (e))

        return True
 def _get_ad_xml_file(self):
     return global_functions.get_template_xml(
         self._get_ad_xml_values(),
         'AttachedDocument')