From 591a5aba56057d6e918153069f5f7e0379c62e4a Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 26 May 2016 17:41:39 +0530 Subject: [PATCH] Added Project in GL Entry and General Ledger report --- .../accounts/doctype/gl_entry/gl_entry.json | 75 ++++++++++++++++++- erpnext/accounts/doctype/gl_entry/gl_entry.py | 10 ++- .../doctype/journal_entry/journal_entry.py | 3 +- .../journal_entry_account.json | 33 +++++++- .../purchase_invoice/purchase_invoice.py | 9 ++- erpnext/accounts/general_ledger.py | 3 +- .../report/general_ledger/general_ledger.py | 12 ++- erpnext/controllers/accounts_controller.py | 3 +- erpnext/controllers/stock_controller.py | 1 + erpnext/patches.txt | 3 +- .../v7_0/update_project_in_gl_entry.py | 18 +++++ .../purchase_receipt/purchase_receipt.py | 6 +- 12 files changed, 156 insertions(+), 20 deletions(-) create mode 100644 erpnext/patches/v7_0/update_project_in_gl_entry.py diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.json b/erpnext/accounts/doctype/gl_entry/gl_entry.json index b7b698c967..71008a6c2e 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.json +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.json @@ -3,6 +3,7 @@ "allow_import": 0, "allow_rename": 0, "autoname": "GL.#######", + "beta": 0, "creation": "2013-01-10 16:34:06", "custom": 0, "docstatus": 0, @@ -16,6 +17,7 @@ "fieldtype": "Date", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 1, "in_list_view": 1, "label": "Posting Date", @@ -25,6 +27,7 @@ "oldfieldtype": "Date", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -40,6 +43,7 @@ "fieldtype": "Date", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 1, "label": "Transaction Date", @@ -49,6 +53,7 @@ "oldfieldtype": "Date", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -64,6 +69,7 @@ "fieldtype": "Link", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 1, "in_list_view": 1, "label": "Account", @@ -74,6 +80,7 @@ "options": "Account", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -89,6 +96,7 @@ "fieldtype": "Link", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, "label": "Party Type", @@ -97,6 +105,7 @@ "options": "DocType", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -112,6 +121,7 @@ "fieldtype": "Dynamic Link", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, "label": "Party", @@ -120,6 +130,7 @@ "options": "party_type", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -135,6 +146,7 @@ "fieldtype": "Link", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 1, "in_list_view": 1, "label": "Cost Center", @@ -145,6 +157,7 @@ "options": "Cost Center", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -160,6 +173,7 @@ "fieldtype": "Currency", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, "label": "Debit Amount", @@ -171,6 +185,7 @@ "permlevel": 0, "precision": "", "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -186,6 +201,7 @@ "fieldtype": "Currency", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, "label": "Credit Amount", @@ -197,6 +213,7 @@ "permlevel": 0, "precision": "", "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -212,6 +229,7 @@ "fieldtype": "Link", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, "label": "Account Currency", @@ -221,6 +239,7 @@ "permlevel": 0, "precision": "", "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -236,6 +255,7 @@ "fieldtype": "Currency", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, "label": "Debit Amount in Account Currency", @@ -245,6 +265,7 @@ "permlevel": 0, "precision": "", "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -260,6 +281,7 @@ "fieldtype": "Currency", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, "label": "Credit Amount in Account Currency", @@ -269,6 +291,7 @@ "permlevel": 0, "precision": "", "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -284,6 +307,7 @@ "fieldtype": "Text", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 1, "in_list_view": 0, "label": "Against", @@ -293,6 +317,7 @@ "oldfieldtype": "Text", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -308,6 +333,7 @@ "fieldtype": "Link", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, "label": "Against Voucher Type", @@ -318,6 +344,7 @@ "options": "DocType", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -333,6 +360,7 @@ "fieldtype": "Dynamic Link", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 1, "in_list_view": 0, "label": "Against Voucher", @@ -343,6 +371,7 @@ "options": "against_voucher_type", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -358,6 +387,7 @@ "fieldtype": "Link", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 1, "in_list_view": 0, "label": "Voucher Type", @@ -368,6 +398,7 @@ "options": "DocType", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -383,6 +414,7 @@ "fieldtype": "Dynamic Link", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 1, "in_list_view": 0, "label": "Voucher No", @@ -393,6 +425,7 @@ "options": "voucher_type", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -400,6 +433,32 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "project", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Project", + "length": 0, + "no_copy": 0, + "options": "Project", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_on_submit": 0, "bold": 0, @@ -408,6 +467,7 @@ "fieldtype": "Text", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 1, "in_list_view": 0, "label": "Remarks", @@ -417,6 +477,7 @@ "oldfieldtype": "Text", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -432,6 +493,7 @@ "fieldtype": "Select", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 1, "in_list_view": 0, "label": "Is Opening", @@ -442,6 +504,7 @@ "options": "No\nYes", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -457,6 +520,7 @@ "fieldtype": "Select", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, "label": "Is Advance", @@ -467,6 +531,7 @@ "options": "No\nYes", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -482,6 +547,7 @@ "fieldtype": "Link", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 1, "in_list_view": 0, "label": "Fiscal Year", @@ -492,6 +558,7 @@ "options": "Fiscal Year", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -507,6 +574,7 @@ "fieldtype": "Link", "hidden": 0, "ignore_user_permissions": 0, + "ignore_xss_filter": 0, "in_filter": 1, "in_list_view": 0, "label": "Company", @@ -517,6 +585,7 @@ "options": "Company", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -535,7 +604,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2015-11-16 06:29:47.382225", + "modified": "2016-05-26 16:22:03.094536", "modified_by": "Administrator", "module": "Accounts", "name": "GL Entry", @@ -602,9 +671,11 @@ "write": 0 } ], + "quick_entry": 1, "read_only": 0, "read_only_onload": 0, "search_fields": "voucher_no,account,posting_date,against_voucher", "sort_field": "modified", - "sort_order": "DESC" + "sort_order": "DESC", + "track_seen": 0 } \ No newline at end of file diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py index dd8d51e024..1f95fb8daf 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.py +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py @@ -54,9 +54,13 @@ class GLEntry(Document): def pl_must_have_cost_center(self): if frappe.db.get_value("Account", self.account, "report_type") == "Profit and Loss": if not self.cost_center and self.voucher_type != 'Period Closing Voucher': - frappe.throw(_("Cost Center is required for 'Profit and Loss' account {0}").format(self.account)) - elif self.cost_center: - self.cost_center = None + frappe.throw(_("Cost Center is required for 'Profit and Loss' account {0}") + .format(self.account)) + else: + if self.cost_center: + self.cost_center = None + if self.project: + self.project = None def check_pl_account(self): if self.is_opening=='Yes' and \ diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 5f9a915868..87942e5424 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -404,7 +404,8 @@ class JournalEntry(AccountsController): "against_voucher_type": d.reference_type, "against_voucher": d.reference_name, "remarks": self.remark, - "cost_center": d.cost_center + "cost_center": d.cost_center, + "project": d.project }) ) diff --git a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json index 28b57bdd9c..dcc32a5e6b 100644 --- a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json +++ b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json @@ -3,6 +3,7 @@ "allow_import": 0, "allow_rename": 0, "autoname": "hash", + "beta": 0, "creation": "2013-02-22 01:27:39", "custom": 0, "docstatus": 0, @@ -552,6 +553,32 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "project", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Project", + "length": 0, + "no_copy": 0, + "options": "Project", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_on_submit": 0, "bold": 0, @@ -638,13 +665,15 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2016-03-07 19:10:27.135795", + "modified": "2016-05-26 16:23:31.354886", "modified_by": "Administrator", "module": "Accounts", "name": "Journal Entry Account", "owner": "Administrator", "permissions": [], + "quick_entry": 0, "read_only": 0, "read_only_onload": 0, - "sort_order": "DESC" + "sort_order": "DESC", + "track_seen": 0 } \ No newline at end of file diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index b31c1aba6f..71e9c420c0 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -408,7 +408,8 @@ class PurchaseInvoice(BuyingController): "against": self.supplier, "debit": warehouse_debit_amount, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), - "cost_center": item.cost_center + "cost_center": item.cost_center, + "project": item.project }, account_currency) ) @@ -419,7 +420,8 @@ class PurchaseInvoice(BuyingController): "against": item.expense_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), - "credit": flt(item.landed_cost_voucher_amount) + "credit": flt(item.landed_cost_voucher_amount), + "project": item.project })) # sub-contracting warehouse @@ -441,7 +443,8 @@ class PurchaseInvoice(BuyingController): "debit_in_account_currency": (flt(item.base_net_amount, item.precision("base_net_amount")) if account_currency==self.company_currency else flt(item.net_amount, item.precision("net_amount"))), - "cost_center": item.cost_center + "cost_center": item.cost_center, + "project": item.project }, account_currency) ) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index bdee391344..be9a884e6e 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -74,7 +74,8 @@ def check_if_in_list(gle, gl_map): and cstr(e.get('party'))==cstr(gle.get('party')) \ and cstr(e.get('against_voucher'))==cstr(gle.get('against_voucher')) \ and cstr(e.get('against_voucher_type')) == cstr(gle.get('against_voucher_type')) \ - and cstr(e.get('cost_center')) == cstr(gle.get('cost_center')): + and cstr(e.get('cost_center')) == cstr(gle.get('cost_center')) \ + and cstr(e.get('project')) == cstr(gle.get('project')): return e def save_entries(gl_map, adv_adj, update_outstanding): diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py index c53ed99857..d10b3d902b 100644 --- a/erpnext/accounts/report/general_ledger/general_ledger.py +++ b/erpnext/accounts/report/general_ledger/general_ledger.py @@ -87,7 +87,8 @@ def get_columns(filters): 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", _("Remarks") + "::400" + _("Project") + ":Link/Project:100", _("Cost Center") + ":Link/Cost Center:100", + _("Remarks") + "::400" ] return columns @@ -109,9 +110,12 @@ def get_gl_entries(filters): group_by_condition = "group by voucher_type, voucher_no, account, cost_center" \ if filters.get("group_by_voucher") else "group by name" - gl_entries = frappe.db.sql("""select posting_date, account, party_type, party, + 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, remarks, against, is_opening {select_fields} + voucher_type, voucher_no, cost_center, project, + remarks, against, is_opening {select_fields} from `tabGL Entry` where company=%(company)s {conditions} {group_by_condition} @@ -283,7 +287,7 @@ def get_result_as_list(data, filters): 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("remarks") + d.get("party_type"), d.get("party"), d.get("project"), d.get("cost_center"), d.get("remarks") ] result.append(row) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index e6d0ee900c..34f098e6de 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -247,7 +247,8 @@ class AccountsController(TransactionBase): 'credit_in_account_currency': 0, 'is_opening': self.get("is_opening") or "No", 'party_type': None, - 'party': None + 'party': None, + 'project': self.get("project") }) gl_dict.update(args) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 845a4d0744..1976cc6c56 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -62,6 +62,7 @@ class StockController(AccountsController): "cost_center": detail.cost_center, "remarks": self.get("remarks") or "Accounting Entry for Stock", "credit": flt(sle.stock_value_difference, 2), + "project": detail.get("project") or self.get("project") })) elif sle.warehouse not in warehouse_with_no_account: warehouse_with_no_account.append(sle.warehouse) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 831b177928..210a9e83df 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -266,4 +266,5 @@ erpnext.patches.v7_0.fix_duplicate_icons erpnext.patches.v7_0.remove_features_setup erpnext.patches.v7_0.update_home_page erpnext.patches.v7_0.create_budget_record -execute:frappe.delete_doc_if_exists("Page", "financial-analytics") \ No newline at end of file +execute:frappe.delete_doc_if_exists("Page", "financial-analytics") +erpnext.patches.v7_0.update_project_in_gl_entry diff --git a/erpnext/patches/v7_0/update_project_in_gl_entry.py b/erpnext/patches/v7_0/update_project_in_gl_entry.py new file mode 100644 index 0000000000..f183a531c1 --- /dev/null +++ b/erpnext/patches/v7_0/update_project_in_gl_entry.py @@ -0,0 +1,18 @@ +import frappe + +def execute(): + for doctype in ("Delivery Note", "Sales Invoice", "Stock Entry"): + frappe.db.sql(""" + update `tabGL Entry` gle, `tab{0}` dt + set gle.project = dt.project + where gle.voucher_type=%s and gle.voucher_no = dt.name + and ifnull(gle.cost_center, '') != '' and ifnull(dt.project, '') != '' + """.format(doctype), doctype) + + for doctype in ("Purchase Receipt", "Purchase Invoice"): + frappe.db.sql(""" + update `tabGL Entry` gle, `tab{0} Item` dt + set gle.project = dt.project + where gle.voucher_type=%s and gle.voucher_no = dt.parent and gle.cost_center=dt.cost_center + and ifnull(gle.cost_center, '') != '' and ifnull(dt.project, '') != '' + """.format(doctype), doctype) \ No newline at end of file diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index a173ae86dc..7cea640d1f 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -222,7 +222,8 @@ class PurchaseReceipt(BuyingController): "against": warehouse_account[d.warehouse]["name"], "cost_center": d.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), - "credit": flt(d.landed_cost_voucher_amount) + "credit": flt(d.landed_cost_voucher_amount), + "project": d.project })) # sub-contracting warehouse @@ -253,7 +254,8 @@ class PurchaseReceipt(BuyingController): "against": warehouse_account[d.warehouse]["name"], "cost_center": d.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), - "debit": divisional_loss + "debit": divisional_loss, + "project": d.project }, stock_rbnb_currency)) elif d.warehouse not in warehouse_with_no_account or \