mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 12:19:12 +00:00
[demo] [minor] Added accounts, moved JV creation to server-side
This commit is contained in:
@@ -339,11 +339,72 @@ def get_default_bank_cash_account(company, voucher_type):
|
||||
account = webnotes.conn.get_value("Company", company,
|
||||
voucher_type=="Bank Voucher" and "default_bank_account" or "default_cash_account")
|
||||
if account:
|
||||
return [{
|
||||
return {
|
||||
"account": account,
|
||||
"balance": get_balance_on(account)
|
||||
}]
|
||||
}
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_payment_entry_from_sales_invoice(sales_invoice):
|
||||
from accounts.utils import get_balance_on
|
||||
si = webnotes.bean("Sales Invoice", sales_invoice)
|
||||
jv = get_payment_entry(si.doc)
|
||||
jv.doc.remark = 'Payment received against Sales Invoice %(name)s. %(remarks)s' % si.doc.fields
|
||||
|
||||
# credit customer
|
||||
jv.doclist[1].account = si.doc.debit_to
|
||||
jv.doclist[1].balance = get_balance_on(si.doc.debit_to)
|
||||
jv.doclist[1].credit = si.doc.outstanding_amount
|
||||
jv.doclist[1].against_invoice = si.doc.name
|
||||
|
||||
# debit bank
|
||||
jv.doclist[2].debit = si.doc.outstanding_amount
|
||||
|
||||
return [d.fields for d in jv.doclist]
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_payment_entry_from_purchase_invoice(purchase_invoice):
|
||||
from accounts.utils import get_balance_on
|
||||
pi = webnotes.bean("Purchase Invoice", purchase_invoice)
|
||||
jv = get_payment_entry(pi.doc)
|
||||
jv.doc.remark = 'Payment against Purchase Invoice %(name)s. %(remarks)s' % pi.doc.fields
|
||||
|
||||
# credit supplier
|
||||
jv.doclist[1].account = pi.doc.credit_to
|
||||
jv.doclist[1].balance = get_balance_on(pi.doc.credit_to)
|
||||
jv.doclist[1].debit = pi.doc.outstanding_amount
|
||||
jv.doclist[1].against_voucher = pi.doc.name
|
||||
|
||||
# credit bank
|
||||
jv.doclist[2].credit = pi.doc.outstanding_amount
|
||||
|
||||
return [d.fields for d in jv.doclist]
|
||||
|
||||
def get_payment_entry(doc):
|
||||
bank_account = get_default_bank_cash_account(doc.company, "Bank Voucher")
|
||||
|
||||
jv = webnotes.new_bean('Journal Voucher')
|
||||
jv.doc.voucher_type = 'Bank Voucher'
|
||||
|
||||
jv.doc.company = doc.company
|
||||
jv.doc.fiscal_year = doc.fiscal_year
|
||||
|
||||
jv.doclist.append({
|
||||
"doctype": "Journal Voucher Detail",
|
||||
"parentfield": "entries"
|
||||
})
|
||||
|
||||
jv.doclist.append({
|
||||
"doctype": "Journal Voucher Detail",
|
||||
"parentfield": "entries"
|
||||
})
|
||||
|
||||
if bank_account:
|
||||
jv.doclist[2].account = bank_account["account"]
|
||||
jv.doclist[2].balance = bank_account["balance"]
|
||||
|
||||
return jv
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_opening_accounts(company):
|
||||
"""get all balance sheet accounts for opening entry"""
|
||||
|
||||
@@ -106,13 +106,13 @@ cur_frm.cscript.is_opening = function(doc, dt, dn) {
|
||||
|
||||
cur_frm.cscript.make_bank_voucher = function() {
|
||||
return wn.call({
|
||||
method: "accounts.doctype.journal_voucher.journal_voucher.get_default_bank_cash_account",
|
||||
method: "accounts.doctype.journal_voucher.journal_voucher.get_payment_entry_from_purchase_invoice",
|
||||
args: {
|
||||
"company": cur_frm.doc.company,
|
||||
"voucher_type": "Bank Voucher"
|
||||
"purchase_invoice": cur_frm.doc.name,
|
||||
},
|
||||
callback: function(r) {
|
||||
cur_frm.cscript.make_jv(cur_frm.doc, null, null, r.message);
|
||||
var doclist = wn.model.sync(r.message);
|
||||
wn.set_route("Form", doclist[0].doctype, doclist[0].name);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -198,31 +198,6 @@ cur_frm.cscript.cost_center = function(doc, cdt, cdn){
|
||||
refresh_field('entries');
|
||||
}
|
||||
|
||||
cur_frm.cscript.make_jv = function(doc, dt, dn, bank_account) {
|
||||
var jv = wn.model.make_new_doc_and_get_name('Journal Voucher');
|
||||
jv = locals['Journal Voucher'][jv];
|
||||
jv.voucher_type = 'Bank Voucher';
|
||||
jv.remark = repl('Payment against voucher %(vn)s for %(rem)s', {vn:doc.name, rem:doc.remarks});
|
||||
jv.total_debit = doc.outstanding_amount;
|
||||
jv.total_credit = doc.outstanding_amount;
|
||||
jv.fiscal_year = doc.fiscal_year;
|
||||
jv.company = doc.company;
|
||||
|
||||
// debit to creditor
|
||||
var d1 = wn.model.add_child(jv, 'Journal Voucher Detail', 'entries');
|
||||
d1.account = doc.credit_to;
|
||||
d1.debit = doc.outstanding_amount;
|
||||
d1.against_voucher = doc.name;
|
||||
|
||||
// credit to bank
|
||||
var d1 = wn.model.add_child(jv, 'Journal Voucher Detail', 'entries');
|
||||
d1.account = bank_account.account;
|
||||
d1.credit = doc.outstanding_amount;
|
||||
d1.balance = bank_account.balance;
|
||||
|
||||
loaddoc('Journal Voucher', jv.name);
|
||||
}
|
||||
|
||||
cur_frm.fields_dict['entries'].grid.get_field('project_name').get_query = function(doc, cdt, cdn) {
|
||||
return{
|
||||
filters:[
|
||||
|
||||
@@ -127,9 +127,9 @@ class DocType(BuyingController):
|
||||
if not self.doc.remarks and self.doc.bill_date:
|
||||
self.doc.remarks = (self.doc.remarks or '') + "\n" + ("Against Bill %s dated %s"
|
||||
% (self.doc.bill_no, formatdate(self.doc.bill_date)))
|
||||
else:
|
||||
if not self.doc.remarks:
|
||||
self.doc.remarks = "No Remarks"
|
||||
|
||||
if not self.doc.remarks:
|
||||
self.doc.remarks = "No Remarks"
|
||||
|
||||
def validate_credit_acc(self):
|
||||
acc = sql("select debit_or_credit, is_pl_account from tabAccount where name = %s",
|
||||
|
||||
@@ -255,13 +255,13 @@ cur_frm.cscript['Make Delivery Note'] = function() {
|
||||
|
||||
cur_frm.cscript.make_bank_voucher = function() {
|
||||
return wn.call({
|
||||
method: "accounts.doctype.journal_voucher.journal_voucher.get_default_bank_cash_account",
|
||||
method: "accounts.doctype.journal_voucher.journal_voucher.get_payment_entry_from_sales_invoice",
|
||||
args: {
|
||||
"company": cur_frm.doc.company,
|
||||
"voucher_type": "Bank Voucher"
|
||||
"sales_invoice": cur_frm.doc.name
|
||||
},
|
||||
callback: function(r) {
|
||||
cur_frm.cscript.make_jv(cur_frm.doc, null, null, r.message);
|
||||
var doclist = wn.model.sync(r.message);
|
||||
wn.set_route("Form", doclist[0].doctype, doclist[0].name);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -395,34 +395,6 @@ cur_frm.cscript.cost_center = function(doc, cdt, cdn){
|
||||
refresh_field(cur_frm.cscript.fname);
|
||||
}
|
||||
|
||||
// Make Journal Voucher
|
||||
// --------------------
|
||||
cur_frm.cscript.make_jv = function(doc, dt, dn, bank_account) {
|
||||
var jv = wn.model.make_new_doc_and_get_name('Journal Voucher');
|
||||
jv = locals['Journal Voucher'][jv];
|
||||
jv.voucher_type = 'Bank Voucher';
|
||||
|
||||
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 = wn.model.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 = wn.model.add_child(jv, 'Journal Voucher Detail', 'entries');
|
||||
d1.account = bank_account.account;
|
||||
d1.debit = doc.outstanding_amount;
|
||||
d1.balance = bank_account.balance;
|
||||
|
||||
loaddoc('Journal Voucher', jv.name);
|
||||
}
|
||||
|
||||
|
||||
cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
|
||||
if(cint(wn.boot.notification_settings.sales_invoice)) {
|
||||
cur_frm.email_doc(wn.boot.notification_settings.sales_invoice_message);
|
||||
|
||||
Reference in New Issue
Block a user