[fixes] setup wizard and other fixes related to cart

This commit is contained in:
Anand Doshi 2015-09-23 12:46:59 +05:30 committed by Rushabh Mehta
parent 52dfc32eca
commit 06ad308ca1
17 changed files with 574 additions and 861 deletions

View File

@ -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();
});

View File

@ -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"
}] }]
} }
] ]

View File

@ -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();
}
});

View File

@ -1,397 +1,397 @@
{ {
"allow_copy": 0, "allow_copy": 0,
"allow_import": 0, "allow_import": 0,
"allow_rename": 0, "allow_rename": 0,
"autoname": "field:label", "autoname": "field:label",
"creation": "2013-06-25 11:48:03", "creation": "2013-06-25 11:48:03",
"custom": 0, "custom": 0,
"description": "Specify conditions to calculate shipping amount", "description": "Specify conditions to calculate shipping amount",
"docstatus": 0, "docstatus": 0,
"doctype": "DocType", "doctype": "DocType",
"fields": [ "fields": [
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"description": "example: Next Day Shipping", "description": "example: Next Day Shipping",
"fieldname": "label", "fieldname": "label",
"fieldtype": "Data", "fieldtype": "Data",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 1, "in_list_view": 1,
"label": "Shipping Rule Label", "label": "Shipping Rule Label",
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 1, "reqd": 1,
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"fieldname": "disabled", "fieldname": "disabled",
"fieldtype": "Check", "fieldtype": "Check",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Disabled", "label": "Disabled",
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
"precision": "", "precision": "",
"print_hide": 0, "print_hide": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"default": "Net Total", "default": "Net Total",
"fieldname": "calculate_based_on", "fieldname": "calculate_based_on",
"fieldtype": "Select", "fieldtype": "Select",
"hidden": 1, "hidden": 1,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 1, "in_list_view": 1,
"label": "Calculate Based On", "label": "Calculate Based On",
"no_copy": 0, "no_copy": 0,
"options": "Net Total\nNet Weight", "options": "Net Total\nNet Weight",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"read_only": 1, "read_only": 1,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"depends_on": "eval:!doc.disabled", "depends_on": "eval:!doc.disabled",
"fieldname": "rule_conditions_section", "fieldname": "rule_conditions_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Shipping Rule Conditions", "label": "Shipping Rule Conditions",
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"fieldname": "conditions", "fieldname": "conditions",
"fieldtype": "Table", "fieldtype": "Table",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Shipping Rule Conditions", "label": "Shipping Rule Conditions",
"no_copy": 0, "no_copy": 0,
"options": "Shipping Rule Condition", "options": "Shipping Rule Condition",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 1, "reqd": 1,
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"depends_on": "eval:!doc.disabled", "depends_on": "eval:!doc.disabled",
"fieldname": "section_break_6", "fieldname": "section_break_6",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Valid for Countries", "label": "Valid for Countries",
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"fieldname": "worldwide_shipping", "fieldname": "worldwide_shipping",
"fieldtype": "Check", "fieldtype": "Check",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Worldwide Shipping", "label": "Worldwide Shipping",
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
"precision": "", "precision": "",
"print_hide": 0, "print_hide": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"depends_on": "eval:!doc.worldwide_shipping", "depends_on": "eval:!doc.worldwide_shipping",
"fieldname": "countries", "fieldname": "countries",
"fieldtype": "Table", "fieldtype": "Table",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Valid for Countries", "label": "Valid for Countries",
"no_copy": 0, "no_copy": 0,
"options": "Shipping Rule Country", "options": "Shipping Rule Country",
"permlevel": 0, "permlevel": 0,
"precision": "", "precision": "",
"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
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"depends_on": "eval:!doc.disabled", "depends_on": "eval:!doc.disabled",
"fieldname": "section_break_10", "fieldname": "section_break_10",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"fieldname": "company", "fieldname": "company",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Company", "label": "Company",
"no_copy": 0, "no_copy": 0,
"options": "Company", "options": "Company",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 1, "reqd": 1,
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"fieldname": "column_break_12", "fieldname": "column_break_12",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"fieldname": "account", "fieldname": "account",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Shipping Account", "label": "Shipping Account",
"no_copy": 0, "no_copy": 0,
"options": "Account", "options": "Account",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 1, "reqd": 1,
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"fieldname": "cost_center", "fieldname": "cost_center",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Cost Center", "label": "Cost Center",
"no_copy": 0, "no_copy": 0,
"options": "Cost Center", "options": "Cost Center",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 1, "reqd": 1,
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
} }
], ],
"hide_heading": 0, "hide_heading": 0,
"hide_toolbar": 0, "hide_toolbar": 0,
"icon": "icon-truck", "icon": "icon-truck",
"idx": 1, "idx": 1,
"in_create": 0, "in_create": 0,
"in_dialog": 0, "in_dialog": 0,
"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",
"owner": "Administrator", "owner": "Administrator",
"permissions": [ "permissions": [
{ {
"amend": 0, "amend": 0,
"apply_user_permissions": 1, "apply_user_permissions": 1,
"cancel": 0, "cancel": 0,
"create": 0, "create": 0,
"delete": 0, "delete": 0,
"email": 1, "email": 1,
"export": 0, "export": 0,
"if_owner": 0, "if_owner": 0,
"import": 0, "import": 0,
"permlevel": 0, "permlevel": 0,
"print": 1, "print": 1,
"read": 1, "read": 1,
"report": 1, "report": 1,
"role": "Accounts User", "role": "Accounts User",
"set_user_permissions": 0, "set_user_permissions": 0,
"share": 0, "share": 0,
"submit": 0, "submit": 0,
"write": 0 "write": 0
}, },
{ {
"amend": 0, "amend": 0,
"apply_user_permissions": 1, "apply_user_permissions": 1,
"cancel": 0, "cancel": 0,
"create": 0, "create": 0,
"delete": 0, "delete": 0,
"email": 1, "email": 1,
"export": 0, "export": 0,
"if_owner": 0, "if_owner": 0,
"import": 0, "import": 0,
"permlevel": 0, "permlevel": 0,
"print": 1, "print": 1,
"read": 1, "read": 1,
"report": 1, "report": 1,
"role": "Sales User", "role": "Sales User",
"set_user_permissions": 0, "set_user_permissions": 0,
"share": 0, "share": 0,
"submit": 0, "submit": 0,
"write": 0 "write": 0
}, },
{ {
"amend": 0, "amend": 0,
"apply_user_permissions": 0, "apply_user_permissions": 0,
"cancel": 0, "cancel": 0,
"create": 1, "create": 1,
"delete": 1, "delete": 1,
"email": 1, "email": 1,
"export": 0, "export": 0,
"if_owner": 0, "if_owner": 0,
"import": 0, "import": 0,
"permlevel": 0, "permlevel": 0,
"print": 1, "print": 1,
"read": 1, "read": 1,
"report": 1, "report": 1,
"role": "Accounts Manager", "role": "Accounts Manager",
"set_user_permissions": 0, "set_user_permissions": 0,
"share": 1, "share": 1,
"submit": 0, "submit": 0,
"write": 1 "write": 1
}, },
{ {
"amend": 0, "amend": 0,
"apply_user_permissions": 0, "apply_user_permissions": 0,
"cancel": 0, "cancel": 0,
"create": 1, "create": 1,
"delete": 1, "delete": 1,
"email": 1, "email": 1,
"export": 0, "export": 0,
"if_owner": 0, "if_owner": 0,
"import": 0, "import": 0,
"permlevel": 0, "permlevel": 0,
"print": 1, "print": 1,
"read": 1, "read": 1,
"report": 1, "report": 1,
"role": "Sales Master Manager", "role": "Sales Master Manager",
"set_user_permissions": 0, "set_user_permissions": 0,
"share": 1, "share": 1,
"submit": 0, "submit": 0,
"write": 1 "write": 1
} }
], ],
"read_only": 0, "read_only": 0,
"read_only_onload": 0 "read_only_onload": 0
} }

View File

@ -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 = []

View File

@ -1,116 +1,100 @@
[ [
{ {
"account": "_Test Account Shipping Charges - _TC", "account": "_Test Account Shipping Charges - _TC",
"calculate_based_on": "Net Total", "calculate_based_on": "Net Total",
"company": "_Test Company", "company": "_Test Company",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"doctype": "Shipping Rule", "doctype": "Shipping Rule",
"label": "_Test Shipping Rule", "label": "_Test Shipping Rule",
"name": "_Test Shipping Rule", "name": "_Test Shipping Rule",
"conditions": [ "conditions": [
{ {
"doctype": "Shipping Rule Condition", "doctype": "Shipping Rule Condition",
"from_value": 0, "from_value": 0,
"parentfield": "conditions", "parentfield": "conditions",
"shipping_amount": 50.0, "shipping_amount": 50.0,
"to_value": 100 "to_value": 100
}, },
{ {
"doctype": "Shipping Rule Condition", "doctype": "Shipping Rule Condition",
"from_value": 101, "from_value": 101,
"parentfield": "conditions", "parentfield": "conditions",
"shipping_amount": 100.0, "shipping_amount": 100.0,
"to_value": 200 "to_value": 200
}, },
{ {
"doctype": "Shipping Rule Condition", "doctype": "Shipping Rule Condition",
"from_value": 201, "from_value": 201,
"parentfield": "conditions", "parentfield": "conditions",
"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",
"calculate_based_on": "Net Total", "calculate_based_on": "Net Total",
"company": "_Test Company", "company": "_Test Company",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"doctype": "Shipping Rule", "doctype": "Shipping Rule",
"label": "_Test Shipping Rule - India", "label": "_Test Shipping Rule - India",
"name": "_Test Shipping Rule - India", "name": "_Test Shipping Rule - India",
"conditions": [ "conditions": [
{ {
"doctype": "Shipping Rule Condition", "doctype": "Shipping Rule Condition",
"from_value": 0, "from_value": 0,
"parentfield": "conditions", "parentfield": "conditions",
"shipping_amount": 50.0, "shipping_amount": 50.0,
"to_value": 100 "to_value": 100
}, },
{ {
"doctype": "Shipping Rule Condition", "doctype": "Shipping Rule Condition",
"from_value": 101, "from_value": 101,
"parentfield": "conditions", "parentfield": "conditions",
"shipping_amount": 100.0, "shipping_amount": 100.0,
"to_value": 200 "to_value": 200
}, },
{ {
"doctype": "Shipping Rule Condition", "doctype": "Shipping Rule Condition",
"from_value": 201, "from_value": 201,
"parentfield": "conditions", "parentfield": "conditions",
"shipping_amount": 0.0 "shipping_amount": 0.0
} }
], ],
"territories": [ "countries": [
{ {"country": "India"}
"doctype": "Applicable Territory",
"parentfield": "territories",
"territory": "_Test Territory India"
}
] ]
}, },
{ {
"account": "_Test Account Shipping Charges - _TC", "account": "_Test Account Shipping Charges - _TC",
"calculate_based_on": "Net Total", "calculate_based_on": "Net Total",
"company": "_Test Company", "company": "_Test Company",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"doctype": "Shipping Rule", "doctype": "Shipping Rule",
"label": "_Test Shipping Rule - Rest of the World", "label": "_Test Shipping Rule - Rest of the World",
"name": "_Test Shipping Rule - Rest of the World", "name": "_Test Shipping Rule - Rest of the World",
"conditions": [ "conditions": [
{ {
"doctype": "Shipping Rule Condition", "doctype": "Shipping Rule Condition",
"from_value": 0, "from_value": 0,
"parentfield": "conditions", "parentfield": "conditions",
"shipping_amount": 500.0, "shipping_amount": 500.0,
"to_value": 1000 "to_value": 1000
}, },
{ {
"doctype": "Shipping Rule Condition", "doctype": "Shipping Rule Condition",
"from_value": 1001, "from_value": 1001,
"parentfield": "conditions", "parentfield": "conditions",
"shipping_amount": 1000.0, "shipping_amount": 1000.0,
"to_value": 2000 "to_value": 2000
}, },
{ {
"doctype": "Shipping Rule Condition", "doctype": "Shipping Rule Condition",
"from_value": 2001, "from_value": 2001,
"parentfield": "conditions", "parentfield": "conditions",
"shipping_amount": 1500.0 "shipping_amount": 1500.0
} }
], ],
"territories": [ "worldwide_shipping": 1
{
"doctype": "Applicable Territory",
"parentfield": "territories",
"territory": "_Test Territory Rest Of The World"
}
]
} }
] ]

View File

@ -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()
@ -25,7 +29,7 @@ class TaxRule(Document):
self.purchase_tax_template = self.supplier = self.supplier_type= None self.purchase_tax_template = self.supplier = self.supplier_type= None
else: else:
self.sales_tax_template= self.customer = self.customer_group= None self.sales_tax_template= self.customer = self.customer_group= None
if not (self.sales_tax_template or self.purchase_tax_template): if not (self.sales_tax_template or self.purchase_tax_template):
frappe.throw(_("Tax Template is mandatory.")) frappe.throw(_("Tax Template is mandatory."))
@ -34,7 +38,7 @@ class TaxRule(Document):
if not frappe.db.get_value("Customer", self.customer, "customer_group") == self.customer_group: if not frappe.db.get_value("Customer", self.customer, "customer_group") == self.customer_group:
frappe.throw(_("Customer {0} does not belong to customer group {1}"). \ frappe.throw(_("Customer {0} does not belong to customer group {1}"). \
format(self.customer, self.customer_group), IncorrectCustomerGroup) format(self.customer, self.customer_group), IncorrectCustomerGroup)
def validate_supplier_type(self): def validate_supplier_type(self):
if self.supplier and self.supplier_type: if self.supplier and self.supplier_type:
if not frappe.db.get_value("Supplier", self.supplier, "supplier_type") == self.supplier_type: if not frappe.db.get_value("Supplier", self.supplier, "supplier_type") == self.supplier_type:
@ -60,28 +64,28 @@ class TaxRule(Document):
"shipping_country": self.shipping_country, "shipping_country": self.shipping_country,
"company": self.company "company": self.company
} }
conds="" conds=""
for d in filters: for d in filters:
if conds: if conds:
conds += " and " conds += " and "
conds += """ifnull({0}, '') = '{1}'""".format(d, frappe.db.escape(cstr(filters[d]))) conds += """ifnull({0}, '') = '{1}'""".format(d, frappe.db.escape(cstr(filters[d])))
if self.from_date and self.to_date: if self.from_date and self.to_date:
conds += """ and ((from_date > '{from_date}' and from_date < '{to_date}') or conds += """ and ((from_date > '{from_date}' and from_date < '{to_date}') or
(to_date > '{from_date}' and to_date < '{to_date}') or (to_date > '{from_date}' and to_date < '{to_date}') or
('{from_date}' > from_date and '{from_date}' < to_date) or ('{from_date}' > from_date and '{from_date}' < to_date) or
('{from_date}' = from_date and '{to_date}' = to_date))""".format(from_date=self.from_date, to_date=self.to_date) ('{from_date}' = from_date and '{to_date}' = to_date))""".format(from_date=self.from_date, to_date=self.to_date)
elif self.from_date and not self.to_date: elif self.from_date and not self.to_date:
conds += """ and to_date > '{from_date}'""".format(from_date = self.from_date) conds += """ and to_date > '{from_date}'""".format(from_date = self.from_date)
elif self.to_date and not self.from_date: elif self.to_date and not self.from_date:
conds += """ and from_date < '{to_date}'""".format(to_date = self.to_date) conds += """ and from_date < '{to_date}'""".format(to_date = self.to_date)
tax_rule = frappe.db.sql("select name, priority \ tax_rule = frappe.db.sql("select name, priority \
from `tabTax Rule` where {0} and name != '{1}'".format(conds, self.name), as_dict=1) from `tabTax Rule` where {0} and name != '{1}'".format(conds, self.name), as_dict=1)
if tax_rule: if tax_rule:
if tax_rule[0].priority == self.priority: if tax_rule[0].priority == self.priority:
frappe.throw(_("Tax Rule Conflicts with {0}".format(tax_rule[0].name)), ConflictingTaxRule) frappe.throw(_("Tax Rule Conflicts with {0}".format(tax_rule[0].name)), ConflictingTaxRule)
@ -95,10 +99,10 @@ def get_party_details(party, party_type, args=None):
else: else:
billing_filters= {party_type: party, "is_primary_address": 1} billing_filters= {party_type: party, "is_primary_address": 1}
shipping_filters= {party_type:party, "is_shipping_address": 1} shipping_filters= {party_type:party, "is_shipping_address": 1}
billing_address= frappe.get_all("Address", fields=["city", "state", "country"], filters= billing_filters) billing_address= frappe.get_all("Address", fields=["city", "state", "country"], filters= billing_filters)
shipping_address= frappe.get_all("Address", fields=["city", "state", "country"], filters= shipping_filters) shipping_address= frappe.get_all("Address", fields=["city", "state", "country"], filters= shipping_filters)
if billing_address: if billing_address:
out["billing_city"]= billing_address[0].city out["billing_city"]= billing_address[0].city
out["billing_state"]= billing_address[0].state out["billing_state"]= billing_address[0].state
@ -108,7 +112,7 @@ def get_party_details(party, party_type, args=None):
out["shipping_city"]= shipping_address[0].city out["shipping_city"]= shipping_address[0].city
out["shipping_state"]= shipping_address[0].state out["shipping_state"]= shipping_address[0].state
out["shipping_country"]= shipping_address[0].country out["shipping_country"]= shipping_address[0].country
return out return out
def get_tax_template(posting_date, args): def get_tax_template(posting_date, args):
@ -121,14 +125,14 @@ def get_tax_template(posting_date, args):
matching = frappe.db.sql("""select * from `tabTax Rule` matching = frappe.db.sql("""select * from `tabTax Rule`
where {0}""".format(" and ".join(conditions)), as_dict = True) where {0}""".format(" and ".join(conditions)), as_dict = True)
if not matching: if not matching:
return None return None
for rule in matching: for rule in matching:
rule.no_of_keys_matched = 0 rule.no_of_keys_matched = 0
for key in args: for key in args:
if rule.get(key): rule.no_of_keys_matched += 1 if rule.get(key): rule.no_of_keys_matched += 1
rule = sorted(matching, lambda b, a: cmp(a.no_of_keys_matched, b.no_of_keys_matched) or cmp(a.priority, b.priority))[0] rule = sorted(matching, lambda b, a: cmp(a.no_of_keys_matched, b.no_of_keys_matched) or cmp(a.priority, b.priority))[0]
return rule.sales_tax_template or rule.purchase_tax_template return rule.sales_tax_template or rule.purchase_tax_template

View File

@ -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 ||
@ -131,8 +119,8 @@ $.extend(erpnext.utils, {
} }
); );
} }
}, },
copy_value_in_all_row: function(doc, dt, dn, table_fieldname, fieldname) { copy_value_in_all_row: function(doc, dt, dn, table_fieldname, fieldname) {
var d = locals[dt][dn]; var d = locals[dt][dn];
if(d[fieldname]){ if(d[fieldname]){

View File

@ -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):
@ -304,7 +301,7 @@ def get_fy_details(fy_start_date, fy_end_date):
return fy return fy
def create_taxes(args): def create_taxes(args):
for i in xrange(1,6): for i in xrange(1,6):
if args.get("tax_" + str(i)): if args.get("tax_" + str(i)):
# replace % in case someone also enters the % symbol # replace % in case someone also enters the % symbol
@ -324,7 +321,7 @@ def create_taxes(args):
raise raise
except RootNotEditable, e: except RootNotEditable, e:
pass pass
def make_tax_head(args, i, tax_group, tax_rate): def make_tax_head(args, i, tax_group, tax_rate):
return frappe.get_doc({ return frappe.get_doc({
"doctype":"Account", "doctype":"Account",

View File

@ -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()

View File

@ -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")))
frappe.local.cookie_manager.set_cookie("cart_count", cart_count)
if hasattr(frappe.local, "cookie_manager"):
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,7 +60,9 @@ 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()
frappe.local.cookie_manager.delete_cookie("cart_count")
if hasattr(frappe.local, "cookie_manager"):
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,27 +189,21 @@ 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.customer_name = company_name or fullname
party.company_name = company_name party.customer_type == "Company" if company_name else "Individual"
party.lead_name = fullname
party.mobile_no = mobile_no
party.phone = phone
else:
party.customer_name = company_name or fullname
party.customer_type == "Company" if company_name else "Individual"
contact_name = frappe.db.get_value("Contact", {"email_id": frappe.session.user, contact_name = frappe.db.get_value("Contact", {"email_id": frappe.session.user,
"customer": party.name}) "customer": party.name})
contact = frappe.get_doc("Contact", contact_name) contact = frappe.get_doc("Contact", contact_name)
contact.first_name = fullname contact.first_name = fullname
contact.last_name = None contact.last_name = None
contact.customer_name = party.customer_name contact.customer_name = party.customer_name
contact.mobile_no = mobile_no contact.mobile_no = mobile_no
contact.phone = phone contact.phone = phone
contact.flags.ignore_permissions = True contact.flags.ignore_permissions = True
contact.save() contact.save()
party_doc = frappe.get_doc(party.as_dict()) party_doc = frappe.get_doc(party.as_dict())
party_doc.flags.ignore_permissions = True party_doc.flags.ignore_permissions = True
@ -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,8 +246,9 @@ 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")
# set it in cookies for using in product page if hasattr(frappe.local, "cookie_manager"):
frappe.local.cookie_manager.set_cookie("selling_price_list", quotation.selling_price_list) # 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): def _set_price_list(quotation, cart_settings):
"""Set price list based on customer or shopping cart default""" """Set price list based on customer or shopping cart default"""
@ -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(),

View File

@ -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)

View File

@ -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")

View File

@ -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)

View File

@ -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 = {
@ -14,4 +10,4 @@ $.extend(cur_frm.cscript, {
frappe.set_route("Report", "Item Price"); frappe.set_route("Report", "Item Price");
}, "icon-money"); }, "icon-money");
} }
}); });

View File

@ -1,67 +1,34 @@
[ [
{ {
"buying": 1, "buying": 1,
"currency": "INR", "currency": "INR",
"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,
"currency": "INR", "currency": "INR",
"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,
"currency": "INR", "currency": "INR",
"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,
"currency": "USD", "currency": "USD",
"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"
}
]
} }
] ]

View File

@ -5,36 +5,31 @@ 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, phone = frappe.db.get_value("Contact", {"email_id": frappe.session.user,
mobile_no = party.mobile_no "customer": party.name}, ["mobile_no", "phone"])
phone = party.phone
else:
mobile_no, phone = frappe.db.get_value("Contact", {"email_id": frappe.session.user,
"customer": party.name}, ["mobile_no", "phone"])
return { return {
"company_name": cstr(party.customer_name if party.doctype == "Customer" else party.company_name), "company_name": cstr(party.customer_name if party.doctype == "Customer" else party.company_name),
"mobile_no": cstr(mobile_no), "mobile_no": cstr(mobile_no),
"phone": cstr(phone) "phone": cstr(phone)
} }
@frappe.whitelist() @frappe.whitelist()
def update_user(fullname, password=None, company_name=None, mobile_no=None, phone=None): def update_user(fullname, password=None, company_name=None, mobile_no=None, phone=None):
from erpnext.shopping_cart.cart import update_party from erpnext.shopping_cart.cart import update_party
update_party(fullname, company_name, mobile_no, phone) update_party(fullname, company_name, mobile_no, phone)
if not fullname: if not fullname:
return _("Name is required") return _("Name is required")
frappe.db.set_value("User", frappe.session.user, "first_name", fullname) frappe.db.set_value("User", frappe.session.user, "first_name", fullname)
frappe.local.cookie_manager.set_cookie("full_name", fullname) frappe.local.cookie_manager.set_cookie("full_name", fullname)
return _("Updated") return _("Updated")