[flat discount] first commit

This commit is contained in:
Akhilesh Darjee
2013-12-23 15:49:08 +05:30
parent 9409efe02a
commit b09dc46e68
9 changed files with 218 additions and 77 deletions

View File

@@ -121,7 +121,7 @@ class SellingController(StockController):
cumulated_tax_fraction += tax.tax_fraction_for_current_item
if cumulated_tax_fraction:
if cumulated_tax_fraction and not self.flat_discount_applied:
item.amount = flt((item.export_amount * self.doc.conversion_rate) /
(1 + cumulated_tax_fraction), self.precision("amount", item))
@@ -158,22 +158,23 @@ class SellingController(StockController):
return current_tax_fraction
def calculate_item_values(self):
for item in self.item_doclist:
self.round_floats_in(item)
if item.adj_rate == 100:
item.export_rate = 0
elif not item.export_rate:
item.export_rate = flt(item.ref_rate * (1.0 - (item.adj_rate / 100.0)),
self.precision("export_rate", item))
item.export_amount = flt(item.export_rate * item.qty,
self.precision("export_amount", item))
if not self.flat_discount_applied:
for item in self.item_doclist:
self.round_floats_in(item)
if item.adj_rate == 100:
item.export_rate = 0
elif not item.export_rate:
item.export_rate = flt(item.ref_rate * (1.0 - (item.adj_rate / 100.0)),
self.precision("export_rate", item))
item.export_amount = flt(item.export_rate * item.qty,
self.precision("export_amount", item))
self._set_in_company_currency(item, "ref_rate", "base_ref_rate")
self._set_in_company_currency(item, "export_rate", "basic_rate")
self._set_in_company_currency(item, "export_amount", "amount")
self._set_in_company_currency(item, "ref_rate", "base_ref_rate")
self._set_in_company_currency(item, "export_rate", "basic_rate")
self._set_in_company_currency(item, "export_amount", "amount")
def calculate_net_total(self):
self.doc.net_total = self.doc.net_total_export = 0.0
@@ -184,6 +185,7 @@ class SellingController(StockController):
self.round_floats_in(self.doc, ["net_total", "net_total_export"])
def calculate_totals(self):
self.total_tax_excluding_actual = 0.0
self.doc.grand_total = flt(self.tax_doclist and \
self.tax_doclist[-1].total or self.doc.net_total, self.precision("grand_total"))
self.doc.grand_total_export = flt(self.doc.grand_total / self.doc.conversion_rate,
@@ -191,12 +193,33 @@ class SellingController(StockController):
self.doc.other_charges_total = flt(self.doc.grand_total - self.doc.net_total,
self.precision("other_charges_total"))
self.doc.other_charges_total_export = flt(self.doc.grand_total_export - self.doc.net_total_export,
self.precision("other_charges_total_export"))
self.doc.other_charges_total_export = flt(self.doc.grand_total_export -
self.doc.net_total_export + flt(self.doc.flat_discount), self.precision("other_charges_total_export"))
self.doc.rounded_total = _round(self.doc.grand_total)
self.doc.rounded_total_export = _round(self.doc.grand_total_export)
if self.doc.flat_discount:
# calculate total tax for flat discount excluding actual
for tax in self.tax_doclist:
if tax.charge_type != "Actual":
self.total_tax_excluding_actual += tax.tax_amount
self.total_amount_for_flat_discount = flt(self.doc.net_total +
self.total_tax_excluding_actual, self.precision("grand_total"))
def apply_flat_discount(self):
distributed_amount = 0.0
if self.doc.flat_discount and self.total_amount_for_flat_discount:
# calculate item amount after flat discount
for item in self.item_doclist:
distributed_amount = self.doc.flat_discount * item.amount / self.total_amount_for_flat_discount
item.amount = flt(item.amount - distributed_amount, self.precision("amount", item))
self.flat_discount_applied = True
self.calculate_taxes_and_totals()
def calculate_outstanding_amount(self):
# NOTE:
# write_off_amount is only for POS Invoice