Merge pull request #17232 from karthikeyan5/develop-woocommerce-fix
fix(woocommerce integration): 403 error and adding defaults
This commit is contained in:
commit
a5265113ce
@ -19,27 +19,24 @@ def verify_request():
|
||||
frappe.get_request_header("X-Wc-Webhook-Signature") and \
|
||||
not sig == bytes(frappe.get_request_header("X-Wc-Webhook-Signature").encode()):
|
||||
frappe.throw(_("Unverified Webhook Data"))
|
||||
frappe.set_user(woocommerce_settings.modified_by)
|
||||
frappe.set_user(woocommerce_settings.creation_user)
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def order(data=None):
|
||||
if not data:
|
||||
verify_request()
|
||||
def order():
|
||||
woocommerce_settings = frappe.get_doc("Woocommerce Settings")
|
||||
if frappe.flags.woocomm_test_order_data:
|
||||
fd = frappe.flags.woocomm_test_order_data
|
||||
event = "created"
|
||||
|
||||
if frappe.request and frappe.request.data:
|
||||
elif frappe.request and frappe.request.data:
|
||||
verify_request()
|
||||
fd = json.loads(frappe.request.data)
|
||||
elif data:
|
||||
fd = data
|
||||
event = frappe.get_request_header("X-Wc-Webhook-Event")
|
||||
|
||||
else:
|
||||
return "success"
|
||||
|
||||
if not data:
|
||||
event = frappe.get_request_header("X-Wc-Webhook-Event")
|
||||
else:
|
||||
event = "created"
|
||||
|
||||
if event == "created":
|
||||
|
||||
raw_billing_data = fd.get("billing")
|
||||
customer_woo_com_email = raw_billing_data.get("email")
|
||||
|
||||
@ -73,7 +70,7 @@ def order(data=None):
|
||||
|
||||
new_sales_order.po_no = fd.get("id")
|
||||
new_sales_order.woocommerce_id = fd.get("id")
|
||||
new_sales_order.naming_series = "SO-"
|
||||
new_sales_order.naming_series = woocommerce_settings.sales_order_series or "SO-WOO-"
|
||||
|
||||
placed_order_date = created_date[0]
|
||||
raw_date = datetime.datetime.strptime(placed_order_date, "%Y-%m-%d")
|
||||
@ -100,10 +97,10 @@ def order(data=None):
|
||||
"item_name": found_item.item_name,
|
||||
"description": found_item.item_name,
|
||||
"delivery_date":order_delivery_date,
|
||||
"uom": "Nos",
|
||||
"uom": woocommerce_settings.uom or _("Nos"),
|
||||
"qty": item.get("quantity"),
|
||||
"rate": item.get("price"),
|
||||
"warehouse": "Stores" + " - " + company_abbr
|
||||
"warehouse": woocommerce_settings.warehouse or "Stores" + " - " + company_abbr
|
||||
})
|
||||
|
||||
add_tax_details(new_sales_order,ordered_items_tax,"Ordered Item tax",0)
|
||||
@ -175,6 +172,7 @@ def link_customer_and_address(raw_billing_data,customer_status):
|
||||
frappe.db.commit()
|
||||
|
||||
def link_item(item_data,item_status):
|
||||
woocommerce_settings = frappe.get_doc("Woocommerce Settings")
|
||||
|
||||
if item_status == 0:
|
||||
#Create Item
|
||||
@ -189,6 +187,7 @@ def link_item(item_data,item_status):
|
||||
item.item_code = "woocommerce - " + str(item_data.get("product_id"))
|
||||
item.woocommerce_id = str(item_data.get("product_id"))
|
||||
item.item_group = "WooCommerce Products"
|
||||
item.stock_uom = woocommerce_settings.uom or _("Nos")
|
||||
item.save()
|
||||
frappe.db.commit()
|
||||
|
||||
@ -209,4 +208,4 @@ def add_tax_details(sales_order,price,desc,status):
|
||||
"account_head": account_head_type,
|
||||
"tax_amount": price,
|
||||
"description": desc
|
||||
})
|
||||
})
|
||||
|
@ -42,4 +42,15 @@ frappe.ui.form.on('Woocommerce Settings', {
|
||||
frm.set_df_property("api_consumer_key", "reqd", frm.doc.enable_sync);
|
||||
frm.set_df_property("api_consumer_secret", "reqd", frm.doc.enable_sync);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
frappe.ui.form.on("Woocommerce Settings", "onload", function () {
|
||||
frappe.call({
|
||||
method: "erpnext.erpnext_integrations.doctype.woocommerce_settings.woocommerce_settings.get_series",
|
||||
callback: function (r) {
|
||||
$.each(r.message, function (key, value) {
|
||||
set_field_options(key, value);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -122,3 +122,9 @@ def generate_secret():
|
||||
woocommerce_settings = frappe.get_doc("Woocommerce Settings")
|
||||
woocommerce_settings.secret = frappe.generate_hash()
|
||||
woocommerce_settings.save()
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_series():
|
||||
return {
|
||||
"sales_order_series" : frappe.get_meta("Sales Order").get_options("naming_series") or "SO-WOO-",
|
||||
}
|
@ -596,3 +596,4 @@ erpnext.patches.v12_0.stock_entry_enhancements
|
||||
erpnext.patches.v10_0.item_barcode_childtable_migrate # 16-02-2019
|
||||
erpnext.patches.v12_0.move_item_tax_to_item_tax_template
|
||||
erpnext.patches.v11_1.set_variant_based_on
|
||||
erpnext.patches.v11_1.woocommerce_set_creation_user
|
||||
|
10
erpnext/patches/v11_1/woocommerce_set_creation_user.py
Normal file
10
erpnext/patches/v11_1/woocommerce_set_creation_user.py
Normal file
@ -0,0 +1,10 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
def execute():
|
||||
woocommerce_setting_enable_sync = frappe.db.sql("SELECT t.value FROM tabSingles t WHERE doctype = 'Woocommerce Settings' AND field = 'enable_sync'", as_dict=True)
|
||||
if len(woocommerce_setting_enable_sync) and woocommerce_setting_enable_sync[0].value == '1':
|
||||
frappe.db.sql("""UPDATE tabSingles
|
||||
SET value = (SELECT t.value FROM tabSingles t WHERE doctype = 'Woocommerce Settings' AND field = 'modified_by')
|
||||
WHERE doctype = 'Woocommerce Settings'
|
||||
AND field = 'creation_user';""")
|
@ -20,15 +20,17 @@ class TestWoocommerce(unittest.TestCase):
|
||||
woo_settings.enable_sync = 1
|
||||
woo_settings.tax_account = "Sales Expenses - W"
|
||||
woo_settings.f_n_f_account = "Expenses - W"
|
||||
woo_settings.creation_user = "Administrator"
|
||||
woo_settings.save(ignore_permissions=True)
|
||||
|
||||
def test_sales_order_for_woocommerece(self):
|
||||
data = {"id":75,"parent_id":0,"number":"74","order_key":"wc_order_5aa1281c2dacb","created_via":"checkout","version":"3.3.3","status":"processing","currency":"INR","date_created":"2018-03-08T12:10:04","date_created_gmt":"2018-03-08T12:10:04","date_modified":"2018-03-08T12:10:04","date_modified_gmt":"2018-03-08T12:10:04","discount_total":"0.00","discount_tax":"0.00","shipping_total":"150.00","shipping_tax":"0.00","cart_tax":"0.00","total":"649.00","total_tax":"0.00","prices_include_tax":False,"customer_id":12,"customer_ip_address":"103.54.99.5","customer_user_agent":"mozilla\\/5.0 (x11; linux x86_64) applewebkit\\/537.36 (khtml, like gecko) chrome\\/64.0.3282.186 safari\\/537.36","customer_note":"","billing":{"first_name":"Tony","last_name":"Stark","company":"Woocommerce","address_1":"Mumbai","address_2":"","city":"Dadar","state":"MH","postcode":"123","country":"IN","email":"tony@gmail.com","phone":"123457890"},"shipping":{"first_name":"Tony","last_name":"Stark","company":"","address_1":"Mumbai","address_2":"","city":"Dadar","state":"MH","postcode":"123","country":"IN"},"payment_method":"cod","payment_method_title":"Cash on delivery","transaction_id":"","date_paid":"","date_paid_gmt":"","date_completed":"","date_completed_gmt":"","cart_hash":"8e76b020d5790066496f244860c4703f","meta_data":[],"line_items":[{"id":80,"name":"Marvel","product_id":56,"variation_id":0,"quantity":1,"tax_class":"","subtotal":"499.00","subtotal_tax":"0.00","total":"499.00","total_tax":"0.00","taxes":[],"meta_data":[],"sku":"","price":499}],"tax_lines":[],"shipping_lines":[{"id":81,"method_title":"Flat rate","method_id":"flat_rate:1","total":"150.00","total_tax":"0.00","taxes":[],"meta_data":[{"id":623,"key":"Items","value":"Marvel × 1"}]}],"fee_lines":[],"coupon_lines":[],"refunds":[]}
|
||||
order(data)
|
||||
frappe.flags.woocomm_test_order_data = {"id":75,"parent_id":0,"number":"74","order_key":"wc_order_5aa1281c2dacb","created_via":"checkout","version":"3.3.3","status":"processing","currency":"INR","date_created":"2018-03-08T12:10:04","date_created_gmt":"2018-03-08T12:10:04","date_modified":"2018-03-08T12:10:04","date_modified_gmt":"2018-03-08T12:10:04","discount_total":"0.00","discount_tax":"0.00","shipping_total":"150.00","shipping_tax":"0.00","cart_tax":"0.00","total":"649.00","total_tax":"0.00","prices_include_tax":False,"customer_id":12,"customer_ip_address":"103.54.99.5","customer_user_agent":"mozilla\\/5.0 (x11; linux x86_64) applewebkit\\/537.36 (khtml, like gecko) chrome\\/64.0.3282.186 safari\\/537.36","customer_note":"","billing":{"first_name":"Tony","last_name":"Stark","company":"Woocommerce","address_1":"Mumbai","address_2":"","city":"Dadar","state":"MH","postcode":"123","country":"IN","email":"tony@gmail.com","phone":"123457890"},"shipping":{"first_name":"Tony","last_name":"Stark","company":"","address_1":"Mumbai","address_2":"","city":"Dadar","state":"MH","postcode":"123","country":"IN"},"payment_method":"cod","payment_method_title":"Cash on delivery","transaction_id":"","date_paid":"","date_paid_gmt":"","date_completed":"","date_completed_gmt":"","cart_hash":"8e76b020d5790066496f244860c4703f","meta_data":[],"line_items":[{"id":80,"name":"Marvel","product_id":56,"variation_id":0,"quantity":1,"tax_class":"","subtotal":"499.00","subtotal_tax":"0.00","total":"499.00","total_tax":"0.00","taxes":[],"meta_data":[],"sku":"","price":499}],"tax_lines":[],"shipping_lines":[{"id":81,"method_title":"Flat rate","method_id":"flat_rate:1","total":"150.00","total_tax":"0.00","taxes":[],"meta_data":[{"id":623,"key":"Items","value":"Marvel × 1"}]}],"fee_lines":[],"coupon_lines":[],"refunds":[]}
|
||||
order()
|
||||
|
||||
self.assertTrue(frappe.get_value("Customer",{"woocommerce_email":"tony@gmail.com"}))
|
||||
self.assertTrue(frappe.get_value("Item",{"woocommerce_id": 56}))
|
||||
self.assertTrue(frappe.get_value("Sales Order",{"woocommerce_id":75}))
|
||||
frappe.flags.woocomm_test_order_data = {}
|
||||
|
||||
def emulate_request():
|
||||
# Emulate Woocommerce Request
|
||||
@ -52,4 +54,4 @@ def emulate_request():
|
||||
r = requests.post(url=url, headers=headers, data=data)
|
||||
|
||||
time.sleep(5)
|
||||
return r
|
||||
return r
|
||||
|
Loading…
Reference in New Issue
Block a user