restructured erpnext and deleted unwanted

This commit is contained in:
nabinhait
2011-07-01 13:34:41 +05:30
parent c1c54c9400
commit ec097975d0
1280 changed files with 54494 additions and 88652 deletions

View File

View File

@@ -0,0 +1,153 @@
$import(Contact Control)
cur_frm.cscript.onload = function(doc,dt,dn){
// history doctypes and scripts
cur_frm.history_dict = {
'Purchase Order' : 'cur_frm.cscript.make_po_list(this.body, this.doc)',
'Purchase Receipt' : 'cur_frm.cscript.make_pr_list(this.body, this.doc)',
'Purchase Invoice' : 'cur_frm.cscript.make_pi_list(this.body, this.doc)'
}
// make contact, history list body
//cur_frm.cscript.make_cl_body();
cur_frm.cscript.make_hl_body();
}
cur_frm.cscript.refresh = function(doc,dt,dn) {
if(sys_defaults.supp_master_name == 'Supplier Name')
hide_field('naming_series');
else
unhide_field('naming_series');
if(doc.__islocal){
hide_field(['Address HTML','Contact HTML']);
//if(doc.country) cur_frm.cscript.get_states(doc,dt,dn);
// set message
//cur_frm.cscript.set_cl_msg(doc);
//cur_frm.cscript.set_hl_msg(doc);
}
else{
unhide_field(['Address HTML','Contact HTML']);
// make lists
cur_frm.cscript.make_address(doc,dt,dn);
cur_frm.cscript.make_contact(doc,dt,dn);
cur_frm.cscript.make_history(doc,dt,dn);
}
}
cur_frm.cscript.make_address = function() {
if(!cur_frm.address_list) {
cur_frm.address_list = new wn.widgets.Listing({
parent: cur_frm.fields_dict['Address HTML'].wrapper,
page_length: 2,
new_doctype: "Address",
new_doc_onload: function(dn) {
ndoc = locals["Address"][dn];
ndoc.supplier = cur_frm.doc.name;
ndoc.supplier_name = cur_frm.doc.supplier_name;
ndoc.address_type = 'Office';
},
new_doc_onsave: function(dn) {
cur_frm.address_list.run()
},
get_query: function() {
return "select name, address_type, address_line1, address_line2, city, state, country, pincode, fax, email_id, phone, is_primary_address, is_shipping_address from tabAddress where supplier='"+cur_frm.docname+"' and docstatus != 2 order by is_primary_address desc"
},
as_dict: 1,
no_results_message: 'No addresses created',
render_row: function(wrapper, data) {
$(wrapper).css('padding','5px 0px');
var link = $ln(wrapper,cstr(data.name), function() { loaddoc("Address", this.dn); }, {fontWeight:'bold'});
link.dn = data.name
$a(wrapper,'span','',{marginLeft:'5px', color: '#666'},(data.is_primary_address ? '[Primary]' : '') + (data.is_shipping_address ? '[Shipping]' : ''));
$a(wrapper,'div','',{marginTop:'5px', color:'#555'},
(data.address_line1 ? data.address_line1 + '<br />' : '') +
(data.address_line2 ? data.address_line2 + '<br />' : '') +
(data.city ? data.city + '<br />' : '') +
(data.state ? data.state + ', ' : '') +
(data.country ? data.country + '<br />' : '') +
(data.pincode ? 'Pincode: ' + data.pincode + '<br />' : '') +
(data.phone ? 'Phone: ' + data.phone + '<br />' : '') +
(data.fax ? 'Fax: ' + data.fax + '<br />' : '') +
(data.email_id ? 'Email: ' + data.email_id + '<br />' : ''));
}
});
}
cur_frm.address_list.run();
}
cur_frm.cscript.make_contact = function() {
if(!cur_frm.contact_list) {
cur_frm.contact_list = new wn.widgets.Listing({
parent: cur_frm.fields_dict['Contact HTML'].wrapper,
page_length: 2,
new_doctype: "Contact",
new_doc_onload: function(dn) {
ndoc = locals["Contact"][dn];
ndoc.supplier = cur_frm.doc.name;
ndoc.supplier_name = cur_frm.doc.supplier_name;
},
new_doc_onsave: function(dn) {
cur_frm.contact_list.run()
},
get_query: function() {
return "select name, first_name, last_name, email_id, phone, mobile_no, department, designation, is_primary_contact from tabContact where supplier='"+cur_frm.docname+"' and docstatus != 2 order by is_primary_contact desc"
},
as_dict: 1,
no_results_message: 'No contacts created',
render_row: function(wrapper, data) {
$(wrapper).css('padding', '5px 0px');
var link = $ln(wrapper, cstr(data.name), function() { loaddoc("Contact", this.dn); }, {fontWeight:'bold'});
link.dn = data.name
$a(wrapper,'span','',{marginLeft:'5px', color: '#666'},(data.is_primary_contact ? '[Primary]' : ''));
$a(wrapper,'div', '',{marginTop:'5px', color:'#555'}, data.first_name + (data.last_name ? ' ' + data.last_name + '<br />' : '<br>') + (data.phone ? 'Tel: ' + data.phone + '<br />' : '') + (data.mobile_no ? 'Mobile: ' + data.mobile_no + '<br />' : '') + (data.email_id ? 'Email: ' + data.email_id + '<br />' : '') + (data.department ? 'Department: ' + data.department + '<br />' : '') + (data.designation ? 'Designation: ' + data.designation + '<br />' : ''));
}
});
}
cur_frm.contact_list.run();
}
// make purchase order list
cur_frm.cscript.make_po_list = function(parent, doc){
var lst = new Listing();
lst.colwidths = ['5%','25%','20%','25%','25%'];
lst.colnames = ['Sr.','Id','Status','PO Date','Grand Total'];
lst.coltypes = ['Data','Link','Data','Data','Currency'];
lst.coloptions = ['','Purchase Order','','','',''];
var q = repl("select name,status,transaction_date, grand_total from `tabPurchase Order` where supplier='%(sup)s' order by transaction_date desc", {'sup':doc.name});
var q_max = repl("select count(name) from `tabPurchase Order` where supplier='%(sup)s'", {'sup':doc.name});
cur_frm.cscript.run_list(lst,parent,q,q_max,doc,'Purchase Order','Purchase Order');
}
// make purchase receipt list
cur_frm.cscript.make_pr_list = function(parent,doc){
var lst = new Listing();
lst.colwidths = ['5%','20%','20%','20%','15%','20%'];
lst.colnames = ['Sr.','Id','Status','Receipt Date','% Billed','Grand Total'];
lst.coltypes = ['Data','Link','Data','Data','Currency','Currency'];
lst.coloptions = ['','Purchase Receipt','','','',''];
var q = repl("select name,status,transaction_date,per_billed,grand_total from `tabPurchase Receipt` where supplier='%(sup)s' order by transaction_date desc", {'sup':doc.name});
var q_max = repl("select count(name) from `tabPurchase Receipt` where supplier='%(sup)s'", {'sup':doc.name});
cur_frm.cscript.run_list(lst,parent,q,q_max,doc,'Purchase Receipt','Purchase Receipt');
}
// make purchase invoice list
cur_frm.cscript.make_pi_list = function(parent,doc){
var lst = new Listing();
lst.colwidths = ['5%','20%','20%','20%','15%','20%'];
lst.colnames = ['Sr.','Id','Posting Date','Credit To','Bill Date','Grand Total'];
lst.coltypes = ['Data','Link','Data','Data','Currency','Currency'];
lst.coloptions = ['','Payable Voucher','','','',''];
var q = repl("select name, posting_date, credit_to, bill_date, grand_total from `tabPayable Voucher` where supplier='%(sup)s' order by posting_date desc", {'sup':doc.name});
var q_max = repl("select count(name) from `tabPayable Voucher` where supplier='%(sup)s'", {'sup':doc.name});
cur_frm.cscript.run_list(lst,parent,q,q_max,doc,'Purchase Invoice','Payable Voucher');
}

View File

@@ -0,0 +1,148 @@
# Please edit this list and import only required elements
import webnotes
from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
from webnotes.model import db_exists
from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType
from webnotes.model.doclist import getlist, copy_doclist
from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
from webnotes import session, form, is_testing, msgprint, errprint
set = webnotes.conn.set
sql = webnotes.conn.sql
get_value = webnotes.conn.get_value
in_transaction = webnotes.conn.in_transaction
convert_to_lists = webnotes.conn.convert_to_lists
# -----------------------------------------------------------------------------------------
class DocType:
def __init__(self, doc, doclist=[]):
self.doc = doc
self.doclist = doclist
def autoname(self):
#get default naming conventional from control panel
supp_master_name = get_defaults()['supp_master_name']
if supp_master_name == 'Supplier Name':
# filter out bad characters in name
#supp = self.doc.supplier_name.replace('&','and').replace('.','').replace("'",'').replace('"','').replace(',','').replace('`','')
supp = self.doc.supplier_name
cust = sql("select name from `tabCustomer` where name = '%s'" % (supp))
cust = cust and cust[0][0] or ''
if cust:
msgprint("You already have a Customer with same name")
raise Exception
self.doc.name = supp
else:
self.doc.name = make_autoname(self.doc.naming_series+'.#####')
# ----------------------------------------
# update credit days and limit in account
# ----------------------------------------
def update_credit_days_limit(self):
sql("update tabAccount set credit_days = '%s' where name = '%s'" % (self.doc.credit_days, self.doc.name + " - " + self.get_company_abbr()))
def on_update(self):
if not self.doc.naming_series:
self.doc.naming_series = ''
# create address
addr_flds = [self.doc.address_line1, self.doc.address_line2, self.doc.city, self.doc.state, self.doc.country, self.doc.pincode]
address_line = "\n".join(filter(lambda x : (x!='' and x!=None),addr_flds))
set(self.doc,'address', address_line)
# create account head
self.create_account_head()
# update credit days and limit in account
self.update_credit_days_limit()
def check_state(self):
return "\n" + "\n".join([i[0] for i in sql("select state_name from `tabState` where `tabState`.country='%s' " % self.doc.country)])
# ACCOUNTS
# -------------------------------------------
def get_payables_group(self):
g = sql("select payables_group from tabCompany where name=%s", self.doc.company)
g = g and g[0][0] or ''
if not g:
msgprint("Update Company master, assign a default group for Payables")
raise Exception
return g
def add_account(self, ac, par, abbr):
arg = {'account_name':ac,'parent_account':par, 'group_or_ledger':'Group', 'company':self.doc.company,'account_type':'','tax_rate':'0'}
t = get_obj('GL Control').add_ac(cstr(arg))
msgprint("Created Group " + t)
def get_company_abbr(self):
return sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0]
def get_parent_account(self, abbr):
if (not self.doc.supplier_type):
msgprint("Supplier Type is mandatory")
raise Exception
if not sql("select name from tabAccount where name=%s", (self.doc.supplier_type + " - " + abbr)):
# if not group created , create it
self.add_account(self.doc.supplier_type, self.get_payables_group(), abbr)
return self.doc.supplier_type + " - " + abbr
def validate(self):
#validation for Naming Series mandatory field...
if get_defaults()['supp_master_name'] == 'Naming Series':
if not self.doc.naming_series:
msgprint("Series is Mandatory.")
raise Exception
# create accont head - in tree under zone + territory
# -------------------------------------------------------
def create_account_head(self):
if self.doc.company :
abbr = self.get_company_abbr()
if not sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)):
parent_account = self.get_parent_account(abbr)
arg = {'account_name':self.doc.name,'parent_account': parent_account, 'group_or_ledger':'Ledger', 'company':self.doc.company,'account_type':'','tax_rate':'0','master_type':'Supplier','master_name':self.doc.name,'address':self.doc.address}
# create
ac = get_obj('GL Control').add_ac(cstr(arg))
msgprint("Created Account Head: "+ac)
else :
msgprint("Please select Company under which you want to create account head")
def get_contacts(self,nm):
if nm:
contact_details =convert_to_lists(sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = '%s'"%nm))
return contact_details
else:
return ''
def delete_supplier_address(self):
for rec in sql("select * from `tabAddress` where supplier='%s'" %(self.doc.name), as_dict=1):
sql("delete from `tabAddress` where name=%s",(rec['name']))
def delete_supplier_contact(self):
for rec in sql("select * from `tabContact` where supplier='%s'" %(self.doc.name), as_dict=1):
sql("delete from `tabContact` where name=%s",(rec['name']))
def on_trash(self):
self.delete_supplier_address()
self.delete_supplier_contact()

View File

@@ -0,0 +1,349 @@
# DocType, Supplier
[
# These values are common in all dictionaries
{
'creation': '2010-08-08 17:09:26',
'docstatus': 0,
'modified': '2011-05-10 17:42:21',
'modified_by': 'Administrator',
'owner': 'Administrator'
},
# These values are common for all DocType
{
'_last_update': '1306471021',
'allow_trash': 1,
'colour': 'White:FFF',
'doctype': 'DocType',
'document_type': 'Master',
'module': 'Buying',
'name': '__common__',
'search_fields': 'supplier_name,supplier_type',
'section_style': 'Tabbed',
'server_code_error': ' ',
'show_in_menu': 0,
'subject': ' ',
'tag_fields': 'supplier_type',
'version': 86
},
# These values are common for all DocField
{
'doctype': 'DocField',
'name': '__common__',
'parent': 'Supplier',
'parentfield': 'fields',
'parenttype': 'DocType'
},
# These values are common for all DocPerm
{
'doctype': 'DocPerm',
'name': '__common__',
'parent': 'Supplier',
'parentfield': 'permissions',
'parenttype': 'DocType',
'read': 1
},
# DocType, Supplier
{
'doctype': 'DocType',
'name': 'Supplier'
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': 'DocPerm',
'idx': 1,
'permlevel': 1,
'role': 'Purchase Manager',
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': 'DocPerm',
'idx': 2,
'permlevel': 0,
'role': 'Purchase Manager',
'submit': 0,
'write': 0
},
# DocPerm
{
'doctype': 'DocPerm',
'idx': 3,
'permlevel': 1,
'role': 'Purchase Master Manager'
},
# DocPerm
{
'amend': 0,
'cancel': 1,
'create': 1,
'doctype': 'DocPerm',
'idx': 4,
'permlevel': 0,
'role': 'Purchase Master Manager',
'submit': 0,
'write': 1
},
# DocField
{
'colour': 'White:FFF',
'description': 'Note: You Can Manage Multiple Address or Contacts via Addresses & Contacts',
'doctype': 'DocField',
'fieldtype': 'Section Break',
'idx': 1,
'label': 'Basic Info',
'oldfieldtype': 'Section Break',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'supplier_name',
'fieldtype': 'Data',
'idx': 2,
'label': 'Supplier Name',
'no_copy': 1,
'oldfieldname': 'supplier_name',
'oldfieldtype': 'Data',
'permlevel': 0,
'reqd': 1
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'supplier_type',
'fieldtype': 'Link',
'idx': 3,
'label': 'Supplier Type',
'oldfieldname': 'supplier_type',
'oldfieldtype': 'Link',
'options': 'Supplier Type',
'permlevel': 0,
'reqd': 1
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 4,
'permlevel': 0,
'width': '50%'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'naming_series',
'fieldtype': 'Select',
'idx': 5,
'label': 'Series',
'no_copy': 1,
'oldfieldname': 'naming_series',
'oldfieldtype': 'Select',
'options': '\nSUPP\nSUPP/10-11/',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'supplier_status',
'fieldtype': 'Select',
'idx': 6,
'label': 'Supplier Status',
'oldfieldname': 'supplier_status',
'oldfieldtype': 'Select',
'options': '\nApproved\nUnapproved',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Section Break',
'idx': 7,
'label': 'Address & Contacts',
'oldfieldtype': 'Column Break',
'permlevel': 0
},
# DocField
{
'colour': 'White:FFF',
'depends_on': 'eval:doc.__islocal',
'doctype': 'DocField',
'fieldtype': 'HTML',
'idx': 8,
'label': 'Address Desc',
'options': '<em>Addresses will appear only when you save the supplier</em>',
'permlevel': 0
},
# DocField
{
'colour': 'White:FFF',
'doctype': 'DocField',
'fieldtype': 'HTML',
'idx': 9,
'label': 'Address HTML',
'permlevel': 1
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 10,
'permlevel': 0,
'width': '50%'
},
# DocField
{
'colour': 'White:FFF',
'depends_on': 'eval:doc.__islocal',
'doctype': 'DocField',
'fieldtype': 'HTML',
'idx': 11,
'label': 'Contact Desc',
'options': '<em>Contact Details will appear only when you save the supplier</em>',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'HTML',
'idx': 12,
'label': 'Contact HTML',
'permlevel': 1
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Section Break',
'idx': 13,
'label': 'More Info',
'oldfieldtype': 'Section Break',
'permlevel': 0
},
# DocField
{
'colour': 'White:FFF',
'description': 'Enter the company name under which Account Head will be created for this Supplier',
'doctype': 'DocField',
'fieldname': 'company',
'fieldtype': 'Link',
'idx': 14,
'in_filter': 1,
'label': 'Company',
'oldfieldname': 'company',
'oldfieldtype': 'Link',
'options': 'Company',
'permlevel': 0,
'reqd': 1,
'search_index': 1
},
# DocField
{
'colour': 'White:FFF',
'description': 'Statutory info and other general information about your Supplier',
'doctype': 'DocField',
'fieldname': 'supplier_details',
'fieldtype': 'Text',
'idx': 15,
'label': 'Supplier Details',
'oldfieldname': 'supplier_details',
'oldfieldtype': 'Code',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 16,
'permlevel': 0,
'width': '50%'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'credit_days',
'fieldtype': 'Int',
'idx': 17,
'label': 'Credit Days',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'website',
'fieldtype': 'Data',
'idx': 18,
'label': 'Website',
'oldfieldname': 'website',
'oldfieldtype': 'Data',
'permlevel': 0
},
# DocField
{
'colour': 'White:FFF',
'depends_on': 'eval:!doc.__islocal',
'doctype': 'DocField',
'fieldtype': 'Section Break',
'idx': 19,
'label': 'Transaction History',
'oldfieldtype': 'Section Break',
'permlevel': 0
},
# DocField
{
'colour': 'White:FFF',
'depends_on': 'eval:!doc.__islocal',
'doctype': 'DocField',
'fieldtype': 'HTML',
'idx': 20,
'label': 'History HTML',
'oldfieldtype': 'HTML',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'trash_reason',
'fieldtype': 'Small Text',
'idx': 21,
'label': 'Trash Reason',
'oldfieldname': 'trash_reason',
'oldfieldtype': 'Small Text',
'permlevel': 1
}
]