Announcing the launch of the Saudi Zatca-2 E-Invoicing app on FrappeCloud

Hi Team,

This query is regarding the implementation of ZATCA KSA E-Invoicing.

I have gone through the video uploaded on YouTube and installed the Zatca app.

While configuring, I am unable to figure out the CSR Config part.

Could you please guide me on how to generate/create the CSR Config file and upload to the ERPNext.

CSR configuration should be in JSON format. See the above replies
CSR Conf

Zatca E-Invoicing Update


We have added a CR number field on the Company setting, it is requirement from Zatca

Please do the following on app/zatca_erpgulf folder

git pull

bench --site yoursitename migrate

bench restart

It will create a field called company registration in the company doctype. Enter CR Number there. ( Not VAT ID )

Error in complaince: {“validationResults”:{“infoMessages”:[{“type”:“INFO”,“code”:“XSD_ZATCA_VALID”,“category”:“XSD validation”,“message”:“Complied with UBL 2.1 standards in line with ZATCA specifications”,“status”:“PASS”}],“warningMessages”:[{“type”:“WARNING”,“code”:“BR-KSA-08”,“category”:“KSA”,“message”:“The seller identification (BT-29) must exist only once with one of the scheme ID (BT-29-1) (CRN, MOM, MLS, SAG, OTH, 700) and must contain only alphanumeric characters. Commercial Registration number with "CRN" as schemeID. Momrah license with "MOM" as schemeID. MHRSD license with "MLS" as schemeID. 700 Number with "700" as schemeID. MISA license with "SAG" as schemeID . Other OD with "OTH" as schemeID.In case of multiple commercial registrations, the seller should fill the commercial registration of the branch in respect of which the Tax Invoice is being issued. In case multiple IDs exist then one of the above must be entered following the sequence specified above.”,“status”:“WARNING”}],“errorMessages”:,“status”:“WARNING”},“reportingStatus”:“REPORTED”,“clearanceStatus”:null,“qrSellertStatus”:null,“qrBuyertStatus”:null}

If you get this error, you missed the CR number on Company settings.
There should be VAT number and CR number on company doctype.
We have added a custom field for CR on company doctype, pull the latest code.

@Support-at-ERPgulf while creating csr i am getting an error that

TypeError: create_csr() missing 1 required positional argument: 'company_abbr'
{
  "data": [
    {
      "company": "TT",
      "csr_config": {
      "csr.common.name": "TST-886431145-300970199900003",
      "csr.serial.number": "1-TST|2-TST|3-ed22f1d8-e6a2-1119-9b58-d9a9f11e874f",
      "csr.organization.identifier": "300990908800003",
      "csr.organization.unit.name": "300990908800003",
      "csr.organization.name": "Your Company name",
      "csr.country.name": "KSA",
      "csr.invoice.type": "1100",
      "csr.location.address": "RIYADH",
      "csr.industry.business.category": "Your company activities"
     }
    }
  ]
}

here is the csr configuration. @Zaid_Zaidu any idea?

Can you check selected company abbr in the company is same as in csr config ?

@Zaid_Zaidu when i checked the code of zatca_erpgulf

    create_csr: function (frm) {
        frappe.call({
            method: "zatca_erpgulf.zatca_erpgulf.sign_invoice.create_csr",
            args: {
                "portal_type":  frm.doc.select
            },
            callback: function (r) {
                if (!r.exc) {
                    frm.save();
                }
            },
        });
    },

there is no argument is passed in the code.
also i have this error i all the functions.
here is my screenshots




@Support-at-ERPgulf can anyone please explain this error.

@Support-at-ERPgulf @Zaid_Zaidu one more thing i want to know is that on saving the zatca erpgulf settings is the values are storing to any table in the database? but i got only zatca_success_log table on bench get-app zatca_erpgulf repo. Another this is that in the code functions of sign_invoice.py i can see many custom fields are being checked with company_doc where i dont have that fields added in my company table too. Is the fields are coming from the zatca_erpgulf on saving the settings? should i need to create fields in database? can anybody help in these doubts and clarify to me? @saud1 @rainoharvest @Ahmed01 @Usama_Naveed anyone please who have finished zatca phase 2 implementation.

any news.

In the new update, we have moved the Zatca setting to the company doctype and don’t use JSON format for the setting page fields. We hope this will reduce the confusion that many in this group complained about.

The Zatca setting page is still there, but it’s just for backward compatibility.

You can put CSR configuration on the Company page without JSON, as shown below.

csr.common.name=TST-886431145-399999999900003
csr.serial.number=1-TST|2-TST|3-ed22f1d8-e6a2-1118-9b58-d9a8f11e874f
csr.organization.identifier=399999999900003
csr.organization.unit.name=399999999900003
csr.organization.name=Test Company LTD
csr.country.name=SA
csr.invoice.type=1100
csr.location.address=RIYADH
csr.industry.business.category=Testing zatca

Also fixed some rounding issues.

Thanks for your feedback and suggestions.

See the latest update here.

See the latest update. No need to use ABBR or JSON format.

@Support-at-ERPgulf Thanks For your response will check with new updated repository.

@Support-at-ERPgulf May i know which are the fields that are taking for building number,street name etc for this zatca phase 2, currently we dont have fields like this right?

Give it on Address line 1 and 2 , we are using it for zatca
make sure PO Box number is 5 digits and valid.

@Support-at-ERPgulf Thank you very much for your valuable response. Just now i have done all the process of zatca and complaince check also get successfull. And all the files got generated too. I have just one more doubt on the xml file.

</cac:Signature><cac:AccountingSupplierParty>
    <cac:Party>
      <cac:PartyIdentification>
        <cbc:ID schemeID="CRN">3578964215</cbc:ID>
      </cac:PartyIdentification>
      <cac:PostalAddress>
        <cbc:StreetName>Near al thamam</cbc:StreetName>
        <cbc:BuildingNumber>6819</cbc:BuildingNumber>
        <cbc:PlotIdentification>Near al thamam</cbc:PlotIdentification>
        <cbc:CitySubdivisionName>no.97</cbc:CitySubdivisionName>
        <cbc:CityName>Jubail</cbc:CityName>
        <cbc:PostalZone>89654</cbc:PostalZone>
        <cbc:CountrySubentity>Eastern Province</cbc:CountrySubentity>
        <cac:Country>
          <cbc:IdentificationCode>SA</cbc:IdentificationCode>
        </cac:Country>
      </cac:PostalAddress>
      <cac:PartyTaxScheme>
        <cbc:CompanyID>399999999900003</cbc:CompanyID>
        <cac:TaxScheme>
          <cbc:ID>VAT</cbc:ID>
        </cac:TaxScheme>
      </cac:PartyTaxScheme>
      <cac:PartyLegalEntity>
        <cbc:RegistrationName>Duplex Solutions (Demo)</cbc:RegistrationName>
      </cac:PartyLegalEntity>
    </cac:Party>
  </cac:AccountingSupplierParty>

here i can see a building number for company has generated with 6819 which column is selected for this in address. where i cannot see this number which is not entered by me.

for address in address_list:
                    cac_PostalAddress = ET.SubElement(cac_Party_1, "cac:PostalAddress")
                    cbc_StreetName = ET.SubElement(cac_PostalAddress, "cbc:StreetName")
                    cbc_StreetName.text = address.address_line1
                    cbc_BuildingNumber = ET.SubElement(cac_PostalAddress, "cbc:BuildingNumber")
                    cbc_BuildingNumber.text = "6819"
                    cbc_PlotIdentification = ET.SubElement(cac_PostalAddress, "cbc:PlotIdentification")
                    cbc_PlotIdentification.text =  address.address_line1
                    cbc_CitySubdivisionName = ET.SubElement(cac_PostalAddress, "cbc:CitySubdivisionName")
                    cbc_CitySubdivisionName.text = address.address_line2
                    cbc_CityName = ET.SubElement(cac_PostalAddress, "cbc:CityName")
                    cbc_CityName.text = address.city
                    cbc_PostalZone = ET.SubElement(cac_PostalAddress, "cbc:PostalZone")
                    cbc_PostalZone.text = address.pincode
                    cbc_CountrySubentity = ET.SubElement(cac_PostalAddress, "cbc:CountrySubentity")
                    cbc_CountrySubentity.text = address.state
                    break

here in the code i can see that building number is given as static also.

Its a bug, will change the code to take it from Address-line-2 and push again later today.

@Support-at-ERPgulf While validating b2c sales invoice xml file through zatca sandbox xml testing portal got errors that

E-invoice-ACC-SINV-2024-00010.xml

Valid : false

Errors
category : QR_CODE_ERROR
code :QRCODE_INVALID
message : Invalid QR code format, Please follow the ZATCA QR code specifications
category : SIGNATURE_ERROR
code :invoiceSignedDataDigestValue
message : wrong invoice hashing
category : SIGNATURE_ERROR
code :X509IssuerName
message : wrong X509IssuerName  
category : XSD_SCHEMA_ERROR
code :SAXParseException
message : Schema validation failed; XML does not comply with UBL 2.1 standards in line with ZATCA specifications. ERROR: org.xml.sax.SAXParseException; lineNumber: 90; columnNumber: 124; cvc-datatype-valid.1.2.1: 'GsiuvGjvchjbFhibcDhjv1886G' is not a valid value for 'base64Binary'.
category : SIGNATURE_ERROR
code :xadesSignedPropertiesDigestValue
message : wrong xadesSignedPropertiesDigestValue  
category : SIGNATURE_ERROR
code :X509SerialNumber
message : wrong X509SerialNumber  
category : SIGNATURE_ERROR
code :signatureValue
message : wrong signature Value 

Is it still under development?

Its bcs you generated with sandbox csr and testing on validation portal.

Post directly to zatca from your invoice screen and if you get any error or warning, post it here