Frozen Accounts Modifier setting in Accounts Settings

This commit is contained in:
Nabin Hait 2013-09-24 12:04:07 +05:30
parent 6c66096fa5
commit 7031ea72ca
6 changed files with 65 additions and 62 deletions

View File

@ -18,12 +18,22 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
cur_frm.toggle_display('account_name', doc.__islocal);
// hide fields if group
cur_frm.toggle_display(['account_type', 'master_type', 'master_name', 'freeze_account',
cur_frm.toggle_display(['account_type', 'master_type', 'master_name',
'credit_days', 'credit_limit', 'tax_rate'], doc.group_or_ledger=='Ledger')
// disable fields
cur_frm.toggle_enable(['account_name', 'debit_or_credit', 'group_or_ledger',
'is_pl_account', 'company'], false);
if(doc.group_or_ledger=='Ledger') {
wn.model.with_doc("Accounts Settings", "Accounts Settings", function (name) {
var accounts_settings = wn.model.get_doc("Accounts Settings", name);
var display = accounts_settings["frozen_accounts_modifier"]
&& in_list(user_roles, accounts_settings["frozen_accounts_modifier"]);
cur_frm.toggle_display('freeze_account', display);
});
}
// read-only for root accounts
if(!doc.parent_account) {

View File

@ -24,6 +24,17 @@ class DocType:
address = webnotes.conn.get_value(self.doc.master_type, self.doc.master_name, "address")
return {'address': address}
def validate(self):
self.validate_master_name()
self.validate_parent()
self.validate_duplicate_account()
self.validate_root_details()
self.validate_mandatory()
self.validate_frozen_accounts_modifier()
if not self.doc.parent_account:
self.doc.parent_account = ''
def validate_master_name(self):
"""Remind to add master name"""
if (self.doc.master_type == 'Customer' or self.doc.master_type == 'Supplier') \
@ -71,6 +82,15 @@ class DocType:
if webnotes.conn.exists("Account", self.doc.name):
if not webnotes.conn.get_value("Account", self.doc.name, "parent_account"):
webnotes.msgprint("Root cannot be edited.", raise_exception=1)
def validate_frozen_accounts_modifier(self):
old_value = webnotes.conn.get_value("Account", self.doc.name, "freeze_account")
if old_value != self.doc.freeze_account:
frozen_accounts_modifier = webnotes.conn.get_value( 'Accounts Settings', None,
'frozen_accounts_modifier')
if not frozen_accounts_modifier or \
frozen_accounts_modifier not in webnotes.user.get_roles():
webnotes.throw(_("You are not authorized to set Frozen value"))
def convert_group_to_ledger(self):
if self.check_if_child_exists():
@ -112,16 +132,6 @@ class DocType:
if not self.doc.is_pl_account:
msgprint("Is PL Account field is mandatory", raise_exception=1)
def validate(self):
self.validate_master_name()
self.validate_parent()
self.validate_duplicate_account()
self.validate_root_details()
self.validate_mandatory()
if not self.doc.parent_account:
self.doc.parent_account = ''
def update_nsm_model(self):
"""update lft, rgt indices for nested set model"""
import webnotes

View File

@ -2,7 +2,7 @@
{
"creation": "2013-01-30 12:49:46",
"docstatus": 0,
"modified": "2013-09-23 23:55:15",
"modified": "2013-09-24 11:22:18",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -23,7 +23,8 @@
"name": "__common__",
"parent": "Account",
"parentfield": "fields",
"parenttype": "DocType"
"parenttype": "DocType",
"permlevel": 0
},
{
"amend": 0,
@ -45,14 +46,12 @@
"fieldname": "properties",
"fieldtype": "Section Break",
"label": "Account Details",
"oldfieldtype": "Section Break",
"permlevel": 0
"oldfieldtype": "Section Break"
},
{
"doctype": "DocField",
"fieldname": "column_break0",
"fieldtype": "Column Break",
"permlevel": 0,
"width": "50%"
},
{
@ -64,7 +63,6 @@
"no_copy": 1,
"oldfieldname": "account_name",
"oldfieldtype": "Data",
"permlevel": 0,
"read_only": 1,
"reqd": 1,
"search_index": 1
@ -77,7 +75,6 @@
"label": "Level",
"oldfieldname": "level",
"oldfieldtype": "Int",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
@ -91,7 +88,6 @@
"oldfieldname": "group_or_ledger",
"oldfieldtype": "Select",
"options": "\nLedger\nGroup",
"permlevel": 0,
"read_only": 1,
"reqd": 1,
"search_index": 1
@ -104,7 +100,6 @@
"label": "Debit or Credit",
"oldfieldname": "debit_or_credit",
"oldfieldtype": "Data",
"permlevel": 0,
"read_only": 1,
"search_index": 1
},
@ -117,7 +112,6 @@
"oldfieldname": "is_pl_account",
"oldfieldtype": "Select",
"options": "Yes\nNo",
"permlevel": 0,
"read_only": 1,
"search_index": 1
},
@ -130,7 +124,6 @@
"oldfieldname": "company",
"oldfieldtype": "Link",
"options": "Company",
"permlevel": 0,
"read_only": 1,
"reqd": 1,
"search_index": 1
@ -139,7 +132,6 @@
"doctype": "DocField",
"fieldname": "column_break1",
"fieldtype": "Column Break",
"permlevel": 0,
"width": "50%"
},
{
@ -150,7 +142,6 @@
"oldfieldname": "parent_account",
"oldfieldtype": "Link",
"options": "Account",
"permlevel": 0,
"search_index": 1
},
{
@ -163,7 +154,6 @@
"oldfieldname": "account_type",
"oldfieldtype": "Select",
"options": "\nFixed Asset Account\nBank or Cash\nExpense Account\nTax\nIncome Account\nChargeable",
"permlevel": 0,
"search_index": 0
},
{
@ -175,7 +165,6 @@
"label": "Rate",
"oldfieldname": "tax_rate",
"oldfieldtype": "Currency",
"permlevel": 0,
"reqd": 0
},
{
@ -186,8 +175,7 @@
"label": "Frozen",
"oldfieldname": "freeze_account",
"oldfieldtype": "Select",
"options": "No\nYes",
"permlevel": 2
"options": "No\nYes"
},
{
"doctype": "DocField",
@ -197,7 +185,6 @@
"label": "Credit Days",
"oldfieldname": "credit_days",
"oldfieldtype": "Int",
"permlevel": 0,
"print_hide": 1
},
{
@ -209,7 +196,6 @@
"oldfieldname": "credit_limit",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1
},
{
@ -220,8 +206,7 @@
"label": "Master Type",
"oldfieldname": "master_type",
"oldfieldtype": "Select",
"options": "\nSupplier\nCustomer\nEmployee",
"permlevel": 0
"options": "\nSupplier\nCustomer\nEmployee"
},
{
"doctype": "DocField",
@ -230,8 +215,7 @@
"label": "Master Name",
"oldfieldname": "master_name",
"oldfieldtype": "Link",
"options": "[Select]",
"permlevel": 0
"options": "[Select]"
},
{
"default": "1",
@ -239,8 +223,7 @@
"doctype": "DocField",
"fieldname": "allow_negative_balance",
"fieldtype": "Check",
"label": "Allow Negative Balance",
"permlevel": 0
"label": "Allow Negative Balance"
},
{
"doctype": "DocField",
@ -248,7 +231,6 @@
"fieldtype": "Int",
"hidden": 1,
"label": "Lft",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
@ -258,7 +240,6 @@
"fieldtype": "Int",
"hidden": 1,
"label": "Rgt",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
@ -268,7 +249,6 @@
"fieldtype": "Data",
"hidden": 1,
"label": "Old Parent",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},

View File

@ -2,7 +2,7 @@
{
"creation": "2013-06-24 15:49:57",
"docstatus": 0,
"modified": "2013-09-23 23:53:25",
"modified": "2013-09-24 11:52:57",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -53,7 +53,7 @@
"label": "Accounts Frozen Upto"
},
{
"description": "Users with this role are allowed to do / modify accounting entry before frozen date",
"description": "Users with this role are allowed to create / modify accounting entry before frozen date",
"doctype": "DocField",
"fieldname": "bde_auth_role",
"fieldtype": "Link",
@ -61,11 +61,11 @@
"options": "Role"
},
{
"description": "Users with this role are allowed to do / modify accounting entries against frozen accounts",
"description": "Users with this role are allowed to set frozen accounts and create / modify accounting entries against frozen accounts",
"doctype": "DocField",
"fieldname": "frozen_accounts_modifier",
"fieldtype": "Link",
"label": "Allowed Role to Edit Entries against Frozen Accounts",
"label": "Frozen Accounts Modifier",
"options": "Role"
},
{

View File

@ -25,6 +25,7 @@ class DocType:
def on_update(self, adv_adj, cancel, update_outstanding = 'Yes'):
self.validate_account_details(adv_adj)
self.validate_cost_center()
self.validate_frozen_account(adv_adj)
self.check_freezing_date(adv_adj)
self.check_negative_balance(adv_adj)
@ -81,31 +82,18 @@ class DocType:
def validate_account_details(self, adv_adj):
"""Account must be ledger, active and not freezed"""
ret = sql("""select group_or_ledger, docstatus, freeze_account, company
ret = sql("""select group_or_ledger, docstatus, company
from tabAccount where name=%s""", self.doc.account, as_dict=1)
if ret and ret[0]["group_or_ledger"]=='Group':
msgprint(_("Account") + ": " + self.doc.account + _(" is not a ledger"), raise_exception=1)
webnotes.throw(_("Account is not a ledger") + "(%s)" % self.doc.account)
if ret and ret[0]["docstatus"]==2:
msgprint(_("Account") + ": " + self.doc.account + _(" is not active"), raise_exception=1)
# Account has been freezed for other users except account manager
if ret and ret[0]["freeze_account"]== 'Yes' and not adv_adj:
frozen_accounts_modifier = webnotes.conn.get_value( 'Accounts Settings', None,
'frozen_accounts_modifier')
if not frozen_accounts_modifier:
webnotes.throw(self.doc.account + _(" is a frozen account. \
Either make the account active or assign role in Accounts Settings \
who can do / modify entries against this account"))
elif frozen_accounts_modifier not in webnotes.user.get_roles():
webnotes.throw(self.doc.account + _(" is a frozen account. ") +
_("To make / edit transactions against this account, you need role") + ": " +
frozen_accounts_modifier)
webnotes.throw(_("Account is not active ") + "(%s)" % self.doc.account)
if self.doc.is_cancelled in ("No", None) and ret and ret[0]["company"] != self.doc.company:
msgprint(_("Account") + ": " + self.doc.account + _(" does not belong to the company") \
+ ": " + self.doc.company, raise_exception=1)
webnotes.throw(_("Account") + ": " + self.doc.account +
_(" does not belong to the company") + ": " + self.doc.company)
def validate_cost_center(self):
if not hasattr(self, "cost_center_company"):
@ -122,7 +110,21 @@ class DocType:
self.doc.cost_center and _get_cost_center_company() != self.doc.company:
msgprint(_("Cost Center") + ": " + self.doc.cost_center \
+ _(" does not belong to the company") + ": " + self.doc.company, raise_exception=True)
def validate_frozen_account(self, adv_adj):
frozen_account = webnotes.conn.get_value("Account", self.doc.account, "freeze_account")
if frozen_account == 'Yes' and not adv_adj:
frozen_accounts_modifier = webnotes.conn.get_value( 'Accounts Settings', None,
'frozen_accounts_modifier')
if not frozen_accounts_modifier:
webnotes.throw(self.doc.account + _(" is a frozen account. \
Either make the account active or assign role in Accounts Settings \
who can do / modify entries against this account"))
elif frozen_accounts_modifier not in webnotes.user.get_roles():
webnotes.throw(self.doc.account + _(" is a frozen account. ") +
_("To make / edit transactions against this account, you need role") + ": " +
frozen_accounts_modifier)
def check_freezing_date(self, adv_adj):
"""
Nobody can do GL Entries where posting date is before freezing date

View File

@ -211,4 +211,5 @@ patch_list = [
"patches.september_2013.p03_update_stock_uom_in_sle",
"patches.september_2013.p03_move_website_to_framework",
"execute:webnotes.bean('Style Settings').save() #2013-09-19",
"execute:webnotes.conn.set_value('Accounts Settings', None, 'frozen_accounts_modifier', 'Accounts Manager') #2013-09-24",
]