added voucher import tool

This commit is contained in:
Rushabh Mehta
2012-09-26 19:00:02 +05:30
parent 47ee285ff9
commit 55fd5f3ed6
16 changed files with 281 additions and 539 deletions

View File

@@ -1 +0,0 @@
from __future__ import unicode_literals

View File

@@ -1,94 +0,0 @@
// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
$.extend(cur_frm.cscript, {
Generate: function(doc, dt, dn) {
if(doc.installment_amount==''){
msgprint('Set Installment Amount before generating schedule');
return;
}
if(doc.no_of_installments==''){
msgprint('Set Number of Installments before generating schedule');
return;
}
if(doc.start_date==''){
msgprint('Set Start Date before generating schedule');
return;
}
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 `tabSales Invoice` tv WHERE debit_to='"+doc.account+"' and tv.%(key)s like '%s' ORDER BY tv.name LIMIT 50"
}

View File

@@ -1,54 +0,0 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
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]

View File

@@ -1,276 +0,0 @@
# DocType, Lease Agreement
[
# These values are common in all dictionaries
{
'creation': '2012-03-27 14:35:44',
'docstatus': 0,
'modified': '2012-03-27 14:35:44',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
# These values are common for all DocType
{
'_last_update': u'1311555967',
'colour': u'White:FFF',
'default_print_format': u'Standard',
'doctype': 'DocType',
'module': u'Accounts',
'name': '__common__',
'section_style': u'Simple',
'show_in_menu': 0,
'version': 24
},
# These values are common for all DocField
{
'doctype': u'DocField',
'name': '__common__',
'parent': u'Lease Agreement',
'parentfield': u'fields',
'parenttype': u'DocType'
},
# These values are common for all DocPerm
{
'create': 1,
'doctype': u'DocPerm',
'name': '__common__',
'parent': u'Lease Agreement',
'parentfield': u'permissions',
'parenttype': u'DocType',
'read': 1,
'role': u'Accounts Manager'
},
# DocType, Lease Agreement
{
'doctype': 'DocType',
'name': u'Lease Agreement'
},
# DocPerm
{
'amend': 1,
'cancel': 1,
'doctype': u'DocPerm',
'submit': 1,
'write': 1
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'doctype': u'DocPerm',
'submit': 0,
'write': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'naming_series',
'fieldtype': u'Select',
'label': u'Naming Series',
'no_copy': 1,
'options': u'\nLA',
'permlevel': 0,
'reqd': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'lessee_info',
'fieldtype': u'Section Break',
'label': u'Lessee Info.',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'account',
'fieldtype': u'Link',
'label': u'Account',
'options': u'Account',
'permlevel': 0,
'reqd': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'lessee_father',
'fieldtype': u'Data',
'label': u'Lessee Father',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'lessee_nic',
'fieldtype': u'Data',
'label': u'Lessee NIC',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'lessee_contact',
'fieldtype': u'Data',
'label': u'Lessee Contact',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'lessee_address',
'fieldtype': u'Text',
'label': u'Lessee Address',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'vehicle_info',
'fieldtype': u'Section Break',
'label': u'Vehicle Info.',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'model_no',
'fieldtype': u'Data',
'label': u'Model No',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'engine_no',
'fieldtype': u'Data',
'label': u'Engine No',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'chassis_no',
'fieldtype': u'Data',
'label': u'Chassis No',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'invoice_and_payment_info',
'fieldtype': u'Section Break',
'label': u'Invoice and Payment Info.',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'doctype': u'DocField',
'fieldname': u'invoice',
'fieldtype': u'Link',
'label': u'Invoice',
'options': u'Sales Invoice',
'permlevel': 0,
'reqd': 1,
'trigger': u'Client'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'invoice_amount',
'fieldtype': u'Currency',
'label': u'Invoice Amount',
'permlevel': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'down_payment',
'fieldtype': u'Currency',
'label': u'Down Payment',
'permlevel': 0,
'reqd': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'start_date',
'fieldtype': u'Date',
'label': u'Start Date',
'permlevel': 0,
'reqd': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'no_of_installments',
'fieldtype': u'Int',
'label': u'No of Installments',
'permlevel': 0,
'reqd': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'installment_amount',
'fieldtype': u'Currency',
'label': u'Installment Amount',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'doctype': u'DocField',
'fieldname': u'generate',
'fieldtype': u'Button',
'label': u'Generate',
'permlevel': 0,
'trigger': u'Client'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'installments',
'fieldtype': u'Table',
'label': u'Installments',
'options': u'Lease Installment',
'permlevel': 0
},
# DocField
{
'allow_on_submit': 1,
'colour': u'White:FFF',
'doctype': u'DocField',
'fieldname': u'installment_reciept',
'fieldtype': u'Button',
'label': u'Installment Reciept',
'permlevel': 0
}
]

View File

@@ -1 +0,0 @@
from __future__ import unicode_literals

View File

@@ -1,86 +0,0 @@
# DocType, Lease Installment
[
# These values are common in all dictionaries
{
'creation': '2012-03-27 14:35:44',
'docstatus': 0,
'modified': '2012-03-27 14:35:44',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
# These values are common for all DocType
{
'colour': u'White:FFF',
'doctype': 'DocType',
'istable': 1,
'module': u'Accounts',
'name': '__common__',
'section_style': u'Simple',
'show_in_menu': 0,
'version': 5
},
# These values are common for all DocField
{
'doctype': u'DocField',
'name': '__common__',
'parent': u'Lease Installment',
'parentfield': u'fields',
'parenttype': u'DocType'
},
# DocType, Lease Installment
{
'doctype': 'DocType',
'name': u'Lease Installment'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'amount',
'fieldtype': u'Currency',
'label': u'Amount',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'due_date',
'fieldtype': u'Date',
'label': u'Due Date',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'cheque_number',
'fieldtype': u'Data',
'label': u'Cheque Number',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'cheque_date',
'fieldtype': u'Date',
'label': u'Cheque Date',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'jv_number',
'fieldtype': u'Link',
'hidden': 0,
'label': u'JV Number',
'options': u'Journal Voucher',
'permlevel': 1
}
]