The Cost Center in Journal Entry Account is not saving on
GL entry when account is not Income or Expense.
How will i able to change this rule
The Cost Center in Journal Entry Account is not saving on
GL entry when account is not Income or Expense.
How will i able to change this rule
Cost center is used to track profit/loss so it cannot be used for other than expense/income accounts. This is accounting standard practice.
What i want to do is to add a Cost Center Filter in the GL Entry but the Journal Entry only saves Income or Expense type accounts Cost center in the tabGL Entry
I cant seem to find the script that triggers this.
Bump this please! I would love to know how to add cost centers (or some other data such as territory, department, etc to journal entries).
Unfortunately, this is not easy. The best way of accomplishing this without messing with core code is the following.
Overall, this requires development of a new custom app for your needs.
When you add a custom field in Journal Entry or Journal Entry Accounts it does not go directly to GL Entry table to be used for filtering later when modifying reports.
You have to add a custom_field in Journal Entry or Journal Entry Accounts
Add a custom_field in gl_entry via doctype
Then open journal_entry.py in erpnext/erpnext/account/doctype/journal_entry
You have to modify this code
gl_map.append(
self.get_gl_dict({
"account": d.account,
"party_type": d.party_type,
"party": d.party,
"against": d.against_account,
"debit": flt(d.debit, d.precision("debit")),
"credit": flt(d.credit, d.precision("credit")),
"account_currency": curr,
"debit_in_account_currency": debit_ac,
"credit_in_account_currency": credit_ac,
"against_voucher_type": d.reference_type,
"against_voucher": d.reference_name,
"remarks": self.remark,
"cost_center": d.cost_center,
"memo": d.memo,
"reference_no": self.reference_no,
"cheque_no": self.cheque_no
For example i added a new custom field in Journal Entry
if d.debit or d.credit:
gl_map.append(
self.get_gl_dict({
"account": d.account,
"party_type": d.party_type,
"party": d.party,
"against": d.against_account,
"debit": flt(d.debit, d.precision("debit")),
"credit": flt(d.credit, d.precision("credit")),
"account_currency": curr,
"debit_in_account_currency": debit_ac,
"credit_in_account_currency": credit_ac,
"against_voucher_type": d.reference_type,
"against_voucher": d.reference_name,
"remarks": self.remark,
"cost_center": d.cost_center,
"memo": d.memo,
"reference_no": self.reference_no,
"cheque_no": self.cheque_no,
"custom_field": self.custom_field
if you added a custom_field in Journal Entry Accounts (use d. instead of self.)
gl_map.append(
self.get_gl_dict({
"account": d.account,
"party_type": d.party_type,
"party": d.party,
"against": d.against_account,
"debit": flt(d.debit, d.precision("debit")),
"credit": flt(d.credit, d.precision("credit")),
"account_currency": curr,
"debit_in_account_currency": debit_ac,
"credit_in_account_currency": credit_ac,
"against_voucher_type": d.reference_type,
"against_voucher": d.reference_name,
"remarks": self.remark,
"cost_center": d.cost_center,
"memo": d.memo,
"reference_no": self.reference_no,
"cheque_no": self.cheque_no,
"custom_field": d.custom_field,
now you can modify the General Ledger Reports in erpnext/erpnext/accounts/reports/general_ledger
Open the general_ledger.js to add filters for example
{
"fieldname":"custom_field",
"label": __("Custom Field"),
"fieldtype": "Data",
},
Now Open general_ledger.py find def get_conditions(filters): add this code in here , after this step you can now filter using custom_field
if filters.get(“custom_field”):
conditions.append(“custom_field=%(custom_field)s”)
def get_columns(filters):
columns = [
_(“Posting Date”) + “90”,
_(“Account”) + “:Link/Account:200”,
_(“Debit”) + “:Float:100”,
_(“Credit”) + “:Float:100”,
_(“Original Debit”)+ “:Float:100”,
_(“Original Credit”)+ “:Float:100”,
_(“Original Currency”)+ “::130”
]
if filters.get("show_in_account_currency"):
columns += [
_("Debit") + " (" + filters.account_currency + ")" + ":Float:100",
_("Credit") + " (" + filters.account_currency + ")" + ":Float:100"
]
columns += [
_("Voucher Type") + "::120",
_("Voucher No") + ":Dynamic Link/Voucher Type:160",
_("Against Account") + "::120",
_("Party Type") + "::80",
_("Party") + "::150",
_("Cost Center") + ":Link/Cost Center:100",
_("Cheque No") + "::80",
_("Reference No") + "::100",
_("Memo") + "::150",
_("Remarks") + "::400"
]
return columns
1 1. Add custom field after Remarks
columns += [
_("Voucher Type") + "::120",
_("Voucher No") + ":Dynamic Link/Voucher Type:160",
_("Against Account") + "::120",
_("Party Type") + "::80",
_("Party") + "::150",
_("Cost Center") + ":Link/Cost Center:100",
_("Cheque No") + "::80",
_("Reference No") + "::100",
_("Memo") + "::150",
_("Remarks") + "::400",
_("Custom Field") + "::150"
]
12 in this code
def get_result_as_list(data, filters):
result = []
for d in data:
row = [d.get(“posting_date”), d.get(“account”), d.get(“debit”), d.get(“credit”), d.get(“debit_currency”), d.get(“credit_currency”), d.get(“account_currency”)]
if filters.get("show_in_account_currency"):
row += [d.get("debit_in_account_currency"), d.get("credit_in_account_currency")]
row += [d.get("voucher_type"), d.get("voucher_no"), d.get("against"),
d.get("party_type"), d.get("party"), d.get("cost_center"), d.get("cheque_no"), d.get("reference_no"), d.get("Memo"), d.get("remarks")
]
result.append(row)
return result
13 Add custom field after d.get remarks
row += [d.get("voucher_type"), d.get("voucher_no"), d.get("against"),
d.get("party_type"), d.get("party"), d.get("cost_center"), d.get("cheque_no"), d.get("reference_no"), d.get("Memo"), d.get("remarks"), d.get("custom_field")
]
14 add custom_field in the query . find def get_gl_entries(filters):
gl_entries = frappe.db.sql(“”"
select
posting_date, account, party_type, party,
sum(debit) as debit, sum(credit) as credit,
voucher_type, voucher_no, cost_center, project,
against_voucher_type, against_voucher,
remarks, against, is_opening {select_fields}
fromtabGL Entry
where company=%(company)s {conditions}
{group_by_condition}
order by posting_date, account"“”
.format(select_fields=select_fields, conditions=get_conditions(filters),
group_by_condition=group_by_condition), filters, as_dict=1)
15 Add custom_field in this code
gl_entries = frappe.db.sql(“”"
select posting_date, account, party_type, party, sum(debit) as debit, sum(credit) as credit, voucher_type, voucher_no, cost_center, project, against_voucher_type, against_voucher, remarks, against, **custom_field,** is_opening {select_fields} from `tabGL Entry` where company=%(company)s {conditions} {group_by_condition} order by posting_date, account"""\ .format(select_fields=select_fields, conditions=get_conditions(filters), group_by_condition=group_by_condition), filters, as_dict=1)
il edit this later im in a hurry