[fixes] setup wizard and other fixes related to cart
This commit is contained in:
parent
52dfc32eca
commit
06ad308ca1
@ -5,6 +5,3 @@ cur_frm.cscript.tax_table = "Sales Taxes and Charges";
|
|||||||
|
|
||||||
{% include "public/js/controllers/accounts.js" %}
|
{% include "public/js/controllers/accounts.js" %}
|
||||||
|
|
||||||
frappe.ui.form.on("Sales Taxes and Charges Template", "onload", function(frm) {
|
|
||||||
erpnext.add_applicable_territory();
|
|
||||||
});
|
|
||||||
|
@ -20,19 +20,7 @@
|
|||||||
"rate": 6.36
|
"rate": 6.36
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"title": "_Test Sales Taxes and Charges Template",
|
"title": "_Test Sales Taxes and Charges Template"
|
||||||
"territories": [
|
|
||||||
{
|
|
||||||
"doctype": "Applicable Territory",
|
|
||||||
"parentfield": "territories",
|
|
||||||
"territory": "All Territories"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Applicable Territory",
|
|
||||||
"parentfield": "territories",
|
|
||||||
"territory": "_Test Territory Rest Of The World"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"company": "_Test Company",
|
"company": "_Test Company",
|
||||||
@ -115,14 +103,7 @@
|
|||||||
"row_id": 7
|
"row_id": 7
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"title": "_Test India Tax Master",
|
"title": "_Test India Tax Master"
|
||||||
"territories": [
|
|
||||||
{
|
|
||||||
"doctype": "Applicable Territory",
|
|
||||||
"parentfield": "territories",
|
|
||||||
"territory": "_Test Territory India"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"company": "_Test Company",
|
"company": "_Test Company",
|
||||||
@ -145,14 +126,7 @@
|
|||||||
"rate": 4
|
"rate": 4
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"title": "_Test Sales Taxes and Charges Template - Rest of the World",
|
"title": "_Test Sales Taxes and Charges Template - Rest of the World"
|
||||||
"territories": [
|
|
||||||
{
|
|
||||||
"doctype": "Applicable Territory",
|
|
||||||
"parentfield": "territories",
|
|
||||||
"territory": "_Test Territory Rest Of The World"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"company": "_Test Company",
|
"company": "_Test Company",
|
||||||
@ -175,14 +149,7 @@
|
|||||||
"rate": 4
|
"rate": 4
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"title": "_Test Sales Taxes and Charges Template 1",
|
"title": "_Test Sales Taxes and Charges Template 1"
|
||||||
"territories": [
|
|
||||||
{
|
|
||||||
"doctype": "Applicable Territory",
|
|
||||||
"parentfield": "territories",
|
|
||||||
"territory": "_Test Territory Rest Of The World"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"company": "_Test Company",
|
"company": "_Test Company",
|
||||||
@ -205,14 +172,7 @@
|
|||||||
"rate": 4
|
"rate": 4
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"title": "_Test Sales Taxes and Charges Template 2",
|
"title": "_Test Sales Taxes and Charges Template 2"
|
||||||
"territories": [
|
|
||||||
{
|
|
||||||
"doctype": "Applicable Territory",
|
|
||||||
"parentfield": "territories",
|
|
||||||
"territory": "_Test Territory Rest Of The World"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype" : "Sales Taxes and Charges Template",
|
"doctype" : "Sales Taxes and Charges Template",
|
||||||
@ -224,9 +184,6 @@
|
|||||||
"cost_center": "Main - _TC",
|
"cost_center": "Main - _TC",
|
||||||
"description": "Test Shopping cart taxes with Tax Rule",
|
"description": "Test Shopping cart taxes with Tax Rule",
|
||||||
"tax_amount": 1000
|
"tax_amount": 1000
|
||||||
}],
|
|
||||||
"territories":[{
|
|
||||||
"territory" : "All Territories"
|
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -239,9 +196,6 @@
|
|||||||
"cost_center": "Main - _TC",
|
"cost_center": "Main - _TC",
|
||||||
"description": "Test Shopping cart taxes with Tax Rule",
|
"description": "Test Shopping cart taxes with Tax Rule",
|
||||||
"tax_amount": 200
|
"tax_amount": 200
|
||||||
}],
|
|
||||||
"territories":[{
|
|
||||||
"territory" : "All Territories"
|
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -1,8 +1,3 @@
|
|||||||
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
// License: GNU General Public License v3. See license.txt
|
// License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
$.extend(cur_frm.cscript, {
|
|
||||||
onload: function() {
|
|
||||||
erpnext.add_applicable_territory();
|
|
||||||
}
|
|
||||||
});
|
|
@ -183,7 +183,7 @@
|
|||||||
"print_hide": 0,
|
"print_hide": 0,
|
||||||
"read_only": 0,
|
"read_only": 0,
|
||||||
"report_hide": 0,
|
"report_hide": 0,
|
||||||
"reqd": 1,
|
"reqd": 0,
|
||||||
"search_index": 0,
|
"search_index": 0,
|
||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
@ -305,7 +305,7 @@
|
|||||||
"is_submittable": 0,
|
"is_submittable": 0,
|
||||||
"issingle": 0,
|
"issingle": 0,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"modified": "2015-09-17 08:30:57.226342",
|
"modified": "2015-09-22 08:30:57.226342",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Shipping Rule",
|
"name": "Shipping Rule",
|
||||||
|
@ -25,6 +25,9 @@ class ShippingRule(Document):
|
|||||||
if self.worldwide_shipping:
|
if self.worldwide_shipping:
|
||||||
self.countries = []
|
self.countries = []
|
||||||
|
|
||||||
|
elif not len([d.country for d in self.countries if d.country]):
|
||||||
|
frappe.throw(_("Please specify a country for this Shipping Rule or check Worldwide Shipping"))
|
||||||
|
|
||||||
def validate_from_to_values(self):
|
def validate_from_to_values(self):
|
||||||
zero_to_values = []
|
zero_to_values = []
|
||||||
|
|
||||||
|
@ -29,13 +29,7 @@
|
|||||||
"shipping_amount": 0.0
|
"shipping_amount": 0.0
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"territories": [
|
"worldwide_shipping": 1
|
||||||
{
|
|
||||||
"doctype": "Applicable Territory",
|
|
||||||
"parentfield": "territories",
|
|
||||||
"territory": "_Test Territory"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"account": "_Test Account Shipping Charges - _TC",
|
"account": "_Test Account Shipping Charges - _TC",
|
||||||
@ -67,12 +61,8 @@
|
|||||||
"shipping_amount": 0.0
|
"shipping_amount": 0.0
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"territories": [
|
"countries": [
|
||||||
{
|
{"country": "India"}
|
||||||
"doctype": "Applicable Territory",
|
|
||||||
"parentfield": "territories",
|
|
||||||
"territory": "_Test Territory India"
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -105,12 +95,6 @@
|
|||||||
"shipping_amount": 1500.0
|
"shipping_amount": 1500.0
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"territories": [
|
"worldwide_shipping": 1
|
||||||
{
|
|
||||||
"doctype": "Applicable Territory",
|
|
||||||
"parentfield": "territories",
|
|
||||||
"territory": "_Test Territory Rest Of The World"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
@ -5,6 +5,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
from frappe.model import default_fields
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import cstr
|
from frappe.utils import cstr
|
||||||
|
|
||||||
@ -13,6 +14,9 @@ class IncorrectSupplierType(frappe.ValidationError): pass
|
|||||||
class ConflictingTaxRule(frappe.ValidationError): pass
|
class ConflictingTaxRule(frappe.ValidationError): pass
|
||||||
|
|
||||||
class TaxRule(Document):
|
class TaxRule(Document):
|
||||||
|
def __setup__(self):
|
||||||
|
self.flags.ignore_these_exceptions_in_test = [ConflictingTaxRule]
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.validate_tax_template()
|
self.validate_tax_template()
|
||||||
self.validate_customer_group()
|
self.validate_customer_group()
|
||||||
|
@ -49,18 +49,6 @@ $.extend(erpnext, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
add_applicable_territory: function() {
|
|
||||||
if(cur_frm.doc.__islocal && (cur_frm.doc.territories || []).length===0) {
|
|
||||||
var default_territory = frappe.defaults.get_user_default("territory");
|
|
||||||
if(default_territory) {
|
|
||||||
var territory = frappe.model.add_child(cur_frm.doc, "Applicable Territory",
|
|
||||||
"territories");
|
|
||||||
territory.territory = default_territory;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
setup_serial_no: function() {
|
setup_serial_no: function() {
|
||||||
var grid_row = cur_frm.open_grid_row();
|
var grid_row = cur_frm.open_grid_row();
|
||||||
if(!grid_row.fields_dict.serial_no ||
|
if(!grid_row.fields_dict.serial_no ||
|
||||||
|
@ -174,10 +174,7 @@ def create_price_lists(args):
|
|||||||
"enabled": 1,
|
"enabled": 1,
|
||||||
"buying": 1 if pl_type == "Buying" else 0,
|
"buying": 1 if pl_type == "Buying" else 0,
|
||||||
"selling": 1 if pl_type == "Selling" else 0,
|
"selling": 1 if pl_type == "Selling" else 0,
|
||||||
"currency": args["currency"],
|
"currency": args["currency"]
|
||||||
"territories": [{
|
|
||||||
"territory": get_root_of("Territory")
|
|
||||||
}]
|
|
||||||
}).insert()
|
}).insert()
|
||||||
|
|
||||||
def set_defaults(args):
|
def set_defaults(args):
|
||||||
|
@ -1,103 +1,2 @@
|
|||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
import frappe
|
|
||||||
from frappe import _
|
|
||||||
from frappe.utils import get_fullname, flt
|
|
||||||
from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import check_shopping_cart_enabled, get_default_territory
|
|
||||||
|
|
||||||
# TODO
|
|
||||||
# validate stock of each item in Website Warehouse or have a list of possible warehouses in Shopping Cart Settings
|
|
||||||
# Below functions are used for test cases
|
|
||||||
|
|
||||||
def get_quotation(user=None):
|
|
||||||
if not user:
|
|
||||||
user = frappe.session.user
|
|
||||||
if user == "Guest":
|
|
||||||
raise frappe.PermissionError
|
|
||||||
|
|
||||||
check_shopping_cart_enabled()
|
|
||||||
party = get_party(user)
|
|
||||||
values = {
|
|
||||||
"order_type": "Shopping Cart",
|
|
||||||
party.doctype.lower(): party.name,
|
|
||||||
"docstatus": 0,
|
|
||||||
"contact_email": user,
|
|
||||||
"selling_price_list": "_Test Price List Rest of the World",
|
|
||||||
"currency": "USD"
|
|
||||||
}
|
|
||||||
|
|
||||||
try:
|
|
||||||
quotation = frappe.get_doc("Quotation", values)
|
|
||||||
|
|
||||||
except frappe.DoesNotExistError:
|
|
||||||
quotation = frappe.new_doc("Quotation")
|
|
||||||
quotation.update(values)
|
|
||||||
if party.doctype == "Customer":
|
|
||||||
quotation.contact_person = frappe.db.get_value("Contact", {"customer": party.name, "email_id": user})
|
|
||||||
quotation.insert(ignore_permissions=True)
|
|
||||||
|
|
||||||
return quotation
|
|
||||||
|
|
||||||
def set_item_in_cart(item_code, qty, user=None):
|
|
||||||
validate_item(item_code)
|
|
||||||
quotation = get_quotation(user=user)
|
|
||||||
qty = flt(qty)
|
|
||||||
quotation_item = quotation.get("items", {"item_code": item_code})
|
|
||||||
if qty==0:
|
|
||||||
if quotation_item:
|
|
||||||
# remove
|
|
||||||
quotation.get("items").remove(quotation_item[0])
|
|
||||||
else:
|
|
||||||
# add or update
|
|
||||||
if quotation_item:
|
|
||||||
quotation_item[0].qty = qty
|
|
||||||
else:
|
|
||||||
quotation.append("items", {
|
|
||||||
"doctype": "Quotation Item",
|
|
||||||
"item_code": item_code,
|
|
||||||
"qty": qty
|
|
||||||
})
|
|
||||||
quotation.save(ignore_permissions=True)
|
|
||||||
return quotation
|
|
||||||
|
|
||||||
def validate_item(item_code):
|
|
||||||
item = frappe.db.get_value("Item", item_code, ["item_name", "show_in_website"], as_dict=True)
|
|
||||||
if not item.show_in_website:
|
|
||||||
frappe.throw(_("{0} cannot be purchased using Shopping Cart").format(item.item_name))
|
|
||||||
|
|
||||||
def get_party(user):
|
|
||||||
def _get_party(user):
|
|
||||||
customer = frappe.db.get_value("Contact", {"email_id": user}, "customer")
|
|
||||||
if customer:
|
|
||||||
return frappe.get_doc("Customer", customer)
|
|
||||||
|
|
||||||
lead = frappe.db.get_value("Lead", {"email_id": user})
|
|
||||||
if lead:
|
|
||||||
return frappe.get_doc("Lead", lead)
|
|
||||||
|
|
||||||
# create a lead
|
|
||||||
lead = frappe.new_doc("Lead")
|
|
||||||
lead.update({
|
|
||||||
"email_id": user,
|
|
||||||
"lead_name": get_fullname(user),
|
|
||||||
"territory": guess_territory()
|
|
||||||
})
|
|
||||||
lead.insert(ignore_permissions=True)
|
|
||||||
|
|
||||||
return lead
|
|
||||||
|
|
||||||
if not getattr(frappe.local, "shopping_cart_party", None):
|
|
||||||
frappe.local.shopping_cart_party = {}
|
|
||||||
|
|
||||||
if not frappe.local.shopping_cart_party.get(user):
|
|
||||||
frappe.local.shopping_cart_party[user] = _get_party(user)
|
|
||||||
|
|
||||||
return frappe.local.shopping_cart_party[user]
|
|
||||||
|
|
||||||
def guess_territory():
|
|
||||||
territory = None
|
|
||||||
if frappe.session.get("session_country"):
|
|
||||||
territory = frappe.db.get_value("Territory", frappe.session.get("session_country"))
|
|
||||||
return territory or get_default_territory()
|
|
||||||
|
@ -17,19 +17,19 @@ def set_cart_count(quotation=None):
|
|||||||
if not quotation:
|
if not quotation:
|
||||||
quotation = _get_cart_quotation()
|
quotation = _get_cart_quotation()
|
||||||
cart_count = cstr(len(quotation.get("items")))
|
cart_count = cstr(len(quotation.get("items")))
|
||||||
|
|
||||||
|
if hasattr(frappe.local, "cookie_manager"):
|
||||||
frappe.local.cookie_manager.set_cookie("cart_count", cart_count)
|
frappe.local.cookie_manager.set_cookie("cart_count", cart_count)
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_cart_quotation(doc=None):
|
def get_cart_quotation(doc=None):
|
||||||
party = get_lead_or_customer()
|
party = get_customer()
|
||||||
|
|
||||||
if not doc:
|
if not doc:
|
||||||
quotation = _get_cart_quotation(party)
|
quotation = _get_cart_quotation(party)
|
||||||
doc = quotation
|
doc = quotation
|
||||||
set_cart_count(quotation)
|
set_cart_count(quotation)
|
||||||
|
|
||||||
print get_applicable_shipping_rules(party)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"doc": decorate_quotation_doc(doc),
|
"doc": decorate_quotation_doc(doc),
|
||||||
"addresses": [{"name": address.name, "display": address.display}
|
"addresses": [{"name": address.name, "display": address.display}
|
||||||
@ -60,6 +60,8 @@ def place_order():
|
|||||||
sales_order.flags.ignore_permissions = True
|
sales_order.flags.ignore_permissions = True
|
||||||
sales_order.insert()
|
sales_order.insert()
|
||||||
sales_order.submit()
|
sales_order.submit()
|
||||||
|
|
||||||
|
if hasattr(frappe.local, "cookie_manager"):
|
||||||
frappe.local.cookie_manager.delete_cookie("cart_count")
|
frappe.local.cookie_manager.delete_cookie("cart_count")
|
||||||
|
|
||||||
return sales_order.name
|
return sales_order.name
|
||||||
@ -156,7 +158,7 @@ def decorate_quotation_doc(doc):
|
|||||||
|
|
||||||
def _get_cart_quotation(party=None):
|
def _get_cart_quotation(party=None):
|
||||||
if not party:
|
if not party:
|
||||||
party = get_lead_or_customer()
|
party = get_customer()
|
||||||
|
|
||||||
quotation = frappe.db.get_value("Quotation",
|
quotation = frappe.db.get_value("Quotation",
|
||||||
{party.doctype.lower(): party.name, "order_type": "Shopping Cart", "docstatus": 0})
|
{party.doctype.lower(): party.name, "order_type": "Shopping Cart", "docstatus": 0})
|
||||||
@ -176,9 +178,9 @@ def _get_cart_quotation(party=None):
|
|||||||
(party.doctype.lower()): party.name
|
(party.doctype.lower()): party.name
|
||||||
})
|
})
|
||||||
|
|
||||||
if party.doctype == "Customer":
|
|
||||||
qdoc.contact_person = frappe.db.get_value("Contact", {"email_id": frappe.session.user,
|
qdoc.contact_person = frappe.db.get_value("Contact", {"email_id": frappe.session.user,
|
||||||
"customer": party.name})
|
"customer": party.name})
|
||||||
|
qdoc.contact_email = frappe.session.user
|
||||||
|
|
||||||
qdoc.flags.ignore_permissions = True
|
qdoc.flags.ignore_permissions = True
|
||||||
qdoc.run_method("set_missing_values")
|
qdoc.run_method("set_missing_values")
|
||||||
@ -187,14 +189,8 @@ def _get_cart_quotation(party=None):
|
|||||||
return qdoc
|
return qdoc
|
||||||
|
|
||||||
def update_party(fullname, company_name=None, mobile_no=None, phone=None):
|
def update_party(fullname, company_name=None, mobile_no=None, phone=None):
|
||||||
party = get_lead_or_customer()
|
party = get_customer()
|
||||||
|
|
||||||
if party.doctype == "Lead":
|
|
||||||
party.company_name = company_name
|
|
||||||
party.lead_name = fullname
|
|
||||||
party.mobile_no = mobile_no
|
|
||||||
party.phone = phone
|
|
||||||
else:
|
|
||||||
party.customer_name = company_name or fullname
|
party.customer_name = company_name or fullname
|
||||||
party.customer_type == "Company" if company_name else "Individual"
|
party.customer_type == "Company" if company_name else "Individual"
|
||||||
|
|
||||||
@ -222,7 +218,7 @@ def update_party(fullname, company_name=None, mobile_no=None, phone=None):
|
|||||||
|
|
||||||
def apply_cart_settings(party=None, quotation=None):
|
def apply_cart_settings(party=None, quotation=None):
|
||||||
if not party:
|
if not party:
|
||||||
party = get_lead_or_customer()
|
party = get_customer()
|
||||||
if not quotation:
|
if not quotation:
|
||||||
quotation = _get_cart_quotation(party)
|
quotation = _get_cart_quotation(party)
|
||||||
|
|
||||||
@ -250,6 +246,7 @@ def set_price_list_and_rate(quotation, cart_settings):
|
|||||||
# refetch values
|
# refetch values
|
||||||
quotation.run_method("set_price_list_and_item_details")
|
quotation.run_method("set_price_list_and_item_details")
|
||||||
|
|
||||||
|
if hasattr(frappe.local, "cookie_manager"):
|
||||||
# set it in cookies for using in product page
|
# set it in cookies for using in product page
|
||||||
frappe.local.cookie_manager.set_cookie("selling_price_list", quotation.selling_price_list)
|
frappe.local.cookie_manager.set_cookie("selling_price_list", quotation.selling_price_list)
|
||||||
|
|
||||||
@ -286,32 +283,38 @@ def set_taxes(quotation, cart_settings):
|
|||||||
# # append taxes
|
# # append taxes
|
||||||
quotation.append_taxes_from_master()
|
quotation.append_taxes_from_master()
|
||||||
|
|
||||||
def get_lead_or_customer():
|
def get_customer(user=None):
|
||||||
customer = frappe.db.get_value("Contact", {"email_id": frappe.session.user}, "customer")
|
if not user:
|
||||||
|
user = frappe.session.user
|
||||||
|
|
||||||
|
customer = frappe.db.get_value("Contact", {"email_id": user}, "customer")
|
||||||
if customer:
|
if customer:
|
||||||
return frappe.get_doc("Customer", customer)
|
return frappe.get_doc("Customer", customer)
|
||||||
|
|
||||||
lead = frappe.db.get_value("Lead", {"email_id": frappe.session.user})
|
|
||||||
if lead:
|
|
||||||
return frappe.get_doc("Lead", lead)
|
|
||||||
else:
|
else:
|
||||||
lead_doc = frappe.get_doc({
|
customer = frappe.new_doc("Customer")
|
||||||
"doctype": "Lead",
|
fullname = get_fullname(user)
|
||||||
"email_id": frappe.session.user,
|
customer.update({
|
||||||
"lead_name": get_fullname(frappe.session.user),
|
"customer_name": fullname,
|
||||||
"territory": guess_territory(),
|
"customer_type": "Individual",
|
||||||
"status": "Open" # TODO: set something better???
|
"customer_group": get_shopping_cart_settings().default_customer_group,
|
||||||
|
"territory": get_root_of("Territory")
|
||||||
})
|
})
|
||||||
|
customer.insert(ignore_permissions=True)
|
||||||
|
|
||||||
if frappe.session.user not in ("Guest", "Administrator"):
|
contact = frappe.new_doc("Contact")
|
||||||
lead_doc.flags.ignore_permissions = True
|
contact.update({
|
||||||
lead_doc.insert()
|
"customer": customer.name,
|
||||||
|
"first_name": fullname,
|
||||||
|
"email_id": user
|
||||||
|
})
|
||||||
|
contact.insert(ignore_permissions=True)
|
||||||
|
|
||||||
return lead_doc
|
return customer
|
||||||
|
|
||||||
def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_page_length=20, party=None):
|
def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_page_length=20, party=None):
|
||||||
if not party:
|
if not party:
|
||||||
party = get_lead_or_customer()
|
party = get_customer()
|
||||||
|
|
||||||
address_docs = frappe.db.sql("""select * from `tabAddress`
|
address_docs = frappe.db.sql("""select * from `tabAddress`
|
||||||
where `{0}`=%s order by name limit {1}, {2}""".format(party.doctype.lower(),
|
where `{0}`=%s order by name limit {1}, {2}""".format(party.doctype.lower(),
|
||||||
|
@ -8,7 +8,6 @@ import frappe
|
|||||||
from frappe import _, msgprint
|
from frappe import _, msgprint
|
||||||
from frappe.utils import comma_and
|
from frappe.utils import comma_and
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils.nestedset import get_root_of
|
|
||||||
|
|
||||||
class ShoppingCartSetupError(frappe.ValidationError): pass
|
class ShoppingCartSetupError(frappe.ValidationError): pass
|
||||||
|
|
||||||
@ -75,9 +74,6 @@ def get_shopping_cart_settings():
|
|||||||
def is_cart_enabled():
|
def is_cart_enabled():
|
||||||
return get_shopping_cart_settings().enabled
|
return get_shopping_cart_settings().enabled
|
||||||
|
|
||||||
def get_default_territory():
|
|
||||||
return get_shopping_cart_settings().default_territory or get_root_of("Territory")
|
|
||||||
|
|
||||||
def check_shopping_cart_enabled():
|
def check_shopping_cart_enabled():
|
||||||
if not get_shopping_cart_settings().enabled:
|
if not get_shopping_cart_settings().enabled:
|
||||||
frappe.throw(_("You need to enable Shopping Cart"), ShoppingCartSetupError)
|
frappe.throw(_("You need to enable Shopping Cart"), ShoppingCartSetupError)
|
||||||
|
@ -19,14 +19,14 @@ class TestShoppingCartSettings(unittest.TestCase):
|
|||||||
def test_exchange_rate_exists(self):
|
def test_exchange_rate_exists(self):
|
||||||
frappe.db.sql("""delete from `tabCurrency Exchange`""")
|
frappe.db.sql("""delete from `tabCurrency Exchange`""")
|
||||||
|
|
||||||
cart_settings = self.test_price_list_territory_overlap()
|
cart_settings = self.get_cart_settings()
|
||||||
controller = cart_settings
|
cart_settings.price_list = "_Test Price List Rest of the World"
|
||||||
self.assertRaises(ShoppingCartSetupError, controller.validate_exchange_rates_exist)
|
self.assertRaises(ShoppingCartSetupError, cart_settings.validate_exchange_rates_exist)
|
||||||
|
|
||||||
from erpnext.setup.doctype.currency_exchange.test_currency_exchange import test_records as \
|
from erpnext.setup.doctype.currency_exchange.test_currency_exchange import test_records as \
|
||||||
currency_exchange_records
|
currency_exchange_records
|
||||||
frappe.get_doc(currency_exchange_records[0]).insert()
|
frappe.get_doc(currency_exchange_records[0]).insert()
|
||||||
controller.validate_exchange_rates_exist()
|
cart_settings.validate_exchange_rates_exist()
|
||||||
|
|
||||||
def test_tax_rule_validation(self):
|
def test_tax_rule_validation(self):
|
||||||
frappe.db.sql("update `tabTax Rule` set use_for_shopping_cart = 0")
|
frappe.db.sql("update `tabTax Rule` set use_for_shopping_cart = 0")
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import unittest
|
import unittest
|
||||||
import frappe
|
import frappe
|
||||||
from erpnext.shopping_cart import get_quotation, set_item_in_cart, get_party
|
from erpnext.shopping_cart.cart import _get_cart_quotation, update_cart, get_customer
|
||||||
|
|
||||||
class TestShoppingCart(unittest.TestCase):
|
class TestShoppingCart(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
@ -23,23 +23,11 @@ class TestShoppingCart(unittest.TestCase):
|
|||||||
self.login_as_new_user()
|
self.login_as_new_user()
|
||||||
|
|
||||||
# test if lead is created and quotation with new lead is fetched
|
# test if lead is created and quotation with new lead is fetched
|
||||||
quotation = get_quotation()
|
quotation = _get_cart_quotation()
|
||||||
self.assertEquals(quotation.quotation_to, "Lead")
|
self.assertEquals(quotation.quotation_to, "Customer")
|
||||||
self.assertEquals(frappe.db.get_value("Lead", quotation.lead, "email_id"),
|
self.assertEquals(frappe.db.get_value("Contact", {"customer": quotation.customer}, "email_id"),
|
||||||
"test_cart_user@example.com")
|
"test_cart_user@example.com")
|
||||||
self.assertEquals(quotation.customer, None)
|
self.assertEquals(quotation.lead, None)
|
||||||
self.assertEquals(quotation.contact_email, frappe.session.user)
|
|
||||||
|
|
||||||
return quotation
|
|
||||||
|
|
||||||
def test_get_cart_lead(self):
|
|
||||||
self.login_as_lead()
|
|
||||||
|
|
||||||
# test if quotation with lead is fetched
|
|
||||||
quotation = get_quotation()
|
|
||||||
self.assertEquals(quotation.quotation_to, "Lead")
|
|
||||||
self.assertEquals(quotation.lead, frappe.db.get_value("Lead", {"email_id": "test_cart_lead@example.com"}))
|
|
||||||
self.assertEquals(quotation.customer, None)
|
|
||||||
self.assertEquals(quotation.contact_email, frappe.session.user)
|
self.assertEquals(quotation.contact_email, frappe.session.user)
|
||||||
|
|
||||||
return quotation
|
return quotation
|
||||||
@ -48,7 +36,7 @@ class TestShoppingCart(unittest.TestCase):
|
|||||||
self.login_as_customer()
|
self.login_as_customer()
|
||||||
|
|
||||||
# test if quotation with customer is fetched
|
# test if quotation with customer is fetched
|
||||||
quotation = get_quotation()
|
quotation = _get_cart_quotation()
|
||||||
self.assertEquals(quotation.quotation_to, "Customer")
|
self.assertEquals(quotation.quotation_to, "Customer")
|
||||||
self.assertEquals(quotation.customer, "_Test Customer")
|
self.assertEquals(quotation.customer, "_Test Customer")
|
||||||
self.assertEquals(quotation.lead, None)
|
self.assertEquals(quotation.lead, None)
|
||||||
@ -57,21 +45,21 @@ class TestShoppingCart(unittest.TestCase):
|
|||||||
return quotation
|
return quotation
|
||||||
|
|
||||||
def test_add_to_cart(self):
|
def test_add_to_cart(self):
|
||||||
self.login_as_lead()
|
self.login_as_customer()
|
||||||
|
|
||||||
# remove from cart
|
# remove from cart
|
||||||
self.remove_all_items_from_cart()
|
self.remove_all_items_from_cart()
|
||||||
|
|
||||||
# add first item
|
# add first item
|
||||||
set_item_in_cart("_Test Item", 1)
|
update_cart("_Test Item", 1)
|
||||||
quotation = self.test_get_cart_lead()
|
quotation = self.test_get_cart_customer()
|
||||||
self.assertEquals(quotation.get("items")[0].item_code, "_Test Item")
|
self.assertEquals(quotation.get("items")[0].item_code, "_Test Item")
|
||||||
self.assertEquals(quotation.get("items")[0].qty, 1)
|
self.assertEquals(quotation.get("items")[0].qty, 1)
|
||||||
self.assertEquals(quotation.get("items")[0].amount, 10)
|
self.assertEquals(quotation.get("items")[0].amount, 10)
|
||||||
|
|
||||||
# add second item
|
# add second item
|
||||||
set_item_in_cart("_Test Item 2", 1)
|
update_cart("_Test Item 2", 1)
|
||||||
quotation = self.test_get_cart_lead()
|
quotation = self.test_get_cart_customer()
|
||||||
self.assertEquals(quotation.get("items")[1].item_code, "_Test Item 2")
|
self.assertEquals(quotation.get("items")[1].item_code, "_Test Item 2")
|
||||||
self.assertEquals(quotation.get("items")[1].qty, 1)
|
self.assertEquals(quotation.get("items")[1].qty, 1)
|
||||||
self.assertEquals(quotation.get("items")[1].amount, 20)
|
self.assertEquals(quotation.get("items")[1].amount, 20)
|
||||||
@ -83,8 +71,8 @@ class TestShoppingCart(unittest.TestCase):
|
|||||||
self.test_add_to_cart()
|
self.test_add_to_cart()
|
||||||
|
|
||||||
# update first item
|
# update first item
|
||||||
set_item_in_cart("_Test Item", 5)
|
update_cart("_Test Item", 5)
|
||||||
quotation = self.test_get_cart_lead()
|
quotation = self.test_get_cart_customer()
|
||||||
self.assertEquals(quotation.get("items")[0].item_code, "_Test Item")
|
self.assertEquals(quotation.get("items")[0].item_code, "_Test Item")
|
||||||
self.assertEquals(quotation.get("items")[0].qty, 5)
|
self.assertEquals(quotation.get("items")[0].qty, 5)
|
||||||
self.assertEquals(quotation.get("items")[0].amount, 50)
|
self.assertEquals(quotation.get("items")[0].amount, 50)
|
||||||
@ -96,8 +84,8 @@ class TestShoppingCart(unittest.TestCase):
|
|||||||
self.test_add_to_cart()
|
self.test_add_to_cart()
|
||||||
|
|
||||||
# remove first item
|
# remove first item
|
||||||
set_item_in_cart("_Test Item", 0)
|
update_cart("_Test Item", 0)
|
||||||
quotation = self.test_get_cart_lead()
|
quotation = self.test_get_cart_customer()
|
||||||
self.assertEquals(quotation.get("items")[0].item_code, "_Test Item 2")
|
self.assertEquals(quotation.get("items")[0].item_code, "_Test Item 2")
|
||||||
self.assertEquals(quotation.get("items")[0].qty, 1)
|
self.assertEquals(quotation.get("items")[0].qty, 1)
|
||||||
self.assertEquals(quotation.get("items")[0].amount, 20)
|
self.assertEquals(quotation.get("items")[0].amount, 20)
|
||||||
@ -105,11 +93,11 @@ class TestShoppingCart(unittest.TestCase):
|
|||||||
self.assertEquals(len(quotation.get("items")), 1)
|
self.assertEquals(len(quotation.get("items")), 1)
|
||||||
|
|
||||||
# remove second item
|
# remove second item
|
||||||
set_item_in_cart("_Test Item 2", 0)
|
update_cart("_Test Item 2", 0)
|
||||||
quotation = self.test_get_cart_lead()
|
quotation = self.test_get_cart_customer()
|
||||||
self.assertEquals(quotation.net_total, 0)
|
|
||||||
self.assertEquals(len(quotation.get("items")), 0)
|
|
||||||
|
|
||||||
|
self.assertEquals(len(quotation.get("items")), 0)
|
||||||
|
self.assertEquals(quotation.net_total, 0)
|
||||||
|
|
||||||
def test_tax_rule(self):
|
def test_tax_rule(self):
|
||||||
self.login_as_customer()
|
self.login_as_customer()
|
||||||
@ -133,7 +121,7 @@ class TestShoppingCart(unittest.TestCase):
|
|||||||
"doctype": "Quotation",
|
"doctype": "Quotation",
|
||||||
"quotation_to": "Customer",
|
"quotation_to": "Customer",
|
||||||
"order_type": "Shopping Cart",
|
"order_type": "Shopping Cart",
|
||||||
"customer": get_party(frappe.session.user).name,
|
"customer": get_customer(frappe.session.user).name,
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"contact_email": frappe.session.user,
|
"contact_email": frappe.session.user,
|
||||||
"selling_price_list": "_Test Price List Rest of the World",
|
"selling_price_list": "_Test Price List Rest of the World",
|
||||||
@ -167,20 +155,10 @@ class TestShoppingCart(unittest.TestCase):
|
|||||||
settings.update({
|
settings.update({
|
||||||
"enabled": 1,
|
"enabled": 1,
|
||||||
"company": "_Test Company",
|
"company": "_Test Company",
|
||||||
"default_territory": "_Test Territory Rest Of The World",
|
|
||||||
"default_customer_group": "_Test Customer Group",
|
"default_customer_group": "_Test Customer Group",
|
||||||
"quotation_series": "_T-Quotation-"
|
"quotation_series": "_T-Quotation-",
|
||||||
|
"price_list": "_Test Price List India"
|
||||||
})
|
})
|
||||||
settings.set("price_lists", [
|
|
||||||
# price lists
|
|
||||||
{"doctype": "Shopping Cart Price List", "parentfield": "price_lists",
|
|
||||||
"selling_price_list": "_Test Price List India"},
|
|
||||||
{"doctype": "Shopping Cart Price List", "parentfield": "price_lists",
|
|
||||||
"selling_price_list": "_Test Price List Rest of the World"}
|
|
||||||
])
|
|
||||||
settings.set("shipping_rules", {"doctype": "Shopping Cart Shipping Rule", "parentfield": "shipping_rules",
|
|
||||||
"shipping_rule": "_Test Shipping Rule - India"})
|
|
||||||
|
|
||||||
|
|
||||||
settings.save()
|
settings.save()
|
||||||
frappe.local.shopping_cart_settings = None
|
frappe.local.shopping_cart_settings = None
|
||||||
@ -194,54 +172,11 @@ class TestShoppingCart(unittest.TestCase):
|
|||||||
def login_as_new_user(self):
|
def login_as_new_user(self):
|
||||||
frappe.set_user("test_cart_user@example.com")
|
frappe.set_user("test_cart_user@example.com")
|
||||||
|
|
||||||
def login_as_lead(self):
|
|
||||||
self.create_lead()
|
|
||||||
frappe.set_user("test_cart_lead@example.com")
|
|
||||||
|
|
||||||
def login_as_customer(self):
|
def login_as_customer(self):
|
||||||
frappe.set_user("test_contact_customer@example.com")
|
frappe.set_user("test_contact_customer@example.com")
|
||||||
|
|
||||||
def create_lead(self):
|
|
||||||
if frappe.db.get_value("Lead", {"email_id": "test_cart_lead@example.com"}):
|
|
||||||
return
|
|
||||||
|
|
||||||
lead = frappe.get_doc({
|
|
||||||
"doctype": "Lead",
|
|
||||||
"email_id": "test_cart_lead@example.com",
|
|
||||||
"lead_name": "_Test Website Lead",
|
|
||||||
"status": "Open",
|
|
||||||
"territory": "_Test Territory Rest Of The World",
|
|
||||||
"company": "_Test Company"
|
|
||||||
})
|
|
||||||
lead.insert(ignore_permissions=True)
|
|
||||||
|
|
||||||
frappe.get_doc({
|
|
||||||
"doctype": "Address",
|
|
||||||
"address_line1": "_Test Address Line 1",
|
|
||||||
"address_title": "_Test Cart Lead Address",
|
|
||||||
"address_type": "Office",
|
|
||||||
"city": "_Test City",
|
|
||||||
"country": "United States",
|
|
||||||
"lead": lead.name,
|
|
||||||
"lead_name": "_Test Website Lead",
|
|
||||||
"is_primary_address": 1,
|
|
||||||
"phone": "+91 0000000000"
|
|
||||||
}).insert(ignore_permissions=True)
|
|
||||||
|
|
||||||
frappe.get_doc({
|
|
||||||
"doctype": "Address",
|
|
||||||
"address_line1": "_Test Address Line 1",
|
|
||||||
"address_title": "_Test Cart Lead Address",
|
|
||||||
"address_type": "Personal",
|
|
||||||
"city": "_Test City",
|
|
||||||
"country": "India",
|
|
||||||
"lead": lead.name,
|
|
||||||
"lead_name": "_Test Website Lead",
|
|
||||||
"phone": "+91 0000000000"
|
|
||||||
}).insert(ignore_permissions=True)
|
|
||||||
|
|
||||||
def remove_all_items_from_cart(self):
|
def remove_all_items_from_cart(self):
|
||||||
quotation = get_quotation()
|
quotation = _get_cart_quotation()
|
||||||
quotation.set("items", [])
|
quotation.set("items", [])
|
||||||
quotation.save(ignore_permissions=True)
|
quotation.save(ignore_permissions=True)
|
||||||
|
|
||||||
|
@ -2,10 +2,6 @@
|
|||||||
// License: GNU General Public License v3. See license.txt
|
// License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
$.extend(cur_frm.cscript, {
|
$.extend(cur_frm.cscript, {
|
||||||
onload: function() {
|
|
||||||
erpnext.add_applicable_territory();
|
|
||||||
},
|
|
||||||
|
|
||||||
refresh: function() {
|
refresh: function() {
|
||||||
cur_frm.add_custom_button(__("Add / Edit Prices"), function() {
|
cur_frm.add_custom_button(__("Add / Edit Prices"), function() {
|
||||||
frappe.route_options = {
|
frappe.route_options = {
|
||||||
|
@ -5,14 +5,7 @@
|
|||||||
"doctype": "Price List",
|
"doctype": "Price List",
|
||||||
"enabled": 1,
|
"enabled": 1,
|
||||||
"price_list_name": "_Test Price List",
|
"price_list_name": "_Test Price List",
|
||||||
"selling": 1,
|
"selling": 1
|
||||||
"territories": [
|
|
||||||
{
|
|
||||||
"doctype": "Applicable Territory",
|
|
||||||
"parentfield": "territories",
|
|
||||||
"territory": "All Territories"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"buying": 1,
|
"buying": 1,
|
||||||
@ -20,14 +13,7 @@
|
|||||||
"doctype": "Price List",
|
"doctype": "Price List",
|
||||||
"enabled": 1,
|
"enabled": 1,
|
||||||
"price_list_name": "_Test Price List 2",
|
"price_list_name": "_Test Price List 2",
|
||||||
"selling": 1,
|
"selling": 1
|
||||||
"territories": [
|
|
||||||
{
|
|
||||||
"doctype": "Applicable Territory",
|
|
||||||
"parentfield": "territories",
|
|
||||||
"territory": "_Test Territory Rest Of The World"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"buying": 1,
|
"buying": 1,
|
||||||
@ -35,14 +21,7 @@
|
|||||||
"doctype": "Price List",
|
"doctype": "Price List",
|
||||||
"enabled": 1,
|
"enabled": 1,
|
||||||
"price_list_name": "_Test Price List India",
|
"price_list_name": "_Test Price List India",
|
||||||
"selling": 1,
|
"selling": 1
|
||||||
"territories": [
|
|
||||||
{
|
|
||||||
"doctype": "Applicable Territory",
|
|
||||||
"parentfield": "territories",
|
|
||||||
"territory": "_Test Territory India"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"buying": 1,
|
"buying": 1,
|
||||||
@ -50,18 +29,6 @@
|
|||||||
"doctype": "Price List",
|
"doctype": "Price List",
|
||||||
"enabled": 1,
|
"enabled": 1,
|
||||||
"price_list_name": "_Test Price List Rest of the World",
|
"price_list_name": "_Test Price List Rest of the World",
|
||||||
"selling": 1,
|
"selling": 1
|
||||||
"territories": [
|
|
||||||
{
|
|
||||||
"doctype": "Applicable Territory",
|
|
||||||
"parentfield": "territories",
|
|
||||||
"territory": "_Test Territory Rest Of The World"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Applicable Territory",
|
|
||||||
"parentfield": "territories",
|
|
||||||
"territory": "_Test Territory United States"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
@ -5,17 +5,13 @@ from __future__ import unicode_literals
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import cstr
|
from frappe.utils import cstr
|
||||||
from erpnext.shopping_cart.cart import get_lead_or_customer
|
from erpnext.shopping_cart.cart import get_customer
|
||||||
|
|
||||||
no_cache = 1
|
no_cache = 1
|
||||||
no_sitemap = 1
|
no_sitemap = 1
|
||||||
|
|
||||||
def get_context(context):
|
def get_context(context):
|
||||||
party = get_lead_or_customer()
|
party = get_customer()
|
||||||
if party.doctype == "Lead":
|
|
||||||
mobile_no = party.mobile_no
|
|
||||||
phone = party.phone
|
|
||||||
else:
|
|
||||||
mobile_no, phone = frappe.db.get_value("Contact", {"email_id": frappe.session.user,
|
mobile_no, phone = frappe.db.get_value("Contact", {"email_id": frappe.session.user,
|
||||||
"customer": party.name}, ["mobile_no", "phone"])
|
"customer": party.name}, ["mobile_no", "phone"])
|
||||||
|
|
||||||
@ -37,4 +33,3 @@ def update_user(fullname, password=None, company_name=None, mobile_no=None, phon
|
|||||||
frappe.local.cookie_manager.set_cookie("full_name", fullname)
|
frappe.local.cookie_manager.set_cookie("full_name", fullname)
|
||||||
|
|
||||||
return _("Updated")
|
return _("Updated")
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user