Anand Doshi | 885e074 | 2015-03-03 14:55:30 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 2 | # License: GNU General Public License v3. See license.txt |
Nabin Hait | bf495c9 | 2013-01-30 12:49:08 +0530 | [diff] [blame] | 3 | |
| 4 | from __future__ import unicode_literals |
Rohit Waghchaure | e9ff191 | 2017-06-19 12:54:59 +0530 | [diff] [blame] | 5 | import frappe, erpnext |
Nabin Hait | 818d967 | 2015-06-22 18:21:38 +0530 | [diff] [blame] | 6 | from frappe.utils import flt, cstr, cint |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 7 | from frappe import _ |
Nabin Hait | e2c200a | 2015-05-28 13:00:37 +0530 | [diff] [blame] | 8 | from frappe.model.meta import get_field_precision |
Nabin Hait | b9bc7d6 | 2016-05-16 14:38:47 +0530 | [diff] [blame] | 9 | from erpnext.accounts.doctype.budget.budget import validate_expense_against_budget |
deepeshgarg007 | 3d11ac0 | 2019-05-19 00:02:01 +0530 | [diff] [blame] | 10 | from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions |
Nabin Hait | bf495c9 | 2013-01-30 12:49:08 +0530 | [diff] [blame] | 11 | |
Nabin Hait | bb77756 | 2013-08-29 18:19:37 +0530 | [diff] [blame] | 12 | |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 13 | class StockAccountInvalidTransaction(frappe.ValidationError): pass |
Nabin Hait | bf495c9 | 2013-01-30 12:49:08 +0530 | [diff] [blame] | 14 | |
Nabin Hait | 9784d27 | 2016-12-30 16:21:35 +0530 | [diff] [blame] | 15 | def make_gl_entries(gl_map, cancel=False, adv_adj=False, merge_entries=True, update_outstanding='Yes', from_repost=False): |
Nabin Hait | 2e296fa | 2013-08-28 18:53:11 +0530 | [diff] [blame] | 16 | if gl_map: |
| 17 | if not cancel: |
| 18 | gl_map = process_gl_map(gl_map, merge_entries) |
nabinhait | c343292 | 2014-07-29 18:06:18 +0530 | [diff] [blame] | 19 | if gl_map and len(gl_map) > 1: |
Nabin Hait | 9784d27 | 2016-12-30 16:21:35 +0530 | [diff] [blame] | 20 | save_entries(gl_map, adv_adj, update_outstanding, from_repost) |
nabinhait | c343292 | 2014-07-29 18:06:18 +0530 | [diff] [blame] | 21 | else: |
nabinhait | 4859b48 | 2014-07-30 14:28:24 +0530 | [diff] [blame] | 22 | frappe.throw(_("Incorrect number of General Ledger Entries found. You might have selected a wrong Account in the transaction.")) |
Nabin Hait | 2e296fa | 2013-08-28 18:53:11 +0530 | [diff] [blame] | 23 | else: |
| 24 | delete_gl_entries(gl_map, adv_adj=adv_adj, update_outstanding=update_outstanding) |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 25 | |
Nabin Hait | 27994c2 | 2013-08-26 16:53:30 +0530 | [diff] [blame] | 26 | def process_gl_map(gl_map, merge_entries=True): |
Nabin Hait | bf495c9 | 2013-01-30 12:49:08 +0530 | [diff] [blame] | 27 | if merge_entries: |
| 28 | gl_map = merge_similar_entries(gl_map) |
Nabin Hait | 27994c2 | 2013-08-26 16:53:30 +0530 | [diff] [blame] | 29 | for entry in gl_map: |
Anand Doshi | 602e825 | 2015-11-16 19:05:46 +0530 | [diff] [blame] | 30 | # toggle debit, credit if negative entry |
Nabin Hait | 88f3cd5 | 2013-10-23 16:29:19 +0530 | [diff] [blame] | 31 | if flt(entry.debit) < 0: |
| 32 | entry.credit = flt(entry.credit) - flt(entry.debit) |
| 33 | entry.debit = 0.0 |
Anand Doshi | 602e825 | 2015-11-16 19:05:46 +0530 | [diff] [blame] | 34 | |
Nabin Hait | c561a49 | 2015-08-19 19:22:34 +0530 | [diff] [blame] | 35 | if flt(entry.debit_in_account_currency) < 0: |
| 36 | entry.credit_in_account_currency = \ |
| 37 | flt(entry.credit_in_account_currency) - flt(entry.debit_in_account_currency) |
| 38 | entry.debit_in_account_currency = 0.0 |
Anand Doshi | 602e825 | 2015-11-16 19:05:46 +0530 | [diff] [blame] | 39 | |
Nabin Hait | 88f3cd5 | 2013-10-23 16:29:19 +0530 | [diff] [blame] | 40 | if flt(entry.credit) < 0: |
| 41 | entry.debit = flt(entry.debit) - flt(entry.credit) |
| 42 | entry.credit = 0.0 |
Anand Doshi | 602e825 | 2015-11-16 19:05:46 +0530 | [diff] [blame] | 43 | |
Nabin Hait | c561a49 | 2015-08-19 19:22:34 +0530 | [diff] [blame] | 44 | if flt(entry.credit_in_account_currency) < 0: |
| 45 | entry.debit_in_account_currency = \ |
| 46 | flt(entry.debit_in_account_currency) - flt(entry.credit_in_account_currency) |
| 47 | entry.credit_in_account_currency = 0.0 |
Anand Doshi | 602e825 | 2015-11-16 19:05:46 +0530 | [diff] [blame] | 48 | |
Nabin Hait | 27994c2 | 2013-08-26 16:53:30 +0530 | [diff] [blame] | 49 | return gl_map |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 50 | |
Nabin Hait | bf495c9 | 2013-01-30 12:49:08 +0530 | [diff] [blame] | 51 | def merge_similar_entries(gl_map): |
| 52 | merged_gl_map = [] |
deepeshgarg007 | 3d11ac0 | 2019-05-19 00:02:01 +0530 | [diff] [blame] | 53 | accounting_dimensions = get_accounting_dimensions() |
Nabin Hait | bf495c9 | 2013-01-30 12:49:08 +0530 | [diff] [blame] | 54 | for entry in gl_map: |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 55 | # if there is already an entry in this account then just add it |
Nabin Hait | bf495c9 | 2013-01-30 12:49:08 +0530 | [diff] [blame] | 56 | # to that entry |
deepeshgarg007 | 3d11ac0 | 2019-05-19 00:02:01 +0530 | [diff] [blame] | 57 | same_head = check_if_in_list(entry, merged_gl_map, accounting_dimensions) |
Nabin Hait | bf495c9 | 2013-01-30 12:49:08 +0530 | [diff] [blame] | 58 | if same_head: |
Nabin Hait | 2e296fa | 2013-08-28 18:53:11 +0530 | [diff] [blame] | 59 | same_head.debit = flt(same_head.debit) + flt(entry.debit) |
Nabin Hait | c561a49 | 2015-08-19 19:22:34 +0530 | [diff] [blame] | 60 | same_head.debit_in_account_currency = \ |
| 61 | flt(same_head.debit_in_account_currency) + flt(entry.debit_in_account_currency) |
Nabin Hait | 2e296fa | 2013-08-28 18:53:11 +0530 | [diff] [blame] | 62 | same_head.credit = flt(same_head.credit) + flt(entry.credit) |
Nabin Hait | c561a49 | 2015-08-19 19:22:34 +0530 | [diff] [blame] | 63 | same_head.credit_in_account_currency = \ |
| 64 | flt(same_head.credit_in_account_currency) + flt(entry.credit_in_account_currency) |
Nabin Hait | bf495c9 | 2013-01-30 12:49:08 +0530 | [diff] [blame] | 65 | else: |
| 66 | merged_gl_map.append(entry) |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 67 | |
Nabin Hait | 815a49e | 2013-08-07 17:00:01 +0530 | [diff] [blame] | 68 | # filter zero debit and credit entries |
Nabin Hait | 2e54da2 | 2015-08-13 12:19:20 +0530 | [diff] [blame] | 69 | merged_gl_map = filter(lambda x: flt(x.debit, 9)!=0 or flt(x.credit, 9)!=0, merged_gl_map) |
Achilles Rasquinha | 908289d | 2018-03-08 13:10:51 +0530 | [diff] [blame] | 70 | merged_gl_map = list(merged_gl_map) |
Rushabh Mehta | 708e47a | 2018-08-08 16:37:31 +0530 | [diff] [blame] | 71 | |
Nabin Hait | bf495c9 | 2013-01-30 12:49:08 +0530 | [diff] [blame] | 72 | return merged_gl_map |
| 73 | |
deepeshgarg007 | 3d11ac0 | 2019-05-19 00:02:01 +0530 | [diff] [blame] | 74 | def check_if_in_list(gle, gl_map, dimensions=None): |
| 75 | account_head_fieldnames = ['party_type', 'party', 'against_voucher', 'against_voucher_type', |
| 76 | 'cost_center', 'project'] |
| 77 | |
| 78 | if dimensions: |
| 79 | account_head_fieldnames = account_head_fieldnames + dimensions |
| 80 | |
Nabin Hait | bb77756 | 2013-08-29 18:19:37 +0530 | [diff] [blame] | 81 | for e in gl_map: |
deepeshgarg007 | 3d11ac0 | 2019-05-19 00:02:01 +0530 | [diff] [blame] | 82 | same_head = True |
| 83 | if e.account != gle.account: |
| 84 | same_head = False |
| 85 | |
| 86 | for fieldname in account_head_fieldnames: |
| 87 | if cstr(e.get(fieldname)) != cstr(gle.get(fieldname)): |
| 88 | same_head = False |
| 89 | |
| 90 | if same_head: |
| 91 | return e |
Nabin Hait | bf495c9 | 2013-01-30 12:49:08 +0530 | [diff] [blame] | 92 | |
Nabin Hait | 9784d27 | 2016-12-30 16:21:35 +0530 | [diff] [blame] | 93 | def save_entries(gl_map, adv_adj, update_outstanding, from_repost=False): |
| 94 | if not from_repost: |
Rohit Waghchaure | a5f4094 | 2017-06-16 15:21:36 +0530 | [diff] [blame] | 95 | validate_account_for_perpetual_inventory(gl_map) |
Rushabh Mehta | 708e47a | 2018-08-08 16:37:31 +0530 | [diff] [blame] | 96 | |
Nabin Hait | e2c200a | 2015-05-28 13:00:37 +0530 | [diff] [blame] | 97 | round_off_debit_credit(gl_map) |
Anand Doshi | 602e825 | 2015-11-16 19:05:46 +0530 | [diff] [blame] | 98 | |
Nabin Hait | bf495c9 | 2013-01-30 12:49:08 +0530 | [diff] [blame] | 99 | for entry in gl_map: |
Nabin Hait | 9784d27 | 2016-12-30 16:21:35 +0530 | [diff] [blame] | 100 | make_entry(entry, adv_adj, update_outstanding, from_repost) |
Rushabh Mehta | 708e47a | 2018-08-08 16:37:31 +0530 | [diff] [blame] | 101 | |
Nabin Hait | 27994c2 | 2013-08-26 16:53:30 +0530 | [diff] [blame] | 102 | # check against budget |
Nabin Hait | 9784d27 | 2016-12-30 16:21:35 +0530 | [diff] [blame] | 103 | if not from_repost: |
| 104 | validate_expense_against_budget(entry) |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 105 | |
Nabin Hait | 9784d27 | 2016-12-30 16:21:35 +0530 | [diff] [blame] | 106 | def make_entry(args, adv_adj, update_outstanding, from_repost=False): |
Nabin Hait | aeba24e | 2013-08-23 15:17:36 +0530 | [diff] [blame] | 107 | args.update({"doctype": "GL Entry"}) |
Rushabh Mehta | a504f06 | 2014-04-04 12:16:26 +0530 | [diff] [blame] | 108 | gle = frappe.get_doc(args) |
Anand Doshi | 6dfd430 | 2015-02-10 14:41:27 +0530 | [diff] [blame] | 109 | gle.flags.ignore_permissions = 1 |
Nabin Hait | 9784d27 | 2016-12-30 16:21:35 +0530 | [diff] [blame] | 110 | gle.flags.from_repost = from_repost |
Nabin Hait | aeba24e | 2013-08-23 15:17:36 +0530 | [diff] [blame] | 111 | gle.insert() |
Nabin Hait | 9784d27 | 2016-12-30 16:21:35 +0530 | [diff] [blame] | 112 | gle.run_method("on_update_with_args", adv_adj, update_outstanding, from_repost) |
Nabin Hait | aeba24e | 2013-08-23 15:17:36 +0530 | [diff] [blame] | 113 | gle.submit() |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 114 | |
Rohit Waghchaure | a5f4094 | 2017-06-16 15:21:36 +0530 | [diff] [blame] | 115 | def validate_account_for_perpetual_inventory(gl_map): |
Rohit Waghchaure | e9ff191 | 2017-06-19 12:54:59 +0530 | [diff] [blame] | 116 | if cint(erpnext.is_perpetual_inventory_enabled(gl_map[0].company)) \ |
Nabin Hait | e7f479b | 2015-06-22 07:31:49 +0530 | [diff] [blame] | 117 | and gl_map[0].voucher_type=="Journal Entry": |
| 118 | aii_accounts = [d[0] for d in frappe.db.sql("""select name from tabAccount |
Nabin Hait | 6d7b0ce | 2017-06-15 11:09:27 +0530 | [diff] [blame] | 119 | where account_type = 'Stock' and is_group=0""")] |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 120 | |
Nabin Hait | e7f479b | 2015-06-22 07:31:49 +0530 | [diff] [blame] | 121 | for entry in gl_map: |
| 122 | if entry.account in aii_accounts: |
| 123 | frappe.throw(_("Account: {0} can only be updated via Stock Transactions") |
| 124 | .format(entry.account), StockAccountInvalidTransaction) |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 125 | |
Nabin Hait | e2c200a | 2015-05-28 13:00:37 +0530 | [diff] [blame] | 126 | def round_off_debit_credit(gl_map): |
| 127 | precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"), |
Rushabh Mehta | 708e47a | 2018-08-08 16:37:31 +0530 | [diff] [blame] | 128 | currency=frappe.get_cached_value('Company', gl_map[0].company, "default_currency")) |
Anand Doshi | 602e825 | 2015-11-16 19:05:46 +0530 | [diff] [blame] | 129 | |
Nabin Hait | e2c200a | 2015-05-28 13:00:37 +0530 | [diff] [blame] | 130 | debit_credit_diff = 0.0 |
| 131 | for entry in gl_map: |
| 132 | entry.debit = flt(entry.debit, precision) |
| 133 | entry.credit = flt(entry.credit, precision) |
| 134 | debit_credit_diff += entry.debit - entry.credit |
Anand Doshi | 602e825 | 2015-11-16 19:05:46 +0530 | [diff] [blame] | 135 | |
Nabin Hait | e2c200a | 2015-05-28 13:00:37 +0530 | [diff] [blame] | 136 | debit_credit_diff = flt(debit_credit_diff, precision) |
Rushabh Mehta | 708e47a | 2018-08-08 16:37:31 +0530 | [diff] [blame] | 137 | |
Nabin Hait | d2a966e | 2017-05-05 10:41:16 +0530 | [diff] [blame] | 138 | if gl_map[0]["voucher_type"] in ("Journal Entry", "Payment Entry"): |
Nabin Hait | fb24a27 | 2016-02-18 19:18:07 +0530 | [diff] [blame] | 139 | allowance = 5.0 / (10**precision) |
| 140 | else: |
Nabin Hait | d2a966e | 2017-05-05 10:41:16 +0530 | [diff] [blame] | 141 | allowance = .5 |
Rushabh Mehta | 708e47a | 2018-08-08 16:37:31 +0530 | [diff] [blame] | 142 | |
Nabin Hait | fb24a27 | 2016-02-18 19:18:07 +0530 | [diff] [blame] | 143 | if abs(debit_credit_diff) >= allowance: |
Nabin Hait | e2c200a | 2015-05-28 13:00:37 +0530 | [diff] [blame] | 144 | frappe.throw(_("Debit and Credit not equal for {0} #{1}. Difference is {2}.") |
| 145 | .format(gl_map[0].voucher_type, gl_map[0].voucher_no, debit_credit_diff)) |
Anand Doshi | 602e825 | 2015-11-16 19:05:46 +0530 | [diff] [blame] | 146 | |
Nabin Hait | e2c200a | 2015-05-28 13:00:37 +0530 | [diff] [blame] | 147 | elif abs(debit_credit_diff) >= (1.0 / (10**precision)): |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 148 | make_round_off_gle(gl_map, debit_credit_diff, precision) |
Anand Doshi | 602e825 | 2015-11-16 19:05:46 +0530 | [diff] [blame] | 149 | |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 150 | def make_round_off_gle(gl_map, debit_credit_diff, precision): |
Nabin Hait | 2e4de83 | 2017-09-19 14:53:16 +0530 | [diff] [blame] | 151 | round_off_account, round_off_cost_center = get_round_off_account_and_cost_center(gl_map[0].company) |
Zarrar | 3523b77 | 2018-08-14 16:28:14 +0530 | [diff] [blame] | 152 | round_off_account_exists = False |
Nabin Hait | 80069a6 | 2015-05-28 19:19:59 +0530 | [diff] [blame] | 153 | round_off_gle = frappe._dict() |
Zarrar | 3523b77 | 2018-08-14 16:28:14 +0530 | [diff] [blame] | 154 | for d in gl_map: |
| 155 | if d.account == round_off_account: |
| 156 | round_off_gle = d |
| 157 | if d.debit_in_account_currency: |
| 158 | debit_credit_diff -= flt(d.debit_in_account_currency) |
| 159 | else: |
| 160 | debit_credit_diff += flt(d.credit_in_account_currency) |
| 161 | round_off_account_exists = True |
| 162 | |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 163 | if round_off_account_exists and abs(debit_credit_diff) <= (1.0 / (10**precision)): |
| 164 | gl_map.remove(round_off_gle) |
| 165 | return |
| 166 | |
Zarrar | 3523b77 | 2018-08-14 16:28:14 +0530 | [diff] [blame] | 167 | if not round_off_gle: |
| 168 | for k in ["voucher_type", "voucher_no", "company", |
| 169 | "posting_date", "remarks", "is_opening"]: |
| 170 | round_off_gle[k] = gl_map[0][k] |
Anand Doshi | 602e825 | 2015-11-16 19:05:46 +0530 | [diff] [blame] | 171 | |
Nabin Hait | e2c200a | 2015-05-28 13:00:37 +0530 | [diff] [blame] | 172 | round_off_gle.update({ |
| 173 | "account": round_off_account, |
Nabin Hait | d4507ac | 2016-01-20 16:14:27 +0530 | [diff] [blame] | 174 | "debit_in_account_currency": abs(debit_credit_diff) if debit_credit_diff < 0 else 0, |
| 175 | "credit_in_account_currency": debit_credit_diff if debit_credit_diff > 0 else 0, |
Nabin Hait | e2c200a | 2015-05-28 13:00:37 +0530 | [diff] [blame] | 176 | "debit": abs(debit_credit_diff) if debit_credit_diff < 0 else 0, |
| 177 | "credit": debit_credit_diff if debit_credit_diff > 0 else 0, |
Nabin Hait | 3c67146 | 2015-05-28 13:19:01 +0530 | [diff] [blame] | 178 | "cost_center": round_off_cost_center, |
| 179 | "party_type": None, |
| 180 | "party": None, |
| 181 | "against_voucher_type": None, |
| 182 | "against_voucher": None |
Nabin Hait | e2c200a | 2015-05-28 13:00:37 +0530 | [diff] [blame] | 183 | }) |
Anand Doshi | 602e825 | 2015-11-16 19:05:46 +0530 | [diff] [blame] | 184 | |
Zarrar | 3523b77 | 2018-08-14 16:28:14 +0530 | [diff] [blame] | 185 | if not round_off_account_exists: |
| 186 | gl_map.append(round_off_gle) |
Nabin Hait | e2c200a | 2015-05-28 13:00:37 +0530 | [diff] [blame] | 187 | |
Nabin Hait | 2e4de83 | 2017-09-19 14:53:16 +0530 | [diff] [blame] | 188 | def get_round_off_account_and_cost_center(company): |
Rushabh Mehta | 708e47a | 2018-08-08 16:37:31 +0530 | [diff] [blame] | 189 | round_off_account, round_off_cost_center = frappe.get_cached_value('Company', company, |
Nabin Hait | 2e4de83 | 2017-09-19 14:53:16 +0530 | [diff] [blame] | 190 | ["round_off_account", "round_off_cost_center"]) or [None, None] |
| 191 | if not round_off_account: |
| 192 | frappe.throw(_("Please mention Round Off Account in Company")) |
| 193 | |
| 194 | if not round_off_cost_center: |
| 195 | frappe.throw(_("Please mention Round Off Cost Center in Company")) |
| 196 | |
| 197 | return round_off_account, round_off_cost_center |
| 198 | |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 199 | def delete_gl_entries(gl_entries=None, voucher_type=None, voucher_no=None, |
Nabin Hait | 2e296fa | 2013-08-28 18:53:11 +0530 | [diff] [blame] | 200 | adv_adj=False, update_outstanding="Yes"): |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 201 | |
Nabin Hait | 53822ae | 2014-03-03 19:18:17 +0530 | [diff] [blame] | 202 | from erpnext.accounts.doctype.gl_entry.gl_entry import validate_balance_type, \ |
Nabin Hait | 11f4195 | 2013-09-24 14:36:55 +0530 | [diff] [blame] | 203 | check_freezing_date, update_outstanding_amt, validate_frozen_account |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 204 | |
Nabin Hait | 2e296fa | 2013-08-28 18:53:11 +0530 | [diff] [blame] | 205 | if not gl_entries: |
Nabin Hait | 56548cb | 2016-07-01 15:58:39 +0530 | [diff] [blame] | 206 | gl_entries = frappe.db.sql(""" |
Rohit Waghchaure | b1391ca | 2016-10-03 12:25:04 +0530 | [diff] [blame] | 207 | select account, posting_date, party_type, party, cost_center, fiscal_year,voucher_type, |
| 208 | voucher_no, against_voucher_type, against_voucher, cost_center, company |
Nabin Hait | 56548cb | 2016-07-01 15:58:39 +0530 | [diff] [blame] | 209 | from `tabGL Entry` |
Nabin Hait | 2e296fa | 2013-08-28 18:53:11 +0530 | [diff] [blame] | 210 | where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no), as_dict=True) |
Nabin Hait | 56548cb | 2016-07-01 15:58:39 +0530 | [diff] [blame] | 211 | |
Nabin Hait | 27994c2 | 2013-08-26 16:53:30 +0530 | [diff] [blame] | 212 | if gl_entries: |
| 213 | check_freezing_date(gl_entries[0]["posting_date"], adv_adj) |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 214 | |
| 215 | frappe.db.sql("""delete from `tabGL Entry` where voucher_type=%s and voucher_no=%s""", |
Nabin Hait | 2e296fa | 2013-08-28 18:53:11 +0530 | [diff] [blame] | 216 | (voucher_type or gl_entries[0]["voucher_type"], voucher_no or gl_entries[0]["voucher_no"])) |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 217 | |
Nabin Hait | 9b09c95 | 2013-08-21 17:47:11 +0530 | [diff] [blame] | 218 | for entry in gl_entries: |
Nabin Hait | 11f4195 | 2013-09-24 14:36:55 +0530 | [diff] [blame] | 219 | validate_frozen_account(entry["account"], adv_adj) |
Nabin Hait | 53822ae | 2014-03-03 19:18:17 +0530 | [diff] [blame] | 220 | validate_balance_type(entry["account"], adv_adj) |
Nabin Hait | 1e1b236 | 2018-01-29 16:45:43 +0530 | [diff] [blame] | 221 | if not adv_adj: |
| 222 | validate_expense_against_budget(entry) |
Rushabh Mehta | 708e47a | 2018-08-08 16:37:31 +0530 | [diff] [blame] | 223 | |
Nabin Hait | 1e1b236 | 2018-01-29 16:45:43 +0530 | [diff] [blame] | 224 | if entry.get("against_voucher") and update_outstanding == 'Yes' and not adv_adj: |
Nabin Hait | 3225102 | 2014-08-29 11:18:32 +0530 | [diff] [blame] | 225 | update_outstanding_amt(entry["account"], entry.get("party_type"), entry.get("party"), entry.get("against_voucher_type"), |
Rushabh Mehta | c38fc71 | 2014-04-16 17:21:25 +0530 | [diff] [blame] | 226 | entry.get("against_voucher"), on_cancel=True) |