[fix] additional fixes after deprecating Fiscal Year

This commit is contained in:
Anand Doshi 2016-03-11 14:56:19 +05:30
parent d9cc14ddd5
commit c75c1d7e3e
6 changed files with 175 additions and 158 deletions

View File

@ -83,7 +83,7 @@
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0, "print_hide_if_no_value": 0,
"read_only": 1, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
"search_index": 0, "search_index": 0,
@ -101,7 +101,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2016-03-03 02:46:44.493856", "modified": "2016-03-03 02:46:44.493857",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Monthly Distribution", "name": "Monthly Distribution",

View File

@ -10,7 +10,7 @@ import frappe.defaults
from erpnext.controllers.buying_controller import BuyingController from erpnext.controllers.buying_controller import BuyingController
from erpnext.accounts.party import get_party_account, get_due_date from erpnext.accounts.party import get_party_account, get_due_date
from erpnext.accounts.utils import get_account_currency from erpnext.accounts.utils import get_account_currency, get_fiscal_year
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import update_billed_amount_based_on_po from erpnext.stock.doctype.purchase_receipt.purchase_receipt import update_billed_amount_based_on_po
form_grid_templates = { form_grid_templates = {
@ -432,11 +432,25 @@ class PurchaseInvoice(BuyingController):
if self.bill_date: if self.bill_date:
if getdate(self.bill_date) > getdate(self.posting_date): if getdate(self.bill_date) > getdate(self.posting_date):
frappe.throw("Supplier Invoice Date cannot be greater than Posting Date") frappe.throw("Supplier Invoice Date cannot be greater than Posting Date")
if self.bill_no: if self.bill_no:
if cint(frappe.db.get_single_value("Accounts Settings", "check_supplier_invoice_uniqueness")): if cint(frappe.db.get_single_value("Accounts Settings", "check_supplier_invoice_uniqueness")):
pi = frappe.db.exists("Purchase Invoice", {"bill_no": self.bill_no, fiscal_year = get_fiscal_year(self.posting_date, company=self.company, as_dict=True)
"name": ("!=", self.name), "docstatus": ("<", 2)})
pi = frappe.db.sql('''select name from `tabPurchase Invoice`
where
bill_no = %(bill_no)s
and name != %(name)s
and docstatus < 2
and posting_date between %(year_start_date)s and %(year_end_date)s''', {
"bill_no": self.bill_no,
"name": self.name,
"year_start_date": fiscal_year.year_start_date,
"year_end_date": fiscal_year.year_end_date
})
if pi: if pi:
pi = pi[0][0]
frappe.throw("Supplier Invoice No exists in Purchase Invoice {0}".format(pi)) frappe.throw("Supplier Invoice No exists in Purchase Invoice {0}".format(pi))
def update_billing_status_in_pr(self, update_modified=True): def update_billing_status_in_pr(self, update_modified=True):

View File

@ -16,10 +16,10 @@ class FiscalYearError(frappe.ValidationError): pass
class BudgetError(frappe.ValidationError): pass class BudgetError(frappe.ValidationError): pass
@frappe.whitelist() @frappe.whitelist()
def get_fiscal_year(date=None, fiscal_year=None, label="Date", verbose=1, company=None): def get_fiscal_year(date=None, fiscal_year=None, label="Date", verbose=1, company=None, as_dict=False):
return get_fiscal_years(date, fiscal_year, label, verbose, company)[0] return get_fiscal_years(date, fiscal_year, label, verbose, company, as_dict=as_dict)[0]
def get_fiscal_years(transaction_date=None, fiscal_year=None, label="Date", verbose=1, company=None): def get_fiscal_years(transaction_date=None, fiscal_year=None, label="Date", verbose=1, company=None, as_dict=False):
# if year start date is 2012-04-01, year end date should be 2013-03-31 (hence subdate) # if year start date is 2012-04-01, year end date should be 2013-03-31 (hence subdate)
cond = " disabled = 0" cond = " disabled = 0"
if fiscal_year: if fiscal_year:
@ -36,10 +36,10 @@ def get_fiscal_years(transaction_date=None, fiscal_year=None, label="Date", verb
"fiscal_year": fiscal_year, "fiscal_year": fiscal_year,
"transaction_date": transaction_date, "transaction_date": transaction_date,
"company": company "company": company
}) }, as_dict=as_dict)
if not fy: if not fy:
error_msg = _("""{0} {1} not in any active Fiscal Year. For more details check {2}.""").format(label, formatdate(transaction_date), "https://erpnext.com/kb/accounts/fiscal-year-error") error_msg = _("""{0} {1} not in any active Fiscal Year. For more details check {2}.""").format(label, formatdate(transaction_date), "https://frappe.github.io/erpnext/user/manual/en/accounts/articles/fiscal-year-error")
if verbose==1: frappe.msgprint(error_msg) if verbose==1: frappe.msgprint(error_msg)
raise FiscalYearError, error_msg raise FiscalYearError, error_msg
return fy return fy
@ -488,4 +488,3 @@ def get_account(account_type=None, root_type=None, is_group=None, account_curren
"account_currency": account_currency or frappe.defaults.get_defaults().currency, "account_currency": account_currency or frappe.defaults.get_defaults().currency,
"company": company or frappe.defaults.get_defaults().company "company": company or frappe.defaults.get_defaults().company
}, "name") }, "name")

View File

@ -40,8 +40,9 @@ frappe.query_reports["Monthly Attendance Sheet"] = {
callback: function(r) { callback: function(r) {
var year_filter = me.filters_by_name.year; var year_filter = me.filters_by_name.year;
year_filter.df.options = r.message; year_filter.df.options = r.message;
year_filter.set_options(r.message.split("\n")[0]); year_filter.df.default = r.message.split("\n")[0];
year_filter.refresh(); year_filter.refresh();
year_filter.set_input(year_filter.df.default);
} }
}); });
} }

View File

@ -3,7 +3,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import cstr, cint from frappe.utils import cstr, cint, getdate
from frappe import msgprint, _ from frappe import msgprint, _
from calendar import monthrange from calendar import monthrange
@ -95,5 +95,8 @@ def get_employee_details():
@frappe.whitelist() @frappe.whitelist()
def get_attendance_years(): def get_attendance_years():
year_list = frappe.db.sql_list("""select distinct YEAR(att_date) from tabAttendance ORDER BY YEAR(att_date)""") year_list = frappe.db.sql_list("""select distinct YEAR(att_date) from tabAttendance ORDER BY YEAR(att_date) DESC""")
if not year_list:
year_list = [getdate().year]
return "\n".join(str(year) for year in year_list) return "\n".join(str(year) for year in year_list)