blob: a1f8c037b30555cf0b40aca65adbb0506937334f [file] [log] [blame]
Anand Doshi885e0742015-03-03 14:55:30 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05302# License: GNU General Public License v3. See license.txt
Nabin Haitbf495c92013-01-30 12:49:08 +05303
4from __future__ import unicode_literals
Rohit Waghchauree9ff1912017-06-19 12:54:59 +05305import frappe, erpnext
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +05306from frappe.utils import flt, cstr, cint, comma_and, today, getdate, formatdate, now
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05307from frappe import _
Anurag Mishraa11e7382019-10-31 15:55:03 +05308from erpnext.accounts.utils import get_stock_and_account_balance
Nabin Haite2c200a2015-05-28 13:00:37 +05309from frappe.model.meta import get_field_precision
Nabin Haitb9bc7d62016-05-16 14:38:47 +053010from erpnext.accounts.doctype.budget.budget import validate_expense_against_budget
deepeshgarg0073d11ac02019-05-19 00:02:01 +053011from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions
Nabin Haitbf495c92013-01-30 12:49:08 +053012
Nabin Haitbb777562013-08-29 18:19:37 +053013
Mangesh-Khairnare5c733b2019-08-08 15:44:11 +053014class ClosedAccountingPeriod(frappe.ValidationError): pass
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053015class StockAccountInvalidTransaction(frappe.ValidationError): pass
Anurag Mishraa11e7382019-10-31 15:55:03 +053016class StockValueAndAccountBalanceOutOfSync(frappe.ValidationError): pass
Nabin Haitbf495c92013-01-30 12:49:08 +053017
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +053018def make_gl_entries(gl_map, cancel=False, adv_adj=False, merge_entries=True, update_outstanding='Yes'):
Nabin Hait2e296fa2013-08-28 18:53:11 +053019 if gl_map:
20 if not cancel:
Mangesh-Khairnare5c733b2019-08-08 15:44:11 +053021 validate_accounting_period(gl_map)
Nabin Hait2e296fa2013-08-28 18:53:11 +053022 gl_map = process_gl_map(gl_map, merge_entries)
Deepesh Garg3c004ad2020-07-02 21:18:29 +053023 print(gl_map, "$$$$$$$$$")
nabinhaitc3432922014-07-29 18:06:18 +053024 if gl_map and len(gl_map) > 1:
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +053025 save_entries(gl_map, adv_adj, update_outstanding)
nabinhaitc3432922014-07-29 18:06:18 +053026 else:
nabinhait4859b482014-07-30 14:28:24 +053027 frappe.throw(_("Incorrect number of General Ledger Entries found. You might have selected a wrong Account in the transaction."))
Nabin Hait2e296fa2013-08-28 18:53:11 +053028 else:
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +053029 make_reverse_gl_entries(gl_map, adv_adj=adv_adj, update_outstanding=update_outstanding)
Anand Doshi652bc072014-04-16 15:21:46 +053030
Mangesh-Khairnare5c733b2019-08-08 15:44:11 +053031def validate_accounting_period(gl_map):
32 accounting_periods = frappe.db.sql(""" SELECT
33 ap.name as name
34 FROM
35 `tabAccounting Period` ap, `tabClosed Document` cd
36 WHERE
37 ap.name = cd.parent
38 AND ap.company = %(company)s
39 AND cd.closed = 1
40 AND cd.document_type = %(voucher_type)s
41 AND %(date)s between ap.start_date and ap.end_date
42 """, {
43 'date': gl_map[0].posting_date,
44 'company': gl_map[0].company,
45 'voucher_type': gl_map[0].voucher_type
46 }, as_dict=1)
47
48 if accounting_periods:
49 frappe.throw(_("You can't create accounting entries in the closed accounting period {0}")
50 .format(accounting_periods[0].name), ClosedAccountingPeriod)
51
Nabin Hait27994c22013-08-26 16:53:30 +053052def process_gl_map(gl_map, merge_entries=True):
Nabin Haitbf495c92013-01-30 12:49:08 +053053 if merge_entries:
54 gl_map = merge_similar_entries(gl_map)
Nabin Hait27994c22013-08-26 16:53:30 +053055 for entry in gl_map:
Anand Doshi602e8252015-11-16 19:05:46 +053056 # toggle debit, credit if negative entry
Nabin Hait88f3cd52013-10-23 16:29:19 +053057 if flt(entry.debit) < 0:
58 entry.credit = flt(entry.credit) - flt(entry.debit)
59 entry.debit = 0.0
Anand Doshi602e8252015-11-16 19:05:46 +053060
Nabin Haitc561a492015-08-19 19:22:34 +053061 if flt(entry.debit_in_account_currency) < 0:
62 entry.credit_in_account_currency = \
63 flt(entry.credit_in_account_currency) - flt(entry.debit_in_account_currency)
64 entry.debit_in_account_currency = 0.0
Anand Doshi602e8252015-11-16 19:05:46 +053065
Nabin Hait88f3cd52013-10-23 16:29:19 +053066 if flt(entry.credit) < 0:
67 entry.debit = flt(entry.debit) - flt(entry.credit)
68 entry.credit = 0.0
Anand Doshi602e8252015-11-16 19:05:46 +053069
Nabin Haitc561a492015-08-19 19:22:34 +053070 if flt(entry.credit_in_account_currency) < 0:
71 entry.debit_in_account_currency = \
72 flt(entry.debit_in_account_currency) - flt(entry.credit_in_account_currency)
73 entry.credit_in_account_currency = 0.0
Anand Doshi602e8252015-11-16 19:05:46 +053074
Nabin Hait27994c22013-08-26 16:53:30 +053075 return gl_map
Anand Doshi652bc072014-04-16 15:21:46 +053076
Nabin Haitbf495c92013-01-30 12:49:08 +053077def merge_similar_entries(gl_map):
78 merged_gl_map = []
deepeshgarg0073d11ac02019-05-19 00:02:01 +053079 accounting_dimensions = get_accounting_dimensions()
Nabin Haitbf495c92013-01-30 12:49:08 +053080 for entry in gl_map:
Anand Doshi652bc072014-04-16 15:21:46 +053081 # if there is already an entry in this account then just add it
Nabin Haitbf495c92013-01-30 12:49:08 +053082 # to that entry
deepeshgarg0073d11ac02019-05-19 00:02:01 +053083 same_head = check_if_in_list(entry, merged_gl_map, accounting_dimensions)
Nabin Haitbf495c92013-01-30 12:49:08 +053084 if same_head:
Nabin Hait2e296fa2013-08-28 18:53:11 +053085 same_head.debit = flt(same_head.debit) + flt(entry.debit)
Nabin Haitc561a492015-08-19 19:22:34 +053086 same_head.debit_in_account_currency = \
87 flt(same_head.debit_in_account_currency) + flt(entry.debit_in_account_currency)
Nabin Hait2e296fa2013-08-28 18:53:11 +053088 same_head.credit = flt(same_head.credit) + flt(entry.credit)
Nabin Haitc561a492015-08-19 19:22:34 +053089 same_head.credit_in_account_currency = \
90 flt(same_head.credit_in_account_currency) + flt(entry.credit_in_account_currency)
Nabin Haitbf495c92013-01-30 12:49:08 +053091 else:
92 merged_gl_map.append(entry)
Anand Doshi652bc072014-04-16 15:21:46 +053093
thefalconx33bfc43d32019-12-13 15:09:51 +053094 company = gl_map[0].company if gl_map else erpnext.get_default_company()
95 company_currency = erpnext.get_company_currency(company)
96 precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"), company_currency)
97
Nabin Hait815a49e2013-08-07 17:00:01 +053098 # filter zero debit and credit entries
thefalconx33bfc43d32019-12-13 15:09:51 +053099 merged_gl_map = filter(lambda x: flt(x.debit, precision)!=0 or flt(x.credit, precision)!=0, merged_gl_map)
Achilles Rasquinha908289d2018-03-08 13:10:51 +0530100 merged_gl_map = list(merged_gl_map)
Rushabh Mehta708e47a2018-08-08 16:37:31 +0530101
Nabin Haitbf495c92013-01-30 12:49:08 +0530102 return merged_gl_map
103
deepeshgarg0073d11ac02019-05-19 00:02:01 +0530104def check_if_in_list(gle, gl_map, dimensions=None):
105 account_head_fieldnames = ['party_type', 'party', 'against_voucher', 'against_voucher_type',
106 'cost_center', 'project']
107
108 if dimensions:
109 account_head_fieldnames = account_head_fieldnames + dimensions
110
Nabin Haitbb777562013-08-29 18:19:37 +0530111 for e in gl_map:
deepeshgarg0073d11ac02019-05-19 00:02:01 +0530112 same_head = True
113 if e.account != gle.account:
114 same_head = False
115
116 for fieldname in account_head_fieldnames:
117 if cstr(e.get(fieldname)) != cstr(gle.get(fieldname)):
118 same_head = False
119
120 if same_head:
121 return e
Nabin Haitbf495c92013-01-30 12:49:08 +0530122
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530123def save_entries(gl_map, adv_adj, update_outstanding):
124 validate_cwip_accounts(gl_map)
Rushabh Mehta708e47a2018-08-08 16:37:31 +0530125
Nabin Haite2c200a2015-05-28 13:00:37 +0530126 round_off_debit_credit(gl_map)
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530127
128 if gl_map:
129 check_freezing_date(gl_map[0]["posting_date"], adv_adj)
130
Nabin Haitbf495c92013-01-30 12:49:08 +0530131 for entry in gl_map:
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530132 make_entry(entry, adv_adj, update_outstanding)
Rushabh Mehta708e47a2018-08-08 16:37:31 +0530133
Nabin Hait27994c22013-08-26 16:53:30 +0530134 # check against budget
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530135 validate_expense_against_budget(entry)
Anand Doshi652bc072014-04-16 15:21:46 +0530136
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530137 validate_account_for_perpetual_inventory(gl_map)
Anurag Mishraa11e7382019-10-31 15:55:03 +0530138
139
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530140def make_entry(args, adv_adj, update_outstanding):
Nabin Haitddc3bb22020-03-17 17:04:18 +0530141 gle = frappe.new_doc("GL Entry")
142 gle.update(args)
Anand Doshi6dfd4302015-02-10 14:41:27 +0530143 gle.flags.ignore_permissions = 1
Saqibfb35a542020-02-27 18:32:19 +0530144 gle.validate()
Saqibfb35a542020-02-27 18:32:19 +0530145 gle.db_insert()
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530146 gle.run_method("on_update_with_args", adv_adj, update_outstanding)
Saqibfb35a542020-02-27 18:32:19 +0530147 gle.flags.ignore_validate = True
Nabin Haitaeba24e2013-08-23 15:17:36 +0530148 gle.submit()
Anand Doshi652bc072014-04-16 15:21:46 +0530149
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530150 # check against budget
151 validate_expense_against_budget(args)
152
Rohit Waghchaurea5f40942017-06-16 15:21:36 +0530153def validate_account_for_perpetual_inventory(gl_map):
Anurag Mishraa11e7382019-10-31 15:55:03 +0530154 if cint(erpnext.is_perpetual_inventory_enabled(gl_map[0].company)):
155 account_list = [gl_entries.account for gl_entries in gl_map]
Anand Doshi652bc072014-04-16 15:21:46 +0530156
Anurag Mishraa11e7382019-10-31 15:55:03 +0530157 aii_accounts = [d.name for d in frappe.get_all("Account",
158 filters={'account_type': 'Stock', 'is_group': 0, 'company': gl_map[0].company})]
159
160 for account in account_list:
161 if account not in aii_accounts:
162 continue
163
164 account_bal, stock_bal, warehouse_list = get_stock_and_account_balance(account,
165 gl_map[0].posting_date, gl_map[0].company)
166
167 if gl_map[0].voucher_type=="Journal Entry":
168 # In case of Journal Entry, there are no corresponding SL entries,
169 # hence deducting currency amount
170 account_bal -= flt(gl_map[0].debit) - flt(gl_map[0].credit)
171 if account_bal == stock_bal:
Nabin Haite7f479b2015-06-22 07:31:49 +0530172 frappe.throw(_("Account: {0} can only be updated via Stock Transactions")
Anurag Mishraa11e7382019-10-31 15:55:03 +0530173 .format(account), StockAccountInvalidTransaction)
174
rohitwaghchaure15111542019-11-28 16:43:39 +0530175 # This has been comment for a temporary, will add this code again on release of immutable ledger
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530176 elif account_bal != stock_bal:
177 precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"),
178 currency=frappe.get_cached_value('Company', gl_map[0].company, "default_currency"))
Maricac9e8a1b2019-11-14 16:13:43 +0530179
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530180 diff = flt(stock_bal - account_bal, precision)
181 error_reason = _("Stock Value ({0}) and Account Balance ({1}) are out of sync for account {2} and it's linked warehouses.").format(
182 stock_bal, account_bal, frappe.bold(account))
183 error_resolution = _("Please create adjustment Journal Entry for amount {0} ").format(frappe.bold(diff))
184 stock_adjustment_account = frappe.db.get_value("Company",gl_map[0].company,"stock_adjustment_account")
Nabin Hait35e8d1e2019-11-25 14:02:51 +0530185
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530186 db_or_cr_warehouse_account =('credit_in_account_currency' if diff < 0 else 'debit_in_account_currency')
187 db_or_cr_stock_adjustment_account = ('debit_in_account_currency' if diff < 0 else 'credit_in_account_currency')
Nabin Hait35e8d1e2019-11-25 14:02:51 +0530188
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530189 journal_entry_args = {
190 'accounts':[
191 {'account': account, db_or_cr_warehouse_account : abs(diff)},
192 {'account': stock_adjustment_account, db_or_cr_stock_adjustment_account : abs(diff) }]
193 }
Nabin Hait35e8d1e2019-11-25 14:02:51 +0530194
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530195 frappe.msgprint(msg="""{0}<br></br>{1}<br></br>""".format(error_reason, error_resolution),
196 raise_exception=StockValueAndAccountBalanceOutOfSync,
197 title=_('Values Out Of Sync'),
198 primary_action={
199 'label': _('Make Journal Entry'),
200 'client_action': 'erpnext.route_to_adjustment_jv',
201 'args': journal_entry_args
202 })
Anand Doshi652bc072014-04-16 15:21:46 +0530203
Anurag Mishra7e1987e2019-08-05 10:18:57 +0530204def validate_cwip_accounts(gl_map):
Saqibf37a46e2019-11-22 16:32:50 +0530205 cwip_enabled = any([cint(ac.enable_cwip_accounting) for ac in frappe.db.get_all("Asset Category","enable_cwip_accounting")])
Maricad00c5982019-11-12 19:17:43 +0530206
207 if cwip_enabled and gl_map[0].voucher_type == "Journal Entry":
Anurag Mishra7e1987e2019-08-05 10:18:57 +0530208 cwip_accounts = [d[0] for d in frappe.db.sql("""select name from tabAccount
209 where account_type = 'Capital Work in Progress' and is_group=0""")]
210
211 for entry in gl_map:
212 if entry.account in cwip_accounts:
Maricad00c5982019-11-12 19:17:43 +0530213 frappe.throw(
214 _("Account: <b>{0}</b> is capital Work in progress and can not be updated by Journal Entry").format(entry.account))
Anurag Mishra7e1987e2019-08-05 10:18:57 +0530215
Nabin Haite2c200a2015-05-28 13:00:37 +0530216def round_off_debit_credit(gl_map):
217 precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"),
Rushabh Mehta708e47a2018-08-08 16:37:31 +0530218 currency=frappe.get_cached_value('Company', gl_map[0].company, "default_currency"))
Anand Doshi602e8252015-11-16 19:05:46 +0530219
Nabin Haite2c200a2015-05-28 13:00:37 +0530220 debit_credit_diff = 0.0
221 for entry in gl_map:
222 entry.debit = flt(entry.debit, precision)
223 entry.credit = flt(entry.credit, precision)
224 debit_credit_diff += entry.debit - entry.credit
Anand Doshi602e8252015-11-16 19:05:46 +0530225
Nabin Haite2c200a2015-05-28 13:00:37 +0530226 debit_credit_diff = flt(debit_credit_diff, precision)
Rushabh Mehta708e47a2018-08-08 16:37:31 +0530227
Nabin Haitd2a966e2017-05-05 10:41:16 +0530228 if gl_map[0]["voucher_type"] in ("Journal Entry", "Payment Entry"):
Nabin Haitfb24a272016-02-18 19:18:07 +0530229 allowance = 5.0 / (10**precision)
230 else:
Nabin Haitd2a966e2017-05-05 10:41:16 +0530231 allowance = .5
Rushabh Mehta708e47a2018-08-08 16:37:31 +0530232
Nabin Haitfb24a272016-02-18 19:18:07 +0530233 if abs(debit_credit_diff) >= allowance:
Nabin Haite2c200a2015-05-28 13:00:37 +0530234 frappe.throw(_("Debit and Credit not equal for {0} #{1}. Difference is {2}.")
235 .format(gl_map[0].voucher_type, gl_map[0].voucher_no, debit_credit_diff))
Anand Doshi602e8252015-11-16 19:05:46 +0530236
Nabin Haite2c200a2015-05-28 13:00:37 +0530237 elif abs(debit_credit_diff) >= (1.0 / (10**precision)):
Nabin Hait34c551d2019-07-03 10:34:31 +0530238 make_round_off_gle(gl_map, debit_credit_diff, precision)
Anand Doshi602e8252015-11-16 19:05:46 +0530239
Nabin Hait34c551d2019-07-03 10:34:31 +0530240def make_round_off_gle(gl_map, debit_credit_diff, precision):
Nabin Hait2e4de832017-09-19 14:53:16 +0530241 round_off_account, round_off_cost_center = get_round_off_account_and_cost_center(gl_map[0].company)
Zarrar3523b772018-08-14 16:28:14 +0530242 round_off_account_exists = False
Nabin Hait80069a62015-05-28 19:19:59 +0530243 round_off_gle = frappe._dict()
Zarrar3523b772018-08-14 16:28:14 +0530244 for d in gl_map:
245 if d.account == round_off_account:
246 round_off_gle = d
247 if d.debit_in_account_currency:
248 debit_credit_diff -= flt(d.debit_in_account_currency)
249 else:
250 debit_credit_diff += flt(d.credit_in_account_currency)
251 round_off_account_exists = True
252
Nabin Hait34c551d2019-07-03 10:34:31 +0530253 if round_off_account_exists and abs(debit_credit_diff) <= (1.0 / (10**precision)):
254 gl_map.remove(round_off_gle)
255 return
256
Zarrar3523b772018-08-14 16:28:14 +0530257 if not round_off_gle:
258 for k in ["voucher_type", "voucher_no", "company",
259 "posting_date", "remarks", "is_opening"]:
260 round_off_gle[k] = gl_map[0][k]
Anand Doshi602e8252015-11-16 19:05:46 +0530261
Nabin Haite2c200a2015-05-28 13:00:37 +0530262 round_off_gle.update({
263 "account": round_off_account,
Nabin Haitd4507ac2016-01-20 16:14:27 +0530264 "debit_in_account_currency": abs(debit_credit_diff) if debit_credit_diff < 0 else 0,
265 "credit_in_account_currency": debit_credit_diff if debit_credit_diff > 0 else 0,
Nabin Haite2c200a2015-05-28 13:00:37 +0530266 "debit": abs(debit_credit_diff) if debit_credit_diff < 0 else 0,
267 "credit": debit_credit_diff if debit_credit_diff > 0 else 0,
Nabin Hait3c671462015-05-28 13:19:01 +0530268 "cost_center": round_off_cost_center,
269 "party_type": None,
270 "party": None,
271 "against_voucher_type": None,
272 "against_voucher": None
Nabin Haite2c200a2015-05-28 13:00:37 +0530273 })
Anand Doshi602e8252015-11-16 19:05:46 +0530274
Zarrar3523b772018-08-14 16:28:14 +0530275 if not round_off_account_exists:
276 gl_map.append(round_off_gle)
Nabin Haite2c200a2015-05-28 13:00:37 +0530277
Nabin Hait2e4de832017-09-19 14:53:16 +0530278def get_round_off_account_and_cost_center(company):
Rushabh Mehta708e47a2018-08-08 16:37:31 +0530279 round_off_account, round_off_cost_center = frappe.get_cached_value('Company', company,
Nabin Hait2e4de832017-09-19 14:53:16 +0530280 ["round_off_account", "round_off_cost_center"]) or [None, None]
281 if not round_off_account:
282 frappe.throw(_("Please mention Round Off Account in Company"))
283
284 if not round_off_cost_center:
285 frappe.throw(_("Please mention Round Off Cost Center in Company"))
286
287 return round_off_account, round_off_cost_center
288
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530289def make_reverse_gl_entries(gl_entries=None, voucher_type=None, voucher_no=None,
290 adv_adj=False, update_outstanding="Yes"):
291 """
292 Get original gl entries of the voucher
293 and make reverse gl entries by swapping debit and credit
294 """
Anand Doshi652bc072014-04-16 15:21:46 +0530295
Nabin Hait2e296fa2013-08-28 18:53:11 +0530296 if not gl_entries:
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530297 gl_entries = frappe.get_all("GL Entry",
298 fields = ["*"],
299 filters = {
300 "voucher_type": voucher_type,
Deepesh Gargb821f222020-05-06 18:12:23 +0530301 "voucher_no": voucher_no,
302 "is_cancelled": 0
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530303 })
Nabin Hait56548cb2016-07-01 15:58:39 +0530304
Nabin Hait27994c22013-08-26 16:53:30 +0530305 if gl_entries:
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530306 set_as_cancel(gl_entries[0]['voucher_type'], gl_entries[0]['voucher_no'])
Nabin Hait27994c22013-08-26 16:53:30 +0530307 check_freezing_date(gl_entries[0]["posting_date"], adv_adj)
Anand Doshi652bc072014-04-16 15:21:46 +0530308
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530309 for entry in gl_entries:
310 entry['name'] = None
311 debit = entry.get('debit', 0)
312 credit = entry.get('credit', 0)
Anand Doshi652bc072014-04-16 15:21:46 +0530313
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530314 debit_in_account_currency = entry.get('debit_in_account_currency', 0)
315 credit_in_account_currency = entry.get('credit_in_account_currency', 0)
Rushabh Mehta708e47a2018-08-08 16:37:31 +0530316
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530317 entry['debit'] = credit
318 entry['credit'] = debit
319 entry['debit_in_account_currency'] = credit_in_account_currency
320 entry['credit_in_account_currency'] = debit_in_account_currency
321
322 entry['remarks'] = "On cancellation of " + entry['voucher_no']
323 entry['is_cancelled'] = 1
324 entry['posting_date'] = today()
325
326 if entry['debit'] or entry['credit']:
327 make_entry(entry, adv_adj, "Yes")
328
329
330def check_freezing_date(posting_date, adv_adj=False):
331 """
332 Nobody can do GL Entries where posting date is before freezing date
333 except authorized person
334 """
335 if not adv_adj:
336 acc_frozen_upto = frappe.db.get_value('Accounts Settings', None, 'acc_frozen_upto')
337 if acc_frozen_upto:
338 frozen_accounts_modifier = frappe.db.get_value( 'Accounts Settings', None,'frozen_accounts_modifier')
339 if getdate(posting_date) <= getdate(acc_frozen_upto) \
340 and not frozen_accounts_modifier in frappe.get_roles():
341 frappe.throw(_("You are not authorized to add or update entries before {0}").format(formatdate(acc_frozen_upto)))
342
343def set_as_cancel(voucher_type, voucher_no):
344 """
345 Set is_cancelled=1 in all original gl entries for the voucher
346 """
347 frappe.db.sql("""update `tabGL Entry` set is_cancelled = 1,
348 modified=%s, modified_by=%s
349 where voucher_type=%s and voucher_no=%s and is_cancelled = 0""",
350 (now(), frappe.session.user, voucher_type, voucher_no))