[demo] [minor] Added accounts, moved JV creation to server-side
This commit is contained in:
parent
80a2f70bad
commit
622c98d6f4
@ -339,11 +339,72 @@ def get_default_bank_cash_account(company, voucher_type):
|
|||||||
account = webnotes.conn.get_value("Company", company,
|
account = webnotes.conn.get_value("Company", company,
|
||||||
voucher_type=="Bank Voucher" and "default_bank_account" or "default_cash_account")
|
voucher_type=="Bank Voucher" and "default_bank_account" or "default_cash_account")
|
||||||
if account:
|
if account:
|
||||||
return [{
|
return {
|
||||||
"account": account,
|
"account": account,
|
||||||
"balance": get_balance_on(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()
|
@webnotes.whitelist()
|
||||||
def get_opening_accounts(company):
|
def get_opening_accounts(company):
|
||||||
"""get all balance sheet accounts for opening entry"""
|
"""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() {
|
cur_frm.cscript.make_bank_voucher = function() {
|
||||||
return wn.call({
|
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: {
|
args: {
|
||||||
"company": cur_frm.doc.company,
|
"purchase_invoice": cur_frm.doc.name,
|
||||||
"voucher_type": "Bank Voucher"
|
|
||||||
},
|
},
|
||||||
callback: function(r) {
|
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');
|
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) {
|
cur_frm.fields_dict['entries'].grid.get_field('project_name').get_query = function(doc, cdt, cdn) {
|
||||||
return{
|
return{
|
||||||
filters:[
|
filters:[
|
||||||
|
@ -127,9 +127,9 @@ class DocType(BuyingController):
|
|||||||
if not self.doc.remarks and self.doc.bill_date:
|
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.remarks = (self.doc.remarks or '') + "\n" + ("Against Bill %s dated %s"
|
||||||
% (self.doc.bill_no, formatdate(self.doc.bill_date)))
|
% (self.doc.bill_no, formatdate(self.doc.bill_date)))
|
||||||
else:
|
|
||||||
if not self.doc.remarks:
|
if not self.doc.remarks:
|
||||||
self.doc.remarks = "No Remarks"
|
self.doc.remarks = "No Remarks"
|
||||||
|
|
||||||
def validate_credit_acc(self):
|
def validate_credit_acc(self):
|
||||||
acc = sql("select debit_or_credit, is_pl_account from tabAccount where name = %s",
|
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() {
|
cur_frm.cscript.make_bank_voucher = function() {
|
||||||
return wn.call({
|
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: {
|
args: {
|
||||||
"company": cur_frm.doc.company,
|
"sales_invoice": cur_frm.doc.name
|
||||||
"voucher_type": "Bank Voucher"
|
|
||||||
},
|
},
|
||||||
callback: function(r) {
|
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);
|
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) {
|
cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
|
||||||
if(cint(wn.boot.notification_settings.sales_invoice)) {
|
if(cint(wn.boot.notification_settings.sales_invoice)) {
|
||||||
cur_frm.email_doc(wn.boot.notification_settings.sales_invoice_message);
|
cur_frm.email_doc(wn.boot.notification_settings.sales_invoice_message);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
import webnotes, os, datetime
|
import webnotes, os, datetime
|
||||||
import webnotes.utils
|
import webnotes.utils
|
||||||
|
from webnotes.utils import random_string
|
||||||
from webnotes.widgets import query_report
|
from webnotes.widgets import query_report
|
||||||
import random
|
import random
|
||||||
import json
|
import json
|
||||||
@ -14,10 +15,12 @@ from core.page.data_import_tool.data_import_tool import upload
|
|||||||
# fix fiscal year
|
# fix fiscal year
|
||||||
|
|
||||||
company = "Wind Power LLC"
|
company = "Wind Power LLC"
|
||||||
|
company_abbr = "WP"
|
||||||
country = "United States"
|
country = "United States"
|
||||||
currency = "USD"
|
currency = "USD"
|
||||||
time_zone = "America/New York"
|
time_zone = "America/New York"
|
||||||
start_date = '2010-01-01'
|
start_date = '2010-01-01'
|
||||||
|
bank_name = "Citibank"
|
||||||
runs_for = 20
|
runs_for = 20
|
||||||
prob = {
|
prob = {
|
||||||
"default": { "make": 0.6, "qty": (1,5) },
|
"default": { "make": 0.6, "qty": (1,5) },
|
||||||
@ -41,6 +44,7 @@ def setup():
|
|||||||
make_customers_suppliers_contacts()
|
make_customers_suppliers_contacts()
|
||||||
make_items()
|
make_items()
|
||||||
make_users_and_employees()
|
make_users_and_employees()
|
||||||
|
make_bank_account()
|
||||||
# make_opening_stock()
|
# make_opening_stock()
|
||||||
# make_opening_accounts()
|
# make_opening_accounts()
|
||||||
|
|
||||||
@ -66,6 +70,7 @@ def simulate():
|
|||||||
run_purchase(current_date)
|
run_purchase(current_date)
|
||||||
run_manufacturing(current_date)
|
run_manufacturing(current_date)
|
||||||
run_stock(current_date)
|
run_stock(current_date)
|
||||||
|
run_accounts(current_date)
|
||||||
|
|
||||||
def run_sales(current_date):
|
def run_sales(current_date):
|
||||||
if can_make("Quotation"):
|
if can_make("Quotation"):
|
||||||
@ -76,6 +81,52 @@ def run_sales(current_date):
|
|||||||
for i in xrange(how_many("Sales Order")):
|
for i in xrange(how_many("Sales Order")):
|
||||||
make_sales_order(current_date)
|
make_sales_order(current_date)
|
||||||
|
|
||||||
|
def run_accounts(current_date):
|
||||||
|
if can_make("Sales Invoice"):
|
||||||
|
from selling.doctype.sales_order.sales_order import make_sales_invoice
|
||||||
|
report = "Ordered Items to be Billed"
|
||||||
|
for so in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Sales Invoice")]:
|
||||||
|
si = webnotes.bean(make_sales_invoice(so))
|
||||||
|
si.doc.posting_date = current_date
|
||||||
|
si.insert()
|
||||||
|
si.submit()
|
||||||
|
webnotes.conn.commit()
|
||||||
|
|
||||||
|
if can_make("Purchase Invoice"):
|
||||||
|
from stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
|
||||||
|
report = "Received Items to be Billed"
|
||||||
|
for pr in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Purchase Invoice")]:
|
||||||
|
pi = webnotes.bean(make_purchase_invoice(pr))
|
||||||
|
pi.doc.posting_date = current_date
|
||||||
|
pi.doc.bill_no = random_string(6)
|
||||||
|
pi.insert()
|
||||||
|
pi.submit()
|
||||||
|
webnotes.conn.commit()
|
||||||
|
|
||||||
|
if can_make("Payment Received"):
|
||||||
|
from accounts.doctype.journal_voucher.journal_voucher import get_payment_entry_from_sales_invoice
|
||||||
|
report = "Accounts Receivable"
|
||||||
|
for si in list(set([r[4] for r in query_report.run(report, {"report_date": current_date })["result"] if r[3]=="Sales Invoice"]))[:how_many("Payment Received")]:
|
||||||
|
jv = webnotes.bean(get_payment_entry_from_sales_invoice(si))
|
||||||
|
jv.doc.posting_date = current_date
|
||||||
|
jv.doc.cheque_no = random_string(6)
|
||||||
|
jv.doc.cheque_date = current_date
|
||||||
|
jv.insert()
|
||||||
|
jv.submit()
|
||||||
|
webnotes.conn.commit()
|
||||||
|
|
||||||
|
if can_make("Payment Made"):
|
||||||
|
from accounts.doctype.journal_voucher.journal_voucher import get_payment_entry_from_purchase_invoice
|
||||||
|
report = "Accounts Payable"
|
||||||
|
for pi in list(set([r[4] for r in query_report.run(report, {"report_date": current_date })["result"] if r[3]=="Purchase Invoice"]))[:how_many("Payment Made")]:
|
||||||
|
jv = webnotes.bean(get_payment_entry_from_purchase_invoice(pi))
|
||||||
|
jv.doc.posting_date = current_date
|
||||||
|
jv.doc.cheque_no = random_string(6)
|
||||||
|
jv.doc.cheque_date = current_date
|
||||||
|
jv.insert()
|
||||||
|
jv.submit()
|
||||||
|
webnotes.conn.commit()
|
||||||
|
|
||||||
def run_stock(current_date):
|
def run_stock(current_date):
|
||||||
# make purchase requests
|
# make purchase requests
|
||||||
if can_make("Purchase Receipt"):
|
if can_make("Purchase Receipt"):
|
||||||
@ -113,8 +164,6 @@ def run_stock(current_date):
|
|||||||
b.submit()
|
b.submit()
|
||||||
webnotes.conn.commit()
|
webnotes.conn.commit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def run_purchase(current_date):
|
def run_purchase(current_date):
|
||||||
# make material requests for purchase items that have negative projected qtys
|
# make material requests for purchase items that have negative projected qtys
|
||||||
if can_make("Material Request"):
|
if can_make("Material Request"):
|
||||||
@ -310,7 +359,7 @@ def complete_setup():
|
|||||||
"fy_start": "1st Jan",
|
"fy_start": "1st Jan",
|
||||||
"industry": "Manufacturing",
|
"industry": "Manufacturing",
|
||||||
"company_name": company,
|
"company_name": company,
|
||||||
"company_abbr": "WP",
|
"company_abbr": company_abbr,
|
||||||
"currency": currency,
|
"currency": currency,
|
||||||
"timezone": time_zone,
|
"timezone": time_zone,
|
||||||
"country": country
|
"country": country
|
||||||
@ -330,7 +379,19 @@ def make_users_and_employees():
|
|||||||
webnotes.conn.commit()
|
webnotes.conn.commit()
|
||||||
|
|
||||||
import_data(["Profile", "Employee", "Salary_Structure"])
|
import_data(["Profile", "Employee", "Salary_Structure"])
|
||||||
|
|
||||||
|
def make_bank_account():
|
||||||
|
ba = webnotes.bean({
|
||||||
|
"doctype": "Account",
|
||||||
|
"account_name": bank_name,
|
||||||
|
"account_type": "Bank or Cash",
|
||||||
|
"group_or_ledger": "Ledger",
|
||||||
|
"parent_account": "Bank Accounts - " + company_abbr,
|
||||||
|
"company": company
|
||||||
|
}).insert()
|
||||||
|
|
||||||
|
webnotes.set_value("Company", company, "default_bank_account", ba.doc.name)
|
||||||
|
|
||||||
def import_data(dt, submit=False):
|
def import_data(dt, submit=False):
|
||||||
if not isinstance(dt, (tuple, list)):
|
if not isinstance(dt, (tuple, list)):
|
||||||
dt = [dt]
|
dt = [dt]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user