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

View File

@ -14,8 +14,8 @@
<h5><a href="#List/Sales Order">Sales Order</a></h5> <h5><a href="#List/Sales Order">Sales Order</a></h5>
<p class="help">Confirmed orders from Customers</p> <p class="help">Confirmed orders from Customers</p>
<br> <br>
<h5><a href="#List/Sales Order">Communication</a></h5> <h5><a href="#List/Communication">Communication</a></h5>
<p class="help">Confirmed orders from Customers</p> <p class="help">All communication records</p>
</div> </div>
<div style="width: 48%; float: right;"> <div style="width: 48%; float: right;">
<h5><a href="#List/Customer">Customer</a></h5> <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_users: add_msg = "Users : "+cstr(appr_users)
if appr_roles: add_msg = "Roles : "+cstr(appr_roles) 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) 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 raise Exception

View File

@ -26,13 +26,13 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) {
cur_frm.cscript.refresh = 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'); else unhide_field('master_name');
if(doc.based_on == 'Not Applicable') hide_field('value'); if(doc.based_on == 'Not Applicable') hide_field('value');
else unhide_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']); hide_field(['master_name','system_role', 'system_user']);
unhide_field(['to_emp','to_designation']); unhide_field(['to_emp','to_designation']);
if(doc.transaction == 'Appraisal') hide_field('value'); 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){ 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 = ''; doc.master_name = '';
refresh_field('master_name'); refresh_field('master_name');
hide_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){ 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 = ''; doc.master_name = doc.system_role = doc.system_user = '';
refresh_many(['master_name','system_role', 'system_user']); refresh_many(['master_name','system_role', 'system_user']);
hide_field(['master_name','system_role', 'system_user']); hide_field(['master_name','system_role', 'system_user']);
unhide_field(['to_emp','to_designation']); unhide_field(['to_emp','to_designation']);
if(doc.transaction == 'Appraisal') { doc.value =0;
doc.value =0; refresh_many('value');
refresh_many('value'); hide_field('value');
hide_field('value');
}
else unhide_field('value');
} }
else { else {
unhide_field(['master_name','system_role', 'system_user','value']); unhide_field(['master_name','system_role', 'system_user','value']);
hide_field(['to_emp','to_designation']); 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'; if(doc.transaction == 'Appraisal') doc.based_on == 'Not Applicable';
} }

View File

@ -8,11 +8,11 @@
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
@ -27,74 +27,80 @@ sql = webnotes.conn.sql
class DocType: class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl
# Duplicate Entry def check_duplicate_entry(self):
# ---------------- exists = sql("""select name, docstatus from `tabAuthorization Rule`
def check_duplicate_entry(self): where transaction = %s and based_on = %s and system_user = %s
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)) and system_role = %s and approving_user = %s and approving_role = %s
auth_exists = exists and exists[0][0] or '' and to_emp =%s and to_designation=%s and name != %s""",
if auth_exists: (self.doc.transaction, self.doc.based_on, cstr(self.doc.system_user),
if cint(exists[0][1]) == 2: cstr(self.doc.system_role), cstr(self.doc.approving_user),
msgprint("Duplicate Entry. Please remove from trash Authorization Rule : %s." %(auth_exists)) cstr(self.doc.approving_role), cstr(self.doc.to_emp),
raise Exception cstr(self.doc.to_designation), self.doc.name))
else: auth_exists = exists and exists[0][0] or ''
msgprint("Duplicate Entry. Please check Authorization Rule : %s." % (auth_exists)) if auth_exists:
raise Exception if cint(exists[0][1]) == 2:
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=1)
# Validate Master Name def validate_master_name(self):
# --------------------- if self.doc.based_on == 'Customerwise Discount' and \
def validate_master_name(self): not sql("select name from tabCustomer where name = '%s' and docstatus != 2" % \
if self.doc.based_on == 'Customerwise Discount' and not sql("select name from tabCustomer where name = '%s' and docstatus != 2" % (self.doc.master_name)): (self.doc.master_name)):
msgprint("Please select valid Customer Name for Customerwise Discount.") msgprint("Please select valid Customer Name for Customerwise Discount",
raise Exception 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)): elif self.doc.based_on == 'Itemwise Discount' and \
msgprint("Please select valid Item Name for Itemwise Discount.") not sql("select name from tabItem where name = '%s' and docstatus != 2" % \
raise Exception (self.doc.master_name)):
elif (self.doc.based_on == 'Grand Total' or self.doc.based_on == 'Average Discount') and self.doc.master_name: msgprint("Please select valid Item Name for Itemwise Discount", raise_exception=1)
msgprint("Please remove Customer / Item Name for %s." % (self.doc.based_on)) elif (self.doc.based_on == 'Grand Total' or \
raise Exception 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 self.doc.transaction != 'Appraisal':
def validate_rule(self): if not self.doc.approving_role and not self.doc.approving_user:
if not self.doc.transaction == 'Expense Claim' and not self.doc.transaction == 'Appraisal': msgprint("Please enter Approving Role or Approving User", raise_exception=1)
if not self.doc.approving_role and not self.doc.approving_user: elif self.doc.system_user and self.doc.system_user == self.doc.approving_user:
msgprint("Please enter Approving Role or Approving User") msgprint("Approving User cannot be same as user the rule is Applicable To (User)",
raise Exception raise_exception=1)
elif self.doc.system_user and self.doc.system_user == self.doc.approving_user: elif self.doc.system_role and self.doc.system_role == self.doc.approving_role:
msgprint("Approving User cannot be same as user the rule is Applicable To (User).") msgprint("Approving Role cannot be same as user the rule is \
raise Exception Applicable To (Role).", raise_exception=1)
elif self.doc.system_role and self.doc.system_role == self.doc.approving_role: elif self.doc.system_user and self.doc.approving_role and \
msgprint("Approving Role cannot be same as user the rule is Applicable To (Role).") has_common([self.doc.approving_role], [x[0] for x in \
raise Exception sql("select role from `tabUserRole` where parent = '%s'" % \
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))]): (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)) msgprint("System User : %s is assigned role : %s. So rule does not make sense" %
raise Exception (self.doc.system_user,self.doc.approving_role), raise_exception=1)
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'): elif self.doc.transaction in ['Purchase Order', 'Purchase Receipt', \
msgprint("You cannot set authorization on basis of Discount for %s." % (self.doc.transaction)) 'Purchase Invoice', 'Stock Entry'] and self.doc.based_on \
raise Exception in ['Average Discount', 'Customerwise Discount', 'Itemwise Discount']:
elif self.doc.based_on == 'Average Discount' and flt(self.doc.value) > 100.00: msgprint("You cannot set authorization on basis of Discount for %s" %
msgprint("Discount cannot given for more than 100 %s." % ('%')) self.doc.transaction, raise_exception=1)
raise Exception elif self.doc.based_on == 'Average Discount' and flt(self.doc.value) > 100.00:
elif self.doc.based_on == 'Customerwise Discount' and not self.doc.master_name: msgprint("Discount cannot given for more than 100%", raise_exception=1)
msgprint("Please enter Customer Name for 'Customerwise Discount'") elif self.doc.based_on == 'Customerwise Discount' and not self.doc.master_name:
raise Exception msgprint("Please enter Customer Name for 'Customerwise Discount'",
else: raise_exception=1)
if self.doc.transaction == 'Appraisal' and self.doc.based_on != 'Not Applicable': else:
msgprint("Based on is 'Not Applicable' while setting authorization rule for 'Appraisal'") if self.doc.transaction == 'Appraisal' and self.doc.based_on != 'Not Applicable':
raise Exception msgprint("Based on should be 'Not Applicable' while setting authorization rule\
if self.doc.transaction == 'Expense Claim' and self.doc.based_on != 'Total Claimed Amount': for 'Appraisal'", raise_exception=1)
msgprint("Authorization rule should be based on 'Total Calimed Amount' while setting authorization rule for 'Expense Claim'")
raise Exception
def validate(self):
self.check_duplicate_entry() def validate(self):
self.validate_rule() self.check_duplicate_entry()
self.validate_master_name() self.validate_rule()
if not self.doc.value: self.doc.value = flt(0) self.validate_master_name()
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 "owner": "Administrator",
{ "docstatus": 0,
'creation': '2012-03-27 14:36:18', "creation": "2012-07-03 13:30:00",
'docstatus': 0, "modified_by": "Administrator",
'modified': '2012-03-27 14:36:18', "modified": "2012-12-12 10:42:42"
'modified_by': u'Administrator', },
'owner': u'Administrator' {
}, "autoname": "AR.####",
"name": "__common__",
# These values are common for all DocType "search_fields": "transaction,based_on,system_user,system_role,approving_user,approving_role",
{ "module": "Setup",
'_last_update': u'1308741898', "doctype": "DocType",
'allow_trash': 1, "document_type": "Master"
'autoname': u'AR.####', },
'colour': u'White:FFF', {
'doctype': 'DocType', "name": "__common__",
'document_type': u'Master', "parent": "Authorization Rule",
'module': u'Setup', "doctype": "DocField",
'name': '__common__', "parenttype": "DocType",
'search_fields': u'transaction,based_on,system_user,system_role,approving_user,approving_role', "permlevel": 0,
'section_style': u'Simple', "parentfield": "fields"
'server_code_error': u' ', },
'version': 58 {
}, "name": "__common__",
"parent": "Authorization Rule",
# These values are common for all DocField "read": 1,
{ "create": 1,
'doctype': u'DocField', "doctype": "DocPerm",
'name': '__common__', "write": 1,
'parent': u'Authorization Rule', "cancel": 1,
'parentfield': u'fields', "parenttype": "DocType",
'parenttype': u'DocType', "role": "System Manager",
'permlevel': 0 "permlevel": 0,
}, "parentfield": "permissions"
},
# These values are common for all DocPerm {
{ "name": "Authorization Rule",
'cancel': 1, "doctype": "DocType"
'create': 1, },
'doctype': u'DocPerm', {
'name': '__common__', "oldfieldtype": "Link",
'parent': u'Authorization Rule', "doctype": "DocField",
'parentfield': u'permissions', "label": "Company",
'parenttype': u'DocType', "oldfieldname": "company",
'permlevel': 0, "fieldname": "company",
'read': 1, "fieldtype": "Link",
'role': u'System Manager', "search_index": 0,
'write': 1 "reqd": 0,
}, "options": "Company"
},
# DocType, Authorization Rule {
{ "oldfieldtype": "Select",
'doctype': 'DocType', "doctype": "DocField",
'name': u'Authorization Rule' "label": "Transaction",
}, "oldfieldname": "transaction",
"fieldname": "transaction",
# DocPerm "fieldtype": "Select",
{ "reqd": 1,
'doctype': u'DocPerm' "options": "\nDelivery Note\nPurchase Invoice\nPurchase Order\nPurchase Receipt\nQuotation\nSales Invoice\nSales Order\nStock Entry\nAppraisal"
}, },
{
# DocPerm "oldfieldtype": "Select",
{ "doctype": "DocField",
'doctype': u'DocPerm' "label": "Based On",
}, "oldfieldname": "based_on",
"fieldname": "based_on",
# DocField "fieldtype": "Select",
{ "reqd": 1,
'doctype': u'DocField', "options": "\nGrand Total\nAverage Discount\nCustomerwise Discount\nItemwise Discount\nNot Applicable"
'fieldname': u'company', },
'fieldtype': u'Link', {
'label': u'Company', "oldfieldtype": "Link",
'oldfieldname': u'company', "doctype": "DocField",
'oldfieldtype': u'Link', "label": "Customer / Item Name",
'options': u'Company', "oldfieldname": "master_name",
'reqd': 0, "fieldname": "master_name",
'search_index': 0 "fieldtype": "Link",
}, "options": "[Select]"
},
# DocField {
{ "oldfieldtype": "Link",
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'transaction', "label": "Applicable To (Role)",
'fieldtype': u'Select', "oldfieldname": "system_role",
'label': u'Transaction', "fieldname": "system_role",
'oldfieldname': u'transaction', "fieldtype": "Link",
'oldfieldtype': u'Select', "options": "Role"
'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",
# DocField "label": "Applicable To (User)",
{ "oldfieldname": "system_user",
'doctype': u'DocField', "fieldname": "system_user",
'fieldname': u'based_on', "fieldtype": "Link",
'fieldtype': u'Select', "options": "Profile"
'label': u'Based On', },
'oldfieldname': u'based_on', {
'oldfieldtype': u'Select', "description": "This will be used for setting rule in HR module",
'options': u'\nGrand Total\nAverage Discount\nCustomerwise Discount\nItemwise Discount\nTotal Claimed Amount\nNot Applicable', "oldfieldtype": "Link",
'reqd': 1, "doctype": "DocField",
'trigger': u'Client' "label": "Applicable To (Employee)",
}, "oldfieldname": "to_emp",
"fieldname": "to_emp",
# DocField "fieldtype": "Link",
{ "search_index": 0,
'doctype': u'DocField', "options": "Employee"
'fieldname': u'master_name', },
'fieldtype': u'Link', {
'label': u'Customer / Item Name', "description": "This will be used for setting rule in HR module",
'oldfieldname': u'master_name', "oldfieldtype": "Link",
'oldfieldtype': u'Link', "doctype": "DocField",
'trigger': u'Client' "label": "Applicable To (Designation)",
}, "oldfieldname": "to_designation",
"fieldname": "to_designation",
# DocField "fieldtype": "Link",
{ "search_index": 0,
'doctype': u'DocField', "options": "Designation"
'fieldname': u'system_role', },
'fieldtype': u'Link', {
'label': u'Applicable To (Role)', "oldfieldtype": "Link",
'oldfieldname': u'system_role', "doctype": "DocField",
'oldfieldtype': u'Link', "label": "Approving Role",
'options': u'Role' "oldfieldname": "approving_role",
}, "fieldname": "approving_role",
"fieldtype": "Link",
# DocField "options": "Role"
{ },
'colour': u'White:FFF', {
'doctype': u'DocField', "oldfieldtype": "Link",
'fieldname': u'system_user', "doctype": "DocField",
'fieldtype': u'Link', "label": "Approving User",
'label': u'Applicable To (User)', "oldfieldname": "approving_user",
'oldfieldname': u'system_user', "fieldname": "approving_user",
'oldfieldtype': u'Link', "fieldtype": "Link",
'options': u'Profile' "options": "Profile"
}, },
{
# DocField "default": "0.00",
{ "oldfieldtype": "Currency",
'colour': u'White:FFF', "doctype": "DocField",
'description': u'This will be used for setting rule in HR module', "label": "Above Value",
'doctype': u'DocField', "oldfieldname": "value",
'fieldname': u'to_emp', "fieldname": "value",
'fieldtype': u'Link', "fieldtype": "Currency"
'label': u'Applicable To (Employee)', },
'oldfieldname': u'to_emp', {
'oldfieldtype': u'Link', "oldfieldtype": "Small Text",
'options': u'Employee', "doctype": "DocField",
'search_index': 0 "label": "Trash Reason",
}, "oldfieldname": "trash_reason",
"fieldname": "trash_reason",
# DocField "fieldtype": "Small Text"
{ },
'colour': u'White:FFF', {
'description': u'This will be used for setting rule in HR module', "doctype": "DocPerm"
'doctype': u'DocField', },
'fieldname': u'to_designation', {
'fieldtype': u'Link', "doctype": "DocPerm"
'label': u'Applicable To (Designation)', }
'oldfieldname': u'to_designation',
'oldfieldtype': u'Link',
'options': u'Designation',
'search_index': 0
},
# 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'
},
# 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'
},
# DocField
{
'default': u'0.00',
'doctype': u'DocField',
'fieldname': u'value',
'fieldtype': u'Currency',
'label': u'Above Value',
'oldfieldname': u'value',
'oldfieldtype': u'Currency'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'trash_reason',
'fieldtype': u'Small Text',
'label': u'Trash Reason',
'oldfieldname': u'trash_reason',
'oldfieldtype': u'Small Text'
}
] ]