diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py index db0ddd807d..f1c5758617 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -423,7 +423,7 @@ class DocType(BuyingController): self.get_gl_dict({ "account": self.doc.credit_to, "against": self.doc.against_expense_account, - "credit": self.doc.grand_total, + "credit": self.doc.total_amount_to_pay, "remarks": self.doc.remarks, "against_voucher": self.doc.name, "against_voucher_type": self.doc.doctype, diff --git a/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js b/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js index 6158e26d8f..53588e0629 100644 --- a/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js +++ b/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js @@ -76,8 +76,9 @@ cur_frm.cscript.add_deduct_tax = function(doc, cdt, cdn) { alert("Please select Category first"); d.add_deduct_tax = ''; } - else if(d.category != 'Total' && d.add_deduct_tax == 'Deduct'){ - alert("You cannot Deduct when category is for valuation or for both(i.e total and valuation)"); + else if(d.category != 'Total' && d.add_deduct_tax == 'Deduct') { + console.log([d.category, d.add_deduct_tax]); + msgprint("You cannot deduct when category is for 'Valuation' or 'Valuation and Total'"); d.add_deduct_tax = ''; } diff --git a/accounts/general_ledger.py b/accounts/general_ledger.py index f7932bf60c..06c101b6b5 100644 --- a/accounts/general_ledger.py +++ b/accounts/general_ledger.py @@ -70,6 +70,10 @@ def save_entries(gl_map, cancel, adv_adj, update_outstanding): for entry in gl_map: gle = Document('GL Entry', fielddata=entry) + # round off upto 2 decimal + gle.debit = flt(gle.debit, 2) + gle.credit = flt(gle.credit, 2) + # toggle debit, credit if negative entry if flt(gle.debit) < 0 or flt(gle.credit) < 0: _swap(gle) diff --git a/buying/doctype/purchase_common/purchase_common.js b/buying/doctype/purchase_common/purchase_common.js index 3a9d89110f..b3f62d58b9 100644 --- a/buying/doctype/purchase_common/purchase_common.js +++ b/buying/doctype/purchase_common/purchase_common.js @@ -778,10 +778,10 @@ cur_frm.cscript.calc_doc_values = function(doc, tname, fname, other_fname) { var calculate_outstanding = function(doc) { // total amount to pay - doc.total_amount_to_pay = flt(flt(doc.net_total) + flt(doc.other_charges_added) - flt(doc.other_charges_deducted)); + doc.total_amount_to_pay = flt(doc.grand_total) - flt(doc.write_off_amount); // outstanding amount - if(doc.docstatus==0) doc.outstanding_amount = flt(doc.net_total) + flt(doc.other_charges_added) - flt(doc.other_charges_deducted) - flt(doc.total_advance); + if(doc.docstatus==0) doc.outstanding_amount = doc.total_amount_to_pay - flt(doc.total_advance); refresh_many(['total_amount_to_pay', 'outstanding_amount']); } diff --git a/patches/february_2013/fix_outstanding.py b/patches/february_2013/fix_outstanding.py new file mode 100644 index 0000000000..226b360a29 --- /dev/null +++ b/patches/february_2013/fix_outstanding.py @@ -0,0 +1,15 @@ +def execute(): + import webnotes + from webnotes.utils import flt + for dt in ["Sales Invoice", "Purchase Invoice"]: + records = webnotes.conn.sql("""select name, outstanding_amount from `tab%s` + where docstatus = 1""" % dt) + for r in records: + outstanding = webnotes.conn.sql(""" + select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0)) from `tabGL Entry` + where against_voucher = %s and against_voucher_type = %s + and ifnull(is_cancelled, 'No') = 'No'""", (r[0], dt)) + if flt(r[1]) != abs(flt(outstanding[0][0])): + # print r, outstanding + webnotes.conn.sql("update `tab%s` set outstanding_amount = %s where name = %s" % + (dt, '%s', '%s'), (abs(flt(outstanding[0][0])), si[0])) \ No newline at end of file diff --git a/patches/february_2013/gle_floating_point_issue_revisited.py b/patches/february_2013/gle_floating_point_issue_revisited.py new file mode 100644 index 0000000000..3fc57bd4e5 --- /dev/null +++ b/patches/february_2013/gle_floating_point_issue_revisited.py @@ -0,0 +1,22 @@ +def execute(): + import webnotes + from webnotes.utils import flt + + records = webnotes.conn.sql("""select name, grand_total, debit_to from `tabSales Invoice` + where docstatus = 1""", as_dict=1) + + for r in records: + gle = webnotes.conn.sql("""select name, debit from `tabGL Entry` + where account = %s and voucher_type = 'Sales Invoice' and voucher_no = %s + and ifnull(is_cancelled, 'No') = 'No' limit 1""", (r.debit_to, r.name), as_dict=1) + if gle: + diff = round((flt(r.grand_total) - flt(gle[0]['debit'])), 2) + + if abs(diff) == 0.01: + # print r.name, r.grand_total, gle[0]['debit'] + webnotes.conn.sql("""update `tabGL Entry` set debit = debit + %s + where name = %s""", (diff, gle[0]['name'])) + + webnotes.conn.sql("""update `tabGL Entry` set credit = credit - %s + where voucher_type = 'Sales Invoice' and voucher_no = %s + and credit > 0 limit 1""", (diff, r.name)) \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index c1fa08f24e..97bdc52e79 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -167,5 +167,5 @@ patch_list = [ "patches.february_2013.account_negative_balance", "patches.february_2013.remove_account_utils_folder", "patches.february_2013.update_company_in_leave_application", - "execute:webnotes.conn.sql_ddl('alter table tabSeries change `name` `name` varchar(100)')" + "execute:webnotes.conn.sql_ddl('alter table tabSeries change `name` `name` varchar(100)')", ] \ No newline at end of file