[Shopping Cart][Fixes] tax calculation based on tax rule

This commit is contained in:
Saurabh 2015-09-11 11:14:07 +05:30
parent ef511b160e
commit def71d4d5d
6 changed files with 68 additions and 61 deletions

View File

@ -7,6 +7,24 @@ cur_frm.add_fetch("supplier", "supplier_type", "supplier_type" );
cur_frm.toggle_reqd("sales_tax_template", cur_frm.doc.tax_type=="Sales");
cur_frm.toggle_reqd("purchase_tax_template", cur_frm.doc.tax_type=="Purchase");
frappe.ui.form.on("Tax Rule", "onload", function(frm) {
if(frm.doc.__islocal){
frm.set_value("use_for_shopping_cart", 1);
}
})
frappe.ui.form.on("Tax Rule", "use_for_shopping_cart", function(frm) {
if(!frm.doc.use_for_shopping_cart && (frappe.get_list("Tax Rule", {"use_for_shopping_cart":1}).length == 0)){
frappe.model.get_value("Shopping Cart Settings", "Shopping Cart Settings", "enabled", function(docfield) {
if(docfield.enabled){
frm.set_value("use_for_shopping_cart", 1);
frappe.throw(__("Shopping Cart is enabled"));
}
});
}
})
frappe.ui.form.on("Tax Rule", "customer", function(frm) {
frappe.call({
method:"erpnext.accounts.doctype.tax_rule.tax_rule.get_party_details",

View File

@ -33,6 +33,28 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "use_for_shopping_cart",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Use for Shopping Cart",
"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,
@ -514,7 +536,7 @@
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"modified": "2015-08-28 02:56:51.283291",
"modified": "2015-09-10 19:27:47.969867",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Tax Rule",

View File

@ -278,7 +278,7 @@ def validate_due_date(posting_date, due_date, party_type, party, company):
frappe.throw(_("Due / Reference Date cannot be after {0}").format(formatdate(default_due_date)))
@frappe.whitelist()
def set_taxes(party, party_type, posting_date, company, customer_group=None, supplier_type=None, billing_address=None, shipping_address=None):
def set_taxes(party, party_type, posting_date, company, customer_group=None, supplier_type=None, billing_address=None, shipping_address=None, for_shopping_cart=None):
from erpnext.accounts.doctype.tax_rule.tax_rule import get_tax_template, get_party_details
args = {
party_type: party,
@ -296,4 +296,8 @@ def set_taxes(party, party_type, posting_date, company, customer_group=None, sup
args.update({"tax_type": "Sales"})
else:
args.update({"tax_type": "Purchase"})
if for_shopping_cart:
args.update({"use_for_shopping_cart": for_shopping_cart})
return get_tax_template(posting_date, args)

View File

@ -266,12 +266,16 @@ def _set_price_list(quotation, cart_settings, billing_territory):
def set_taxes(quotation, cart_settings, billing_territory):
"""set taxes based on billing territory"""
quotation.taxes_and_charges = cart_settings.get_tax_master(billing_territory)
# clear table
from erpnext.accounts.party import set_taxes
quotation.taxes_and_charges = set_taxes(quotation.customer, "Customer", \
quotation.transaction_date, quotation.company, None, None, \
quotation.customer_address, quotation.shipping_address_name, 1)
#
# # clear table
quotation.set("taxes", [])
# append taxes
#
# # append taxes
quotation.append_taxes_from_master()
def get_lead_or_customer():
@ -357,6 +361,7 @@ def get_shipping_rules(party=None, quotation=None, cart_settings=None):
shipping_territory = get_address_territory(quotation.shipping_address_name) or \
party.territory
shipping_rules = cart_settings.get_shipping_rules(shipping_territory)
return shipping_rules

View File

@ -221,48 +221,6 @@
"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,
"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": "sales_taxes_and_charges_masters",
"fieldtype": "Table",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Taxes and Charges",
"no_copy": 0,
"options": "Shopping Cart Taxes and Charges Master",
"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,
@ -274,7 +232,7 @@
"is_submittable": 0,
"issingle": 1,
"istable": 0,
"modified": "2015-02-05 05:11:46.714019",
"modified": "2015-09-10 19:05:17.386135",
"modified_by": "Administrator",
"module": "Shopping Cart",
"name": "Shopping Cart Settings",

View File

@ -20,15 +20,15 @@ class ShoppingCartSettings(Document):
def validate(self):
if self.enabled:
self.validate_price_lists()
self.validate_tax_masters()
self.validate_exchange_rates_exist()
self.validate_tax_rule()
def validate_overlapping_territories(self, parentfield, fieldname):
# for displaying message
doctype = self.meta.get_field(parentfield).options
# specify atleast one entry in the table
self.validate_table_has_rows(parentfield, raise_exception=ShoppingCartSetupError)
# self.validate_table_has_rows(parentfield, raise_exception=ShoppingCartSetupError)
territory_name_map = self.get_territory_name_map(parentfield, fieldname)
for territory, names in territory_name_map.items():
@ -48,20 +48,14 @@ class ShoppingCartSettings(Document):
msgprint(_("Please specify a Price List which is valid for Territory") +
": " + self.default_territory, raise_exception=ShoppingCartSetupError)
def validate_tax_masters(self):
self.validate_overlapping_territories("sales_taxes_and_charges_masters",
"sales_taxes_and_charges_master")
def get_territory_name_map(self, parentfield, fieldname):
territory_name_map = {}
# entries in table
names = [doc.get(fieldname) for doc in self.get(parentfield)]
if names:
# for condition in territory check
parenttype = frappe.get_meta(self.meta.get_options(parentfield)).get_options(fieldname)
# to validate territory overlap
# make a map of territory: [list of names]
# if list against each territory has more than one element, raise exception
@ -75,7 +69,6 @@ class ShoppingCartSettings(Document):
if len(territory_name_map[territory]) > 1:
territory_name_map[territory].sort(key=lambda val: names.index(val))
return territory_name_map
def validate_exchange_rates_exist(self):
@ -131,7 +124,11 @@ class ShoppingCartSettings(Document):
"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", debug=1):
frappe.throw(frappe._("Set Tax Rule for shopping cart"), ShoppingCartSetupError)
def get_tax_master(self, billing_territory):
tax_master = self.get_name_from_territory(billing_territory, "sales_taxes_and_charges_masters",
"sales_taxes_and_charges_master")
@ -170,6 +167,9 @@ def check_shopping_cart_enabled():
def apply_shopping_cart_settings(quotation, method):
"""Called via a validate hook on Quotation"""
"""no hooks call added yet. same functionality is in cart.py, which will get triggered by cart.js"""
from erpnext.shopping_cart import get_party
if quotation.order_type != "Shopping Cart":
return