Features Setting

1. Features Setting DocType
2. Startup.js will be added with a function which binds with refresh of doc
3. Startup.js contains the Features dictionary
This commit is contained in:
Brahma K 2011-08-25 16:20:16 +05:30
parent db87672d47
commit 29d5549bde
10 changed files with 33 additions and 435 deletions

View File

@ -1,54 +0,0 @@
$.extend(cur_frm.cscript, {
Generate: function(doc, dt, dn) {
cur_frm.cscript.clear_installments(doc);
for(var i=0; i< doc.no_of_installments; i++) {
d = LocalDB.add_child(doc, 'Loan Installment', 'installments');
d.amount = doc.loan_amount / doc.no_of_installments;
d.due_date = dateutil.add_months(doc.start_date, i+1);
}
cur_frm.refresh();
},
/* submit:function(doc){
data=doc.get_values();
data['']=
$c_obj(make_doclist(dt,dn),'loan_post',data,function(){});
},*/
refresh: function(doc) {
cur_frm.cscript.hide_show_buttons(doc);
},
hide_show_buttons: function(doc) {
if(doc.docstatus==0) {
hide_field('Installment Reciept'); unhide_field('Generate');
} else if (doc.docstatus==1) {
unhide_field('Installment Reciept');hide_field('Generate');
}
},
clear_installments: function(doc) {
$.each(getchildren('Loan Installment', doc.name, 'installments', 'Loan'),
function(i, d) {
LocalDB.delete_doc('Loan Installment', d.name);
}
)
},
'Installment Reciept': function(doc, dt, dn) {
var d = new wn.widgets.Dialog({
width: 500,
title: 'Add a new payment installment',
fields: [
{fieldtype:'Data', label:'Cheque Number', fieldname:'cheque_number', reqd:1},
{fieldtype:'Date', label:'Cheque Date', fieldname:'cheque_date', reqd:1},
{fieldtype:'Link', label:'Bank Account', fieldname:'bank_account', reqd:1, options:'Account'},
{fieldtype:'Button', label:'Update',fieldname:'update'}
]
})
d.show();
d.fields_dict.update.input.onclick = function() {
var data = d.get_values();
if(data) {
$c_obj(make_doclist(dt,dn),'loan_installment_post',data,function(){cur_frm.refresh(); d.hide();});
}
}
}
})

View File

@ -1,48 +0,0 @@
import webnotes
from webnotes.model.doc import make_autoname, Document, addchild
from webnotes import msgprint
from webnotes.utils import get_defaults
import json
from accounts.utils import post_jv
sql = webnotes.conn.sql
class DocType:
def __init__(self, doc, doclist):
self.doc, self.doclist = doc, doclist
def autoname(self):
"""
Create Loan Id using naming_series pattern
"""
self.doc.name = make_autoname(self.doc.naming_series+ '.#####')
def loan_post(self):
data['voucher_type']='Loan Issue'
data['naming_series']='JV'
data['fiscal_year'] = get_defaults()['fiscal_year'] # To be modified to take care
data['company'] = get_defaults()['company']
data['debit_account'] = self.doc['receivable_account']
data['credit_account'] = self.doc['account']
data['amount'] = self.doc.loan_amount
jv_name=post_jv(data)
def loan_installment_post(self, args):
"""
Posts the loan receipt into Journal Voucher
"""
next_inst = sql("select amount,name from `tabLoan Installment` where parent=%s and ifnull(cheque_number,'')='' order by due_date limit 1",self.doc.name)
data = json.loads(args)
data['voucher_type']='Loan Receipt'
data['naming_series']='JV'
data['amount']=next_inst[0][0]
data['debit_account']=data.get('bank_account')
data['credit_account']=self.doc.account
data['fiscal_year']=get_defaults()['fiscal_year']
data['company']=get_defaults()['company']
jv_name=post_jv(data)
sql("update `tabLoan Installment` set cheque_number=%s, cheque_date=%s, jv_number=%s where name=%s",(data.get('cheque_number'),data.get('cheque_date'),jv_name,next_inst[0][1]))
self.doclist = [Document(d.doctype, d.name) for d in self.doclist]

View File

@ -1,172 +0,0 @@
# DocType, Loan
[
# These values are common in all dictionaries
{
'creation': '2011-07-15 10:35:26',
'docstatus': 0,
'modified': '2011-07-18 12:12:19',
'modified_by': 'Administrator',
'owner': 'Administrator'
},
# These values are common for all DocType
{
'_last_update': '1310963215',
'colour': 'White:FFF',
'doctype': 'DocType',
'module': 'Accounts',
'name': '__common__',
'section_style': 'Simple',
'show_in_menu': 0,
'version': 15
},
# These values are common for all DocField
{
'doctype': 'DocField',
'name': '__common__',
'parent': 'Loan',
'parentfield': 'fields',
'parenttype': 'DocType',
'permlevel': 0
},
# These values are common for all DocPerm
{
'doctype': 'DocPerm',
'name': '__common__',
'parent': 'Loan',
'parentfield': 'permissions',
'parenttype': 'DocType',
'read': 1,
'role': 'Accounts User'
},
# DocType, Loan
{
'doctype': 'DocType',
'name': 'Loan'
},
# DocPerm
{
'cancel': 1,
'create': 1,
'doctype': 'DocPerm',
'idx': 1,
'permlevel': 0,
'submit': 1,
'write': 1
},
# DocPerm
{
'doctype': 'DocPerm',
'idx': 2,
'permlevel': 1
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'naming_series',
'fieldtype': 'Select',
'idx': 1,
'label': 'Naming Series',
'options': '\nLOAN',
'reqd': 1
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'account',
'fieldtype': 'Link',
'idx': 2,
'label': 'Account',
'options': 'Account',
'reqd': 1
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'receivable_account',
'fieldtype': 'Link',
'idx': 3,
'label': 'Receivable Account',
'options': 'Account'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'invoice',
'fieldtype': 'Link',
'idx': 4,
'label': 'Invoice',
'options': 'Receivable Voucher',
'reqd': 1
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'loan_amount',
'fieldtype': 'Currency',
'idx': 5,
'label': 'Loan Amount',
'reqd': 1
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'start_date',
'fieldtype': 'Date',
'idx': 6,
'label': 'Start Date',
'reqd': 1
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'no_of_installments',
'fieldtype': 'Int',
'idx': 7,
'label': 'No of Installments',
'reqd': 1
},
# DocField
{
'colour': 'White:FFF',
'doctype': 'DocField',
'fieldtype': 'Button',
'idx': 8,
'label': 'Generate',
'trigger': 'Client'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'installments',
'fieldtype': 'Table',
'idx': 9,
'label': 'Installments',
'options': 'Loan Installment'
},
# DocField
{
'allow_on_submit': 1,
'colour': 'White:FFF',
'doctype': 'DocField',
'fieldtype': 'Button',
'idx': 10,
'label': 'Installment Reciept'
}
]

View File

@ -1,17 +0,0 @@
import unittest
import webnotes
from webnotes.model.code import get_obj
class TestScheduleGeneartion(unittest.TestCase):
def setUp(self):
webnotes.conn.begin()
# create a mock loan
self.loan = get_obj('Loan', 'LOAN00001')
def test_generation(self):
"test the genaration of loan installments"
self.loan.generate()
self.assertEqual(self.loan.get_installment_total(), self.loan.doc.loan_amount)
def tearDown(self):
webnotes.conn.rollback()

View File

@ -1,111 +0,0 @@
# DocType, Loan Installment
[
# These values are common in all dictionaries
{
'creation': '2011-07-15 10:36:42',
'docstatus': 0,
'modified': '2011-07-15 15:48:34',
'modified_by': 'Administrator',
'owner': 'Administrator'
},
# These values are common for all DocType
{
'colour': 'White:FFF',
'doctype': 'DocType',
'istable': 1,
'module': 'Accounts',
'name': '__common__',
'section_style': 'Simple',
'show_in_menu': 0,
'version': 4
},
# These values are common for all DocField
{
'doctype': 'DocField',
'name': '__common__',
'parent': 'Loan Installment',
'parentfield': 'fields',
'parenttype': 'DocType'
},
# DocType, Loan Installment
{
'doctype': 'DocType',
'name': 'Loan Installment'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'amount',
'fieldtype': 'Currency',
'idx': 1,
'label': 'Amount',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'due_date',
'fieldtype': 'Date',
'idx': 2,
'label': 'Due Date',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'cheque_number',
'fieldtype': 'Data',
'idx': 3,
'label': 'Cheque Number',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'cheque_date',
'fieldtype': 'Date',
'idx': 4,
'label': 'Cheque Date',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'deposit_date',
'fieldtype': 'Date',
'idx': 5,
'label': 'Deposit Date',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'realized_date',
'fieldtype': 'Date',
'idx': 6,
'label': 'Realized Date',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'jv_number',
'fieldtype': 'Link',
'hidden': 0,
'idx': 7,
'label': 'JV Number',
'options': 'Journal Voucher',
'permlevel': 1
}
]

View File

@ -18,10 +18,10 @@ cur_frm.cscript.onload = function(doc,dt,dn) {
if(!doc.voucher_date) set_multiple(dt,dn,{voucher_date:get_today()});
if(!doc.due_date) set_multiple(dt,dn,{due_date:get_today()});
if(!doc.posting_date) set_multiple(dt,dn,{posting_date:get_today()});
//for previously created sales invoice, set required field related to pos
if(doc.is_pos ==1) cur_frm.cscript.is_pos(doc, dt, dn);
hide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']);
}
}
@ -37,10 +37,10 @@ cur_frm.cscript.onload_post_render = function(doc, dt, dn) {
}
);
}
if(!doc.customer && doc.__islocal) {
// new -- load default taxes
cur_frm.cscript.load_taxes(doc, cdt, cdn);
cur_frm.cscript.load_taxes(doc, cdt, cdn);
}
}
@ -61,19 +61,19 @@ cur_frm.cscript.refresh = function(doc, dt, dn) {
// Show / Hide button
cur_frm.clear_custom_buttons();
if(doc.docstatus==1) {
if(doc.docstatus==1) {
cur_frm.add_custom_button('View Ledger', cur_frm.cscript['View Ledger Entry']);
cur_frm.add_custom_button('Send SMS', cur_frm.cscript['Send SMS']);
unhide_field('Repair Outstanding Amt');
if(doc.is_pos==1 && doc.update_stock!=1)
cur_frm.add_custom_button('Make Delivery', cur_frm.cscript['Make Delivery Note']);
if(doc.outstanding_amount!=0)
cur_frm.add_custom_button('Make Payment Entry', cur_frm.cscript['Make Bank Voucher']);
}
else
else
hide_field('Repair Outstanding Amt');
cur_frm.cscript.is_opening(doc, dt, dn);
cur_frm.cscript.hide_fields(doc, cdt, cdn);
@ -117,13 +117,13 @@ cur_frm.cscript.customer = function(doc,dt,dn) {
var doc = locals[cur_frm.doctype][cur_frm.docname];
get_server_fields('get_debit_to','','',doc, dt, dn, 0);
cur_frm.refresh();
}
}
if(doc.customer) $c_obj(make_doclist(doc.doctype, doc.name), 'get_default_customer_address', '', callback);
if(doc.customer) $c_obj(make_doclist(doc.doctype, doc.name), 'get_default_customer_address', '', callback);
if(doc.customer) unhide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']);
}
cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {
cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {
if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
}
@ -152,15 +152,15 @@ cur_frm.cscript.debit_to = function(doc,dt,dn) {
var callback2 = function(r,rt) {
var doc = locals[cur_frm.doctype][cur_frm.docname];
cur_frm.refresh();
}
}
var callback = function(r,rt) {
var doc = locals[cur_frm.doctype][cur_frm.docname];
var doc = locals[cur_frm.doctype][cur_frm.docname];
if(doc.customer) $c_obj(make_doclist(dt,dn), 'get_default_customer_address', '', callback2);
if(doc.customer) unhide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']);
cur_frm.refresh();
}
if(doc.debit_to && doc.posting_date){
get_server_fields('get_cust_and_due_date','','',doc,dt,dn,1,callback);
}
@ -187,13 +187,13 @@ cur_frm.cscript.project_name = function(doc,cdt,cdn){
//Set debit and credit to zero on adding new row
//----------------------------------------------
cur_frm.fields_dict['entries'].grid.onrowadd = function(doc, cdt, cdn){
cl = getchildren('RV Detail', doc.name, cur_frm.cscript.fname, doc.doctype);
acc = '';
cc = '';
for(var i = 0; i<cl.length; i++) {
if (cl[i].idx == 1){
acc = cl[i].income_account;
cc = cl[i].cost_center;
@ -221,7 +221,7 @@ cur_frm.cscript.is_opening = function(doc, dt, dn) {
// Get Items based on SO or DN Selected
cur_frm.cscript['Get Items'] = function(doc, dt, dn) {
var callback = function(r,rt) {
var callback = function(r,rt) {
unhide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']);
cur_frm.refresh();
}
@ -335,10 +335,10 @@ cur_frm.fields_dict.sales_order_main.get_query = function(doc) {
// Delivery Note
// --------------
cur_frm.fields_dict.delivery_note_main.get_query = function(doc) {
if (doc.customer)
return 'SELECT DISTINCT `tabDelivery Note`.`name` FROM `tabDelivery Note` WHERE `tabDelivery Note`.company = "' + doc.company + '" and `tabDelivery Note`.`docstatus` = 1 and ifnull(`tabDelivery Note`.per_billed,0) < 100 and `tabDelivery Note`.`customer` = "' + doc.customer + '" and `tabDelivery Note`.%(key)s LIKE "%s" ORDER BY `tabDelivery Note`.`name` DESC LIMIT 50';
if (doc.customer)
return 'SELECT DISTINCT `tabDelivery Note`.`name` FROM `tabDelivery Note` WHERE `tabDelivery Note`.company = "' + doc.company + '" and `tabDelivery Note`.`docstatus` = 1 and ifnull(`tabDelivery Note`.per_billed,0) < 100 and `tabDelivery Note`.`customer` = "' + doc.customer + '" and `tabDelivery Note`.%(key)s LIKE "%s" ORDER BY `tabDelivery Note`.`name` DESC LIMIT 50';
else
return 'SELECT DISTINCT `tabDelivery Note`.`name` FROM `tabDelivery Note` WHERE `tabDelivery Note`.company = "' + doc.company + '" and `tabDelivery Note`.`docstatus` = 1 and ifnull(`tabDelivery Note`.per_billed,0) < 100 and `tabDelivery Note`.%(key)s LIKE "%s" ORDER BY `tabDelivery Note`.`name` DESC LIMIT 50';
return 'SELECT DISTINCT `tabDelivery Note`.`name` FROM `tabDelivery Note` WHERE `tabDelivery Note`.company = "' + doc.company + '" and `tabDelivery Note`.`docstatus` = 1 and ifnull(`tabDelivery Note`.per_billed,0) < 100 and `tabDelivery Note`.%(key)s LIKE "%s" ORDER BY `tabDelivery Note`.`name` DESC LIMIT 50';
}
@ -393,18 +393,18 @@ cur_frm.cscript.make_jv = function(doc, dt, dn) {
jv.company = doc.company;
jv.remark = repl('Payment received against invoice %(vn)s for %(rem)s', {vn:doc.name, rem:doc.remarks});
jv.fiscal_year = doc.fiscal_year;
// debit to creditor
var d1 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries');
d1.account = doc.debit_to;
d1.credit = doc.outstanding_amount;
d1.against_invoice = doc.name;
// credit to bank
var d1 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries');
d1.debit = doc.outstanding_amount;
loaddoc('Journal Voucher', jv.name);
}

View File

@ -13,7 +13,7 @@ sql = webnotes.conn.sql
get_value = webnotes.conn.get_value
in_transaction = webnotes.conn.in_transaction
convert_to_lists = webnotes.conn.convert_to_lists
# -----------------------------------------------------------------------------------------
@ -21,7 +21,7 @@ class DocType:
def __init__(self, doc, doclist=[]):
self.doc = doc
self.doclist = doclist
# Autoname
def autoname(self):
p = self.doc.fiscal_year
@ -35,7 +35,7 @@ class DocType:
'default_bom' : item and item[0]['default_bom'] or ''
}
return ret
def validate(self):
if not self.doc.production_item :
msgprint("Please enter Production Item")
@ -62,7 +62,7 @@ class DocType:
if flt(bom_detail[0]['docstatus']) != 1:
msgprint("BOM := '%s' is not Submitted BOM." % self.doc.bom_no)
raise Exception
def update_status(self, status):
# Set Status
if status == 'Stopped':
@ -78,7 +78,7 @@ class DocType:
# Update Planned Qty of Production Item
qty = (flt(self.doc.qty) - flt(self.doc.produced_qty)) * ((status == 'Stopped') and -1 or 1)
get_obj('Warehouse', self.doc.fg_warehouse).update_bin(0, 0, 0, 0, flt(qty), self.doc.production_item, now())
# Acknowledge user
msgprint(self.doc.doctype + ": " + self.doc.name + " has been %s and status has been updated as %s." % (cstr(status), cstr(self.doc.status)))
@ -99,6 +99,6 @@ class DocType:
# Set Status AS "Submitted"
set(self.doc,'status', 'Cancelled')
# decrease Planned Qty of Prooduction Item by Qty
get_obj('Warehouse', self.doc.fg_warehouse).update_bin(0, 0, 0, 0,-flt(self.doc.qty), self.doc.production_item, now())

View File

@ -28,7 +28,7 @@ cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) {
if(doc.quotation) cur_frm.cscript['Pull Quotation Details'](doc,cdt,cdn);
} else {
cur_frm.cscript.load_taxes(doc, cdt, cdn);
}
}
}
// Refresh
@ -70,7 +70,7 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
} else {
hide_field(['Repair Sales Order', 'Send SMS', 'message', 'customer_mobile_no'])
}
pscript.apply_feature_settings();
}
//customer