[Shopping Cart][Fixes] tax calculation based on tax rule
This commit is contained in:
parent
ef511b160e
commit
def71d4d5d
@ -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("sales_tax_template", cur_frm.doc.tax_type=="Sales");
|
||||||
cur_frm.toggle_reqd("purchase_tax_template", cur_frm.doc.tax_type=="Purchase");
|
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.ui.form.on("Tax Rule", "customer", function(frm) {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method:"erpnext.accounts.doctype.tax_rule.tax_rule.get_party_details",
|
method:"erpnext.accounts.doctype.tax_rule.tax_rule.get_party_details",
|
||||||
|
|||||||
@ -33,6 +33,28 @@
|
|||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 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,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
@ -514,7 +536,7 @@
|
|||||||
"is_submittable": 0,
|
"is_submittable": 0,
|
||||||
"issingle": 0,
|
"issingle": 0,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"modified": "2015-08-28 02:56:51.283291",
|
"modified": "2015-09-10 19:27:47.969867",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Tax Rule",
|
"name": "Tax Rule",
|
||||||
|
|||||||
@ -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.throw(_("Due / Reference Date cannot be after {0}").format(formatdate(default_due_date)))
|
||||||
|
|
||||||
@frappe.whitelist()
|
@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
|
from erpnext.accounts.doctype.tax_rule.tax_rule import get_tax_template, get_party_details
|
||||||
args = {
|
args = {
|
||||||
party_type: party,
|
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"})
|
args.update({"tax_type": "Sales"})
|
||||||
else:
|
else:
|
||||||
args.update({"tax_type": "Purchase"})
|
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)
|
return get_tax_template(posting_date, args)
|
||||||
@ -266,12 +266,16 @@ def _set_price_list(quotation, cart_settings, billing_territory):
|
|||||||
|
|
||||||
def set_taxes(quotation, cart_settings, billing_territory):
|
def set_taxes(quotation, cart_settings, billing_territory):
|
||||||
"""set taxes based on billing territory"""
|
"""set taxes based on billing territory"""
|
||||||
quotation.taxes_and_charges = cart_settings.get_tax_master(billing_territory)
|
from erpnext.accounts.party import set_taxes
|
||||||
|
|
||||||
# clear table
|
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", [])
|
quotation.set("taxes", [])
|
||||||
|
#
|
||||||
# append taxes
|
# # append taxes
|
||||||
quotation.append_taxes_from_master()
|
quotation.append_taxes_from_master()
|
||||||
|
|
||||||
def get_lead_or_customer():
|
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 \
|
shipping_territory = get_address_territory(quotation.shipping_address_name) or \
|
||||||
party.territory
|
party.territory
|
||||||
|
|
||||||
|
|
||||||
shipping_rules = cart_settings.get_shipping_rules(shipping_territory)
|
shipping_rules = cart_settings.get_shipping_rules(shipping_territory)
|
||||||
|
|
||||||
return shipping_rules
|
return shipping_rules
|
||||||
|
|||||||
@ -221,48 +221,6 @@
|
|||||||
"search_index": 0,
|
"search_index": 0,
|
||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 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,
|
"hide_heading": 0,
|
||||||
@ -274,7 +232,7 @@
|
|||||||
"is_submittable": 0,
|
"is_submittable": 0,
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"modified": "2015-02-05 05:11:46.714019",
|
"modified": "2015-09-10 19:05:17.386135",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Shopping Cart",
|
"module": "Shopping Cart",
|
||||||
"name": "Shopping Cart Settings",
|
"name": "Shopping Cart Settings",
|
||||||
|
|||||||
@ -20,15 +20,15 @@ class ShoppingCartSettings(Document):
|
|||||||
def validate(self):
|
def validate(self):
|
||||||
if self.enabled:
|
if self.enabled:
|
||||||
self.validate_price_lists()
|
self.validate_price_lists()
|
||||||
self.validate_tax_masters()
|
|
||||||
self.validate_exchange_rates_exist()
|
self.validate_exchange_rates_exist()
|
||||||
|
self.validate_tax_rule()
|
||||||
|
|
||||||
def validate_overlapping_territories(self, parentfield, fieldname):
|
def validate_overlapping_territories(self, parentfield, fieldname):
|
||||||
# for displaying message
|
# for displaying message
|
||||||
doctype = self.meta.get_field(parentfield).options
|
doctype = self.meta.get_field(parentfield).options
|
||||||
|
|
||||||
# specify atleast one entry in the table
|
# 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)
|
territory_name_map = self.get_territory_name_map(parentfield, fieldname)
|
||||||
for territory, names in territory_name_map.items():
|
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") +
|
msgprint(_("Please specify a Price List which is valid for Territory") +
|
||||||
": " + self.default_territory, raise_exception=ShoppingCartSetupError)
|
": " + 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):
|
def get_territory_name_map(self, parentfield, fieldname):
|
||||||
territory_name_map = {}
|
territory_name_map = {}
|
||||||
|
|
||||||
# entries in table
|
# entries in table
|
||||||
names = [doc.get(fieldname) for doc in self.get(parentfield)]
|
names = [doc.get(fieldname) for doc in self.get(parentfield)]
|
||||||
|
|
||||||
if names:
|
if names:
|
||||||
# for condition in territory check
|
# for condition in territory check
|
||||||
parenttype = frappe.get_meta(self.meta.get_options(parentfield)).get_options(fieldname)
|
parenttype = frappe.get_meta(self.meta.get_options(parentfield)).get_options(fieldname)
|
||||||
|
|
||||||
# to validate territory overlap
|
# to validate territory overlap
|
||||||
# make a map of territory: [list of names]
|
# make a map of territory: [list of names]
|
||||||
# if list against each territory has more than one element, raise exception
|
# 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:
|
if len(territory_name_map[territory]) > 1:
|
||||||
territory_name_map[territory].sort(key=lambda val: names.index(val))
|
territory_name_map[territory].sort(key=lambda val: names.index(val))
|
||||||
|
|
||||||
return territory_name_map
|
return territory_name_map
|
||||||
|
|
||||||
def validate_exchange_rates_exist(self):
|
def validate_exchange_rates_exist(self):
|
||||||
@ -131,7 +124,11 @@ class ShoppingCartSettings(Document):
|
|||||||
"price_lists", "selling_price_list")
|
"price_lists", "selling_price_list")
|
||||||
|
|
||||||
return price_list and price_list[0] or None
|
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):
|
def get_tax_master(self, billing_territory):
|
||||||
tax_master = self.get_name_from_territory(billing_territory, "sales_taxes_and_charges_masters",
|
tax_master = self.get_name_from_territory(billing_territory, "sales_taxes_and_charges_masters",
|
||||||
"sales_taxes_and_charges_master")
|
"sales_taxes_and_charges_master")
|
||||||
@ -170,6 +167,9 @@ def check_shopping_cart_enabled():
|
|||||||
|
|
||||||
def apply_shopping_cart_settings(quotation, method):
|
def apply_shopping_cart_settings(quotation, method):
|
||||||
"""Called via a validate hook on Quotation"""
|
"""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
|
from erpnext.shopping_cart import get_party
|
||||||
if quotation.order_type != "Shopping Cart":
|
if quotation.order_type != "Shopping Cart":
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user