Fiscal year autofetch added
diff --git a/erpnext/accounts/doctype/fiscal_year/fiscal_year.json b/erpnext/accounts/doctype/fiscal_year/fiscal_year.json
index 0f7aefd..ed98b39 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 0000000..e69de29
--- /dev/null
+++ b/erpnext/accounts/doctype/fiscal_year_company/__init__.py
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 0000000..5de4d3c
--- /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 0000000..76a8bd4
--- /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 69269d0..2c2018e 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.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 1638296..180a211 100644
--- a/erpnext/accounts/doctype/journal_voucher/journal_voucher.json
+++ b/erpnext/accounts/doctype/journal_voucher/journal_voucher.json
@@ -389,20 +389,6 @@
"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",
"in_filter": 1,
@@ -417,6 +403,20 @@
"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",
"fieldtype": "Link",
@@ -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 cf57a61..fb4a86c 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -12,26 +12,29 @@
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 9433ebe..3d66cd1 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.js
@@ -211,3 +211,26 @@
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 3a12485..355a11c 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 @@
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 ef7d03e..748678a 100644
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -12,6 +12,22 @@
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 96dee3d..8acf1a0 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 @@
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 5f78758..8cbfbef 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.json
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.json
@@ -510,17 +510,6 @@
"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",
"fieldtype": "Link",
@@ -539,6 +528,17 @@
"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",
"fieldtype": "Link",
@@ -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",