Merge branch 'master' of github.com:webnotes/erpnext

This commit is contained in:
Rushabh Mehta 2012-12-12 14:33:34 +05:30
commit 2e580fc345
6 changed files with 247 additions and 292 deletions

View File

@ -20,6 +20,7 @@ import webnotes
from webnotes.utils import add_days
from webnotes.model.wrapper import getlist
from webnotes import form, msgprint
from webnotes.model.code import get_obj
sql = webnotes.conn.sql
@ -36,8 +37,8 @@ class DocType:
def on_submit(self):
if self.doc.approval_status=="Draft":
webnotes.msgprint("""Please set Approval Status to 'Approved' or 'Rejected' before submitting""",
raise_exception=1)
webnotes.msgprint("""Please set Approval Status to 'Approved' or \
'Rejected' before submitting""", raise_exception=1)
def validate_fiscal_year(self):
fy=sql("select year_start_date from `tabFiscal Year` where name='%s'"%self.doc.fiscal_year)
@ -57,5 +58,6 @@ def get_approver_list():
roles = [r[0] for r in webnotes.conn.sql("""select distinct parent from `tabUserRole`
where role='Expense Approver'""")]
if not roles:
webnotes.msgprint("No Expense Approvers. Please assign 'Expense Approver' Role to atleast one user.")
webnotes.msgprint("No Expense Approvers. Please assign 'Expense Approver' \
Role to atleast one user.")
return roles

View File

@ -14,8 +14,8 @@
<h5><a href="#List/Sales Order">Sales Order</a></h5>
<p class="help">Confirmed orders from Customers</p>
<br>
<h5><a href="#List/Sales Order">Communication</a></h5>
<p class="help">Confirmed orders from Customers</p>
<h5><a href="#List/Communication">Communication</a></h5>
<p class="help">All communication records</p>
</div>
<div style="width: 48%; float: right;">
<h5><a href="#List/Customer">Customer</a></h5>

View File

@ -60,7 +60,7 @@ class DocType(TransactionBase):
if appr_users: add_msg = "Users : "+cstr(appr_users)
if appr_roles: add_msg = "Roles : "+cstr(appr_roles)
if appr_users and appr_roles: add_msg = "Users : "+cstr(appr_users)+" or "+"Roles : "+cstr(appr_roles)
msgprint("You do not have an authority to submit this %s %s. Please send for approval to %s" % (doctype_name, msg, add_msg))
msgprint("You are not authorize to submit this %s %s. Please send for approval to %s" % (doctype_name, msg, add_msg))
raise Exception

View File

@ -26,13 +26,13 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) {
cur_frm.cscript.refresh = function(doc,cdt,cdn){
if(doc.based_on == 'Grand Total' || doc.based_on == 'Average Discount' || doc.based_on == 'Total Claimed Amount' || doc.based_on == 'Not Applicable') hide_field('master_name');
if(doc.based_on == 'Grand Total' || doc.based_on == 'Average Discount' || doc.based_on == 'Not Applicable') hide_field('master_name');
else unhide_field('master_name');
if(doc.based_on == 'Not Applicable') hide_field('value');
else unhide_field('value');
if(doc.transaction == 'Expense Claim' || doc.transaction == 'Appraisal'){
if(doc.transaction == 'Appraisal'){
hide_field(['master_name','system_role', 'system_user']);
unhide_field(['to_emp','to_designation']);
if(doc.transaction == 'Appraisal') hide_field('value');
@ -45,7 +45,7 @@ cur_frm.cscript.refresh = function(doc,cdt,cdn){
}
cur_frm.cscript.based_on = function(doc){
if(doc.based_on == 'Grand Total' || doc.based_on == 'Average Discount' || doc.based_on == 'Total Claimed Amount' || doc.based_on == 'Not Applicable'){
if(doc.based_on == 'Grand Total' || doc.based_on == 'Average Discount' || doc.based_on == 'Not Applicable'){
doc.master_name = '';
refresh_field('master_name');
hide_field('master_name');
@ -63,24 +63,20 @@ cur_frm.cscript.based_on = function(doc){
}
cur_frm.cscript.transaction = function(doc,cdt,cdn){
if(doc.transaction == 'Expense Claim' || doc.transaction == 'Appraisal'){
if (doc.transaction == 'Appraisal'){
doc.master_name = doc.system_role = doc.system_user = '';
refresh_many(['master_name','system_role', 'system_user']);
hide_field(['master_name','system_role', 'system_user']);
unhide_field(['to_emp','to_designation']);
if(doc.transaction == 'Appraisal') {
doc.value =0;
refresh_many('value');
hide_field('value');
}
else unhide_field('value');
}
else {
unhide_field(['master_name','system_role', 'system_user','value']);
hide_field(['to_emp','to_designation']);
}
if(doc.transaction == 'Expense Claim') doc.based_on = 'Total Claimed Amount';
if(doc.transaction == 'Appraisal') doc.based_on == 'Not Applicable';
}

View File

@ -31,70 +31,76 @@ class DocType:
self.doc, self.doclist = d, dl
# Duplicate Entry
# ----------------
def check_duplicate_entry(self):
exists = sql("select name, docstatus from `tabAuthorization Rule` where transaction = %s and based_on = %s and system_user = %s and system_role = %s and approving_user = %s and approving_role = %s and to_emp =%s and to_designation=%s and name != %s", (self.doc.transaction, self.doc.based_on, cstr(self.doc.system_user), cstr(self.doc.system_role), cstr(self.doc.approving_user), cstr(self.doc.approving_role), cstr(self.doc.to_emp), cstr(self.doc.to_designation), self.doc.name))
exists = sql("""select name, docstatus from `tabAuthorization Rule`
where transaction = %s and based_on = %s and system_user = %s
and system_role = %s and approving_user = %s and approving_role = %s
and to_emp =%s and to_designation=%s and name != %s""",
(self.doc.transaction, self.doc.based_on, cstr(self.doc.system_user),
cstr(self.doc.system_role), cstr(self.doc.approving_user),
cstr(self.doc.approving_role), cstr(self.doc.to_emp),
cstr(self.doc.to_designation), self.doc.name))
auth_exists = exists and exists[0][0] or ''
if auth_exists:
if cint(exists[0][1]) == 2:
msgprint("Duplicate Entry. Please remove from trash Authorization Rule : %s." %(auth_exists))
raise Exception
msgprint("""Duplicate Entry. Please untrash Authorization Rule : %s \
from Recycle Bin""" % (auth_exists), raise_exception=1)
else:
msgprint("Duplicate Entry. Please check Authorization Rule : %s." % (auth_exists))
raise Exception
msgprint("Duplicate Entry. Please check Authorization Rule : %s" %
(auth_exists), raise_exception=1)
# Validate Master Name
# ---------------------
def validate_master_name(self):
if self.doc.based_on == 'Customerwise Discount' and not sql("select name from tabCustomer where name = '%s' and docstatus != 2" % (self.doc.master_name)):
msgprint("Please select valid Customer Name for Customerwise Discount.")
raise Exception
elif self.doc.based_on == 'Itemwise Discount' and not sql("select name from tabItem where name = '%s' and docstatus != 2" % (self.doc.master_name)):
msgprint("Please select valid Item Name for Itemwise Discount.")
raise Exception
elif (self.doc.based_on == 'Grand Total' or self.doc.based_on == 'Average Discount') and self.doc.master_name:
msgprint("Please remove Customer / Item Name for %s." % (self.doc.based_on))
raise Exception
if self.doc.based_on == 'Customerwise Discount' and \
not sql("select name from tabCustomer where name = '%s' and docstatus != 2" % \
(self.doc.master_name)):
msgprint("Please select valid Customer Name for Customerwise Discount",
raise_exception=1)
elif self.doc.based_on == 'Itemwise Discount' and \
not sql("select name from tabItem where name = '%s' and docstatus != 2" % \
(self.doc.master_name)):
msgprint("Please select valid Item Name for Itemwise Discount", raise_exception=1)
elif (self.doc.based_on == 'Grand Total' or \
self.doc.based_on == 'Average Discount') and self.doc.master_name:
msgprint("Please remove Customer/Item Name for %s." %
self.doc.based_on, raise_exception=1)
# Validate Rule
# --------------
def validate_rule(self):
if not self.doc.transaction == 'Expense Claim' and not self.doc.transaction == 'Appraisal':
if self.doc.transaction != 'Appraisal':
if not self.doc.approving_role and not self.doc.approving_user:
msgprint("Please enter Approving Role or Approving User")
raise Exception
msgprint("Please enter Approving Role or Approving User", raise_exception=1)
elif self.doc.system_user and self.doc.system_user == self.doc.approving_user:
msgprint("Approving User cannot be same as user the rule is Applicable To (User).")
raise Exception
msgprint("Approving User cannot be same as user the rule is Applicable To (User)",
raise_exception=1)
elif self.doc.system_role and self.doc.system_role == self.doc.approving_role:
msgprint("Approving Role cannot be same as user the rule is Applicable To (Role).")
raise Exception
elif self.doc.system_user and self.doc.approving_role and has_common([self.doc.approving_role],[x[0] for x in sql("select role from `tabUserRole` where parent = '%s'" % (self.doc.system_user))]):
msgprint("System User : %s is assigned role : %s. So rule does not make sense." % (self.doc.system_user,self.doc.approving_role))
raise Exception
elif (self.doc.transaction == 'Purchase Order' or self.doc.transaction == 'Purchase Receipt' or self.doc.transaction == 'Purchase Invoice' or self.doc.transaction == 'Stock Entry') and (self.doc.based_on == 'Average Discount' or self.doc.based_on == 'Customerwise Discount' or self.doc.based_on == 'Itemwise Discount'):
msgprint("You cannot set authorization on basis of Discount for %s." % (self.doc.transaction))
raise Exception
msgprint("Approving Role cannot be same as user the rule is \
Applicable To (Role).", raise_exception=1)
elif self.doc.system_user and self.doc.approving_role and \
has_common([self.doc.approving_role], [x[0] for x in \
sql("select role from `tabUserRole` where parent = '%s'" % \
(self.doc.system_user))]):
msgprint("System User : %s is assigned role : %s. So rule does not make sense" %
(self.doc.system_user,self.doc.approving_role), raise_exception=1)
elif self.doc.transaction in ['Purchase Order', 'Purchase Receipt', \
'Purchase Invoice', 'Stock Entry'] and self.doc.based_on \
in ['Average Discount', 'Customerwise Discount', 'Itemwise Discount']:
msgprint("You cannot set authorization on basis of Discount for %s" %
self.doc.transaction, raise_exception=1)
elif self.doc.based_on == 'Average Discount' and flt(self.doc.value) > 100.00:
msgprint("Discount cannot given for more than 100 %s." % ('%'))
raise Exception
msgprint("Discount cannot given for more than 100%", raise_exception=1)
elif self.doc.based_on == 'Customerwise Discount' and not self.doc.master_name:
msgprint("Please enter Customer Name for 'Customerwise Discount'")
raise Exception
msgprint("Please enter Customer Name for 'Customerwise Discount'",
raise_exception=1)
else:
if self.doc.transaction == 'Appraisal' and self.doc.based_on != 'Not Applicable':
msgprint("Based on is 'Not Applicable' while setting authorization rule for 'Appraisal'")
raise Exception
if self.doc.transaction == 'Expense Claim' and self.doc.based_on != 'Total Claimed Amount':
msgprint("Authorization rule should be based on 'Total Calimed Amount' while setting authorization rule for 'Expense Claim'")
raise Exception
msgprint("Based on should be 'Not Applicable' while setting authorization rule\
for 'Appraisal'", raise_exception=1)
def validate(self):
self.check_duplicate_entry()
self.validate_rule()
self.validate_master_name()
if not self.doc.value: self.doc.value = flt(0)
if not self.doc.value: self.doc.value = 0.0

View File

@ -1,212 +1,163 @@
# DocType, Authorization Rule
[
# These values are common in all dictionaries
{
'creation': '2012-03-27 14:36:18',
'docstatus': 0,
'modified': '2012-03-27 14:36:18',
'modified_by': u'Administrator',
'owner': u'Administrator'
"owner": "Administrator",
"docstatus": 0,
"creation": "2012-07-03 13:30:00",
"modified_by": "Administrator",
"modified": "2012-12-12 10:42:42"
},
# These values are common for all DocType
{
'_last_update': u'1308741898',
'allow_trash': 1,
'autoname': u'AR.####',
'colour': u'White:FFF',
'doctype': 'DocType',
'document_type': u'Master',
'module': u'Setup',
'name': '__common__',
'search_fields': u'transaction,based_on,system_user,system_role,approving_user,approving_role',
'section_style': u'Simple',
'server_code_error': u' ',
'version': 58
"autoname": "AR.####",
"name": "__common__",
"search_fields": "transaction,based_on,system_user,system_role,approving_user,approving_role",
"module": "Setup",
"doctype": "DocType",
"document_type": "Master"
},
# These values are common for all DocField
{
'doctype': u'DocField',
'name': '__common__',
'parent': u'Authorization Rule',
'parentfield': u'fields',
'parenttype': u'DocType',
'permlevel': 0
"name": "__common__",
"parent": "Authorization Rule",
"doctype": "DocField",
"parenttype": "DocType",
"permlevel": 0,
"parentfield": "fields"
},
# These values are common for all DocPerm
{
'cancel': 1,
'create': 1,
'doctype': u'DocPerm',
'name': '__common__',
'parent': u'Authorization Rule',
'parentfield': u'permissions',
'parenttype': u'DocType',
'permlevel': 0,
'read': 1,
'role': u'System Manager',
'write': 1
"name": "__common__",
"parent": "Authorization Rule",
"read": 1,
"create": 1,
"doctype": "DocPerm",
"write": 1,
"cancel": 1,
"parenttype": "DocType",
"role": "System Manager",
"permlevel": 0,
"parentfield": "permissions"
},
# DocType, Authorization Rule
{
'doctype': 'DocType',
'name': u'Authorization Rule'
"name": "Authorization Rule",
"doctype": "DocType"
},
# DocPerm
{
'doctype': u'DocPerm'
"oldfieldtype": "Link",
"doctype": "DocField",
"label": "Company",
"oldfieldname": "company",
"fieldname": "company",
"fieldtype": "Link",
"search_index": 0,
"reqd": 0,
"options": "Company"
},
# DocPerm
{
'doctype': u'DocPerm'
"oldfieldtype": "Select",
"doctype": "DocField",
"label": "Transaction",
"oldfieldname": "transaction",
"fieldname": "transaction",
"fieldtype": "Select",
"reqd": 1,
"options": "\nDelivery Note\nPurchase Invoice\nPurchase Order\nPurchase Receipt\nQuotation\nSales Invoice\nSales Order\nStock Entry\nAppraisal"
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'company',
'fieldtype': u'Link',
'label': u'Company',
'oldfieldname': u'company',
'oldfieldtype': u'Link',
'options': u'Company',
'reqd': 0,
'search_index': 0
"oldfieldtype": "Select",
"doctype": "DocField",
"label": "Based On",
"oldfieldname": "based_on",
"fieldname": "based_on",
"fieldtype": "Select",
"reqd": 1,
"options": "\nGrand Total\nAverage Discount\nCustomerwise Discount\nItemwise Discount\nNot Applicable"
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'transaction',
'fieldtype': u'Select',
'label': u'Transaction',
'oldfieldname': u'transaction',
'oldfieldtype': u'Select',
'options': u'\nDelivery Note\nPurchase Invoice\nPurchase Order\nPurchase Receipt\nQuotation\nSales Invoice\nSales Order\nStock Entry\nExpense Claim\nAppraisal',
'reqd': 1
"oldfieldtype": "Link",
"doctype": "DocField",
"label": "Customer / Item Name",
"oldfieldname": "master_name",
"fieldname": "master_name",
"fieldtype": "Link",
"options": "[Select]"
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'based_on',
'fieldtype': u'Select',
'label': u'Based On',
'oldfieldname': u'based_on',
'oldfieldtype': u'Select',
'options': u'\nGrand Total\nAverage Discount\nCustomerwise Discount\nItemwise Discount\nTotal Claimed Amount\nNot Applicable',
'reqd': 1,
'trigger': u'Client'
"oldfieldtype": "Link",
"doctype": "DocField",
"label": "Applicable To (Role)",
"oldfieldname": "system_role",
"fieldname": "system_role",
"fieldtype": "Link",
"options": "Role"
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'master_name',
'fieldtype': u'Link',
'label': u'Customer / Item Name',
'oldfieldname': u'master_name',
'oldfieldtype': u'Link',
'trigger': u'Client'
"oldfieldtype": "Link",
"doctype": "DocField",
"label": "Applicable To (User)",
"oldfieldname": "system_user",
"fieldname": "system_user",
"fieldtype": "Link",
"options": "Profile"
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'system_role',
'fieldtype': u'Link',
'label': u'Applicable To (Role)',
'oldfieldname': u'system_role',
'oldfieldtype': u'Link',
'options': u'Role'
"description": "This will be used for setting rule in HR module",
"oldfieldtype": "Link",
"doctype": "DocField",
"label": "Applicable To (Employee)",
"oldfieldname": "to_emp",
"fieldname": "to_emp",
"fieldtype": "Link",
"search_index": 0,
"options": "Employee"
},
# DocField
{
'colour': u'White:FFF',
'doctype': u'DocField',
'fieldname': u'system_user',
'fieldtype': u'Link',
'label': u'Applicable To (User)',
'oldfieldname': u'system_user',
'oldfieldtype': u'Link',
'options': u'Profile'
"description": "This will be used for setting rule in HR module",
"oldfieldtype": "Link",
"doctype": "DocField",
"label": "Applicable To (Designation)",
"oldfieldname": "to_designation",
"fieldname": "to_designation",
"fieldtype": "Link",
"search_index": 0,
"options": "Designation"
},
# DocField
{
'colour': u'White:FFF',
'description': u'This will be used for setting rule in HR module',
'doctype': u'DocField',
'fieldname': u'to_emp',
'fieldtype': u'Link',
'label': u'Applicable To (Employee)',
'oldfieldname': u'to_emp',
'oldfieldtype': u'Link',
'options': u'Employee',
'search_index': 0
"oldfieldtype": "Link",
"doctype": "DocField",
"label": "Approving Role",
"oldfieldname": "approving_role",
"fieldname": "approving_role",
"fieldtype": "Link",
"options": "Role"
},
# DocField
{
'colour': u'White:FFF',
'description': u'This will be used for setting rule in HR module',
'doctype': u'DocField',
'fieldname': u'to_designation',
'fieldtype': u'Link',
'label': u'Applicable To (Designation)',
'oldfieldname': u'to_designation',
'oldfieldtype': u'Link',
'options': u'Designation',
'search_index': 0
"oldfieldtype": "Link",
"doctype": "DocField",
"label": "Approving User",
"oldfieldname": "approving_user",
"fieldname": "approving_user",
"fieldtype": "Link",
"options": "Profile"
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'approving_role',
'fieldtype': u'Link',
'label': u'Approving Role',
'oldfieldname': u'approving_role',
'oldfieldtype': u'Link',
'options': u'Role'
"default": "0.00",
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Above Value",
"oldfieldname": "value",
"fieldname": "value",
"fieldtype": "Currency"
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'approving_user',
'fieldtype': u'Link',
'label': u'Approving User',
'oldfieldname': u'approving_user',
'oldfieldtype': u'Link',
'options': u'Profile'
"oldfieldtype": "Small Text",
"doctype": "DocField",
"label": "Trash Reason",
"oldfieldname": "trash_reason",
"fieldname": "trash_reason",
"fieldtype": "Small Text"
},
# DocField
{
'default': u'0.00',
'doctype': u'DocField',
'fieldname': u'value',
'fieldtype': u'Currency',
'label': u'Above Value',
'oldfieldname': u'value',
'oldfieldtype': u'Currency'
"doctype": "DocPerm"
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'trash_reason',
'fieldtype': u'Small Text',
'label': u'Trash Reason',
'oldfieldname': u'trash_reason',
'oldfieldtype': u'Small Text'
"doctype": "DocPerm"
}
]