From df28eefa4bcbdde4e860cefe20bed8d3dcf17059 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 4 Jun 2013 12:10:33 +0530 Subject: [PATCH] [payment reconciliation] do not allow negative outstanding in case of against_jv --- accounts/doctype/gl_entry/gl_entry.py | 25 +++++++++++++------- accounts/page/accounts_home/accounts_home.js | 5 ++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/accounts/doctype/gl_entry/gl_entry.py b/accounts/doctype/gl_entry/gl_entry.py index 429cc104a7b..112e449f97d 100644 --- a/accounts/doctype/gl_entry/gl_entry.py +++ b/accounts/doctype/gl_entry/gl_entry.py @@ -42,9 +42,9 @@ class DocType: self.check_negative_balance(adv_adj) # Update outstanding amt on against voucher - if self.doc.against_voucher and self.doc.against_voucher_type not in \ - ('Journal Voucher','POS') and update_outstanding == 'Yes': - self.update_outstanding_amt() + if self.doc.against_voucher and self.doc.against_voucher_type != "POS" \ + and update_outstanding == 'Yes': + self.update_outstanding_amt() def check_mandatory(self): mandatory = ['account','remarks','voucher_type','voucher_no','fiscal_year','company'] @@ -164,16 +164,25 @@ class DocType: and ifnull(is_cancelled,'No') = 'No'""", (self.doc.against_voucher, self.doc.against_voucher_type))[0][0] or 0.0) - if self.doc.against_voucher_type=='Purchase Invoice': - # amount to debit + if self.doc.against_voucher_type == 'Purchase Invoice': bal = -bal + elif self.doc.against_voucher_type == "Journal Voucher": + against_voucher_amount = flt(webnotes.conn.sql("""select sum(debit) - sum(credit) + from `tabGL Entry` where voucher_type = 'Journal Voucher' and voucher_no = %s + and account = %s""", (self.doc.against_voucher, self.doc.account))[0][0]) + + bal = against_voucher_amount + bal + if against_voucher_amount < 0: + bal = -bal + # Validation : Outstanding can not be negative if bal < 0 and self.doc.is_cancelled == 'No': msgprint(_("Outstanding for Voucher ") + self.doc.against_voucher + - _(" will become ") + fmt_money(bal) + _("Outstanding cannot be less than zero. \ + _(" will become ") + fmt_money(bal) + _(". Outstanding cannot be less than zero. \ Please match exact outstanding."), raise_exception=1) # Update outstanding amt on against voucher - sql("update `tab%s` set outstanding_amount=%s where name='%s'"% - (self.doc.against_voucher_type, bal, self.doc.against_voucher)) \ No newline at end of file + if self.doc.against_voucher_type in ["Sales Invoice", "Purchase Invoice"]: + sql("update `tab%s` set outstanding_amount=%s where name='%s'"% + (self.doc.against_voucher_type, bal, self.doc.against_voucher)) \ No newline at end of file diff --git a/accounts/page/accounts_home/accounts_home.js b/accounts/page/accounts_home/accounts_home.js index f187a54cdc6..10c0fc0b85a 100644 --- a/accounts/page/accounts_home/accounts_home.js +++ b/accounts/page/accounts_home/accounts_home.js @@ -237,6 +237,11 @@ wn.module_page["Accounts"] = [ route: "query-report/Customer Account Head", doctype: "Account" }, + { + "label":wn._("Item-wise Sales Register"), + route: "query-report/Item-wise Sales Register", + doctype: "Sales Invoice" + }, ] } ]