From 78fa6954e5d0003f26bb5e03f9ab67feb0a5ecb8 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Fri, 3 Oct 2014 17:43:02 +0530 Subject: [PATCH] Fiscal year autofetch added --- .../doctype/fiscal_year/fiscal_year.json | 18 +++---- .../doctype/fiscal_year_company/__init__.py | 0 .../fiscal_year_company.json | 51 +++++++++++++++++++ .../fiscal_year_company.py | 9 ++++ .../journal_voucher/journal_voucher.js | 6 +++ .../journal_voucher/journal_voucher.json | 30 +++++------ erpnext/accounts/utils.py | 19 ++++--- .../doctype/purchase_order/purchase_order.js | 23 +++++++++ erpnext/public/js/transaction.js | 7 +++ erpnext/public/js/utils.js | 16 ++++++ .../stock/doctype/stock_entry/stock_entry.js | 14 +++-- .../doctype/stock_entry/stock_entry.json | 24 ++++----- 12 files changed, 167 insertions(+), 50 deletions(-) create mode 100644 erpnext/accounts/doctype/fiscal_year_company/__init__.py create mode 100644 erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.json create mode 100644 erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.py diff --git a/erpnext/accounts/doctype/fiscal_year/fiscal_year.json b/erpnext/accounts/doctype/fiscal_year/fiscal_year.json index 0f7aefd312..ed98b394fb 100644 --- a/erpnext/accounts/doctype/fiscal_year/fiscal_year.json +++ b/erpnext/accounts/doctype/fiscal_year/fiscal_year.json @@ -39,23 +39,17 @@ "reqd": 1 }, { - "default": "No", - "description": "Entries are not allowed against this Fiscal Year if the year is closed.", - "fieldname": "is_fiscal_year_closed", - "fieldtype": "Select", - "in_list_view": 1, - "label": "Year Closed", - "no_copy": 1, - "oldfieldname": "is_fiscal_year_closed", - "oldfieldtype": "Select", - "options": "\nNo\nYes", + "fieldname": "company", + "fieldtype": "Table", + "label": "List of Companies", + "options": "Fiscal Year Company", "permlevel": 0, - "reqd": 0 + "precision": "" } ], "icon": "icon-calendar", "idx": 1, - "modified": "2014-07-14 05:30:56.843180", + "modified": "2014-10-02 13:40:40.298965", "modified_by": "Administrator", "module": "Accounts", "name": "Fiscal Year", diff --git a/erpnext/accounts/doctype/fiscal_year_company/__init__.py b/erpnext/accounts/doctype/fiscal_year_company/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.json b/erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.json new file mode 100644 index 0000000000..5de4d3cb34 --- /dev/null +++ b/erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.json @@ -0,0 +1,51 @@ +{ + "allow_copy": 0, + "allow_import": 0, + "allow_rename": 0, + "creation": "2014-10-02 13:35:44.155278", + "custom": 0, + "docstatus": 0, + "doctype": "DocType", + "document_type": "Master", + "fields": [ + { + "allow_on_submit": 0, + "fieldname": "company", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 1, + "label": "Company", + "no_copy": 0, + "options": "Company", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + } + ], + "hide_heading": 0, + "hide_toolbar": 0, + "in_create": 0, + "in_dialog": 0, + "is_submittable": 0, + "issingle": 0, + "istable": 1, + "modified": "2014-10-02 13:35:44.155278", + "modified_by": "Administrator", + "module": "Accounts", + "name": "Fiscal Year Company", + "name_case": "", + "owner": "Administrator", + "permissions": [], + "read_only": 0, + "read_only_onload": 0, + "sort_field": "modified", + "sort_order": "DESC" +} \ No newline at end of file diff --git a/erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.py b/erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.py new file mode 100644 index 0000000000..76a8bd40d1 --- /dev/null +++ b/erpnext/accounts/doctype/fiscal_year_company/fiscal_year_company.py @@ -0,0 +1,9 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe.model.document import Document + +class FiscalYearCompany(Document): + pass diff --git a/erpnext/accounts/doctype/journal_voucher/journal_voucher.js b/erpnext/accounts/doctype/journal_voucher/journal_voucher.js index 69269d07e9..2c2018e330 100644 --- a/erpnext/accounts/doctype/journal_voucher/journal_voucher.js +++ b/erpnext/accounts/doctype/journal_voucher/journal_voucher.js @@ -2,6 +2,7 @@ // License: GNU General Public License v3. See license.txt frappe.provide("erpnext.accounts"); +frappe.require("assets/erpnext/js/utils.js"); erpnext.accounts.JournalVoucher = frappe.ui.form.Controller.extend({ onload: function() { @@ -153,6 +154,11 @@ cur_frm.cscript.refresh = function(doc) { cur_frm.cscript.company = function(doc, cdt, cdn) { cur_frm.refresh_fields(); + erpnext.get_fiscal_year(doc); +} + +cur_frm.cscript.posting_date = function(doc, cdt, cdn){ + erpnext.get_fiscal_year(doc); } cur_frm.cscript.is_opening = function(doc, cdt, cdn) { diff --git a/erpnext/accounts/doctype/journal_voucher/journal_voucher.json b/erpnext/accounts/doctype/journal_voucher/journal_voucher.json index 1638296c5c..180a21105d 100644 --- a/erpnext/accounts/doctype/journal_voucher/journal_voucher.json +++ b/erpnext/accounts/doctype/journal_voucher/journal_voucher.json @@ -388,20 +388,6 @@ "read_only": 1, "report_hide": 1 }, - { - "fieldname": "fiscal_year", - "fieldtype": "Link", - "in_filter": 1, - "label": "Fiscal Year", - "oldfieldname": "fiscal_year", - "oldfieldtype": "Select", - "options": "Fiscal Year", - "permlevel": 0, - "print_hide": 1, - "read_only": 0, - "reqd": 1, - "search_index": 1 - }, { "fieldname": "company", "fieldtype": "Link", @@ -416,6 +402,20 @@ "reqd": 1, "search_index": 1 }, + { + "fieldname": "fiscal_year", + "fieldtype": "Link", + "in_filter": 1, + "label": "Fiscal Year", + "oldfieldname": "fiscal_year", + "oldfieldtype": "Select", + "options": "Fiscal Year", + "permlevel": 0, + "print_hide": 1, + "read_only": 0, + "reqd": 1, + "search_index": 1 + }, { "allow_on_submit": 1, "fieldname": "select_print_heading", @@ -447,7 +447,7 @@ "icon": "icon-file-text", "idx": 1, "is_submittable": 1, - "modified": "2014-09-09 05:35:31.217863", + "modified": "2014-10-02 14:51:20.624847", "modified_by": "Administrator", "module": "Accounts", "name": "Journal Voucher", diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index cf57a61fe5..fb4a86c8f6 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -12,26 +12,29 @@ import frappe.desk.reportview class FiscalYearError(frappe.ValidationError): pass class BudgetError(frappe.ValidationError): pass +@frappe.whitelist() +def get_fiscal_year(date=None, fiscal_year=None, label="Date", verbose=1, company=None): + return get_fiscal_years(date, fiscal_year, label, verbose, company)[0] -def get_fiscal_year(date=None, fiscal_year=None, label="Date", verbose=1): - return get_fiscal_years(date, fiscal_year, label, verbose)[0] - -def get_fiscal_years(date=None, fiscal_year=None, label="Date", verbose=1): +def get_fiscal_years(date=None, fiscal_year=None, label="Date", verbose=1, company=None): # if year start date is 2012-04-01, year end date should be 2013-03-31 (hence subdate) cond = "" if fiscal_year: cond = "name = '%s'" % fiscal_year.replace("'", "\'") + elif company: + cond = """('%s' in (select company from `tabFiscal Year Company` + where `tabFiscal Year Company`.parent = `tabFiscal Year`.name)) + and '%s' >= year_start_date and '%s' <= year_end_date """ %(company, date, date) else: - cond = "'%s' >= year_start_date and '%s' <= year_end_date" % \ - (date, date) + cond = "'%s' >= year_start_date and '%s' <= year_end_date" %(date, date) + fy = frappe.db.sql("""select name, year_start_date, year_end_date from `tabFiscal Year` where %s order by year_start_date desc""" % cond) if not fy: error_msg = _("""{0} {1} not in any Fiscal Year""").format(label, formatdate(date)) - if verbose: frappe.msgprint(error_msg) + if verbose==1: frappe.msgprint(error_msg) raise FiscalYearError, error_msg - return fy def validate_fiscal_year(date, fiscal_year, label="Date"): diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js index 9433ebe20c..3d66cd1f22 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order.js @@ -211,3 +211,26 @@ cur_frm.cscript.send_sms = function() { var sms_man = new SMSManager(cur_frm.doc); } +cur_frm.cscript.company = function(doc, cdt, cdn) { + get_fiscal_year(doc); +} + +cur_frm.cscript.transaction_date = function(doc, cdt, cdn){ + get_fiscal_year(doc); +} + +function get_fiscal_year(doc) { + frappe.call({ + type:"GET", + method: "erpnext.accounts.utils.get_fiscal_year", + args: { + "company": doc.company, + "date": doc.transaction_date, + "verbose": '0' + }, + callback: function(r) { + var arr = r.message + if (arr != null) cur_frm.set_value("fiscal_year",arr[0]); + } + }); +} \ No newline at end of file diff --git a/erpnext/public/js/transaction.js b/erpnext/public/js/transaction.js index 3a12485019..355a11c01a 100644 --- a/erpnext/public/js/transaction.js +++ b/erpnext/public/js/transaction.js @@ -3,6 +3,8 @@ frappe.provide("erpnext"); frappe.require("assets/erpnext/js/controllers/stock_controller.js"); +frappe.require("assets/erpnext/js/utils.js"); + erpnext.TransactionController = erpnext.stock.StockController.extend({ onload: function() { @@ -221,6 +223,11 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ this.frm.script_manager.trigger("currency"); this.apply_pricing_rule(); } + erpnext.get_fiscal_year(this.frm.doc); + }, + + posting_date: function() { + erpnext.get_fiscal_year(this.frm.doc); }, get_company_currency: function() { diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index ef7d03ea45..748678a497 100644 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -12,6 +12,22 @@ $.extend(erpnext, { return frappe.boot.sysdefaults.currency; }, + get_fiscal_year: function(doc) { + frappe.call({ + type:"GET", + method: "erpnext.accounts.utils.get_fiscal_year", + args: { + "company": doc.company, + "date": doc.posting_date, + "verbose": '0' + }, + callback: function(r) { + var arr = r.message + if (arr != null) cur_frm.set_value("fiscal_year",arr[0]); + } + }); + }, + toggle_naming_series: function() { if(cur_frm.fields_dict.naming_series) { cur_frm.toggle_display("naming_series", cur_frm.doc.__islocal?true:false); diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 96dee3da4f..8acf1a0f3f 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -1,10 +1,10 @@ -// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors -// License: GNU General Public License v3. See license.txt +// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt cur_frm.cscript.tname = "Stock Entry Detail"; cur_frm.cscript.fname = "mtn_details"; frappe.require("assets/erpnext/js/controllers/stock_controller.js"); +frappe.require("assets/erpnext/js/utils.js"); frappe.provide("erpnext.stock"); erpnext.stock.StockEntry = erpnext.stock.StockController.extend({ @@ -462,4 +462,12 @@ cur_frm.fields_dict.supplier.get_query = function(doc, cdt, cdn) { return { query: "erpnext.controllers.queries.supplier_query" } } cur_frm.add_fetch('production_order', 'total_fixed_cost', 'total_fixed_cost'); -cur_frm.add_fetch('bom_no', 'total_fixed_cost', 'total_fixed_cost'); \ No newline at end of file +cur_frm.add_fetch('bom_no', 'total_fixed_cost', 'total_fixed_cost'); + +cur_frm.cscript.company = function(doc, cdt, cdn) { + erpnext.get_fiscal_year(doc); +} + +cur_frm.cscript.posting_date = function(doc, cdt, cdn){ + erpnext.get_fiscal_year(doc); +} diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.json b/erpnext/stock/doctype/stock_entry/stock_entry.json index 5f78758c6c..8cbfbef1ea 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.json +++ b/erpnext/stock/doctype/stock_entry/stock_entry.json @@ -509,17 +509,6 @@ "permlevel": 0, "read_only": 1 }, - { - "fieldname": "fiscal_year", - "fieldtype": "Link", - "in_filter": 0, - "label": "Fiscal Year", - "options": "Fiscal Year", - "permlevel": 0, - "print_hide": 1, - "read_only": 0, - "reqd": 1 - }, { "allow_on_submit": 0, "fieldname": "company", @@ -538,6 +527,17 @@ "reqd": 1, "search_index": 0 }, + { + "fieldname": "fiscal_year", + "fieldtype": "Link", + "in_filter": 0, + "label": "Fiscal Year", + "options": "Fiscal Year", + "permlevel": 0, + "print_hide": 1, + "read_only": 0, + "reqd": 1 + }, { "allow_on_submit": 1, "fieldname": "select_print_heading", @@ -585,7 +585,7 @@ "is_submittable": 1, "issingle": 0, "max_attachments": 0, - "modified": "2014-09-16 15:56:37.514676", + "modified": "2014-10-03 14:55:44.916658", "modified_by": "Administrator", "module": "Stock", "name": "Stock Entry",