Beispiel #1
0
    def _get_xml_values(self, ClTec):
        msg1 = _("'%s' does not have a valid isic code")
        msg2 = _("'%s' does not have a isic code established.")
        supplier = self.company_id.partner_id

        if supplier.isic_id:
            if supplier.isic_id.code == '0000':
                raise UserError(msg1 % supplier.name)
        else:
            raise UserError(msg2 % supplier.name)

        NitOFE = supplier.identification_document
        IdSoftware = self.company_id.software_id
        SoftwarePIN = self.company_id.software_pin
        ID = self.invoice_id.number
        software_security_code = global_functions.get_software_security_code(
            IdSoftware, SoftwarePIN, ID)
        TipoAmbie = self.company_id.profile_execution_id
        customer = self.invoice_id.partner_id
        NitAdq = customer.identification_document
        document_type_code = False

        if customer.document_type_id:
            document_type_code = customer.document_type_id.code

        if document_type_code not in ('11', '12', '13', '21', '22', '31', '41',
                                      '42', '50', '91'):
            if customer.person_type == '2':
                NitAdq = '2222222222'

        if TipoAmbie == '1':
            QRCodeURL = DIAN['catalogo']
        else:
            QRCodeURL = DIAN['catalogo-hab']

        create_date = datetime.strptime(self.invoice_id.create_date,
                                        '%Y-%m-%d %H:%M:%S')
        create_date = create_date.replace(tzinfo=timezone('UTC'))
        IssueDate = self.invoice_id.date_invoice
        IssueTime = create_date.astimezone(
            timezone('America/Bogota')).strftime('%H:%M:%S-05:00')
        ValFac = self.invoice_id.amount_untaxed
        einvoicing_taxes = self.invoice_id._get_einvoicing_taxes()
        ValImp1 = einvoicing_taxes['TaxesTotal']['01']['total']
        ValImp2 = einvoicing_taxes['TaxesTotal']['04']['total']
        ValImp3 = einvoicing_taxes['TaxesTotal']['03']['total']
        ValOtroIm = ValImp2 - ValImp3
        TaxInclusiveAmount = ValFac + ValImp1 + ValImp2 + ValImp3
        #El valor a pagar puede verse afectado, por anticipos, y descuentos y
        #cargos a nivel de factura
        PayableAmount = TaxInclusiveAmount
        cufe_cude = global_functions.get_cufe_cude(
            ID, IssueDate, IssueTime, str('{:.2f}'.format(ValFac)), '01',
            str('{:.2f}'.format(ValImp1)), '04', str('{:.2f}'.format(ValImp2)),
            '03', str('{:.2f}'.format(ValImp3)),
            str('{:.2f}'.format(TaxInclusiveAmount)), NitOFE, NitAdq, ClTec,
            SoftwarePIN, TipoAmbie)
        partition_key = 'co|' + IssueDate.split(
            '-')[2] + '|' + cufe_cude['CUFE/CUDE'][:2]
        emission_date = IssueDate.replace('-', '')
        QRCodeURL = QRCodeURL.format(cufe_cude['CUFE/CUDE'], partition_key,
                                     emission_date)

        self.write({
            'invoice_url':
            QRCodeURL,
            'cufe_cude_uncoded':
            cufe_cude['CUFE/CUDEUncoded'],
            'cufe_cude':
            cufe_cude['CUFE/CUDE'],
            'software_security_code_uncoded':
            software_security_code['SoftwareSecurityCodeUncoded'],
            'software_security_code':
            software_security_code['SoftwareSecurityCode']
        })

        return {
            'ProviderIDschemeID':
            supplier.check_digit,
            'ProviderIDschemeName':
            supplier.document_type_id.code,
            'ProviderID':
            NitOFE,
            'SoftwareID':
            IdSoftware,
            'SoftwareSecurityCode':
            software_security_code['SoftwareSecurityCode'],
            'NitAdquiriente':
            NitAdq,
            'QRCodeURL':
            QRCodeURL,
            'ProfileExecutionID':
            TipoAmbie,
            'ID':
            ID,
            'UUID':
            cufe_cude['CUFE/CUDE'],
            'IssueDate':
            IssueDate,
            'IssueTime':
            IssueTime,
            'ValIva':
            '{:.2f}'.format(ValImp1),
            'ValOtroIm':
            '{:.2f}'.format(ValOtroIm),
            'DueDate':
            self.invoice_id.date_due,
            'DocumentCurrencyCode':
            self.invoice_id.currency_id.name,
            'LineCountNumeric':
            len(self.invoice_id.invoice_line_ids),
            'IndustryClassificationCode':
            supplier.isic_id.code,
            'AccountingSupplierParty':
            supplier._get_accounting_partner_party_values(),
            'AccountingCustomerParty':
            customer._get_accounting_partner_party_values(),
            'Delivery':
            customer._get_delivery_values(),
            'DeliveryTerms': {
                'LossRiskResponsibilityCode': False,
                'LossRisk': False
            },
            'PaymentMeansID':
            self.invoice_id.payment_mean_id.code,
            'PaymentMeansCode':
            self.invoice_id.payment_mean_code_id.code,
            'PaymentDueDate':
            self.invoice_id.date_due,
            'PaymentExchangeRate':
            self.invoice_id._get_payment_exchange_rate(),
            'TaxesTotal':
            einvoicing_taxes['TaxesTotal'],
            'WithholdingTaxesTotal':
            einvoicing_taxes['WithholdingTaxesTotal'],
            'LineExtensionAmount':
            '{:.2f}'.format(self.invoice_id.amount_untaxed),
            'TaxExclusiveAmount':
            '{:.2f}'.format(self.invoice_id.amount_untaxed),
            'TaxInclusiveAmount':
            '{:.2f}'.format(TaxInclusiveAmount),
            'PayableAmount':
            '{:.2f}'.format(PayableAmount)
        }
    def _get_xml_values(self):
        active_dian_resolution = self.invoice_id._get_active_dian_resolution()
        einvoicing_taxes = self.invoice_id._get_einvoicing_taxes()
        create_date = datetime.strptime(self.invoice_id.create_date,
                                        '%Y-%m-%d %H:%M:%S')
        create_date = create_date.replace(tzinfo=timezone('UTC'))
        ID = self.invoice_id.number
        IssueDate = self.invoice_id.date_invoice
        IssueTime = create_date.astimezone(
            timezone('America/Bogota')).strftime('%H:%M:%S-05:00')
        NitOFE = self.invoice_id.company_id.partner_id.identification_document
        NitAdq = self.invoice_id.partner_id.identification_document
        ClTec = False
        SoftwarePIN = False
        IdSoftware = self.invoice_id.company_id.software_id

        if self.invoice_id.type == 'out_invoice':
            ClTec = active_dian_resolution['technical_key']
        else:
            SoftwarePIN = self.invoice_id.company_id.software_pin

        ValFac = self.invoice_id.amount_untaxed
        ValImp1 = einvoicing_taxes['01']['total']
        ValImp2 = einvoicing_taxes['04']['total']
        ValImp3 = einvoicing_taxes['03']['total']
        ValTot = ValFac + ValImp1 + ValImp2 + ValImp3
        cufe_cude = global_functions.get_cufe_cude(
            ID,
            IssueDate,
            IssueTime,
            str('{:.2f}'.format(ValFac)),
            '01',
            str('{:.2f}'.format(ValImp1)),
            '04',
            str('{:.2f}'.format(ValImp2)),
            '03',
            str('{:.2f}'.format(ValImp3)),
            str('{:.2f}'.format(ValTot)),  #invoice.amount_total
            NitOFE,
            NitAdq,
            ClTec,
            SoftwarePIN,
            self.invoice_id.company_id.profile_execution_id)
        software_security_code = global_functions.get_software_security_code(
            IdSoftware, self.invoice_id.company_id.software_pin, ID)
        period_dates = global_functions.get_period_dates(IssueDate)

        self.write({
            'cufe_cude_uncoded':
            cufe_cude['CUFE/CUDEUncoded'],
            'cufe_cude':
            cufe_cude['CUFE/CUDE'],
            'software_security_code_uncoded':
            software_security_code['SoftwareSecurityCodeUncoded'],
            'software_security_code':
            software_security_code['SoftwareSecurityCode']
        })

        return {
            'InvoiceAuthorization':
            active_dian_resolution['resolution_number'],
            'StartDate':
            active_dian_resolution['date_from'],
            'EndDate':
            active_dian_resolution['date_to'],
            'Prefix':
            active_dian_resolution['prefix'],
            'From':
            active_dian_resolution['number_from'],
            'To':
            active_dian_resolution['number_to'],
            'ProviderIDschemeID':
            self.invoice_id.company_id.partner_id.check_digit,
            'ProviderIDschemeName':
            self.invoice_id.company_id.partner_id.document_type_id.code,
            'ProviderID':
            NitOFE,
            'NitAdquiriente':
            NitAdq,
            'SoftwareID':
            IdSoftware,
            'SoftwareSecurityCode':
            software_security_code['SoftwareSecurityCode'],
            'ProfileExecutionID':
            self.invoice_id.company_id.profile_execution_id,
            'ID':
            ID,
            'UUID':
            cufe_cude['CUFE/CUDE'],
            'partitionKey':
            'co|' + IssueDate.split('-')[2] + '|' + cufe_cude['CUFE/CUDE'][:2],
            'emissionDate':
            IssueDate.replace('-', ''),
            'IssueDate':
            IssueDate,
            'IssueTime':
            IssueTime,
            'InvoiceTypeCode':
            '01',
            'LineCountNumeric':
            len(self.invoice_id.invoice_line_ids),
            'DocumentCurrencyCode':
            self.invoice_id.currency_id.name,
            'InvoicePeriodStartDate':
            period_dates['PeriodStartDate'],
            'InvoicePeriodEndDate':
            period_dates['PeriodEndDate'],
            'AccountingSupplierParty':
            self.invoice_id._get_accounting_supplier_party_values(),
            'AccountingCustomerParty':
            self.invoice_id._get_accounting_customer_party_values(),
            'TaxRepresentativeParty':
            self.invoice_id._get_tax_representative_party_values(),
            'PaymentMeansID':
            self.invoice_id.payment_mean_id.code,
            'PaymentMeansCode':
            '10',
            'PaymentDueDate':
            self.invoice_id.date_due,
            'PaymentID':
            'Efectivo',
            'TaxTotalIVA':
            einvoicing_taxes['01']['total'],
            'TaxSubtotalIVA':
            einvoicing_taxes['01']['taxes'],
            'TaxTotalICA':
            einvoicing_taxes['04']['total'],
            'TaxSubtotalICA':
            einvoicing_taxes['04']['taxes'],
            'TaxTotalINC':
            einvoicing_taxes['03']['total'],
            'TaxSubtotalINC':
            einvoicing_taxes['03']['taxes'],
            'LineExtensionAmount':
            '{:.2f}'.format(self.invoice_id.amount_untaxed),
            'TaxExclusiveAmount':
            '{:.2f}'.format(self.invoice_id.amount_untaxed),
            'TaxInclusiveAmount':
            '{:.2f}'.format(ValTot),  #self.invoice_id.amount_total
            'PrepaidAmount':
            '{:.2f}'.format(0),
            'PayableAmount':
            '{:.2f}'.format(ValTot),  #self.invoice_id.amount_total
            'InvoiceLines':
            self.invoice_id._get_invoice_lines()
        }