Closed saud-2 closed 3 months ago
Hello,
We've previously tested against the sandbox environment and went live for customers on the production environment. We'll check whether there are issues on the simulation environment.
Do you get error details in the Error Log
list? If you have SSH access, you can also look for logs/zatca.log
inside the bench. It may contain more details.
No details in logs/zatca.log
2024-06-20 09:54:48,032 INFO zatca CSR config: csr.common.name=XXXXXXX csr.serial.number= 1-ERPNext|2-15|3-1 csr.organization.identifier=XXXXXXXXX csr.organization.unit.name=XXXXXXX csr.organization.name=XXXXXXXX csr.country.name=SA csr.invoice.type=1100 csr.location.address=XXXXXXXXXXX csr.industry.business.category=Retail 2024-06-20 09:54:48,047 INFO zatca Running: ['/home/frappe/frappe-bench/sites/zatca/zatca-cli/bin/zatca-cli', 'csr', '-c', '/tmp/tmp_802swor-csr-XXXXXXXXX.properties', '-o', 'XXXXXXXXXX.csr', '-k', 'XXXXXXXXX.privkey'] 2024-06-20 09:54:49,352 INFO zatca CSR generated successfully 2024-06-20 09:55:53,448 ERROR zatca An HTTP error occurred 2024-06-20 09:55:53,453 INFO zatca Response: {'code': 'Invalid-Request', 'message': 'System failed to process your request'}
even with sandbox environment . integration is done successfully however when I created new invoice become rejected and the reason was "requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://gw-fatoora.zatca.gov.sa/e-invoicing/developer-portal/invoices/reporting/single" and no error details in error log or zatca.log Note: OTP is from production portal there is no OTP for sandbox.
Sales Invoice Additional Fields
list to find the one generated for the rejected invoice. Switch to the validation tab and check if there are any errors. Validation errors could result in a 400 bad request. Note that the validation tab relies on having Validate Generated XML
enabled in the integration tab of ZATCA Business Settings
.399999999900003
if I recall correctly.[XSD] validation result : PASSED [EN] validation result : PASSED [KSA] validation result : PASSED [QR] validation result : PASSED [SIGNATURE] validation result : PASSED [PIH] validation result : PASSED *** GLOBAL VALIDATION RESULT = PASSED
VAT registration number 3XXXXXXXXX00003
Compliance Check Result
The result is accepted but in the same time there is error log.
Is there any error here?
There's no error in the compliance checks you're getting. They look fine.
The compliance check creates some invoices to submit to the compliance API then rolls them back. It uses the Error Log
table to store the responses in all cases, success or failure, because the tabError Log
table uses the MyISAM
non-transactional engine, so the logs are stored even after roll-back.
Validation looks fine too. If these are results from the sandbox API, then the problem causing 400 on invoice reporting would likely be that the VAT you're using is not the hard-coded VAT they use in the sandbox.
The VAT I'm using is 3XXXXXXXXX00003 . Is it applicable with sandbox ?
I don't think so. Please try 399999999900003
من: Saud @.> تم الإرسال: Monday, June 24, 2024 1:10:07 AM إلى: lavaloon-eg/ksa_compliance @.> نسخة: Muhammad Haggag @.>; Comment @.> الموضوع: Re: [lavaloon-eg/ksa_compliance] Integration error (Issue #62)
The VAT I'm using is 3XXXXXXXXX00003 . Is it applicable with sandbox ?
— Reply to this email directly, view it on GitHubhttps://github.com/lavaloon-eg/ksa_compliance/issues/62#issuecomment-2185338465, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AALG35G2SWSYBBIQSZ7AQXDZI5BT7AVCNFSM6AAAAABJRRB3UOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBVGMZTQNBWGU. You are receiving this because you commented.Message ID: @.***>
I tried this one 399999999900003 and it is accepted but mine not and it is same code 3xxxxxxxxx00003. how to fix it ?
The sandbox is mainly used to make sure your invoices and configuration is supported by the app; i.e. it leads to valid invoices accepted by ZATCA. Thus, it doesn't really allow you to specify your own VAT and test with it. That's what the simulation environment is for.
If the invoice configurations you produce are limited, you can verify them all on the sandbox and then go live (production).
In the mean time, I will consult our quality team to see if they've checked the simulation environment and get back to you.
There's a fix on the development branch (develop
) for the simulation environment if you'd like to give it a try. It's in version 0.20.1
, but also relies on CLI version 2.0.1
. If you want to give it a try:
0.20.1
by switching to develop
I don't know how to switch to develop. shall I uninstall master branch first then install develop branch ?
It depends on whether this is self-hosted or on frappe cloud. On frappe cloud, you go to the bench, switch to the "Apps" tab, click the "..." next to the app and select "Change Branch".
Make sure you're using a test instance or site, since the develop branch is for stuff that's under test. If you're not in a hurry, you can wait until next week when it'll be merged into master following testing and any fixes necessary
installed develop branch and in last step " Get Production CSID" I got attached error.
This is zatca.log
2024-06-28 11:45:32,914 INFO zatca Running: ['/home/frappe/frappe-bench/sites/zatca/zatca-cli/bin/zatca-cli', 'csr', '-c', '/tmp/tmpbmgvgji0-csr-310xxxxxxx00003.properties', '-o', '310xxxxxxx00003.csr', '-k', '310xxxxxxx00003.privkey'] 2024-06-28 11:45:33,492 INFO zatca CSR generated successfully 2024-06-28 11:46:28,784 ERROR zatca An HTTP error occurred: System failed to process your request 2024-06-28 11:46:28,784 INFO zatca Response: {"code":"Invalid-Request","message":"System failed to process your request"} 2024-06-28 11:47:55,281 ERROR zatca An HTTP error occurred: System failed to process your request 2024-06-28 11:47:55,282 INFO zatca Response: {"code":"Invalid-Request","message":"System failed to process your request"}
Is this on sandbox, simulation, or production environment? (developer-portal
, simulation
, or core
in the URL). For the simulation environment the CSR command should include a -s
flag to generate a simulation CSR, which doesn't seem to be the case here.
simulation. URL is https://gw-fatoora.zatca.gov.sa/e-invoicing/simulation/ OTP is from simulation portal . I don't type any command, I just put OTP.
Can you confirm that it's version 0.20.1? (from the help menu)
Perhaps we missed a step in the update on frappe cloud. I asked one of our frappe cloud admins and he said changing the branch on the bench should be followed up by updating the site itself. I'm not sure how to do that since I don't use frappe cloud much, I tend to work more with the self-hosted instances for our larger customers that don't fit on frappe cloud.
yes it's version is 0.20.1. and I am on self hosting not frappe cloud.
OK, good to know. Let's figure out why it's not detecting the simulation environment.
The code to detect the simulation environment is in apps/ksa_compliance/ksa_compliance/ksa_compliance/doctype/zatca_business_settings/zatca_business_settings.py
. Open the file with an editor (vim or nano) and look for is_simulation_environment
. It should be a property returning a boolean.
Next, we should try it out from python. Run bench console
, then run:
settings = frappe.get_last_doc('ZATCA Business Settings')
settings.is_simulation_server
(You can replace get_last_doc with get_doc('ZATCA Business Settings', 'name-of-your-settings')
if it's not the last document)
Does it properly report True
for your environment?
apps/ksa_compliance/ksa_compliance/ksa_compliance/doctype/zatca_business_settings/zatca_business_settings.py. Open the file with an editor (vim or nano) and look for is_simulation_environment. It should be a property returning a boolean.
@property def is_simulation_server(self) -> bool: return self.fatoora_server_url.startswith('https://gw-fatoora.zatca.gov.sa/e-invoicing/simulation')
settings = frappe.get_last_doc('ZATCA Business Settings')
-bash: syntax error near unexpected token `('
settings = frappe.get_last_doc('ZATCA Business Settings')
-bash: syntax error near unexpected token `('
You need to paste those commands into a python console run with bench console
. It should look something like this:
:~/frappe-bench/apps/ksa_compliance/ksa_compliance/ksa_compliance/doctype/zatca_business_settings$ bench console Apps in this namespace: frappe, erpnext
ProgrammingError Traceback (most recent call last) Cell In[1], line 1 ----> 1 settings = frappe.get_last_doc('ZATCA Business Settings')
File ~/frappe-bench/apps/frappe/frappe/init.py:1344, in get_last_doc(doctype, filters, order_by, for_update) 1342 def get_last_doc(doctype, filters=None, order_by="creation desc", *, for_update=False): 1343 """Get last created document of this type.""" -> 1344 d = get_all(doctype, filters=filters, limit_page_length=1, order_by=order_by, pluck="name") 1345 if d: 1346 return get_doc(doctype, d[0], for_update=for_update)
File ~/frappe-bench/apps/frappe/frappe/init.py:2057, in get_all(doctype, *args, *kwargs) 2055 if "limit_page_length" not in kwargs: 2056 kwargs["limit_page_length"] = 0 -> 2057 return get_list(doctype, args, **kwargs)
File ~/frappe-bench/apps/frappe/frappe/init.py:2032, in get_list(doctype, *args, kwargs)
2013 """List database query via frappe.model.db_query
. Will also check for permissions.
2014
2015 :param doctype: DocType on which query is to be made.
(...)
2028 frappe.get_list("ToDo", fields="", filters = [["modified", ">", "2014-01-01"]])
2029 """
2030 import frappe.model.db_query
-> 2032 return frappe.model.db_query.DatabaseQuery(doctype).execute(args, kwargs)
File ~/frappe-bench/apps/frappe/frappe/model/db_query.py:185, in DatabaseQuery.execute(self, fields, filters, or_filters, docstatus, group_by, order_by, limit_start, limit_page_length, as_list, with_childnames, debug, ignore_permissions, user, with_comment_count, join, distinct, start, page_length, limit, ignore_ifnull, save_user_settings, save_user_settings_fields, update, add_total_row, user_settings, reference_doctype, run, strict, pluck, ignore_ddl, parent_doctype) 175 kwargs = { 176 "as_list": as_list, 177 "with_comment_count": with_comment_count, (...) 181 "parent_doctype": parent_doctype, 182 } | self.dict 183 return controller.get_list(kwargs) --> 185 self.columns = self.get_table_columns() 187 # no table & ignore_ddl, return 188 if not self.columns:
File ~/frappe-bench/apps/frappe/frappe/model/db_query.py:546, in DatabaseQuery.get_table_columns(self) 544 def get_table_columns(self): 545 try: --> 546 return get_table_columns(self.doctype) 547 except frappe.db.TableMissingError: 548 if self.ignore_ddl:
File ~/frappe-bench/apps/frappe/frappe/model/meta.py:73, in get_table_columns(doctype) 72 def get_table_columns(doctype): ---> 73 return frappe.db.get_table_columns(doctype)
File ~/frappe-bench/apps/frappe/frappe/database/database.py:1197, in Database.get_table_columns(self, doctype) 1195 columns = self.get_db_table_columns("tab" + doctype) 1196 if not columns: -> 1197 raise self.TableMissingError("DocType", doctype) 1198 return columns
ProgrammingError: ('DocType', 'ZATCA Business Settings')
NameError Traceback (most recent call last) Cell In[2], line 1 ----> 1 settings.is_simulation_server
NameError: name 'settings' is not defined
In [3]:
(You can replace get_last_doc with get_doc('ZATCA Business Settings', 'name-of-your-settings') if it's not the last document)
:~/frappe-bench/apps/ksa_compliance/ksa_compliance/ksa_compliance/doctype/zatca_business_settings$ bench console Apps in this namespace: frappe, erpnext
ModuleNotFoundError Traceback (most recent call last) File ~/frappe-bench/apps/frappe/frappe/modules/utils.py:250, in load_doctype_module(doctype, module, prefix, suffix) 249 try: --> 250 doctype_python_modules[key] = frappe.get_module(module_name) 251 except ImportError as e:
File ~/frappe-bench/apps/frappe/frappe/init.py:1476, in get_module(modulename)
1475 """Returns a module object for given Python module name using importlib.import_module
."""
-> 1476 return importlib.import_module(modulename)
File /usr/lib/python3.11/importlib/init.py:126, in import_module(name, package) 125 level += 1 --> 126 return _bootstrap._gcd_import(name[level:], package, level)
File
File
File
File
File
File
File
ModuleNotFoundError: No module named 'frappe.core.doctype.zatca_business_settings'
The above exception was the direct cause of the following exception:
ImportError Traceback (most recent call last) Cell In[1], line 1 ----> 1 settings = frappe.get_doc('ZATCA Business Settings', 'Aziziya branch')
File ~/frappe-bench/apps/frappe/frappe/init.py:1333, in get_doc(*args, kwargs)
1316 """Return a frappe.model.document.Document
object of the given type and name.
1317
1318 :param arg1: DocType name as string or* document JSON.
(...)
1329
1330 """
1331 import frappe.model.document
-> 1333 doc = frappe.model.document.get_doc(args, **kwargs)
1335 # Replace cache if stale one exists
1336 if not kwargs.get("for_update") and (key := can_cache_doc(args)) and cache.exists(key):
File ~/frappe-bench/apps/frappe/frappe/model/document.py:83, in get_doc(*args, *kwargs) 80 else: 81 raise ValueError('"doctype" is a required key') ---> 83 controller = get_controller(doctype) 84 if controller: 85 return controller(args, **kwargs)
File ~/frappe-bench/apps/frappe/frappe/model/base_document.py:70, in get_controller(doctype) 68 site_controllers = frappe.controllers.setdefault(frappe.local.site, {}) 69 if doctype not in site_controllers: ---> 70 site_controllers[doctype] = import_controller(doctype) 72 return site_controllers[doctype]
File ~/frappe-bench/apps/frappe/frappe/model/base_document.py:95, in import_controller(doctype) 92 module = frappe.get_module(module_path) 94 else: ---> 95 module = load_doctype_module(doctype, modulename) 96 classname = doctype.replace(" ", "").replace("-", "") 98 class = getattr(module, classname, None)
File ~/frappe-bench/apps/frappe/frappe/modules/utils.py:254, in load_doctype_module(doctype, module, prefix, suffix)
252 msg = f"Module import failed for {doctype}, the DocType you're trying to open might be deleted."
253 msg += f"
Error: {e}"
--> 254 raise ImportError(msg) from e
256 return doctype_python_modules[key]
ImportError: Module import failed for ZATCA Business Settings, the DocType you're trying to open might be deleted.
Error: No module named 'frappe.core.doctype.zatca_business_settings'
NameError Traceback (most recent call last) Cell In[2], line 1 ----> 1 settings.is_simulation_server
NameError: name 'settings' is not defined
In [3]:
Apps in this namespace: frappe, erpnext
This seems to indicate ksa_compliance is not installed in that site. Do you have multiple sites on the bench?
yes I have two sites, I installed it in one site for testing .
In that case, you need to run bench --site name-of-your-site console
Apps in this namespace: frappe, erpnext, ksa_compliance
In [1]: settings = frappe.get_last_doc('ZATCA Business Settings')
In [2]: settings.is_simulation_server Out[2]: False
In [3]:
Apps in this namespace: frappe, erpnext, ksa_compliance
In [1]: settings = frappe.get_doc('ZATCA Business Settings', 'Aziziya branch')
In [2]: settings.is_simulation_server Out[2]: False
In [3]:
OK, so it's clearly not detecting it. Either the configured URL is wrong (perhaps it has leading whitespace?) or the URL in the code is wrong. Can you paste settings.fatoora_server_url
in the console after the settings = ...
line?
Apps in this namespace: frappe, erpnext, ksa_compliance
In [1]: settings = frappe.get_last_doc('ZATCA Business Settings')
In [2]: settings.fatoora_server_url Out[2]: ' https://gw-fatoora.zatca.gov.sa/e-invoicing/simulation/'
In [3]:
In [2]: settings.fatoora_server_url Out[2]: ' https://gw-fatoora.zatca.gov.sa/e-invoicing/simulation/' Out[2]: ' https://gw-fatoora.zatca.gov.sa/e-invoicing/simulation/'
There's a leading space in the configured URL, before the 'https'. Please remove that, and save the ZATCA Business Settings and try onboarding again.
yes you are right . there was a space before URL.
Now I am integrated
Thank you .
Thanks for reporting the issue and bearing with us until we resolved it. We'll be fixing the logic to automatically trim the URL before processing it to make sure this trip up someone else.
I completed the steps of integration with no issue until the last step ( get production CSID) I got the attached Error.
Regards