Lease Agreement
Used by leasing and loan agents (i.e. Automobile leasing etc) for receipt follow up and reporting Account Transactions Upload Uploads transactions from a csv files, creates Journal Vouchers and submits
This commit is contained in:
parent
8a76466d7c
commit
d7db2ea20f
0
accounts/doctype/lease_agreement/__init__.py
Normal file
0
accounts/doctype/lease_agreement/__init__.py
Normal file
66
accounts/doctype/lease_agreement/lease_agreement.js
Normal file
66
accounts/doctype/lease_agreement/lease_agreement.js
Normal file
@ -0,0 +1,66 @@
|
||||
$.extend(cur_frm.cscript, {
|
||||
Generate: function(doc, dt, dn) {
|
||||
cur_frm.cscript.clear_installments(doc);
|
||||
tot=0;i=0;
|
||||
while(tot<flt(doc.invoice_amount)-flt(doc.down_payment)){
|
||||
d = LocalDB.add_child(doc, 'Lease Installment', 'installments');
|
||||
d.amount = flt(doc.installment_amount) < flt(doc.invoice_amount)-flt(doc.down_payment)-tot ? flt(doc.installment_amount) : flt(doc.invoice_amount)-flt(doc.down_payment)-tot
|
||||
d.due_date = dateutil.add_months(doc.start_date, i+1);
|
||||
tot += flt(doc.installment_amount)
|
||||
i++;
|
||||
}
|
||||
cur_frm.refresh();
|
||||
},
|
||||
refresh: function(doc) {
|
||||
cur_frm.cscript.hide_show_buttons(doc);
|
||||
},
|
||||
hide_show_buttons: function(doc) {
|
||||
if(doc.docstatus==0) {
|
||||
hide_field('Installment Reciept'); show_field('Generate');
|
||||
} else if (doc.docstatus==1) {
|
||||
show_field('Installment Reciept');hide_field('Generate');
|
||||
}
|
||||
},
|
||||
clear_installments: function(doc) {
|
||||
$.each(getchildren('Lease Installment', doc.name, 'installments', 'Lease Agreement'),
|
||||
function(i, d) {
|
||||
LocalDB.delete_doc('Lease Installment', d.name);
|
||||
}
|
||||
)
|
||||
},
|
||||
no_of_installments: function(doc)
|
||||
{
|
||||
if(flt(doc.no_of_installments)!=0) {
|
||||
doc.installment_amount = (flt(doc.invoice_amount)- flt(doc.down_payment))/flt(doc.no_of_installments);
|
||||
refresh_field('installment_amount');
|
||||
}
|
||||
},
|
||||
'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),'lease_installment_post',data,function(){cur_frm.refresh(); d.hide();});
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
cur_frm.add_fetch('invoice','grand_total','invoice_amount');
|
||||
|
||||
cur_frm.fields_dict.invoice.get_query=function(doc){
|
||||
|
||||
return "SELECT tv.name FROM `tabReceivable Voucher` tv WHERE debit_to='"+doc.account+"' and tv.%(key)s like '%s' ORDER BY tv.name LIMIT 50"
|
||||
}
|
37
accounts/doctype/lease_agreement/lease_agreement.py
Normal file
37
accounts/doctype/lease_agreement/lease_agreement.py
Normal file
@ -0,0 +1,37 @@
|
||||
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 Lease Id using naming_series pattern
|
||||
"""
|
||||
self.doc.name = make_autoname(self.doc.naming_series+ '.#####')
|
||||
|
||||
def lease_installment_post(self, args):
|
||||
"""
|
||||
Posts the Installment receipt into Journal Voucher
|
||||
"""
|
||||
next_inst = sql("select amount,name from `tabLease Installment` where parent=%s and ifnull(cheque_number,'')='' order by due_date limit 1",self.doc.name)
|
||||
|
||||
data = json.loads(args)
|
||||
data['voucher_type']='Lease 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 `tabLease 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]
|
0
accounts/doctype/lease_installment/__init__.py
Normal file
0
accounts/doctype/lease_installment/__init__.py
Normal file
27
accounts/utils/__init__.py
Normal file
27
accounts/utils/__init__.py
Normal file
@ -0,0 +1,27 @@
|
||||
from webnotes.model.doc import make_autoname, Document, addchild
|
||||
# Posts JV
|
||||
|
||||
def post_jv(data):
|
||||
jv = Document('Journal Voucher')
|
||||
jv.voucher_type = data.get('voucher_type')
|
||||
jv.naming_series = data.get('naming_series')
|
||||
jv.voucher_date = data.get('cheque_date')
|
||||
jv.posting_date = data.get('cheque_date')
|
||||
jv.cheque_no = data.get('cheque_number')
|
||||
jv.cheque_date = data.get('cheque_date')
|
||||
jv.fiscal_year = data.get('fiscal_year') # To be modified to take care
|
||||
jv.company = data.get('company')
|
||||
|
||||
jv.save(1)
|
||||
|
||||
jc = addchild(jv,'entries','Journal Voucher Detail',0)
|
||||
jc.account = data.get('debit_account')
|
||||
jc.debit = data.get('amount')
|
||||
jc.save()
|
||||
|
||||
jc = addchild(jv,'entries','Journal Voucher Detail',0)
|
||||
jc.account = data.get('credit_account')
|
||||
jc.credit = data.get('amount')
|
||||
jc.save()
|
||||
|
||||
return jv.name
|
@ -0,0 +1,18 @@
|
||||
|
||||
//--------- ONLOAD -------------
|
||||
cur_frm.cscript.onload = function(doc, cdt, cdn) {
|
||||
}
|
||||
|
||||
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
||||
if(!doc.file_list) {
|
||||
set_field_options('Upload Accounts Transactions Help', '<div class="help_box">To upload transactions, please attach a (.csv) file with 5 columns - <b>Date, Transaction Number, Account, Debit Amount, Credit Amount</b> (no headings necessary). See attachments box in the right column</div>')
|
||||
} else {
|
||||
set_field_options('Upload Accounts Transactions Help', '<div class="help_box">To update transactions from the attachment, please click on "Upload Accounts Transactions"</div>')
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript['Upload Accounts Transactions'] = function(doc, cdt, cdn) {
|
||||
if(confirm("This action will append all transactions and cannot be un-done. Are you sure you want to continue?")) {
|
||||
$c_obj([doc], 'upload_accounts_transactions', '', function(r, rt) { });
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
# 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, d, dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
self.cl = []
|
||||
|
||||
# upload transactions
|
||||
def upload_accounts_transactions(self):
|
||||
import csv
|
||||
data = csv.reader(self.get_csv_data().splitlines())
|
||||
|
||||
abbr = sql("select concat(' - ',abbr) as abbr from tabCompany where name=%s",self.doc.company)
|
||||
updated = 0
|
||||
jv_name=''
|
||||
# jv = Document('Journal Voucher')
|
||||
global line,jv,name,jv_go
|
||||
for line in data:
|
||||
if len(line)>=7: #Minimum no of fields
|
||||
if line[3]!=jv_name: #Create JV
|
||||
if jv_name!='':
|
||||
jv_go = get_obj('Journal Voucher',name, with_children=1)
|
||||
jv_go.validate()
|
||||
jv_go.on_submit()
|
||||
|
||||
jv_name=line[3]
|
||||
jv = Document('Journal Voucher')
|
||||
jv.voucher_type = line[0]
|
||||
jv.naming_series = line[1]
|
||||
jv.voucher_date = formatdate(line[2])
|
||||
jv.posting_date = formatdate(line[2])
|
||||
# jv.name = line[3]
|
||||
jv.fiscal_year = self.doc.fiscal_year
|
||||
jv.company = self.doc.company
|
||||
jv.remark = len(line)==8 and line[3]+' '+line[7] or line[3]+' Uploaded Record'
|
||||
jv.docstatus=1
|
||||
jv.save(1)
|
||||
name=jv.name
|
||||
|
||||
jc = addchild(jv,'entries','Journal Voucher Detail',0)
|
||||
jc.account = line[4]+abbr[0][0]
|
||||
jc.cost_center=len(line)==9 and line[8] or self.doc.default_cost_center
|
||||
if line[5]!='':
|
||||
jc.debit = line[5]
|
||||
else:
|
||||
jc.credit = line[6]
|
||||
jc.save()
|
||||
|
||||
else: #Create JV Child
|
||||
jc = addchild(jv,'entries','Journal Voucher Detail',0)
|
||||
jc.account = line[4]+abbr[0][0]
|
||||
jc.cost_center=len(line)==9 and line[8] or self.doc.default_cost_center
|
||||
if line[5]!='':
|
||||
jc.debit = line[5]
|
||||
else:
|
||||
jc.credit = line[6]
|
||||
jc.save()
|
||||
else:
|
||||
msgprint("[Ignored] Incorrect format: %s" % str(line))
|
||||
if jv_name!='':
|
||||
jv_go = get_obj('Journal Voucher',name, with_children=1)
|
||||
jv_go.validate()
|
||||
jv_go.on_submit()
|
||||
|
||||
msgprint("<b>%s</b> items updated" % updated)
|
||||
|
||||
# clear prices
|
||||
def clear_prices(self):
|
||||
cnt = sql("select count(*) from `tabRef Rate Detail` where price_list_name = %s", self.doc.name)
|
||||
sql("delete from `tabRef Rate Detail` where price_list_name = %s", self.doc.name)
|
||||
msgprint("%s prices cleared" % cnt[0][0])
|
||||
|
||||
# Update CSV data
|
||||
def get_csv_data(self):
|
||||
if not self.doc.file_list:
|
||||
msgprint("File not attached!")
|
||||
raise Exception
|
||||
|
||||
fid = self.doc.file_list.split(',')[1]
|
||||
|
||||
from webnotes.utils import file_manager
|
||||
fn, content = file_manager.get_file(fid)
|
||||
|
||||
if not type(content) == str:
|
||||
content = content.tostring()
|
||||
|
||||
return content
|
Loading…
x
Reference in New Issue
Block a user