[Feature] Shipping Rule Calculation based on Net Weight (#11770)

* [new] Calculate shipping tax based on weight

* [fix] Change field name weight to weight_per_unit in SI Item

* [new] Shipping Rule based tax for selling module

* [new] Shipping rule based on weight added to Buying module

* [fix] Conflict in jsons

* [fix] Removed Redudant add_fetch

* [fix] Codacy fixed

* [fix] Print hide added
This commit is contained in:
Vishal Dhayagude
2017-11-29 16:09:59 +05:30
committed by Nabin Hait
parent 2d1cbd0b2e
commit d42242df22
24 changed files with 32124 additions and 30853 deletions

View File

@@ -24,7 +24,7 @@ class calculate_taxes_and_totals(object):
if self.doc.doctype in ["Sales Invoice", "Purchase Invoice"]:
self.calculate_total_advance()
if self.doc.meta.get_field("other_charges_calculation"):
self.set_item_wise_tax_breakup()
@@ -70,6 +70,7 @@ class calculate_taxes_and_totals(object):
item.net_rate = item.rate
item.amount = flt(item.rate * item.qty, item.precision("amount"))
item.net_amount = item.amount
item.total_weight = flt(item.weight_per_unit * item.qty)
self._set_in_company_currency(item, ["price_list_rate", "rate", "net_rate", "amount", "net_amount"])
@@ -163,13 +164,13 @@ class calculate_taxes_and_totals(object):
return tax.rate
def calculate_net_total(self):
self.doc.total = self.doc.base_total = self.doc.net_total = self.doc.base_net_total = 0.0
self.doc.total = self.doc.base_total = self.doc.net_total = self.doc.base_net_total = self.doc.total_net_weight= 0.0
for item in self.doc.get("items"):
self.doc.total += item.amount
self.doc.base_total += item.base_amount
self.doc.net_total += item.net_amount
self.doc.base_net_total += item.base_net_amount
self.doc.total_net_weight += item.total_weight
self.doc.round_floats_in(self.doc, ["total", "base_total", "net_total", "base_net_total"])
@@ -279,7 +280,7 @@ class calculate_taxes_and_totals(object):
def round_off_totals(self, tax):
tax.tax_amount = flt(tax.tax_amount, tax.precision("tax_amount"))
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount,
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount,
tax.precision("tax_amount"))
def manipulate_grand_total_for_inclusive_tax(self):
@@ -416,14 +417,14 @@ class calculate_taxes_and_totals(object):
self.doc.total_advance = flt(total_allocated_amount, self.doc.precision("total_advance"))
if self.doc.party_account_currency == self.doc.currency:
invoice_total = flt(self.doc.grand_total - flt(self.doc.write_off_amount),
invoice_total = flt(self.doc.grand_total - flt(self.doc.write_off_amount),
self.doc.precision("grand_total"))
else:
base_write_off_amount = flt(flt(self.doc.write_off_amount) * self.doc.conversion_rate,
base_write_off_amount = flt(flt(self.doc.write_off_amount) * self.doc.conversion_rate,
self.doc.precision("base_write_off_amount"))
invoice_total = flt(self.doc.grand_total * self.doc.conversion_rate,
invoice_total = flt(self.doc.grand_total * self.doc.conversion_rate,
self.doc.precision("grand_total")) - base_write_off_amount
if invoice_total > 0 and self.doc.total_advance > invoice_total:
frappe.throw(_("Advance amount cannot be greater than {0} {1}")
.format(self.doc.party_account_currency, invoice_total))
@@ -523,12 +524,12 @@ class calculate_taxes_and_totals(object):
def set_item_wise_tax_breakup(self):
self.doc.other_charges_calculation = get_itemised_tax_breakup_html(self.doc)
def get_itemised_tax_breakup_html(doc):
if not doc.taxes:
return
frappe.flags.company = doc.company
# get headers
tax_accounts = []
for tax in doc.taxes:
@@ -538,14 +539,14 @@ def get_itemised_tax_breakup_html(doc):
tax_accounts.append(tax.description)
headers = get_itemised_tax_breakup_header(doc.doctype + " Item", tax_accounts)
# get tax breakup data
itemised_tax, itemised_taxable_amount = get_itemised_tax_breakup_data(doc)
get_rounded_tax_amount(itemised_tax, doc.precision("tax_amount", "taxes"))
frappe.flags.company = None
return frappe.render_template(
"templates/includes/itemised_tax_breakup.html", dict(
headers=headers,
@@ -578,7 +579,7 @@ def get_itemised_tax(taxes):
if item_tax_map:
for item_code, tax_data in item_tax_map.items():
itemised_tax.setdefault(item_code, frappe._dict())
if isinstance(tax_data, list):
itemised_tax[item_code][tax.description] = frappe._dict(dict(
tax_rate=flt(tax_data[0]),