Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Muzzy73 master #2

Merged
merged 33 commits into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
31b79eb
format: remove unnecessary codes and clean indentations
iRaySpace May 19, 2021
0298bff
feat(woocommerce_requests): added params
iRaySpace May 19, 2021
813bc17
fix(woocommerce_requests): extend if ok
iRaySpace May 19, 2021
739702f
fix(woocommerce_requests): orders as params
iRaySpace May 19, 2021
b8b6e37
fix(woocommerce_requests): page idx
iRaySpace May 19, 2021
f5a29b9
Merge pull request #1 from Muzzy73/dev
Muzzy73 May 19, 2021
4eccc35
format(sync_orders): indent
iRaySpace May 19, 2021
98dd157
format(api): indentation
iRaySpace May 19, 2021
b4274df
refactor(api): separate customers and orders for easy execute
iRaySpace May 20, 2021
9d9cefc
format(sync_orders): remove unused args
iRaySpace May 20, 2021
e4c09ad
format(sync_products): clean code and indent
iRaySpace May 20, 2021
bdbc286
fix(sync_orders): should only close if order is created
iRaySpace May 20, 2021
a48789d
fix(woocommerce_requests): 400 error on woocommerce items
iRaySpace May 20, 2021
c2fce3c
format(sync_products): indent
iRaySpace May 20, 2021
38431d9
fix(sync_orders): log error
iRaySpace May 20, 2021
e4f2135
Merge pull request #2 from Muzzy73/dev
Muzzy73 May 20, 2021
d83a851
Update woocommerce_config.json
Muzzy73 May 20, 2021
94e8619
feat(sync_products): added sku
iRaySpace May 21, 2021
0d0edec
Merge pull request #3 from Muzzy73/dev
Muzzy73 May 21, 2021
4f7db17
Update sync_products.py
Muzzy73 Aug 16, 2021
bba78d9
Update sync_orders.py
Muzzy73 Aug 16, 2021
cc88b19
Update sync_products.py
Muzzy73 Aug 16, 2021
337d54b
Update api.py
Muzzy73 Aug 16, 2021
16b6e3e
fix(sync_orders): cint
iRaySpace Aug 17, 2021
6160c4a
Merge pull request #4 from Muzzy73/dev
Muzzy73 Aug 17, 2021
9816869
Update item.json
Muzzy73 Oct 1, 2021
46ed9e9
Typos & Spellings fix
Muzzy73 Oct 13, 2022
e9df804
Typos & Spellings fix
Muzzy73 Oct 13, 2022
dfa84c5
Typos & spelling fix
Muzzy73 Oct 13, 2022
45260fc
Spellings & Typos fix
Muzzy73 Oct 13, 2022
5995d81
Update README.md
Muzzy73 Oct 13, 2022
90c5cf8
Update README.md
Muzzy73 Oct 13, 2022
0f2c70b
Merge branch 'master' of github.com:Muzzy73/WooCommerceConnector into…
Haschtl Oct 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
## ERPNext WooCommerce Connector
ERPNext WooCommerce Connector
WooCommerce connector app for ERPNext. This connector allows synchronisation of items, stock, customers, addresses, sales orders, sales invoices and payment entries between WooCommerce instance & ERPNext. It requires the Frappe Framework and ERPNext (https://erpnext.com/).

WooCommerce connector for ERPNext

This connector allows the synchronisation of items, stock, customers, addresses, sales orders, sales invoices and payment entries to a WooCommerce instance.

It requires the Frappe Framework and [ERPNext](https://erpnext.org).

#### License

AGPL
#### License AGPL

#### Installation

On the ERPNext server, run
SSH into ERPNext server and follow below commands

$ cd /home/frappe/frappe-bench
$ bench get-app https://github.com/libracore/woocommerceconnector.git
$ bench get-app https://github.com/muzzy73/woocommerceconnector.git
$ bench install-app woocommerceconnector
$ bench migrate
$ bench clear-cache
155 changes: 112 additions & 43 deletions woocommerceconnector/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
from .utils import disable_woocommerce_sync_on_exception, make_woocommerce_log
from frappe.utils.background_jobs import enqueue


@frappe.whitelist()
def check_hourly_sync():
woocommerce_settings = frappe.get_doc("WooCommerce Config")
if woocommerce_settings.hourly_sync == 1:
sync_woocommerce()


@frappe.whitelist()
def sync_woocommerce():
"""Enqueue longjob for syncing woocommerce"""
Expand All @@ -29,88 +31,155 @@ def sync_woocommerce():
# apply minimal timeout of 60 sec
if timeout < 60:
timeout = 60
enqueue("woocommerceconnector.api.sync_woocommerce_resources", queue='long', timeout=timeout)
frappe.msgprint(_("Queued for syncing. It may take a few minutes to an hour if this is your first sync."))
enqueue(
"woocommerceconnector.api.sync_woocommerce_resources",
queue="long",
timeout=timeout,
)
frappe.msgprint(
_(
"Queued for syncing. It may take a few minutes to an hour if this is your first sync."
)
)


@frappe.whitelist()
def sync_woocommerce_resources():
woocommerce_settings = frappe.get_doc("WooCommerce Config")

make_woocommerce_log(title="Sync Job Queued", status="Queued", method=frappe.local.form_dict.cmd, message="Sync Job Queued")

make_woocommerce_log(
title="Sync Job Queued",
status="Queued",
method=frappe.local.form_dict.cmd,
message="Sync Job Queued",
)

if woocommerce_settings.enable_woocommerce:
make_woocommerce_log(title="Sync Job Started", status="Started", method=frappe.local.form_dict.cmd, message="Sync Job Started")
try :
make_woocommerce_log(
title="Sync Job Started",
status="Started",
method=frappe.local.form_dict.cmd,
message="Sync Job Started",
)
try:
validate_woocommerce_settings(woocommerce_settings)
sync_start_time = frappe.utils.now()
frappe.local.form_dict.count_dict = {}
frappe.local.form_dict.count_dict["customers"] = 0
frappe.local.form_dict.count_dict["products"] = 0
frappe.local.form_dict.count_dict["orders"] = 0
sync_products(woocommerce_settings.price_list, woocommerce_settings.warehouse, True if woocommerce_settings.sync_items_from_woocommerce_to_erp == 1 else False)
sync_customers()
sync_orders()
frappe.local.form_dict.count_dict = {"customers": 0, "products": 0, "orders": 0}
sync_products(
woocommerce_settings.price_list,
woocommerce_settings.warehouse,
True
if woocommerce_settings.sync_items_from_woocommerce_to_erp == 1
else False,
)
sync_customers_and_orders()
# close_synced_woocommerce_orders() # DO NOT GLOBALLY CLOSE
if woocommerce_settings.sync_item_qty_from_erpnext_to_woocommerce:
update_item_stock_qty()
frappe.db.set_value("WooCommerce Config", None, "last_sync_datetime", sync_start_time)
make_woocommerce_log(title="Sync Completed", status="Success", method=frappe.local.form_dict.cmd,
message= "Updated {customers} customer(s), {products} item(s), {orders} order(s)".format(**frappe.local.form_dict.count_dict))
frappe.db.set_value(
"WooCommerce Config", None, "last_sync_datetime", sync_start_time
)
make_woocommerce_log(
title="Sync Completed",
status="Success",
method=frappe.local.form_dict.cmd,
message="Updated {customers} customer(s), {products} item(s), {orders} order(s)".format(
**frappe.local.form_dict.count_dict
),
)

except Exception as e:
if e.args[0] and hasattr(e.args[0], "startswith") and e.args[0].startswith("402"):
make_woocommerce_log(title="woocommerce has suspended your account", status="Error",
method="sync_woocommerce_resources", message=_("""woocommerce has suspended your account till
if (
e.args[0]
and hasattr(e.args[0], "startswith")
and e.args[0].startswith("402")
):
make_woocommerce_log(
title="woocommerce has suspended your account",
status="Error",
method="sync_woocommerce_resources",
message=_(
"""woocommerce has suspended your account till
you complete the payment. We have disabled ERPNext woocommerce Sync. Please enable it once
your complete the payment at woocommerce."""), exception=True)
your complete the payment at woocommerce."""
),
exception=True,
)

disable_woocommerce_sync_on_exception()

else:
make_woocommerce_log(title="sync has terminated", status="Error", method="sync_woocommerce_resources",
message=frappe.get_traceback(), exception=True)

make_woocommerce_log(
title="sync has terminated",
status="Error",
method="sync_woocommerce_resources",
message=frappe.get_traceback(),
exception=True,
)

elif frappe.local.form_dict.cmd == "woocommerceconnector.api.sync_woocommerce":
make_woocommerce_log(
title="woocommerce connector is disabled",
status="Error",
method="sync_woocommerce_resources",
message=_("""woocommerce connector is not enabled. Click on 'Connect to woocommerce' to connect ERPNext and your woocommerce store."""),
exception=True)
message=_(
"""woocommerce connector is not enabled. Click on 'Connect to woocommerce' to connect ERPNext and your woocommerce store."""
),
exception=True,
)


def validate_woocommerce_settings(woocommerce_settings):
"""
This will validate mandatory fields and access token or app credentials
by calling validate() of WooCommerce Config.
This will validate mandatory fields and access token or app credentials
by calling validate() of WooCommerce Config.
"""
try:
woocommerce_settings.save()
except woocommerceError:
disable_woocommerce_sync_on_exception()


@frappe.whitelist()
def get_log_status():
log = frappe.db.sql("""select name, status from `tabwoocommerce Log`
order by modified desc limit 1""", as_dict=1)
log = frappe.db.sql(
"""select name, status from `tabwoocommerce Log`
order by modified desc limit 1""",
as_dict=1,
)
if log:
if log[0].status=="Queued":
if log[0].status == "Queued":
message = _("Last sync request is queued")
alert_class = "alert-warning"
elif log[0].status=="Error":
message = _("Last sync request was failed, check <a href='../desk#Form/woocommerce Log/{0}'> here</a>"
.format(log[0].name))
elif log[0].status == "Error":
message = _(
"Last sync request was failed, check <a href='../desk#Form/woocommerce Log/{0}'> here</a>".format(
log[0].name
)
)
alert_class = "alert-danger"
else:
message = _("Last sync request was successful")
alert_class = "alert-success"

return {
"text": message,
"alert_class": alert_class
}


return {"text": message, "alert_class": alert_class}


@frappe.whitelist()
def sync_woocommerce_ids():
"Enqueue longjob for syncing woocommerce"
enqueue("woocommerceconnector.sync_products.add_w_id_to_erp", queue='long', timeout=1500)
frappe.msgprint(_("Queued for syncing. It may take a few minutes to an hour if this is your first sync."))
"""Enqueue longjob for syncing woocommerce"""
enqueue(
"woocommerceconnector.sync_products.add_w_id_to_erp", queue="long", timeout=1500
)
frappe.msgprint(
_(
"Queued for syncing. It may take a few minutes to an hour if this is your first sync."
)
)


def sync_customers_and_orders():
if not frappe.local.form_dict.count_dict:
frappe.local.form_dict.count_dict = {"customers": 0, "orders": 0}
sync_customers()
sync_orders()
30 changes: 15 additions & 15 deletions woocommerceconnector/fixtures/custom_field.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"in_filter": 0,
"in_list_view": 0,
"insert_after": "naming_series",
"label": "woocommerce Customer Id",
"label": "WooCommerce Customer ID",
"modified": "2016-01-15 17:25:28.991818",
"name": "Customer-woocommerce_customer_id",
"no_copy": 1,
Expand Down Expand Up @@ -122,7 +122,7 @@
"in_filter": 0,
"in_list_view": 0,
"insert_after": "fax",
"label": "woocommerce Address Id",
"label": "WooCommerce Address ID",
"modified": "2016-01-15 17:50:52.213743",
"name": "Address-woocommerce_address_id",
"no_copy": 1,
Expand Down Expand Up @@ -157,7 +157,7 @@
"in_filter": 0,
"in_list_view": 0,
"insert_after": "woocommerce_address_id",
"label": "woocommerce Address Company Name",
"label": "WooCommerce Address Company Name",
"modified": "2016-01-15 17:50:52.213743",
"name": "Address-woocommerce_company_name",
"no_copy": 1,
Expand Down Expand Up @@ -192,7 +192,7 @@
"in_filter": 0,
"in_list_view": 0,
"insert_after": "title",
"label": "woocommerce Order Id",
"label": "WooCommerce Order ID",
"modified": "2016-01-18 09:55:50.764524",
"name": "Sales Order-woocommerce_order_id",
"no_copy": 1,
Expand Down Expand Up @@ -227,7 +227,7 @@
"in_filter": 0,
"in_list_view": 0,
"insert_after": "item_code",
"label": "woocommerce Product Id",
"label": "Woocommerce Product ID",
"modified": "2016-01-19 15:44:16.132952",
"name": "Item-woocommerce_product_id",
"no_copy": 1,
Expand Down Expand Up @@ -262,7 +262,7 @@
"in_filter": 0,
"in_list_view": 0,
"insert_after": "naming_series",
"label": "woocommerce Order Id",
"label": "WooCommerce Order ID",
"modified": "2016-01-19 16:30:12.261797",
"name": "Sales Invoice-woocommerce_order_id",
"no_copy": 1,
Expand Down Expand Up @@ -297,7 +297,7 @@
"in_filter": 0,
"in_list_view": 0,
"insert_after": "title",
"label": "woocommerce Order Id",
"label": "WooCommerce Order ID",
"modified": "2016-01-19 16:30:31.201198",
"name": "Delivery Note-woocommerce_order_id",
"no_copy": 1,
Expand Down Expand Up @@ -367,7 +367,7 @@
"in_filter": 0,
"in_list_view": 0,
"insert_after": "is_stock_item",
"label": "Sync With woocommerce",
"label": "Sync With WooCommerce",
"modified": "2015-10-12 15:54:31.997714",
"name": "Item-sync_with_woocommerce",
"no_copy": 0,
Expand Down Expand Up @@ -402,7 +402,7 @@
"in_filter": 0,
"in_list_view": 0,
"insert_after": "is_frozen",
"label": "Sync With woocommerce",
"label": "Sync With WooCommerce",
"modified": "2015-10-01 17:31:55.758826",
"name": "Customer-sync_with_woocommerce",
"no_copy": 0,
Expand Down Expand Up @@ -437,7 +437,7 @@
"in_filter": 0,
"in_list_view": 0,
"insert_after": "item_code",
"label": "Variant Id",
"label": "Variant ID",
"modified": "2015-11-09 18:26:50.825858",
"name": "Item-woocommerce_variant_id",
"no_copy": 1,
Expand Down Expand Up @@ -472,7 +472,7 @@
"in_filter": 0,
"in_list_view": 0,
"insert_after": "item_code",
"label": "Sync Quantity With woocommerce",
"label": "Sync Quantity With WooCommerce",
"modified": "2015-12-29 08:37:46.183295",
"name": "Item-sync_qty_with_woocommerce",
"no_copy": 0,
Expand Down Expand Up @@ -507,7 +507,7 @@
"in_filter": 0,
"in_list_view": 0,
"insert_after": "title",
"label": "woocommerce Fulfillment Id",
"label": "WooCommerce Fulfillment ID",
"modified": "2016-01-20 23:50:35.609543",
"name": "Delivery Note-woocommerce_fulfillment_id",
"no_copy": 1,
Expand Down Expand Up @@ -542,7 +542,7 @@
"in_filter": 0,
"in_list_view": 0,
"insert_after": "supplier_name",
"label": "woocommerce Supplier Id",
"label": "WooCommerce Supplier ID",
"modified": "2016-02-01 15:41:25.818306",
"name": "Supplier-woocommerce_supplier_id",
"no_copy": 1,
Expand Down Expand Up @@ -577,7 +577,7 @@
"in_filter": 0,
"in_list_view": 0,
"insert_after": "section_break_11",
"label": "woocommerce_description",
"label": "WooCommerce Description (Will show on WooCommerce website)",
"modified": "2016-06-15 12:15:36.325581",
"name": "Item-woocommerce_description",
"no_copy": 0,
Expand All @@ -594,4 +594,4 @@
"unique": 0,
"width": null
}
]
]
Loading