[selling/buying] [fixes] fixes in client side code, server side code, print formats

This commit is contained in:
Anand Doshi
2013-05-28 17:23:36 +05:30
parent a3d8494c77
commit 923d41dfd2
37 changed files with 352 additions and 324 deletions

View File

@@ -32,7 +32,7 @@ class AccountsController(TransactionBase):
validate_conversion_rate(self.doc.currency, self.doc.conversion_rate,
self.meta.get_label("conversion_rate"), self.doc.company)
# self.calculate_taxes_and_totals()
self.calculate_taxes_and_totals()
self.validate_value("grand_total", ">=", 0)
self.set_total_in_words()
@@ -84,9 +84,6 @@ class AccountsController(TransactionBase):
def calculate_taxes_and_totals(self):
self.doc.conversion_rate = flt(self.doc.conversion_rate)
# TODO validate conversion rate
self.item_doclist = self.doclist.get({"parentfield": self.fname})
self.tax_doclist = self.doclist.get({"parentfield": self.other_fname})
@@ -264,6 +261,15 @@ class AccountsController(TransactionBase):
item.fields[base_field] = flt((flt(item.fields[print_field],
self.precision(print_field, item)) * self.doc.conversion_rate),
self.precision(base_field, item))
def calculate_total_advance(self, parenttype, advance_parentfield):
if self.doc.doctype == parenttype and self.doc.docstatus < 2:
sum_of_allocated_amount = sum([flt(adv.allocated_amount, self.precision("allocated_amount", adv))
for adv in self.doclist.get({"parentfield": advance_parentfield})])
self.doc.total_advance = flt(sum_of_allocated_amount, self.precision("total_advance"))
self.calculate_outstanding_amount()
def get_gl_dict(self, args, cancel=None):
"""this method populates the common properties of a gl entry record"""

View File

@@ -50,7 +50,7 @@ class BuyingController(StockController):
self.set_missing_item_details(get_item_details)
def set_supplier_defaults(self):
self.get_default_supplier_address()
self.get_default_supplier_address(self.doc.fields)
def get_purchase_tax_details(self):
self.doclist = self.doc.clear_table(self.doclist, "purchase_tax_details")
@@ -93,7 +93,7 @@ class BuyingController(StockController):
def calculate_taxes_and_totals(self):
self.other_fname = "purchase_tax_details"
super(BuyingController, self).calculate_taxes_and_totals()
self.calculate_outstanding_amount()
self.calculate_total_advance("Purchase Invoice", "advance_allocation_details")
def calculate_item_values(self):
# hack! - cleaned up in _cleanup()
@@ -168,6 +168,10 @@ class BuyingController(StockController):
item.purchase_rate = item.rate
del item.fields["rate"]
if not self.meta.get_field("item_tax_amount", parentfield=self.fname):
for item in self.item_doclist:
del item.fields["item_tax_amount"]
def set_item_tax_amount(self, item, tax, current_tax_amount):
"""
item_tax_amount is the total tax amount applied on that item

View File

@@ -102,9 +102,9 @@ class SellingController(StockController):
super(SellingController, self).calculate_taxes_and_totals()
self.calculate_total_advance("Sales Invoice", "advance_adjustment_details")
self.calculate_commission()
self.calculate_contribution()
# self.calculate_outstanding_amount()
def determine_exclusive_rate(self):
if not any((cint(tax.included_in_print_rate) for tax in self.tax_doclist)):
@@ -201,15 +201,27 @@ class SellingController(StockController):
self.doc.rounded_total = round(self.doc.grand_total)
self.doc.rounded_total_export = round(self.doc.grand_total_export)
def calculate_commission(self):
self.round_floats_in(self.doc, ["net_total", "commission_rate"])
if self.doc.commission_rate > 100.0:
msgprint(_(self.meta.get_label("commission_rate")) + " " +
_("cannot be greater than 100"), raise_exception=True)
self.doc.total_commission = flt(self.doc.net_total * self.doc.commission_rate / 100.0,
self.precision("total_commission"))
def calculate_outstanding_amount(self):
# NOTE:
# write_off_amount is only for POS Invoice
# total_advance is only for non POS Invoice
if self.doc.doctype == "Sales Invoice" and self.doc.docstatus < 2:
self.round_floats_in(self.doc, ["grand_total", "total_advance", "write_off_amount",
"paid_amount"])
total_amount_to_pay = self.doc.grand_total - self.doc.write_off_amount
self.doc.outstanding_amount = flt(total_amount_to_pay - self.doc.total_advance - self.doc.paid_amount,
self.precision("outstanding_amount"))
def calculate_commission(self):
if self.meta.get_field("commission_rate"):
self.round_floats_in(self.doc, ["net_total", "commission_rate"])
if self.doc.commission_rate > 100.0:
msgprint(_(self.meta.get_label("commission_rate")) + " " +
_("cannot be greater than 100"), raise_exception=True)
self.doc.total_commission = flt(self.doc.net_total * self.doc.commission_rate / 100.0,
self.precision("total_commission"))
def calculate_contribution(self):
total = 0.0