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

problem syncing items and orders with variants #46

Open
khoran opened this issue Jun 16, 2021 · 8 comments
Open

problem syncing items and orders with variants #46

khoran opened this issue Jun 16, 2021 · 8 comments

Comments

@khoran
Copy link

khoran commented Jun 16, 2021

I'm setting up a new ERPNext and WooCommerce system. I have been able to successfully sync normal items (without variants) to woocommerce from ERPNext, and also place order in wooCommerce and have them appear in ERPNext. So I know the connection settings are good.

I'm not really sure how items with variants in ERPNext are supposed to work with WooCommerce, so I've just been experimenting.

I created an item with variants called TEST-01, then created a color attribute and variants with Green and Red versions. My first question is, should the "Sync With woocommerce" option be checked on only the template, only the variants, or on all of them? Also, where should the stock levels be managed, template or variants? If I check only the variants, nothing syncs and I get an error:

Method
sync_woocommerce_items

...
frappe.exceptions.TimestampMismatchError: Error: Document has been modified after you have opened it (2021-06-16 13:51:44.866065, 2021-06-16 13:52:11.798361). Please refresh to get the latest document.

Subsequent syncs don't produce any errors, but don't sync the items either.

Then I tried checking the template along with the variants. In that scenario, the TEST-01 product then appears in woocommerce, but I also get these errors:

WooCommerce post error 201
Method
post_request

Message:
https://galcom.org/wp-json/wc/v3/products: {'id': 4380, 'name': 'TEST-01', 'slug': '', 'permalink': 'https://galcom.org/?post_type=product&p=4380', 'date_created': '2021-06-16T14:52:09', 'date_created_gmt': '2021-06-16T18:52:09', 'date_modified': '2021-06-16T14:52:09', 'date_modified_gmt': '2021-06-16T18:52:09', 'type': 'variable', 'status': 'draft', 'featured': False, 'catalog_visibility': 'visible', 'description': 'TEST-01', 'short_description': 'TEST-01', 'sku': '', 'price': '', 'regular_price': '', 'sale_price': '', 'date_on_sale_from': None, 'date_on_sale_from_gmt': None, 'date_on_sale_to': None, 'date_on_sale_to_gmt': None, 'on_sale': False, 'purchasable': False, 'total_sales': 0, 'virtual': False, 'downloadable': False, 'downloads': [], 'download_limit': -1, 'download_expiry': -1, 'external_url': '', 'button_text': '', 'tax_status': 'taxable', 'tax_class': '', 'manage_stock': False, 'stock_quantity': None, 'backorders': 'no', 'backorders_allowed': False, 'backordered': False, 'sold_individually': False, 'weight': '', 'dimensions': {'length': '', 'width': '', 'height': ''}, 'shipping_required': True, 'shipping_taxable': True, 'shipping_class': '', 'shipping_class_id': 0, 'reviews_allowed': True, 'average_rating': '0', 'rating_count': 0, 'upsell_ids': [], 'cross_sell_ids': [], 'parent_id': 0, 'purchase_note': '', 'categories': [{'id': 25, 'name': 'Uncategorized', 'slug': 'uncategorized'}], 'tags': [], 'images': [], 'attributes': [{'id': 0, 'name': 'Colour', 'position': 1, 'visible': True, 'variation': True, 'options': ['Red', 'Green']}], 'default_attributes': [], 'variations': [], 'grouped_products': [], 'menu_order': 0, 'price_html': '', 'related_ids': [4360], 'meta_data': [], 'stock_status': 'outofstock', '_links': {'self': [{'href': 'https://galcom.org/wp-json/wc/v3/products/4380'}], 'collection': [{'href': 'https://galcom.org/wp-json/wc/v3/products'}]}}

Request Data
{"name": "TEST-01", "description": "TEST-01", "short_description": "TEST-01", "regular_price": "1.42", "type": "variable", "attributes": [{"name": "Colour", "visible": "True", "variation": "True", "position": 1, "options": ["Red", "Green"]}], "status": "draft"}



WooCommerce post error 201

Method
post_request

Message
https://galcom.org/wp-json/wc/v3/products/4380/variations: {'id': 4381, 'date_created': '2021-06-16T14:52:11', 'date_created_gmt': '2021-06-16T18:52:11', 'date_modified': '2021-06-16T14:52:11', 'date_modified_gmt': '2021-06-16T18:52:11', 'description': '', 'permalink': 'https://galcom.org/?post_type=product&p=4380&attribute_colour=Green', 'sku': '', 'price': '3.1', 'regular_price': '3.1', 'sale_price': '', 'date_on_sale_from': None, 'date_on_sale_from_gmt': None, 'date_on_sale_to': None, 'date_on_sale_to_gmt': None, 'on_sale': False, 'status': 'publish', 'purchasable': True, 'virtual': False, 'downloadable': False, 'downloads': [], 'download_limit': -1, 'download_expiry': -1, 'tax_status': 'taxable', 'tax_class': '', 'manage_stock': True, 'stock_quantity': 1000, 'stock_status': 'instock', 'backorders': 'no', 'backorders_allowed': False, 'backordered': False, 'weight': '', 'dimensions': {'length': '', 'width': '', 'height': ''}, 'shipping_class': '', 'shipping_class_id': 0, 'image': None, 'attributes': [{'id': 0, 'name': 'Colour', 'option': 'Green'}], 'menu_order': 0, 'meta_data': [], '_links': {'self': [{'href': 'https://galcom.org/wp-json/wc/v3/products/4380/variations/4381'}], 'collection': [{'href': 'https://galcom.org/wp-json/wc/v3/products/4380/variations'}], 'up': [{'href': 'https://galcom.org/wp-json/wc/v3/products/4380'}]}}

Request Data
{"regular_price": "3.1", "stock_quantity": "1000", "manage_stock": "True", "item_name": "TEST-01-GRE", "attributes": [{"name": "Colour", "option": "Green"}]}

Looking at the product in woocommerce, under the "Variations" section, I can see that both colors are listed as possible variations, but only the Green variant has been instantiated.

I then created an order in woocommerce, selecting the green variant as an item. Then I saved the order and triggered another sync. Then I get this error:

Item missing in ERPNext!

Method
valid_customer_and_product

Message
Item with id 4380 is missing in ERPNext! The Order 4382 will not be imported! For details of order see below

Request Data
{"id": 4382, "parent_id": 0, "status": "pending", "currency": "CAD", "version": "5.1.0", "prices_include_tax": false, "date_created": "2021-06-16T14:56:50", "date_modified": "2021-06-16T14:57:23", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "0.00", "shipping_tax": "0.00", "cart_tax": "0.00", "total": "3.10", "total_tax": "0.00", "customer_id": 67, "order_key": "wc_order_iLT7fxqhUUxY5", "billing": {"first_name": "Kevin", "last_name": "Horan", "company": "", "address_1": "22885 Kuna ct", "address_2": "", "city": "Wildomar", "state": "CA", "postcode": "92595", "country": "US", "email": "khoran512@gmail.com", "phone": "9519705307"}, "shipping": {"first_name": "Kevin", "last_name": "Horan", "company": "", "address_1": "22885 Kuna ct", "address_2": "", "city": "Wildomar", "state": "CA", "postcode": "92595", "country": "US"}, "payment_method": "", "payment_method_title": "", "transaction_id": "", "customer_ip_address": "", "customer_user_agent": "", "created_via": "admin", "customer_note": "", "date_completed": null, "date_paid": null, "cart_hash": "", "number": "4382", "meta_data": [], "line_items": [{"id": 12, "name": "TEST-01 - Green", "product_id": 4380, "variation_id": 4381, "quantity": 1, "tax_class": "", "subtotal": "3.10", "subtotal_tax": "0.00", "total": "3.10", "total_tax": "0.00", "taxes": [], "meta_data": [{"id": 137, "key": "colour", "value": "Green", "display_key": "Colour", "display_value": "Green"}], "sku": "", "price": 3.1, "parent_name": "TEST-01"}], "tax_lines": [], "shipping_lines": [], "fee_lines": [], "coupon_lines": [], "refunds": [], "date_created_gmt": "2021-06-16T18:56:50", "date_modified_gmt": "2021-06-16T18:57:23", "date_completed_gmt": null, "date_paid_gmt": null, "currency_symbol": "$", "_links": {"self": [{"href": "https://galcom.org/wp-json/wc/v3/orders/4382"}], "collection": [{"href": "https://galcom.org/wp-json/wc/v3/orders"}], "customer": [{"href": "https://galcom.org/wp-json/wc/v3/customers/67"}]}}

So am I doing something wrong, or is there a bug somewhere? What's the correct procedure to handle this? I've looked for documentation, but I haven't been able to find any details.

Thanks for making this! And for any help.

Versions:
ERPNext: v12.21.0 (version-12)
Frappe Framework: v12.18.0 (version-12)
WooCommerce Connector: v1.6.0 (master)
WooCommerce Plugin (in Wordpress): 5.1.0

@FreezeS
Copy link
Contributor

FreezeS commented Jun 16, 2021

You can check out this fork, it has many improvements: https://github.com/Muzzy73/WooCommerceConnector

This also has some small improvements over Muzzy73 but they are related to variants: https://github.com/aadhilpm/WooCommerceConnector

Hope these modifications will be merged into main (this branch) soon.

@FreezeS
Copy link
Contributor

FreezeS commented Jun 16, 2021

I forgot to mention: you need to check Sync with WooCommerce on both the template and each item variants otherwise this won't work. You want to check Sync Quantity With woocommerce only for the variants if you keep stock for them.

@khoran
Copy link
Author

khoran commented Jun 16, 2021

Thanks, I'll try the aadhilpm one out. Since I already have the libracore version installed, do you know if I can just run the same bench commands to install the new one, or do I have to fully uninstall the current version first? It would be nice to not have to re-configure from scratch.

@FreezeS
Copy link
Contributor

FreezeS commented Jun 16, 2021

If you uninstall and reinstall a new branch it keeps all the settings except the tax accounts for taxes and shipping. However, from my experience, this code is far from being ready for production so, beware.

@thomasoceguera
Copy link

I found that you need to be sure that the actual template item exists in ERPN and that it has the (woocommerce_product_id) set with the correct numbers.
i.e
Template item ERPN (woocommerce_product_id)= master item id in woocommerce
variant item ERPN (woocommerce_product_id) = variant id in woocommerce

One thing to note is that if you had the original default WooCommerce Sync, set up. The one that comes with ERPN, it will have created a field called woocommerce_id. This is not the field that the libracore connector or any forkof it uses. This can be confusing because of the names.

@rasos
Copy link

rasos commented Dec 12, 2021

We are observing a similar problem - but not with variants:

"Item Price added for Woocommerce - 337 in Price List Firmenkunden\", \"alert\": 1}", "{\"message\": \"Error: Document has been modified after you have opened it (2021-12-11 11:33:21.774526, 2021-12-11 11:33:21.832179).

There seems to be some race condition when a new item is ordered the first time and has not yet been generated in ERPnext. It tries to add a price but then the document is changed as it seems to set a standard price which causes the exception.

@webbosolutions
Copy link

@thomasoceguera hello
didi you fix this problem please?

@alphaomegaphi
Copy link

Facing the same issue in ERPNext V15, any clue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants