mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-20 21:49:18 +00:00
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:
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
|
||||
Reference in New Issue
Block a user