make gl entry only if amount is there
diff --git a/accounts/doctype/journal_voucher/journal_voucher.py b/accounts/doctype/journal_voucher/journal_voucher.py
index 2e1bc7e..4f20308 100644
--- a/accounts/doctype/journal_voucher/journal_voucher.py
+++ b/accounts/doctype/journal_voucher/journal_voucher.py
@@ -248,22 +248,23 @@
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 5f7e848..98bfda5 100644
--- a/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -422,16 +422,17 @@
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 @@
"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 7d9a78a..8ffe17d 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/accounts/doctype/sales_invoice/sales_invoice.py
@@ -637,16 +637,17 @@
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 @@
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"""