From 98c6bbf1e7e30b6110591beb53233047f94fbe5c Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 4 Feb 2013 18:35:54 +0530 Subject: [PATCH] make gl entry only if amount is there --- .../journal_voucher/journal_voucher.py | 33 ++++++++++--------- .../purchase_invoice/purchase_invoice.py | 25 +++++++------- .../doctype/sales_invoice/sales_invoice.py | 26 ++++++++------- 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/accounts/doctype/journal_voucher/journal_voucher.py b/accounts/doctype/journal_voucher/journal_voucher.py index 2e1bc7e5e5..4f20308369 100644 --- a/accounts/doctype/journal_voucher/journal_voucher.py +++ b/accounts/doctype/journal_voucher/journal_voucher.py @@ -248,22 +248,23 @@ class DocType(AccountsController): from accounts.general_ledger import make_gl_entries gl_map = [] for d in self.doclist.get({"parentfield": "entries"}): - gl_map.append( - self.get_gl_dict({ - "account": d.account, - "against": d.against_account, - "debit": d.debit, - "credit": d.credit, - "against_voucher_type": ((d.against_voucher and "Purchase Invoice") - or (d.against_invoice and "Sales Invoice") - or (d.against_jv and "Journal Voucher")), - "against_voucher": d.against_voucher or d.against_invoice or d.against_jv, - "remarks": self.doc.remark, - "cost_center": d.cost_center - }, cancel) - ) - - make_gl_entries(gl_map, cancel=cancel, adv_adj=adv_adj) + if d.debit or d.credit: + gl_map.append( + self.get_gl_dict({ + "account": d.account, + "against": d.against_account, + "debit": d.debit, + "credit": d.credit, + "against_voucher_type": ((d.against_voucher and "Purchase Invoice") + or (d.against_invoice and "Sales Invoice") + or (d.against_jv and "Journal Voucher")), + "against_voucher": d.against_voucher or d.against_invoice or d.against_jv, + "remarks": self.doc.remark, + "cost_center": d.cost_center + }, cancel) + ) + if gl_map: + make_gl_entries(gl_map, cancel=cancel, adv_adj=adv_adj) def get_outstanding(self, args): args = eval(args) diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py index 5f7e848a53..98bfda554d 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -422,16 +422,17 @@ class DocType(BuyingController): abbr = self.get_company_abbr() # parent's gl entry - gl_entries.append( - self.get_gl_dict({ - "account": self.doc.credit_to, - "against": self.doc.against_expense_account, - "credit": self.doc.grand_total, - "remarks": self.doc.remarks, - "against_voucher": self.doc.name, - "against_voucher_type": self.doc.doctype, - }, is_cancel) - ) + if self.doc.grand_total: + gl_entries.append( + self.get_gl_dict({ + "account": self.doc.credit_to, + "against": self.doc.against_expense_account, + "credit": self.doc.grand_total, + "remarks": self.doc.remarks, + "against_voucher": self.doc.name, + "against_voucher_type": self.doc.doctype, + }, is_cancel) + ) # tax table gl entries for tax in getlist(self.doclist, "purchase_tax_details"): @@ -506,7 +507,9 @@ class DocType(BuyingController): "cost_center": self.doc.write_off_cost_center }, is_cancel) ) - make_gl_entries(gl_entries, cancel=is_cancel) + + if gl_entries: + make_gl_entries(gl_entries, cancel=is_cancel) def check_next_docstatus(self): diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py index 7d9a78abd8..8ffe17d1d7 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.py +++ b/accounts/doctype/sales_invoice/sales_invoice.py @@ -637,16 +637,17 @@ class DocType(SellingController): abbr = self.get_company_abbr() # parent's gl entry - gl_entries.append( - self.get_gl_dict({ - "account": self.doc.debit_to, - "against": self.doc.against_income_account, - "debit": self.doc.grand_total, - "remarks": self.doc.remarks, - "against_voucher": self.doc.name, - "against_voucher_type": self.doc.doctype, - }, is_cancel) - ) + if self.doc.grand_total: + gl_entries.append( + self.get_gl_dict({ + "account": self.doc.debit_to, + "against": self.doc.against_income_account, + "debit": self.doc.grand_total, + "remarks": self.doc.remarks, + "against_voucher": self.doc.name, + "against_voucher_type": self.doc.doctype, + }, is_cancel) + ) # tax table gl entries for tax in self.doclist.get({"parentfield": "other_charges"}): @@ -745,8 +746,9 @@ class DocType(SellingController): update_outstanding = self.doc.is_pos and self.doc.write_off_account and 'No' or 'Yes' merge_entries=cint(self.doc.is_pos)!=1 and 1 or 0 - make_gl_entries(gl_entries, cancel=is_cancel, - update_outstanding=update_outstanding, merge_entries=merge_entries) + if gl_entries: + make_gl_entries(gl_entries, cancel=is_cancel, + update_outstanding=update_outstanding, merge_entries=merge_entries) def update_c_form(self): """Update amended id in C-form"""