blob: cf3deb828f463cf738667f6286de338f263d3f65 [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)
nabinhaitc3432922014-07-29 18:06:18 +053023 if gl_map and len(gl_map) > 1:
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +053024 save_entries(gl_map, adv_adj, update_outstanding)
nabinhaitc3432922014-07-29 18:06:18 +053025 else:
nabinhait4859b482014-07-30 14:28:24 +053026 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 +053027 else:
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +053028 make_reverse_gl_entries(gl_map, adv_adj=adv_adj, update_outstanding=update_outstanding)
Anand Doshi652bc072014-04-16 15:21:46 +053029
Mangesh-Khairnare5c733b2019-08-08 15:44:11 +053030def validate_accounting_period(gl_map):
31 accounting_periods = frappe.db.sql(""" SELECT
32 ap.name as name
33 FROM
34 `tabAccounting Period` ap, `tabClosed Document` cd
35 WHERE
36 ap.name = cd.parent
37 AND ap.company = %(company)s
38 AND cd.closed = 1
39 AND cd.document_type = %(voucher_type)s
40 AND %(date)s between ap.start_date and ap.end_date
41 """, {
42 'date': gl_map[0].posting_date,
43 'company': gl_map[0].company,
44 'voucher_type': gl_map[0].voucher_type
45 }, as_dict=1)
46
47 if accounting_periods:
48 frappe.throw(_("You can't create accounting entries in the closed accounting period {0}")
49 .format(accounting_periods[0].name), ClosedAccountingPeriod)
50
Nabin Hait27994c22013-08-26 16:53:30 +053051def process_gl_map(gl_map, merge_entries=True):
Nabin Haitbf495c92013-01-30 12:49:08 +053052 if merge_entries:
53 gl_map = merge_similar_entries(gl_map)
Nabin Hait27994c22013-08-26 16:53:30 +053054 for entry in gl_map:
Anand Doshi602e8252015-11-16 19:05:46 +053055 # toggle debit, credit if negative entry
Nabin Hait88f3cd52013-10-23 16:29:19 +053056 if flt(entry.debit) < 0:
57 entry.credit = flt(entry.credit) - flt(entry.debit)
58 entry.debit = 0.0
Anand Doshi602e8252015-11-16 19:05:46 +053059
Nabin Haitc561a492015-08-19 19:22:34 +053060 if flt(entry.debit_in_account_currency) < 0:
61 entry.credit_in_account_currency = \
62 flt(entry.credit_in_account_currency) - flt(entry.debit_in_account_currency)
63 entry.debit_in_account_currency = 0.0
Anand Doshi602e8252015-11-16 19:05:46 +053064
Nabin Hait88f3cd52013-10-23 16:29:19 +053065 if flt(entry.credit) < 0:
66 entry.debit = flt(entry.debit) - flt(entry.credit)
67 entry.credit = 0.0
Anand Doshi602e8252015-11-16 19:05:46 +053068
Nabin Haitc561a492015-08-19 19:22:34 +053069 if flt(entry.credit_in_account_currency) < 0:
70 entry.debit_in_account_currency = \
71 flt(entry.debit_in_account_currency) - flt(entry.credit_in_account_currency)
72 entry.credit_in_account_currency = 0.0
Anand Doshi602e8252015-11-16 19:05:46 +053073
Nabin Hait27994c22013-08-26 16:53:30 +053074 return gl_map
Anand Doshi652bc072014-04-16 15:21:46 +053075
Nabin Haitbf495c92013-01-30 12:49:08 +053076def merge_similar_entries(gl_map):
77 merged_gl_map = []
deepeshgarg0073d11ac02019-05-19 00:02:01 +053078 accounting_dimensions = get_accounting_dimensions()
Nabin Haitbf495c92013-01-30 12:49:08 +053079 for entry in gl_map:
Anand Doshi652bc072014-04-16 15:21:46 +053080 # if there is already an entry in this account then just add it
Nabin Haitbf495c92013-01-30 12:49:08 +053081 # to that entry
deepeshgarg0073d11ac02019-05-19 00:02:01 +053082 same_head = check_if_in_list(entry, merged_gl_map, accounting_dimensions)
Nabin Haitbf495c92013-01-30 12:49:08 +053083 if same_head:
Nabin Hait2e296fa2013-08-28 18:53:11 +053084 same_head.debit = flt(same_head.debit) + flt(entry.debit)
Nabin Haitc561a492015-08-19 19:22:34 +053085 same_head.debit_in_account_currency = \
86 flt(same_head.debit_in_account_currency) + flt(entry.debit_in_account_currency)
Nabin Hait2e296fa2013-08-28 18:53:11 +053087 same_head.credit = flt(same_head.credit) + flt(entry.credit)
Nabin Haitc561a492015-08-19 19:22:34 +053088 same_head.credit_in_account_currency = \
89 flt(same_head.credit_in_account_currency) + flt(entry.credit_in_account_currency)
Nabin Haitbf495c92013-01-30 12:49:08 +053090 else:
91 merged_gl_map.append(entry)
Anand Doshi652bc072014-04-16 15:21:46 +053092
thefalconx33bfc43d32019-12-13 15:09:51 +053093 company = gl_map[0].company if gl_map else erpnext.get_default_company()
94 company_currency = erpnext.get_company_currency(company)
95 precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"), company_currency)
96
Nabin Hait815a49e2013-08-07 17:00:01 +053097 # filter zero debit and credit entries
thefalconx33bfc43d32019-12-13 15:09:51 +053098 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 +053099 merged_gl_map = list(merged_gl_map)
Rushabh Mehta708e47a2018-08-08 16:37:31 +0530100
Nabin Haitbf495c92013-01-30 12:49:08 +0530101 return merged_gl_map
102
deepeshgarg0073d11ac02019-05-19 00:02:01 +0530103def check_if_in_list(gle, gl_map, dimensions=None):
104 account_head_fieldnames = ['party_type', 'party', 'against_voucher', 'against_voucher_type',
105 'cost_center', 'project']
106
107 if dimensions:
108 account_head_fieldnames = account_head_fieldnames + dimensions
109
Nabin Haitbb777562013-08-29 18:19:37 +0530110 for e in gl_map:
deepeshgarg0073d11ac02019-05-19 00:02:01 +0530111 same_head = True
112 if e.account != gle.account:
113 same_head = False
114
115 for fieldname in account_head_fieldnames:
116 if cstr(e.get(fieldname)) != cstr(gle.get(fieldname)):
117 same_head = False
118
119 if same_head:
120 return e
Nabin Haitbf495c92013-01-30 12:49:08 +0530121
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530122def save_entries(gl_map, adv_adj, update_outstanding):
123 validate_cwip_accounts(gl_map)
Rushabh Mehta708e47a2018-08-08 16:37:31 +0530124
Nabin Haite2c200a2015-05-28 13:00:37 +0530125 round_off_debit_credit(gl_map)
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530126
127 if gl_map:
128 check_freezing_date(gl_map[0]["posting_date"], adv_adj)
129
Nabin Haitbf495c92013-01-30 12:49:08 +0530130 for entry in gl_map:
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530131 make_entry(entry, adv_adj, update_outstanding)
Rushabh Mehta708e47a2018-08-08 16:37:31 +0530132
Nabin Hait27994c22013-08-26 16:53:30 +0530133 # check against budget
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530134 validate_expense_against_budget(entry)
Anand Doshi652bc072014-04-16 15:21:46 +0530135
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530136 validate_account_for_perpetual_inventory(gl_map)
Anurag Mishraa11e7382019-10-31 15:55:03 +0530137
138
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530139def make_entry(args, adv_adj, update_outstanding):
Nabin Haitddc3bb22020-03-17 17:04:18 +0530140 gle = frappe.new_doc("GL Entry")
141 gle.update(args)
Anand Doshi6dfd4302015-02-10 14:41:27 +0530142 gle.flags.ignore_permissions = 1
Deepesh Garg8230e412020-06-29 21:20:05 +0530143 gle.insert()
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530144 gle.run_method("on_update_with_args", adv_adj, update_outstanding)
Nabin Haitaeba24e2013-08-23 15:17:36 +0530145 gle.submit()
Anand Doshi652bc072014-04-16 15:21:46 +0530146
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530147 # check against budget
148 validate_expense_against_budget(args)
149
Rohit Waghchaurea5f40942017-06-16 15:21:36 +0530150def validate_account_for_perpetual_inventory(gl_map):
Anurag Mishraa11e7382019-10-31 15:55:03 +0530151 if cint(erpnext.is_perpetual_inventory_enabled(gl_map[0].company)):
152 account_list = [gl_entries.account for gl_entries in gl_map]
Anand Doshi652bc072014-04-16 15:21:46 +0530153
Anurag Mishraa11e7382019-10-31 15:55:03 +0530154 aii_accounts = [d.name for d in frappe.get_all("Account",
155 filters={'account_type': 'Stock', 'is_group': 0, 'company': gl_map[0].company})]
156
157 for account in account_list:
158 if account not in aii_accounts:
159 continue
160
Deepesh Garg9119b4c2020-07-28 08:49:44 +0530161 # Always use current date to get stock and account balance as there can future entries for
162 # other items
Anurag Mishraa11e7382019-10-31 15:55:03 +0530163 account_bal, stock_bal, warehouse_list = get_stock_and_account_balance(account,
Deepesh Garg9119b4c2020-07-28 08:49:44 +0530164 getdate(), gl_map[0].company)
Anurag Mishraa11e7382019-10-31 15:55:03 +0530165
166 if gl_map[0].voucher_type=="Journal Entry":
167 # In case of Journal Entry, there are no corresponding SL entries,
168 # hence deducting currency amount
169 account_bal -= flt(gl_map[0].debit) - flt(gl_map[0].credit)
170 if account_bal == stock_bal:
Nabin Haite7f479b2015-06-22 07:31:49 +0530171 frappe.throw(_("Account: {0} can only be updated via Stock Transactions")
Anurag Mishraa11e7382019-10-31 15:55:03 +0530172 .format(account), StockAccountInvalidTransaction)
173
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530174 elif account_bal != stock_bal:
175 precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"),
176 currency=frappe.get_cached_value('Company', gl_map[0].company, "default_currency"))
Maricac9e8a1b2019-11-14 16:13:43 +0530177
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530178 diff = flt(stock_bal - account_bal, precision)
179 error_reason = _("Stock Value ({0}) and Account Balance ({1}) are out of sync for account {2} and it's linked warehouses.").format(
180 stock_bal, account_bal, frappe.bold(account))
181 error_resolution = _("Please create adjustment Journal Entry for amount {0} ").format(frappe.bold(diff))
182 stock_adjustment_account = frappe.db.get_value("Company",gl_map[0].company,"stock_adjustment_account")
Nabin Hait35e8d1e2019-11-25 14:02:51 +0530183
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530184 db_or_cr_warehouse_account =('credit_in_account_currency' if diff < 0 else 'debit_in_account_currency')
185 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 +0530186
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530187 journal_entry_args = {
188 'accounts':[
189 {'account': account, db_or_cr_warehouse_account : abs(diff)},
190 {'account': stock_adjustment_account, db_or_cr_stock_adjustment_account : abs(diff) }]
191 }
Nabin Hait35e8d1e2019-11-25 14:02:51 +0530192
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530193 frappe.msgprint(msg="""{0}<br></br>{1}<br></br>""".format(error_reason, error_resolution),
194 raise_exception=StockValueAndAccountBalanceOutOfSync,
195 title=_('Values Out Of Sync'),
196 primary_action={
197 'label': _('Make Journal Entry'),
198 'client_action': 'erpnext.route_to_adjustment_jv',
199 'args': journal_entry_args
200 })
Anand Doshi652bc072014-04-16 15:21:46 +0530201
Anurag Mishra7e1987e2019-08-05 10:18:57 +0530202def validate_cwip_accounts(gl_map):
Saqibf37a46e2019-11-22 16:32:50 +0530203 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 +0530204
205 if cwip_enabled and gl_map[0].voucher_type == "Journal Entry":
Anurag Mishra7e1987e2019-08-05 10:18:57 +0530206 cwip_accounts = [d[0] for d in frappe.db.sql("""select name from tabAccount
207 where account_type = 'Capital Work in Progress' and is_group=0""")]
208
209 for entry in gl_map:
210 if entry.account in cwip_accounts:
Maricad00c5982019-11-12 19:17:43 +0530211 frappe.throw(
212 _("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 +0530213
Nabin Haite2c200a2015-05-28 13:00:37 +0530214def round_off_debit_credit(gl_map):
215 precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"),
Rushabh Mehta708e47a2018-08-08 16:37:31 +0530216 currency=frappe.get_cached_value('Company', gl_map[0].company, "default_currency"))
Anand Doshi602e8252015-11-16 19:05:46 +0530217
Nabin Haite2c200a2015-05-28 13:00:37 +0530218 debit_credit_diff = 0.0
219 for entry in gl_map:
220 entry.debit = flt(entry.debit, precision)
221 entry.credit = flt(entry.credit, precision)
222 debit_credit_diff += entry.debit - entry.credit
Anand Doshi602e8252015-11-16 19:05:46 +0530223
Nabin Haite2c200a2015-05-28 13:00:37 +0530224 debit_credit_diff = flt(debit_credit_diff, precision)
Rushabh Mehta708e47a2018-08-08 16:37:31 +0530225
Nabin Haitd2a966e2017-05-05 10:41:16 +0530226 if gl_map[0]["voucher_type"] in ("Journal Entry", "Payment Entry"):
Nabin Haitfb24a272016-02-18 19:18:07 +0530227 allowance = 5.0 / (10**precision)
228 else:
Nabin Haitd2a966e2017-05-05 10:41:16 +0530229 allowance = .5
Rushabh Mehta708e47a2018-08-08 16:37:31 +0530230
Nabin Haitfb24a272016-02-18 19:18:07 +0530231 if abs(debit_credit_diff) >= allowance:
Nabin Haite2c200a2015-05-28 13:00:37 +0530232 frappe.throw(_("Debit and Credit not equal for {0} #{1}. Difference is {2}.")
233 .format(gl_map[0].voucher_type, gl_map[0].voucher_no, debit_credit_diff))
Anand Doshi602e8252015-11-16 19:05:46 +0530234
Nabin Haite2c200a2015-05-28 13:00:37 +0530235 elif abs(debit_credit_diff) >= (1.0 / (10**precision)):
Nabin Hait34c551d2019-07-03 10:34:31 +0530236 make_round_off_gle(gl_map, debit_credit_diff, precision)
Anand Doshi602e8252015-11-16 19:05:46 +0530237
Nabin Hait34c551d2019-07-03 10:34:31 +0530238def make_round_off_gle(gl_map, debit_credit_diff, precision):
Nabin Hait2e4de832017-09-19 14:53:16 +0530239 round_off_account, round_off_cost_center = get_round_off_account_and_cost_center(gl_map[0].company)
Zarrar3523b772018-08-14 16:28:14 +0530240 round_off_account_exists = False
Nabin Hait80069a62015-05-28 19:19:59 +0530241 round_off_gle = frappe._dict()
Zarrar3523b772018-08-14 16:28:14 +0530242 for d in gl_map:
243 if d.account == round_off_account:
244 round_off_gle = d
245 if d.debit_in_account_currency:
246 debit_credit_diff -= flt(d.debit_in_account_currency)
247 else:
248 debit_credit_diff += flt(d.credit_in_account_currency)
249 round_off_account_exists = True
250
Nabin Hait34c551d2019-07-03 10:34:31 +0530251 if round_off_account_exists and abs(debit_credit_diff) <= (1.0 / (10**precision)):
252 gl_map.remove(round_off_gle)
253 return
254
Zarrar3523b772018-08-14 16:28:14 +0530255 if not round_off_gle:
256 for k in ["voucher_type", "voucher_no", "company",
257 "posting_date", "remarks", "is_opening"]:
258 round_off_gle[k] = gl_map[0][k]
Anand Doshi602e8252015-11-16 19:05:46 +0530259
Nabin Haite2c200a2015-05-28 13:00:37 +0530260 round_off_gle.update({
261 "account": round_off_account,
Nabin Haitd4507ac2016-01-20 16:14:27 +0530262 "debit_in_account_currency": abs(debit_credit_diff) if debit_credit_diff < 0 else 0,
263 "credit_in_account_currency": debit_credit_diff if debit_credit_diff > 0 else 0,
Nabin Haite2c200a2015-05-28 13:00:37 +0530264 "debit": abs(debit_credit_diff) if debit_credit_diff < 0 else 0,
265 "credit": debit_credit_diff if debit_credit_diff > 0 else 0,
Nabin Hait3c671462015-05-28 13:19:01 +0530266 "cost_center": round_off_cost_center,
267 "party_type": None,
268 "party": None,
269 "against_voucher_type": None,
270 "against_voucher": None
Nabin Haite2c200a2015-05-28 13:00:37 +0530271 })
Anand Doshi602e8252015-11-16 19:05:46 +0530272
Zarrar3523b772018-08-14 16:28:14 +0530273 if not round_off_account_exists:
274 gl_map.append(round_off_gle)
Nabin Haite2c200a2015-05-28 13:00:37 +0530275
Nabin Hait2e4de832017-09-19 14:53:16 +0530276def get_round_off_account_and_cost_center(company):
Rushabh Mehta708e47a2018-08-08 16:37:31 +0530277 round_off_account, round_off_cost_center = frappe.get_cached_value('Company', company,
Nabin Hait2e4de832017-09-19 14:53:16 +0530278 ["round_off_account", "round_off_cost_center"]) or [None, None]
279 if not round_off_account:
280 frappe.throw(_("Please mention Round Off Account in Company"))
281
282 if not round_off_cost_center:
283 frappe.throw(_("Please mention Round Off Cost Center in Company"))
284
285 return round_off_account, round_off_cost_center
286
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530287def make_reverse_gl_entries(gl_entries=None, voucher_type=None, voucher_no=None,
288 adv_adj=False, update_outstanding="Yes"):
289 """
290 Get original gl entries of the voucher
291 and make reverse gl entries by swapping debit and credit
292 """
Anand Doshi652bc072014-04-16 15:21:46 +0530293
Nabin Hait2e296fa2013-08-28 18:53:11 +0530294 if not gl_entries:
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530295 gl_entries = frappe.get_all("GL Entry",
296 fields = ["*"],
297 filters = {
298 "voucher_type": voucher_type,
Deepesh Gargb821f222020-05-06 18:12:23 +0530299 "voucher_no": voucher_no,
300 "is_cancelled": 0
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530301 })
Nabin Hait56548cb2016-07-01 15:58:39 +0530302
Nabin Hait27994c22013-08-26 16:53:30 +0530303 if gl_entries:
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530304 set_as_cancel(gl_entries[0]['voucher_type'], gl_entries[0]['voucher_no'])
Nabin Hait27994c22013-08-26 16:53:30 +0530305 check_freezing_date(gl_entries[0]["posting_date"], adv_adj)
Anand Doshi652bc072014-04-16 15:21:46 +0530306
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530307 for entry in gl_entries:
308 entry['name'] = None
309 debit = entry.get('debit', 0)
310 credit = entry.get('credit', 0)
Anand Doshi652bc072014-04-16 15:21:46 +0530311
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530312 debit_in_account_currency = entry.get('debit_in_account_currency', 0)
313 credit_in_account_currency = entry.get('credit_in_account_currency', 0)
Rushabh Mehta708e47a2018-08-08 16:37:31 +0530314
Deepesh Garg2a9c5ba2020-04-30 10:38:58 +0530315 entry['debit'] = credit
316 entry['credit'] = debit
317 entry['debit_in_account_currency'] = credit_in_account_currency
318 entry['credit_in_account_currency'] = debit_in_account_currency
319
320 entry['remarks'] = "On cancellation of " + entry['voucher_no']
321 entry['is_cancelled'] = 1
322 entry['posting_date'] = today()
323
324 if entry['debit'] or entry['credit']:
325 make_entry(entry, adv_adj, "Yes")
326
327
328def check_freezing_date(posting_date, adv_adj=False):
329 """
330 Nobody can do GL Entries where posting date is before freezing date
331 except authorized person
332 """
333 if not adv_adj:
334 acc_frozen_upto = frappe.db.get_value('Accounts Settings', None, 'acc_frozen_upto')
335 if acc_frozen_upto:
336 frozen_accounts_modifier = frappe.db.get_value( 'Accounts Settings', None,'frozen_accounts_modifier')
337 if getdate(posting_date) <= getdate(acc_frozen_upto) \
338 and not frozen_accounts_modifier in frappe.get_roles():
339 frappe.throw(_("You are not authorized to add or update entries before {0}").format(formatdate(acc_frozen_upto)))
340
341def set_as_cancel(voucher_type, voucher_no):
342 """
343 Set is_cancelled=1 in all original gl entries for the voucher
344 """
345 frappe.db.sql("""update `tabGL Entry` set is_cancelled = 1,
346 modified=%s, modified_by=%s
347 where voucher_type=%s and voucher_no=%s and is_cancelled = 0""",
348 (now(), frappe.session.user, voucher_type, voucher_no))