Fiscal year autofetch added

This commit is contained in:
Neil Trini Lasrado 2014-10-03 17:43:02 +05:30
parent ce89c2f192
commit 78fa6954e5
12 changed files with 167 additions and 50 deletions

View File

@ -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",

View File

@ -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"
}

View File

@ -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

View File

@ -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) {

View File

@ -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",

View File

@ -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"):

View File

@ -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]);
}
});
}

View File

@ -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() {

View File

@ -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);

View File

@ -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');
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);
}

View File

@ -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",