Fixed conflict while merging with develop branch

This commit is contained in:
Nabin Hait
2014-01-20 17:18:16 +05:30
36 changed files with 529 additions and 193 deletions

View File

@@ -132,6 +132,12 @@ class AccountsController(TransactionBase):
self.doclist.append(tax)
def calculate_taxes_and_totals(self):
self.discount_amount_applied = False
self._calculate_taxes_and_totals()
if self.meta.get_field(self.doc.doctype, "discount_amount"):
self.apply_discount_amount()
def _calculate_taxes_and_totals(self):
# validate conversion rate
company_currency = get_company_currency(self.doc.company)
if not self.doc.currency or self.doc.currency == company_currency:
@@ -140,7 +146,7 @@ class AccountsController(TransactionBase):
else:
validate_conversion_rate(self.doc.currency, self.doc.conversion_rate,
self.meta.get_label("conversion_rate"), self.doc.company)
self.doc.conversion_rate = flt(self.doc.conversion_rate)
self.item_doclist = self.doclist.get({"parentfield": self.fname})
self.tax_doclist = self.doclist.get({"parentfield": self.other_fname})
@@ -156,17 +162,19 @@ class AccountsController(TransactionBase):
self.calculate_totals()
self._cleanup()
# TODO
# print format: show net_total_export instead of net_total
def initialize_taxes(self):
for tax in self.tax_doclist:
tax.item_wise_tax_detail = {}
for fieldname in ["tax_amount", "total",
"tax_amount_for_current_item", "grand_total_for_current_item",
"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]:
tax.fields[fieldname] = 0.0
tax_fields = ["total", "tax_amount_after_discount_amount",
"tax_amount_for_current_item", "grand_total_for_current_item",
"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]
if not self.discount_amount_applied:
tax_fields.append("tax_amount")
for fieldname in tax_fields:
tax.fields[fieldname] = 0.0
self.validate_on_previous_row(tax)
self.validate_inclusive_tax(tax)
self.round_floats_in(tax)
@@ -214,11 +222,11 @@ class AccountsController(TransactionBase):
"charge_type": tax.charge_type,
})
elif tax.charge_type == "On Previous Row Amount" and \
not cint(self.tax_doclist[tax.row_id - 1].included_in_print_rate):
not cint(self.tax_doclist[cint(tax.row_id) - 1].included_in_print_rate):
# referred row should also be inclusive
_on_previous_row_error(tax.row_id)
elif tax.charge_type == "On Previous Row Total" and \
not all([cint(t.included_in_print_rate) for t in self.tax_doclist[:tax.row_id - 1]]):
not all([cint(t.included_in_print_rate) for t in self.tax_doclist[:cint(tax.row_id) - 1]]):
# all rows about the reffered tax should be inclusive
_on_previous_row_error("1 - %d" % (tax.row_id,))
@@ -226,14 +234,14 @@ class AccountsController(TransactionBase):
# maintain actual tax rate based on idx
actual_tax_dict = dict([[tax.idx, tax.rate] for tax in self.tax_doclist
if tax.charge_type == "Actual"])
for n, item in enumerate(self.item_doclist):
item_tax_map = self._load_item_tax_rate(item.item_tax_rate)
for i, tax in enumerate(self.tax_doclist):
# tax_amount represents the amount of tax for the current step
current_tax_amount = self.get_current_tax_amount(item, tax, item_tax_map)
# Adjust divisional loss to the last item
if tax.charge_type == "Actual":
actual_tax_dict[tax.idx] -= current_tax_amount
@@ -245,7 +253,10 @@ class AccountsController(TransactionBase):
tax.tax_amount_for_current_item = current_tax_amount
# accumulate tax amount into tax.tax_amount
tax.tax_amount += current_tax_amount
if not self.discount_amount_applied:
tax.tax_amount += current_tax_amount
tax.tax_amount_after_discount_amount += current_tax_amount
if tax.category:
# if just for valuation, do not add the tax amount in total
@@ -259,22 +270,36 @@ class AccountsController(TransactionBase):
# note: grand_total_for_current_item contains the contribution of
# item's amount, previously applied tax and the current tax on that item
if i==0:
tax.grand_total_for_current_item = flt(item.amount +
current_tax_amount, self.precision("total", tax))
tax.grand_total_for_current_item = flt(item.amount + current_tax_amount,
self.precision("total", tax))
else:
tax.grand_total_for_current_item = \
flt(self.tax_doclist[i-1].grand_total_for_current_item +
flt(self.tax_doclist[i-1].grand_total_for_current_item +
current_tax_amount, self.precision("total", tax))
# in tax.total, accumulate grand total of each item
tax.total += tax.grand_total_for_current_item
# set precision in the last item iteration
if n == len(self.item_doclist) - 1:
tax.total = flt(tax.total, self.precision("total", tax))
tax.tax_amount = flt(tax.tax_amount, self.precision("tax_amount", tax))
self.round_off_totals(tax)
# adjust Discount Amount loss in last tax iteration
if i == (len(self.tax_doclist) - 1) and self.discount_amount_applied:
self.adjust_discount_amount_loss(tax)
def round_off_totals(self, tax):
tax.total = flt(tax.total, self.precision("total", tax))
tax.tax_amount = flt(tax.tax_amount, self.precision("tax_amount", tax))
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount,
self.precision("tax_amount", tax))
def adjust_discount_amount_loss(self, tax):
discount_amount_loss = self.doc.grand_total - flt(self.doc.discount_amount) - tax.total
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount +
discount_amount_loss, self.precision("tax_amount", tax))
tax.total = flt(tax.total + discount_amount_loss, self.precision("total", tax))
def get_current_tax_amount(self, item, tax, item_tax_map):
tax_rate = self._get_tax_rate(tax, item_tax_map)
current_tax_amount = 0.0
@@ -293,9 +318,9 @@ class AccountsController(TransactionBase):
elif tax.charge_type == "On Previous Row Total":
current_tax_amount = (tax_rate / 100.0) * \
self.tax_doclist[cint(tax.row_id) - 1].grand_total_for_current_item
current_tax_amount = flt(current_tax_amount, self.precision("tax_amount", tax))
# store tax breakup for each item
key = item.item_code or item.item_name
if tax.item_wise_tax_detail.get(key):