dvdl16 / woocommerce_fusion

WooCommerce connector for ERPNext v15
https://finfoot.tech
Other
27 stars 24 forks source link

[BUG] `clear_sync_hash_and_run_item` fails when item is not linked to WooCommerce #97

Closed dvdl16 closed 4 months ago

dvdl16 commented 4 months ago

Current Behavior

Scheduled job woocommerce_fusion.tasks.sync_items.clear_sync_hash_and_run_item_sync fails for items without links to WooCommerce Products

Steps To Reproduce

  1. Go to Scheduled Job Log
  2. Filter for woocommerce_fusion.tasks.sync_items.clear_sync_hash_and_run_item_sync
  3. See errors

Expected Behavior

Job should not fail

Anything else?

Traceback with variables (most recent call last):
  File "apps/frappe/frappe/utils/background_jobs.py", line 220, in execute_job
    retval = method(**kwargs)
      site = 'site.com'
      method = <function clear_sync_hash_and_run_item_sync at 0x72d0a2814fe0>
      event = None
      job_name = 'woocommerce_fusion.tasks.sync_items.clear_sync_hash_and_run_item_sync'
      kwargs = {'item_code': 'XYZ001'}
      user = 'user@site.com'
      is_async = True
      retry = 0
      retval = None
      method_name = 'woocommerce_fusion.tasks.sync_items.clear_sync_hash_and_run_item_sync'
      before_job_task = 'frappe.monitor.start'
  File "apps/woocommerce_fusion/woocommerce_fusion/tasks/sync_items.py", line 586, in clear_sync_hash_and_run_item_sync
    run_item_sync(item_code=item_code, enqueue=True)
      item_code = 'XYZ001'
      iws = Table('tabItem WooCommerce Server')
      iwss = []
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
      args = ()
      kwargs = {'item_code': 'XYZ001', 'enqueue': True}
      apply_condition = <function whitelist.<locals>.innerfn.<locals>.<lambda> at 0x72d0a2814180>
      func = <function run_item_sync at 0x72d0a27ff740>
  File "apps/woocommerce_fusion/woocommerce_fusion/tasks/sync_items.py", line 55, in run_item_sync
    frappe.throw(_("No WooCommerce Servers defined for Item {0}").format(item_code))
      item_code = 'XYZ001'
      woocommerce_product_name = None
      enqueue = True
      item = <Item: XYZ001>
  File "apps/frappe/frappe/__init__.py", line 645, in throw
    msgprint(
      msg = 'No WooCommerce Servers defined for Item XYZ001'
      exc = <class 'frappe.exceptions.ValidationError'>
      title = None
      is_minimizable = False
      wide = False
      as_list = False
      primary_action = None
  File "apps/frappe/frappe/__init__.py", line 610, in msgprint
    _raise_exception()
      msg = 'No WooCommerce Servers defined for Item XYZ001'
      title = None
      raise_exception = <class 'frappe.exceptions.ValidationError'>
      as_table = False
      as_list = False
      indicator = 'red'
      alert = False
      primary_action = None
      is_minimizable = False
      wide = False
      realtime = False
      sys = <module 'sys' (built-in)>
      _raise_exception = <function msgprint.<locals>._raise_exception at 0x72d0a1c67c40>
      inspect = <module 'inspect' from '/usr/local/lib/python3.11/inspect.py'>
      out = {'message': 'No WooCommerce Servers defined for Item XYZ001', 'title': 'Message', 'indicator': 'red', 'raise_exception': 1, '__frappe_exc_id': 'a2d09a7a3a6445e9c9ed81e5eba0cae62e8ff58b54107fcbfd2ae4a6'}
  File "apps/frappe/frappe/__init__.py", line 561, in _raise_exception
    raise exc
      exc = ValidationError('No WooCommerce Servers defined for Item XYZ001')
      inspect = <module 'inspect' from '/usr/local/lib/python3.11/inspect.py'>
      msg = 'No WooCommerce Servers defined for Item XYZ001'
      out = {'message': 'No WooCommerce Servers defined for Item XYZ001', 'title': 'Message', 'indicator': 'red', 'raise_exception': 1, '__frappe_exc_id': 'a2d09a7a3a6445e9c9ed81e5eba0cae62e8ff58b54107fcbfd2ae4a6'}
      raise_exception = <class 'frappe.exceptions.ValidationError'>
frappe.exceptions.ValidationError: No WooCommerce Servers defined for Item XYZ001

Environment and Versions

Agriculture: v0.0.1
Customisations for [redacted]: v1.2.3
South Africa Customisations: v0.1.6
ERPNext: v15.27.7
Frappe Framework: v15.29.2
Frappe HR: v15.22.3
WooCommerce Fusion: v1.6.0

Operating System

Windows

What browsers are you seeing the problem on?

Chrome, Firefox

dvdl16 commented 4 months ago

Also fix

Traceback (most recent call last):
  File "apps/woocommerce_fusion/woocommerce_fusion/tasks/sync_items.py", line 142, in run
    self.sync_wc_product_with_erpnext_item()
  File "apps/woocommerce_fusion/woocommerce_fusion/tasks/sync_items.py", line 234, in sync_wc_product_with_erpnext_item
    self.update_woocommerce_product(self.woocommerce_product, self.item)
  File "apps/woocommerce_fusion/woocommerce_fusion/tasks/sync_items.py", line 259, in update_woocommerce_product
    if self.set_product_fields(wc_product, item):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/woocommerce_fusion/woocommerce_fusion/tasks/sync_items.py", line 481, in set_product_fields
    return wc_product_dirty
           ^^^^^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'wc_product_dirty' where it is not associated with a value