ERPNext 'b'VAT' syntax error with the WooCommerce Integration

ERPNext Version: 14.75.2
Frappe Version: 14.85.0
WooCommerce Connector Version: 1.7.0 (master)
Server: Ubuntu 22.04.5

I’m stumped as to what I need to do to fix this issue I’m facing, and hoping that someone with more knowledge can help me out. I have tried searching the forums, and Libracore’s github for answers to no avail.

The only changes to the master branch that I have changed is line 37 to 40 of sync_orders.py which doesn’t seem to be related to my issue.

                        if e.args and e.args[0] and e.args[0].startswith("402"):
                            raise e
                        else:
                            make_woocommerce_log(title=e.message if hasattr(e, 'message') else str(e), status="Error", method="sync_woocommerce_orders", message=frappe.get_traceback(),
                            request_data=woocommerce_order, exception=True)

Error Method

sync_woocommerce_resources

Message

Traceback (most recent call last):
  File "apps/woocommerceconnector/woocommerceconnector/sync_orders.py", line 30, in sync_woocommerce_orders
    create_order(woocommerce_order, woocommerce_settings)
  File "apps/woocommerceconnector/woocommerceconnector/sync_orders.py", line 164, in create_order
    so = create_sales_order(woocommerce_order, woocommerce_settings, company)
  File "apps/woocommerceconnector/woocommerceconnector/sync_orders.py", line 211, in create_sales_order
    "taxes": get_order_taxes(woocommerce_order, woocommerce_settings),
  File "apps/woocommerceconnector/woocommerceconnector/sync_orders.py", line 362, in get_order_taxes
    "account_head": get_tax_account_head(woocommerce_tax),
  File "apps/woocommerceconnector/woocommerceconnector/sync_orders.py", line 426, in get_tax_account_head
    tax_account =  frappe.db.get_value("woocommerce Tax Account", \
  File "apps/frappe/frappe/database/database.py", line 568, in get_value
    result = self.get_values(
  File "apps/frappe/frappe/database/database.py", line 672, in get_values
    out = self._get_values_from_table(
  File "apps/frappe/frappe/database/database.py", line 910, in _get_values_from_table
    return query.run(as_dict=as_dict, debug=debug, update=update, run=run, pluck=pluck)
  File "apps/frappe/frappe/query_builder/utils.py", line 87, in execute_query
    result = frappe.db.sql(query, params, *args, **kwargs)  # nosemgrep
  File "apps/frappe/frappe/database/database.py", line 244, in sql
    self._cursor.execute(query, values)
  File "env/lib/python3.10/site-packages/pymysql/cursors.py", line 153, in execute
    result = self._query(query)
  File "env/lib/python3.10/site-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 563, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 825, in _read_query_result
    result.read()
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 1199, in read
    first_packet = self.connection._read_packet()
  File "env/lib/python3.10/site-packages/pymysql/connections.py", line 775, in _read_packet
    packet.raise_for_error()
  File "env/lib/python3.10/site-packages/pymysql/protocol.py", line 219, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "env/lib/python3.10/site-packages/pymysql/err.py", line 150, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'b'VAT' ORDER BY `modified` DESC LIMIT 1' at line 1")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "apps/woocommerceconnector/woocommerceconnector/api.py", line 52, in sync_woocommerce_resources
    sync_orders()
  File "apps/woocommerceconnector/woocommerceconnector/sync_orders.py", line 15, in sync_orders
    sync_woocommerce_orders()
  File "apps/woocommerceconnector/woocommerceconnector/sync_orders.py", line 37, in sync_woocommerce_orders
    if e.args and e.args[0] and e.args[0].startswith("402"):
AttributeError: 'int' object has no attribute 'startswith'

Here is a screenshot of WoocommerceConfig:

Any help would be greatly appreciated.

Hope you are using the below app. Seems fixed here

Hello @Kaviya_Periyasamy thank you for taking the time to respond.

That’s the version I am using. The use of .decode(“utf-8”) was the cause of one of the errors I was facing. I’ve actually managed to fix the script for our use case. The steps I took are listed below.

Removed UTF-8 decoding from e.args

Original:

if e.args and e.args[0] and e.args[0].decode("utf-8").startswith("402"):

Amended:

if isinstance(e.args[0], str) and e.args[0].startswith("402"):

Removed UTF-8 encoding from shipping_title and tax_title variables.

Shipping Title Original:

        shipping_title = shipping.get("method_title").encode("utf-8")

Shipping Title Amended:

        shipping_title = shipping.get("method_title")

Tax Title Original:

    tax_title = tax.get("name").encode("utf-8") or tax.get("method_title").encode("utf-8")

Tax Title Amended:

    tax_title = tax.get("name") or tax.get("method_title")

I also didn’t like that the script automatically marked orders as “Complete” when a sales order is successfully synced. So, I removed the function that handles this.
Original:

            # close this order as synced
            close_synced_woocommerce_order(woocommerce_order.get("id"))
1 Like