[Shopping Cart][Fixes] tax calculation based on tax rule
This commit is contained in:
parent
def71d4d5d
commit
957e7a37be
@ -115,7 +115,7 @@ def get_tax_template(posting_date, args):
|
||||
conditions.append("ifnull({0}, '') in ('', '{1}')".format(key, frappe.db.escape(cstr(value))))
|
||||
|
||||
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, debug=True)
|
||||
|
||||
if not matching:
|
||||
return None
|
||||
|
@ -278,7 +278,9 @@ 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, for_shopping_cart=None):
|
||||
def set_taxes(party, party_type, posting_date, company, customer_group=None, supplier_type=None,
|
||||
billing_address=None, shipping_address=None, use_for_shopping_cart=None):
|
||||
|
||||
from erpnext.accounts.doctype.tax_rule.tax_rule import get_tax_template, get_party_details
|
||||
args = {
|
||||
party_type: party,
|
||||
@ -288,7 +290,8 @@ def set_taxes(party, party_type, posting_date, company, customer_group=None, sup
|
||||
}
|
||||
|
||||
if billing_address or shipping_address:
|
||||
args.update(get_party_details(party, party_type, {"billing_address": billing_address, "shipping_address": shipping_address }))
|
||||
args.update(get_party_details(party, party_type, {"billing_address": billing_address, \
|
||||
"shipping_address": shipping_address }))
|
||||
else:
|
||||
args.update(get_party_details(party, party_type))
|
||||
|
||||
@ -297,7 +300,8 @@ def set_taxes(party, party_type, posting_date, company, customer_group=None, sup
|
||||
else:
|
||||
args.update({"tax_type": "Purchase"})
|
||||
|
||||
if for_shopping_cart:
|
||||
args.update({"use_for_shopping_cart": for_shopping_cart})
|
||||
if use_for_shopping_cart:
|
||||
print "use_for_shopping_cart", use_for_shopping_cart
|
||||
args.update({"use_for_shopping_cart": use_for_shopping_cart})
|
||||
|
||||
return get_tax_template(posting_date, args)
|
@ -126,7 +126,7 @@ class ShoppingCartSettings(Document):
|
||||
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):
|
||||
if not frappe.db.get_value("Tax Rule", {"use_for_shopping_cart" : 1}, "name"):
|
||||
frappe.throw(frappe._("Set Tax Rule for shopping cart"), ShoppingCartSetupError)
|
||||
|
||||
def get_tax_master(self, billing_territory):
|
||||
|
@ -43,28 +43,6 @@ class TestShoppingCartSettings(unittest.TestCase):
|
||||
|
||||
return cart_settings
|
||||
|
||||
def test_taxes_territory_overlap(self):
|
||||
cart_settings = self.get_cart_settings()
|
||||
|
||||
def _add_tax_master(tax_master):
|
||||
cart_settings.append("sales_taxes_and_charges_masters", {
|
||||
"doctype": "Shopping Cart Taxes and Charges Master",
|
||||
"sales_taxes_and_charges_master": tax_master
|
||||
})
|
||||
|
||||
for tax_master in ("_Test Sales Taxes and Charges Template", "_Test India Tax Master"):
|
||||
_add_tax_master(tax_master)
|
||||
|
||||
controller = cart_settings
|
||||
controller.validate_overlapping_territories("sales_taxes_and_charges_masters",
|
||||
"sales_taxes_and_charges_master")
|
||||
|
||||
_add_tax_master("_Test Sales Taxes and Charges Template - Rest of the World")
|
||||
|
||||
controller = cart_settings
|
||||
self.assertRaises(ShoppingCartSetupError, controller.validate_overlapping_territories,
|
||||
"sales_taxes_and_charges_masters", "sales_taxes_and_charges_master")
|
||||
|
||||
def test_exchange_rate_exists(self):
|
||||
frappe.db.sql("""delete from `tabCurrency Exchange`""")
|
||||
|
||||
@ -77,3 +55,13 @@ class TestShoppingCartSettings(unittest.TestCase):
|
||||
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
|
||||
if not frappe.db.get_value("Tax Rule", {"use_for_shopping_cart": 1}, "name"):
|
||||
print "here"
|
||||
self.assertRaises(ShoppingCartSetupError, cart_settings.validate_tax_rule)
|
||||
|
||||
|
@ -109,6 +109,54 @@ 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):
|
||||
frappe.set_user("Administrator")
|
||||
self.create_tax_rule()
|
||||
quotation = self.test_get_cart_customer()
|
||||
set_item_in_cart("_Test Item", 1)
|
||||
|
||||
from erpnext.accounts.party import set_taxes
|
||||
|
||||
tax_rule_master = set_taxes(quotation.customer, "Customer", \
|
||||
quotation.transaction_date, quotation.company, None, None, \
|
||||
quotation.customer_address, quotation.shipping_address_name, 1)
|
||||
|
||||
self.assertEquals(quotation.taxes_and_charges, tax_rule_master)
|
||||
self.assertEquals(quotation.total_taxes_and_charges, "1000")
|
||||
|
||||
def create_tax_rule(self):
|
||||
for tax_rule_setting in [{"priority": 1, "use_for_shopping_cart": 1}, {"priority": 2, "use_for_shopping_cart": 0}]:
|
||||
tax_template = self.get_tax_template(tax_rule_setting['priority']).name
|
||||
print tax_template
|
||||
tax_rule = frappe.get_doc({
|
||||
"doctype": "Tax Rule",
|
||||
"tax_type" : "Sales",
|
||||
"sales_tax_template": tax_template,
|
||||
"use_for_shopping_cart": tax_rule_setting["use_for_shopping_cart"],
|
||||
"billing_city": "_Test City",
|
||||
"billing_country": "India",
|
||||
"shipping_city": "_Test City",
|
||||
"shipping_country": "India",
|
||||
"priority": tax_rule_setting['priority']
|
||||
}).insert()
|
||||
|
||||
def get_tax_template(self, priority):
|
||||
return frappe.get_doc({
|
||||
"doctype" : "Sales Taxes and Charges Template",
|
||||
"title": "_Test Tax %s"%priority,
|
||||
"company": "_Test Company",
|
||||
"taxes":[{
|
||||
"charge_type": "Actual",
|
||||
"account_head": "Sales Expenses - _TC",
|
||||
"cost_center": "Main - _TC",
|
||||
"description": "Test Shopping cart taxes with Tax Rule",
|
||||
"tax_amount": 1000*priority
|
||||
}],
|
||||
"territories":[{
|
||||
"territory" : "All Territories"
|
||||
}]
|
||||
}).insert()
|
||||
|
||||
# helper functions
|
||||
def enable_shopping_cart(self):
|
||||
@ -131,13 +179,6 @@ class TestShoppingCart(unittest.TestCase):
|
||||
{"doctype": "Shopping Cart Price List", "parentfield": "price_lists",
|
||||
"selling_price_list": "_Test Price List Rest of the World"}
|
||||
])
|
||||
settings.set("sales_taxes_and_charges_masters", [
|
||||
# tax masters
|
||||
{"doctype": "Shopping Cart Taxes and Charges Master", "parentfield": "sales_taxes_and_charges_masters",
|
||||
"sales_taxes_and_charges_master": "_Test India Tax Master"},
|
||||
{"doctype": "Shopping Cart Taxes and Charges Master", "parentfield": "sales_taxes_and_charges_masters",
|
||||
"sales_taxes_and_charges_master": "_Test Sales Taxes and Charges Template - Rest of the World"},
|
||||
])
|
||||
settings.set("shipping_rules", {"doctype": "Shopping Cart Shipping Rule", "parentfield": "shipping_rules",
|
||||
"shipping_rule": "_Test Shipping Rule - India"})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user