[cleanup] added single price list for shopping cart, removed Applicable Territory
This commit is contained in:
parent
8ffd483e24
commit
72fbf902d7
@ -164,29 +164,6 @@
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"description": "Specify a list of Territories, for which, this Taxes Master is valid",
|
||||
"fieldname": "territories",
|
||||
"fieldtype": "Table",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Valid for Territories",
|
||||
"no_copy": 0,
|
||||
"options": "Applicable Territory",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
}
|
||||
],
|
||||
"hide_heading": 0,
|
||||
@ -198,7 +175,7 @@
|
||||
"is_submittable": 0,
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"modified": "2015-09-11 12:19:46.488710",
|
||||
"modified": "2015-09-17 07:09:28.797959",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Sales Taxes and Charges Template",
|
||||
@ -206,7 +183,7 @@
|
||||
"permissions": [
|
||||
{
|
||||
"amend": 0,
|
||||
"apply_user_permissions": 0,
|
||||
"apply_user_permissions": 1,
|
||||
"cancel": 0,
|
||||
"create": 0,
|
||||
"delete": 0,
|
||||
|
@ -5,7 +5,6 @@ from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from erpnext.controllers.accounts_controller import validate_taxes_and_charges, validate_inclusive_tax
|
||||
from frappe.utils.nestedset import get_root_of
|
||||
|
||||
class SalesTaxesandChargesTemplate(Document):
|
||||
def validate(self):
|
||||
@ -20,10 +19,6 @@ def valdiate_taxes_and_charges_template(doc):
|
||||
where ifnull(is_default,0) = 1 and name != %s and company = %s""".format(doc.doctype),
|
||||
(doc.name, doc.company))
|
||||
|
||||
if doc.meta.get_field("territories"):
|
||||
if not doc.territories:
|
||||
doc.append("territories", {"territory": get_root_of("Territory") })
|
||||
|
||||
for tax in doc.get("taxes"):
|
||||
validate_taxes_and_charges(tax)
|
||||
validate_inclusive_tax(tax, doc)
|
||||
|
@ -35,14 +35,16 @@
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "column_break_2",
|
||||
"fieldtype": "Column Break",
|
||||
"fieldname": "disabled",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Disabled",
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
@ -78,6 +80,7 @@
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"depends_on": "eval:!doc.disabled",
|
||||
"fieldname": "rule_conditions_section",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
@ -121,12 +124,14 @@
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"depends_on": "eval:!doc.disabled",
|
||||
"fieldname": "section_break_6",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Valid for Countries",
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
@ -141,6 +146,29 @@
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "worldwide_shipping",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Worldwide Shipping",
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"depends_on": "eval:!doc.worldwide_shipping",
|
||||
"fieldname": "countries",
|
||||
"fieldtype": "Table",
|
||||
"hidden": 0,
|
||||
@ -164,8 +192,9 @@
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "column_break_8",
|
||||
"fieldtype": "Column Break",
|
||||
"depends_on": "eval:!doc.disabled",
|
||||
"fieldname": "section_break_10",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
@ -206,8 +235,8 @@
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "section_break_10",
|
||||
"fieldtype": "Section Break",
|
||||
"fieldname": "column_break_12",
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
@ -244,26 +273,6 @@
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "column_break_12",
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
@ -296,7 +305,7 @@
|
||||
"is_submittable": 0,
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"modified": "2015-09-17 06:44:05.127516",
|
||||
"modified": "2015-09-17 08:30:57.226342",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Shipping Rule",
|
||||
|
@ -22,6 +22,9 @@ class ShippingRule(Document):
|
||||
self.sort_shipping_rule_conditions()
|
||||
self.validate_overlapping_shipping_rule_conditions()
|
||||
|
||||
if self.worldwide_shipping:
|
||||
self.countries = []
|
||||
|
||||
def validate_from_to_values(self):
|
||||
zero_to_values = []
|
||||
|
||||
|
@ -103,6 +103,19 @@ def set_other_values(out, party, party_type):
|
||||
if party.get("default_" + f):
|
||||
out[f] = party.get("default_" + f)
|
||||
|
||||
def get_default_price_list(party):
|
||||
"""Return default price list for party (Document object)"""
|
||||
if party.default_price_list:
|
||||
return party.default_price_list
|
||||
|
||||
if party.doctype == "Customer":
|
||||
price_list = frappe.db.get_value("Customer Group",
|
||||
party.customer_group, "default_price_list")
|
||||
if price_list:
|
||||
return price_list
|
||||
|
||||
return None
|
||||
|
||||
def set_price_list(out, party, party_type, given_price_list):
|
||||
# price list
|
||||
price_list = filter(None, get_user_permissions().get("Price List", []))
|
||||
@ -110,11 +123,7 @@ def set_price_list(out, party, party_type, given_price_list):
|
||||
price_list = price_list[0] if len(price_list)==1 else None
|
||||
|
||||
if not price_list:
|
||||
price_list = party.default_price_list
|
||||
|
||||
if not price_list and party_type=="Customer":
|
||||
price_list = frappe.db.get_value("Customer Group",
|
||||
party.customer_group, "default_price_list")
|
||||
price_list = get_default_price_list(party)
|
||||
|
||||
if not price_list:
|
||||
price_list = given_price_list
|
||||
|
@ -209,3 +209,5 @@ erpnext.patches.v6_0.fix_planned_qty
|
||||
erpnext.patches.v6_0.multi_currency
|
||||
erpnext.patches.v6_2.remove_newsletter_duplicates
|
||||
erpnext.patches.v6_2.fix_missing_default_taxes_and_lead
|
||||
erpnext.patches.v5_8.tax_rule
|
||||
erpnext.patches.v6_3.convert_applicable_territory
|
||||
|
17
erpnext/patches/v6_3/convert_applicable_territory.py
Normal file
17
erpnext/patches/v6_3/convert_applicable_territory.py
Normal file
@ -0,0 +1,17 @@
|
||||
import frappe
|
||||
|
||||
def execute():
|
||||
# for price list
|
||||
countries = frappe.db.sql_list("select name from tabCountry")
|
||||
|
||||
for doctype in ("Price List", "Shipping Rule"):
|
||||
for at in frappe.db.sql("""select name, parent, territory from `tabApplicable Territory` where
|
||||
parenttype = %s """, doctype, as_dict=True):
|
||||
if at.territory in countries:
|
||||
parent = frappe.get_doc(doctype, at.parent)
|
||||
if not parent.countries:
|
||||
parent.append("countries", {"country": at.territory})
|
||||
parent.save()
|
||||
|
||||
|
||||
frappe.delete_doc("DocType", "Applicable Territory")
|
@ -1,50 +0,0 @@
|
||||
{
|
||||
"allow_copy": 0,
|
||||
"allow_import": 0,
|
||||
"allow_rename": 0,
|
||||
"creation": "2013-06-20 12:48:38",
|
||||
"custom": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"fields": [
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"description": "",
|
||||
"fieldname": "territory",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Territory",
|
||||
"no_copy": 0,
|
||||
"options": "Territory",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
}
|
||||
],
|
||||
"hide_heading": 0,
|
||||
"hide_toolbar": 0,
|
||||
"idx": 1,
|
||||
"in_create": 0,
|
||||
"in_dialog": 0,
|
||||
"is_submittable": 0,
|
||||
"issingle": 0,
|
||||
"istable": 1,
|
||||
"modified": "2015-01-01 14:29:58.724652",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"name": "Applicable Territory",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"read_only": 0,
|
||||
"read_only_onload": 0
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# MIT License. See license.txt
|
||||
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
from frappe.model.document import Document
|
||||
|
||||
class ApplicableTerritory(Document):
|
||||
pass
|
@ -131,8 +131,11 @@ def update_cart_address(address_fieldname, address_name):
|
||||
quotation.flags.ignore_permissions = True
|
||||
quotation.save()
|
||||
|
||||
return frappe.render_template("templates/includes/cart/cart_address.html",
|
||||
get_cart_quotation(quotation))
|
||||
context = get_cart_quotation(quotation)
|
||||
return {
|
||||
"taxes": frappe.render_template("templates/includes/order/order_taxes.html",
|
||||
context),
|
||||
}
|
||||
|
||||
def guess_territory():
|
||||
territory = None
|
||||
@ -224,21 +227,19 @@ def apply_cart_settings(party=None, quotation=None):
|
||||
quotation = _get_cart_quotation(party)
|
||||
|
||||
cart_settings = frappe.get_doc("Shopping Cart Settings")
|
||||
billing_territory = get_address_territory(quotation.customer_address) or \
|
||||
party.territory or get_root_of("Territory")
|
||||
|
||||
set_price_list_and_rate(quotation, cart_settings, billing_territory)
|
||||
set_price_list_and_rate(quotation, cart_settings)
|
||||
|
||||
quotation.run_method("calculate_taxes_and_totals")
|
||||
|
||||
set_taxes(quotation, cart_settings, billing_territory)
|
||||
set_taxes(quotation, cart_settings)
|
||||
|
||||
_apply_shipping_rule(party, quotation, cart_settings)
|
||||
|
||||
def set_price_list_and_rate(quotation, cart_settings, billing_territory):
|
||||
def set_price_list_and_rate(quotation, cart_settings):
|
||||
"""set price list based on billing territory"""
|
||||
|
||||
_set_price_list(quotation, cart_settings, billing_territory)
|
||||
_set_price_list(quotation, cart_settings)
|
||||
|
||||
# reset values
|
||||
quotation.price_list_currency = quotation.currency = \
|
||||
@ -252,24 +253,29 @@ def set_price_list_and_rate(quotation, cart_settings, billing_territory):
|
||||
# set it in cookies for using in product page
|
||||
frappe.local.cookie_manager.set_cookie("selling_price_list", quotation.selling_price_list)
|
||||
|
||||
def _set_price_list(quotation, cart_settings, billing_territory):
|
||||
def _set_price_list(quotation, cart_settings):
|
||||
"""Set price list based on customer or shopping cart default"""
|
||||
if quotation.selling_price_list:
|
||||
return
|
||||
|
||||
# check if customer price list exists
|
||||
selling_price_list = None
|
||||
if quotation.customer:
|
||||
selling_price_list = frappe.db.get_value("Customer", quotation.customer, "default_price_list")
|
||||
from erpnext.accounts.party import get_default_price_list
|
||||
selling_price_list = get_default_price_list(frappe.get_doc("Customer", quotation.customer))
|
||||
|
||||
# else check for territory based price list
|
||||
if not selling_price_list:
|
||||
selling_price_list = cart_settings.get_price_list(billing_territory)
|
||||
selling_price_list = cart_settings.price_list
|
||||
|
||||
quotation.selling_price_list = selling_price_list
|
||||
|
||||
def set_taxes(quotation, cart_settings, billing_territory):
|
||||
def set_taxes(quotation, cart_settings):
|
||||
"""set taxes based on billing territory"""
|
||||
from erpnext.accounts.party import set_taxes
|
||||
|
||||
|
||||
customer_group = frappe.db.get_value("Customer", quotation.customer, "customer_group")
|
||||
|
||||
|
||||
quotation.taxes_and_charges = set_taxes(quotation.customer, "Customer", \
|
||||
quotation.transaction_date, quotation.company, customer_group, None, \
|
||||
quotation.customer_address, quotation.shipping_address_name, 1)
|
||||
@ -331,38 +337,39 @@ def apply_shipping_rule(shipping_rule):
|
||||
return get_cart_quotation(quotation)
|
||||
|
||||
def _apply_shipping_rule(party=None, quotation=None, cart_settings=None):
|
||||
shipping_rules = get_shipping_rules(party, quotation, cart_settings)
|
||||
if not quotation.shipping_rule:
|
||||
shipping_rules = get_shipping_rules(quotation, cart_settings)
|
||||
|
||||
if not shipping_rules:
|
||||
return
|
||||
if not shipping_rules:
|
||||
return
|
||||
|
||||
elif quotation.shipping_rule not in shipping_rules:
|
||||
quotation.shipping_rule = shipping_rules[0]
|
||||
elif quotation.shipping_rule not in shipping_rules:
|
||||
quotation.shipping_rule = shipping_rules[0]
|
||||
|
||||
quotation.run_method("apply_shipping_rule")
|
||||
quotation.run_method("calculate_taxes_and_totals")
|
||||
if quotation.shipping_rule:
|
||||
quotation.run_method("apply_shipping_rule")
|
||||
quotation.run_method("calculate_taxes_and_totals")
|
||||
|
||||
def get_applicable_shipping_rules(party=None, quotation=None):
|
||||
shipping_rules = get_shipping_rules(party, quotation)
|
||||
shipping_rules = get_shipping_rules(quotation)
|
||||
|
||||
if shipping_rules:
|
||||
rule_label_map = frappe.db.get_values("Shipping Rule", shipping_rules, "label")
|
||||
# we need this in sorted order as per the position of the rule in the settings page
|
||||
return [[rule, rule_label_map.get(rule)] for rule in shipping_rules]
|
||||
|
||||
def get_shipping_rules(party=None, quotation=None, cart_settings=None):
|
||||
if not party:
|
||||
party = get_lead_or_customer()
|
||||
def get_shipping_rules(quotation=None, cart_settings=None):
|
||||
if not quotation:
|
||||
quotation = _get_cart_quotation()
|
||||
if not cart_settings:
|
||||
cart_settings = frappe.get_doc("Shopping Cart Settings")
|
||||
|
||||
# set shipping rule based on shipping territory
|
||||
shipping_territory = get_address_territory(quotation.shipping_address_name) or \
|
||||
party.territory
|
||||
|
||||
shipping_rules = cart_settings.get_shipping_rules(shipping_territory)
|
||||
shipping_rules = []
|
||||
if quotation.shipping_address_name:
|
||||
country = frappe.db.get_value("Address", quotation.shipping_address_name, "country")
|
||||
if country:
|
||||
shipping_rules = frappe.db.sql_list("""select distinct sr.name
|
||||
from `tabShipping Rule Country` src, `tabShipping Rule` sr
|
||||
where src.country = %s and
|
||||
sr.disabled != 1 and sr.name = src.parent""", country)
|
||||
|
||||
return shipping_rules
|
||||
|
||||
|
@ -1,49 +0,0 @@
|
||||
{
|
||||
"allow_copy": 0,
|
||||
"allow_import": 0,
|
||||
"allow_rename": 0,
|
||||
"creation": "2013-06-20 16:00:18",
|
||||
"custom": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"fields": [
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "selling_price_list",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Price List",
|
||||
"no_copy": 0,
|
||||
"options": "Price List",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
}
|
||||
],
|
||||
"hide_heading": 0,
|
||||
"hide_toolbar": 0,
|
||||
"idx": 1,
|
||||
"in_create": 0,
|
||||
"in_dialog": 0,
|
||||
"is_submittable": 0,
|
||||
"issingle": 0,
|
||||
"istable": 1,
|
||||
"modified": "2013-12-20 19:30:47",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Shopping Cart",
|
||||
"name": "Shopping Cart Price List",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"read_only": 0,
|
||||
"read_only_onload": 0
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
from frappe.model.document import Document
|
||||
|
||||
class ShoppingCartPriceList(Document):
|
||||
pass
|
@ -75,17 +75,17 @@
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"description": "<a href=\"#Sales Browser/Territory\">Add / Edit</a>",
|
||||
"fieldname": "default_territory",
|
||||
"fieldname": "price_list",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 1,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Default Territory",
|
||||
"in_list_view": 0,
|
||||
"label": "Price List",
|
||||
"no_copy": 0,
|
||||
"options": "Territory",
|
||||
"options": "Price List",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
@ -118,7 +118,7 @@
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"description": "<a href=\"#Sales Browser/Customer Group\">Add / Edit</a>",
|
||||
"description": "",
|
||||
"fieldname": "default_customer_group",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
@ -157,91 +157,6 @@
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "section_break_6",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "price_lists",
|
||||
"fieldtype": "Table",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Price Lists",
|
||||
"no_copy": 0,
|
||||
"options": "Shopping Cart Price List",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "column_break_10",
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "shipping_rules",
|
||||
"fieldtype": "Table",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Shipping Rules",
|
||||
"no_copy": 0,
|
||||
"options": "Shopping Cart Shipping Rule",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
}
|
||||
],
|
||||
"hide_heading": 0,
|
||||
@ -253,7 +168,7 @@
|
||||
"is_submittable": 0,
|
||||
"issingle": 1,
|
||||
"istable": 0,
|
||||
"modified": "2015-09-11 19:03:54.750937",
|
||||
"modified": "2015-09-17 07:56:09.176098",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Shopping Cart",
|
||||
"name": "Shopping Cart Settings",
|
||||
|
@ -18,7 +18,6 @@ class ShoppingCartSettings(Document):
|
||||
|
||||
def validate(self):
|
||||
if self.enabled:
|
||||
self.validate_tax_masters()
|
||||
self.validate_exchange_rates_exist()
|
||||
|
||||
def validate_exchange_rates_exist(self):
|
||||
@ -29,7 +28,7 @@ class ShoppingCartSettings(Document):
|
||||
raise_exception=ShoppingCartSetupError)
|
||||
|
||||
price_list_currency_map = frappe.db.get_values("Price List",
|
||||
[d.selling_price_list for d in self.get("price_lists")],
|
||||
[self.price_list],
|
||||
"currency")
|
||||
|
||||
# check if all price lists have a currency
|
||||
@ -52,14 +51,6 @@ class ShoppingCartSettings(Document):
|
||||
msgprint(_("Missing Currency Exchange Rates for {0}").format(comma_and(missing)),
|
||||
raise_exception=ShoppingCartSetupError)
|
||||
|
||||
def get_price_list(self, billing_territory):
|
||||
price_list = self.get_name_from_territory(billing_territory, "price_lists", "selling_price_list")
|
||||
if not (price_list and price_list[0]):
|
||||
price_list = self.get_name_from_territory(self.default_territory or get_root_of("Territory"),
|
||||
"price_lists", "selling_price_list")
|
||||
|
||||
return price_list and price_list[0] or None
|
||||
|
||||
def validate_tax_rule(self):
|
||||
if not frappe.db.get_value("Tax Rule", {"use_for_shopping_cart" : 1}, "name"):
|
||||
frappe.throw(frappe._("Set Tax Rule for shopping cart"), ShoppingCartSetupError)
|
||||
|
@ -11,55 +11,29 @@ from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings
|
||||
class TestShoppingCartSettings(unittest.TestCase):
|
||||
def setUp(self):
|
||||
frappe.db.sql("""delete from `tabSingles` where doctype="Shipping Cart Settings" """)
|
||||
frappe.db.sql("""delete from `tabShopping Cart Price List`""")
|
||||
frappe.db.sql("""delete from `tabShopping Cart Shipping Rule`""")
|
||||
|
||||
|
||||
def get_cart_settings(self):
|
||||
return frappe.get_doc({"doctype": "Shopping Cart Settings",
|
||||
"company": "_Test Company"})
|
||||
|
||||
def test_price_list_territory_overlap(self):
|
||||
cart_settings = self.get_cart_settings()
|
||||
|
||||
def _add_price_list(price_list):
|
||||
cart_settings.append("price_lists", {
|
||||
"doctype": "Shopping Cart Price List",
|
||||
"selling_price_list": price_list
|
||||
})
|
||||
|
||||
for price_list in ("_Test Price List Rest of the World", "_Test Price List India",
|
||||
"_Test Price List"):
|
||||
_add_price_list(price_list)
|
||||
|
||||
controller = cart_settings
|
||||
controller.validate_overlapping_territories("price_lists", "selling_price_list")
|
||||
|
||||
_add_price_list("_Test Price List 2")
|
||||
|
||||
controller = cart_settings
|
||||
self.assertRaises(ShoppingCartSetupError, controller.validate_overlapping_territories,
|
||||
"price_lists", "selling_price_list")
|
||||
|
||||
return cart_settings
|
||||
|
||||
|
||||
def test_exchange_rate_exists(self):
|
||||
frappe.db.sql("""delete from `tabCurrency Exchange`""")
|
||||
|
||||
|
||||
cart_settings = self.test_price_list_territory_overlap()
|
||||
controller = cart_settings
|
||||
self.assertRaises(ShoppingCartSetupError, controller.validate_exchange_rates_exist)
|
||||
|
||||
|
||||
from erpnext.setup.doctype.currency_exchange.test_currency_exchange import test_records as \
|
||||
currency_exchange_records
|
||||
frappe.get_doc(currency_exchange_records[0]).insert()
|
||||
controller.validate_exchange_rates_exist()
|
||||
|
||||
|
||||
def test_tax_rule_validation(self):
|
||||
frappe.db.sql("update `tabTax Rule` set use_for_shopping_cart = 0")
|
||||
frappe.db.commit()
|
||||
|
||||
|
||||
cart_settings = self.get_cart_settings()
|
||||
cart_settings.enabled = 1
|
||||
cart_settings.enabled = 1
|
||||
if not frappe.db.get_value("Tax Rule", {"use_for_shopping_cart": 1}, "name"):
|
||||
self.assertRaises(ShoppingCartSetupError, cart_settings.validate_tax_rule)
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@ class TestShoppingCart(unittest.TestCase):
|
||||
# test if lead is created and quotation with new lead is fetched
|
||||
quotation = get_quotation()
|
||||
self.assertEquals(quotation.quotation_to, "Lead")
|
||||
self.assertEquals(frappe.db.get_value("Lead", quotation.lead, "email_id"),
|
||||
self.assertEquals(frappe.db.get_value("Lead", quotation.lead, "email_id"),
|
||||
"test_cart_user@example.com")
|
||||
self.assertEquals(quotation.customer, None)
|
||||
self.assertEquals(quotation.contact_email, frappe.session.user)
|
||||
@ -61,7 +61,7 @@ class TestShoppingCart(unittest.TestCase):
|
||||
|
||||
# remove from cart
|
||||
self.remove_all_items_from_cart()
|
||||
|
||||
|
||||
# add first item
|
||||
set_item_in_cart("_Test Item", 1)
|
||||
quotation = self.test_get_cart_lead()
|
||||
@ -109,12 +109,12 @@ class TestShoppingCart(unittest.TestCase):
|
||||
quotation = self.test_get_cart_lead()
|
||||
self.assertEquals(quotation.net_total, 0)
|
||||
self.assertEquals(len(quotation.get("items")), 0)
|
||||
|
||||
|
||||
def test_taxe_rule(self):
|
||||
|
||||
|
||||
def test_tax_rule(self):
|
||||
self.login_as_customer()
|
||||
quotation = self.create_quotation()
|
||||
|
||||
|
||||
from erpnext.accounts.party import set_taxes
|
||||
|
||||
tax_rule_master = set_taxes(quotation.customer, "Customer", \
|
||||
@ -123,12 +123,12 @@ class TestShoppingCart(unittest.TestCase):
|
||||
|
||||
self.assertEquals(quotation.taxes_and_charges, tax_rule_master)
|
||||
self.assertEquals(quotation.total_taxes_and_charges, 1000.0)
|
||||
|
||||
|
||||
self.remove_test_quotation(quotation)
|
||||
|
||||
|
||||
def create_quotation(self):
|
||||
quotation = frappe.new_doc("Quotation")
|
||||
|
||||
|
||||
values = {
|
||||
"doctype": "Quotation",
|
||||
"quotation_to": "Customer",
|
||||
@ -146,13 +146,13 @@ class TestShoppingCart(unittest.TestCase):
|
||||
"taxes": frappe.get_doc("Sales Taxes and Charges Template", "_Test Tax 1").taxes,
|
||||
"company": "_Test Company"
|
||||
}
|
||||
|
||||
|
||||
quotation.update(values)
|
||||
|
||||
|
||||
quotation.insert(ignore_permissions=True)
|
||||
|
||||
|
||||
return quotation
|
||||
|
||||
|
||||
def remove_test_quotation(self, quotation):
|
||||
frappe.set_user("Administrator")
|
||||
quotation.delete()
|
||||
@ -180,7 +180,7 @@ class TestShoppingCart(unittest.TestCase):
|
||||
])
|
||||
settings.set("shipping_rules", {"doctype": "Shopping Cart Shipping Rule", "parentfield": "shipping_rules",
|
||||
"shipping_rule": "_Test Shipping Rule - India"})
|
||||
|
||||
|
||||
|
||||
settings.save()
|
||||
frappe.local.shopping_cart_settings = None
|
||||
@ -239,11 +239,11 @@ class TestShoppingCart(unittest.TestCase):
|
||||
"lead_name": "_Test Website Lead",
|
||||
"phone": "+91 0000000000"
|
||||
}).insert(ignore_permissions=True)
|
||||
|
||||
|
||||
def remove_all_items_from_cart(self):
|
||||
quotation = get_quotation()
|
||||
quotation.set("items", [])
|
||||
quotation.save(ignore_permissions=True)
|
||||
|
||||
|
||||
test_dependencies = ["Sales Taxes and Charges Template", "Price List", "Item Price", "Shipping Rule", "Currency Exchange",
|
||||
"Customer Group", "Lead", "Customer", "Contact", "Address", "Item", "Tax Rule"]
|
||||
|
@ -33,7 +33,7 @@ $.extend(shopping_cart, {
|
||||
},
|
||||
callback: function(r) {
|
||||
if(!r.exc) {
|
||||
$('.cart-addresses').html(r.message);
|
||||
$(".cart-tax-items").html(r.message.taxes);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -54,12 +54,14 @@ $.extend(shopping_cart, {
|
||||
// bind update button
|
||||
$(".cart-items").on("change", ".cart-qty", function() {
|
||||
var item_code = $(this).attr("data-item-code");
|
||||
frappe.freeze();
|
||||
shopping_cart.update_cart({
|
||||
item_code: item_code,
|
||||
qty: $(this).val(),
|
||||
with_items: 1,
|
||||
btn: this,
|
||||
callback: function(r) {
|
||||
frappe.unfreeze();
|
||||
if(!r.exc) {
|
||||
$(".cart-items").html(r.message.items);
|
||||
$(".cart-tax-items").html(r.message.taxes);
|
||||
|
Loading…
Reference in New Issue
Block a user