mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 21:59:13 +00:00
Sourced wnframework-modules from Google Code as erpnext
This commit is contained in:
0
accounts/doctype/__init__.py
Normal file
0
accounts/doctype/__init__.py
Normal file
0
accounts/doctype/account/__init__.py
Normal file
0
accounts/doctype/account/__init__.py
Normal file
87
accounts/doctype/account/account.js
Normal file
87
accounts/doctype/account/account.js
Normal file
@@ -0,0 +1,87 @@
|
||||
// Fetch parent details
|
||||
// -----------------------------------------
|
||||
cur_frm.add_fetch('parent_account', 'debit_or_credit', 'debit_or_credit');
|
||||
cur_frm.add_fetch('parent_account', 'is_pl_account', 'is_pl_account');
|
||||
|
||||
// Hide tax rate based on account type
|
||||
// -----------------------------------------
|
||||
cur_frm.cscript.account_type = function(doc, cdt, cdn) {
|
||||
if(doc.account_type == 'Tax') unhide_field(['tax_rate']);
|
||||
else hide_field(['tax_rate']);
|
||||
}
|
||||
|
||||
// Onload
|
||||
// -----------------------------------------
|
||||
cur_frm.cscript.onload = function(doc, cdt, cdn) {
|
||||
cur_frm.cscript.account_type(doc, cdt, cdn);
|
||||
// hide India specific fields
|
||||
var cp = locals['Control Panel']['Control Panel'];
|
||||
if(cp.country == 'India')
|
||||
unhide_field(['pan_number', 'tds_applicable', 'tds_details', 'TDS']);
|
||||
else
|
||||
hide_field(['pan_number', 'tds_applicable', 'tds_details', 'TDS']);
|
||||
}
|
||||
|
||||
// Refresh
|
||||
// -----------------------------------------
|
||||
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
||||
root_acc = [' Application of Funds (Assets)','Expenses','Income','Source of Funds (Liabilities)'];
|
||||
if(inList(root_acc, doc.account_name))
|
||||
cur_frm.perm = [[1,0,0], [1,0,0]];
|
||||
cur_frm.cscript.hide_unhide_group_ledger(doc);
|
||||
}
|
||||
|
||||
// Hide/unhide group or ledger
|
||||
// -----------------------------------------
|
||||
cur_frm.cscript.hide_unhide_group_ledger = function(doc) {
|
||||
hide_field(['Convert to Group', 'Convert to Ledger']);
|
||||
if (cstr(doc.group_or_ledger) == 'Group') unhide_field('Convert to Ledger');
|
||||
else if (cstr(doc.group_or_ledger) == 'Ledger') unhide_field('Convert to Group');
|
||||
}
|
||||
|
||||
// Convert group to ledger
|
||||
// -----------------------------------------
|
||||
cur_frm.cscript['Convert to Ledger'] = function(doc, cdt, cdn) {
|
||||
$c_obj(make_doclist(cdt,cdn),'convert_group_to_ledger','',function(r,rt) {
|
||||
if(r.message == 1) {
|
||||
doc.group_or_ledger = 'Ledger';
|
||||
refresh_field('group_or_ledger');
|
||||
cur_frm.cscript.hide_unhide_group_ledger(doc);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Convert ledger to group
|
||||
// -----------------------------------------
|
||||
cur_frm.cscript['Convert to Group'] = function(doc, cdt, cdn) {
|
||||
$c_obj(make_doclist(cdt,cdn),'convert_ledger_to_group','',function(r,rt) {
|
||||
if(r.message == 1) {
|
||||
doc.group_or_ledger = 'Group';
|
||||
refresh_field('group_or_ledger');
|
||||
cur_frm.cscript.hide_unhide_group_ledger(doc);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Master name get query
|
||||
// -----------------------------------------
|
||||
cur_frm.fields_dict['master_name'].get_query=function(doc){
|
||||
if (doc.master_type){
|
||||
return 'SELECT `tab'+doc.master_type+'`.name FROM `tab'+doc.master_type+'` WHERE `tab'+doc.master_type+'`.name LIKE "%s" and `tab'+doc.master_type+'`.docstatus != 2 ORDER BY `tab'+doc.master_type+'`.name LIMIT 50';
|
||||
}
|
||||
else alert("Please select master type");
|
||||
}
|
||||
|
||||
// Get customer/supplier address
|
||||
// -----------------------------------------
|
||||
cur_frm.cscript.master_name = function(doc,cdt,cdn){
|
||||
if(doc.master_name){
|
||||
get_server_fields('get_address','','',doc,cdt,cdn);
|
||||
}
|
||||
}
|
||||
|
||||
// parent account get query
|
||||
// -----------------------------------------
|
||||
cur_frm.fields_dict['parent_account'].get_query = function(doc){
|
||||
return 'SELECT DISTINCT `tabAccount`.name FROM `tabAccount` WHERE `tabAccount`.group_or_ledger="Group" AND `tabAccount`.docstatus != 2 AND `tabAccount`.company="'+ doc.company+'" AND `tabAccount`.company is not NULL AND `tabAccount`.name LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50';
|
||||
}
|
||||
259
accounts/doctype/account/account.py
Normal file
259
accounts/doctype/account/account.py
Normal file
@@ -0,0 +1,259 @@
|
||||
# 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.nsm_parent_field = 'parent_account'
|
||||
|
||||
def autoname(self):
|
||||
company_abbr = sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0]
|
||||
self.doc.name = self.doc.account_name.strip() + ' - ' + company_abbr
|
||||
|
||||
# Get customer/supplier address
|
||||
# ==================================================================
|
||||
def get_address(self):
|
||||
add=sql("Select address from `tab%s` where name='%s'"%(self.doc.master_type,self.doc.master_name))
|
||||
ret={'address':add[0][0]}
|
||||
return cstr(ret)
|
||||
|
||||
|
||||
# check whether master name entered for supplier/customer
|
||||
# ==================================================================
|
||||
def validate_master_name(self):
|
||||
if (self.doc.master_type == 'Customer' or self.doc.master_type == 'Supplier') and not self.doc.master_name:
|
||||
msgprint("Message: Please enter Master Name once the account is created.")
|
||||
|
||||
|
||||
# Rate is mandatory for tax account
|
||||
# ==================================================================
|
||||
def validate_rate_for_tax(self):
|
||||
if self.doc.account_type == 'Tax' and not self.doc.tax_rate:
|
||||
msgprint("Please Enter Rate", raise_exception=1)
|
||||
|
||||
# Fetch Parent Details and validation for account not to be created under ledger
|
||||
# ==================================================================
|
||||
def validate_parent(self):
|
||||
if self.doc.parent_account:
|
||||
par = sql("select name, group_or_ledger, is_pl_account, debit_or_credit from tabAccount where name =%s",self.doc.parent_account)
|
||||
if not par:
|
||||
msgprint("Parent account does not exists", raise_exception=1)
|
||||
elif par and par[0][0] == self.doc.name:
|
||||
msgprint("You can not assign itself as parent account", raise_exception=1)
|
||||
elif par and par[0][1] != 'Group':
|
||||
msgprint("Parent account can not be a ledger", raise_exception=1)
|
||||
elif par and self.doc.debit_or_credit and par[0][3] != self.doc.debit_or_credit:
|
||||
msgprint("You can not move a %s account under %s account" % (self.doc.debit_or_credit, par[0][3]), raise_exception=1)
|
||||
elif par and not self.doc.is_pl_account:
|
||||
self.doc.is_pl_account = par[0][2]
|
||||
self.doc.debit_or_credit = par[0][3]
|
||||
|
||||
# Account name must be unique
|
||||
# ==================================================================
|
||||
def validate_duplicate_account(self):
|
||||
if (self.doc.__islocal or (not self.doc.name)) and sql("select name from tabAccount where account_name=%s and company=%s", (self.doc.account_name, self.doc.company)):
|
||||
msgprint("Account Name already exists, please rename", raise_exception=1)
|
||||
|
||||
# validate root details
|
||||
# ==================================================================
|
||||
def validate_root_details(self):
|
||||
#does not exists parent
|
||||
if self.doc.account_name in ['Income','Source of Funds', 'Expenses','Application of Funds'] and self.doc.parent_account:
|
||||
msgprint("You can not assign parent for root account", raise_exception=1)
|
||||
|
||||
# Debit / Credit
|
||||
if self.doc.account_name in ['Income','Source of Funds']:
|
||||
self.doc.debit_or_credit = 'Credit'
|
||||
elif self.doc.account_name in ['Expenses','Application of Funds']:
|
||||
self.doc.debit_or_credit = 'Debit'
|
||||
|
||||
# Is PL Account
|
||||
if self.doc.account_name in ['Income','Expenses']:
|
||||
self.doc.is_pl_account = 'Yes'
|
||||
elif self.doc.account_name in ['Source of Funds','Application of Funds']:
|
||||
self.doc.is_pl_account = 'No'
|
||||
|
||||
# Convert group to ledger
|
||||
# ==================================================================
|
||||
def convert_group_to_ledger(self):
|
||||
if self.check_if_child_exists():
|
||||
msgprint("Account: %s has existing child. You can not convert this account to ledger" % (self.doc.name), raise_exception=1)
|
||||
elif self.check_prev_bal_exists():
|
||||
msgprint("Account with balance can not be converted to ledger.", raise_exception=1)
|
||||
else:
|
||||
self.doc.group_or_ledger = 'Ledger'
|
||||
self.doc.save()
|
||||
return 1
|
||||
|
||||
# Convert ledger to group
|
||||
# ==================================================================
|
||||
def convert_ledger_to_group(self):
|
||||
if self.check_prev_bal_exists():
|
||||
msgprint("Account with balance can not be converted to group.", raise_exception=1)
|
||||
else:
|
||||
self.doc.group_or_ledger = 'Group'
|
||||
self.doc.save()
|
||||
return 1
|
||||
|
||||
# Check if any previous balance exists
|
||||
# ==================================================================
|
||||
def check_prev_bal_exists(self):
|
||||
bal = sql("select balance from `tabAccount Balance` where parent = '%s' and ifnull(balance, 0) > 0" % (self.doc.name))
|
||||
return bal and flt(bal[0][0]) or 0
|
||||
|
||||
# check if child exists
|
||||
# ==================================================================
|
||||
def check_if_child_exists(self):
|
||||
return sql("select name from `tabAccount` where parent_account = %s and docstatus<2", self.doc.name)
|
||||
|
||||
# Update balance
|
||||
# ==================================================================
|
||||
def update_balance(self, fy, period_det, flag = 1):
|
||||
# update in all parents
|
||||
for p in period_det:
|
||||
sql("update `tabAccount Balance` t1, `tabAccount` t2 set t1.balance = t1.balance + (%s), t1.opening = t1.opening + (%s), t1.debit = t1.debit + (%s), t1.credit = t1.credit + (%s) where t1.period = %s and t1.account = t2.name and t2.lft<=%s and t2.rgt>=%s", (flt(flag)*flt(p[1]), flt(flag)*flt(p[2]), flt(flag)*flt(p[3]), flt(flag)*flt(p[4]), p[0], self.doc.lft, self.doc.rgt))
|
||||
|
||||
|
||||
# change parent balance
|
||||
# ==================================================================
|
||||
def change_parent_bal(self):
|
||||
period_det = []
|
||||
fy = sql("select name from `tabFiscal Year` where if(ifnull(is_fiscal_year_closed, 'No'),ifnull(is_fiscal_year_closed, 'No'), 'No') = 'No'")
|
||||
for f in fy:
|
||||
# get my opening, balance
|
||||
per = sql("select period, balance, opening, debit, credit from `tabAccount Balance` where account = %s and fiscal_year = %s", (self.doc.name, f[0]))
|
||||
for p in per:
|
||||
period_det.append([p[0], p[1], p[2], p[3], p[4]])
|
||||
|
||||
# deduct balance from old_parent
|
||||
op = get_obj('Account',self.doc.old_parent)
|
||||
op.update_balance(fy, period_det, -1)
|
||||
|
||||
# add to new parent_account
|
||||
flag = 1
|
||||
if op.doc.debit_or_credit != self.doc.debit_or_credit:
|
||||
flag = -1
|
||||
|
||||
get_obj('Account', self.doc.parent_account).update_balance(fy, period_det, flag)
|
||||
msgprint('Balances updated')
|
||||
|
||||
# VALIDATE
|
||||
# ==================================================================
|
||||
def validate(self):
|
||||
self.validate_master_name()
|
||||
self.validate_rate_for_tax()
|
||||
self.validate_parent()
|
||||
self.validate_duplicate_account()
|
||||
self.validate_root_details()
|
||||
|
||||
# Defaults
|
||||
if not self.doc.parent_account:
|
||||
self.doc.parent_account = ''
|
||||
|
||||
# parent changed
|
||||
if self.doc.old_parent and self.doc.parent_account and (self.doc.parent_account != self.doc.old_parent):
|
||||
self.change_parent_bal()
|
||||
|
||||
# Add current fiscal year balance
|
||||
# ==================================================================
|
||||
def set_year_balance(self):
|
||||
p = sql("select name, start_date, end_date, fiscal_year from `tabPeriod` where docstatus != 2 and period_type in ('Month', 'Year')")
|
||||
for d in p:
|
||||
if not sql("select name from `tabAccount Balance` where account=%s and period=%s", (self.doc.name, d[0])):
|
||||
ac = Document('Account Balance')
|
||||
ac.account = self.doc.name
|
||||
ac.period = d[0]
|
||||
ac.start_date = d[1].strftime('%Y-%m-%d')
|
||||
ac.end_date = d[2].strftime('%Y-%m-%d')
|
||||
ac.fiscal_year = d[3]
|
||||
ac.opening = 0
|
||||
ac.debit = 0
|
||||
ac.credit = 0
|
||||
ac.balance = 0
|
||||
ac.save(1)
|
||||
|
||||
# Update Node Set Model
|
||||
# ==================================================================
|
||||
def update_nsm_model(self):
|
||||
import webnotes
|
||||
import webnotes.utils.nestedset
|
||||
webnotes.utils.nestedset.update_nsm(self)
|
||||
|
||||
# ON UPDATE
|
||||
# ==================================================================
|
||||
def on_update(self):
|
||||
# update nsm
|
||||
self.update_nsm_model()
|
||||
# Add curret year balance
|
||||
self.set_year_balance()
|
||||
|
||||
|
||||
# Check user role for approval process
|
||||
# ==================================================================
|
||||
def get_authorized_user(self):
|
||||
# Check logged-in user is authorized
|
||||
if get_value('Manage Account', None, 'credit_controller') in webnotes.user.get_roles():
|
||||
return 1
|
||||
|
||||
# Check Credit limit for customer
|
||||
# ==================================================================
|
||||
def check_credit_limit(self, account, company, tot_outstanding):
|
||||
# Get credit limit
|
||||
credit_limit_from = 'Customer'
|
||||
|
||||
cr_limit = sql("select t1.credit_limit from tabCustomer t1, `tabAccount` t2 where t2.name='%s' and t1.name = t2.master_name" % account)
|
||||
credit_limit = cr_limit and flt(cr_limit[0][0]) or 0
|
||||
if not credit_limit:
|
||||
credit_limit = get_value('Company', company, 'credit_limit')
|
||||
credit_limit_from = 'global settings in the Company'
|
||||
|
||||
# If outstanding greater than credit limit and not authorized person raise exception
|
||||
if credit_limit > 0 and flt(tot_outstanding) > credit_limit and not self.get_authorized_user():
|
||||
msgprint("Total Outstanding amount (%s) for <b>%s</b> can not be greater than credit limit (%s). To change your credit limit settings, please update the <b>%s</b>" \
|
||||
% (fmt_money(tot_outstanding), account, fmt_money(credit_limit), credit_limit_from), raise_exception=1)
|
||||
|
||||
# Account with balance cannot be inactive
|
||||
# ==================================================================
|
||||
def check_balance_before_trash(self):
|
||||
if flt(self.get_curr_bal()) != 0:
|
||||
msgprint("Account with existing balance can not be trashed", raise_exception=1)
|
||||
if self.check_if_child_exists():
|
||||
msgprint("Child account exists for this account. You can not make trash this account.", raise_exception=1)
|
||||
|
||||
|
||||
# get current year balance
|
||||
# ==================================================================
|
||||
def get_curr_bal(self):
|
||||
bal = sql("select balance from `tabAccount Balance` where period = '%s' and parent = '%s'" % (get_defaults()['fiscal_year'], self.doc.name))
|
||||
return bal and flt(bal[0][0]) or 0
|
||||
|
||||
# On Trash
|
||||
# ==================================================================
|
||||
def on_trash(self):
|
||||
# Check balance before trash
|
||||
self.check_balance_before_trash()
|
||||
# rebuild tree
|
||||
set(self.doc,'old_parent', '')
|
||||
self.update_nsm_model()
|
||||
|
||||
# On restore
|
||||
# ==================================================================
|
||||
def on_restore(self):
|
||||
# rebuild tree
|
||||
self.update_nsm_model()
|
||||
1290
accounts/doctype/account/account.txt
Normal file
1290
accounts/doctype/account/account.txt
Normal file
File diff suppressed because it is too large
Load Diff
0
accounts/doctype/account_balance/__init__.py
Normal file
0
accounts/doctype/account_balance/__init__.py
Normal file
417
accounts/doctype/account_balance/account_balance.txt
Normal file
417
accounts/doctype/account_balance/account_balance.txt
Normal file
@@ -0,0 +1,417 @@
|
||||
[
|
||||
{
|
||||
'_last_update': None,
|
||||
'allow_attach': None,
|
||||
'allow_copy': None,
|
||||
'allow_email': None,
|
||||
'allow_print': None,
|
||||
'allow_rename': None,
|
||||
'allow_trash': None,
|
||||
'autoname': '_ACB.######',
|
||||
'change_log': None,
|
||||
'client_script': None,
|
||||
'client_script_core': None,
|
||||
'client_string': None,
|
||||
'colour': 'White:FFF',
|
||||
'creation': '2010-08-08 17:08:51',
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocType',
|
||||
'document_type': None,
|
||||
'dt_template': None,
|
||||
'hide_heading': None,
|
||||
'hide_toolbar': None,
|
||||
'idx': None,
|
||||
'in_create': None,
|
||||
'in_dialog': None,
|
||||
'is_transaction_doc': None,
|
||||
'issingle': None,
|
||||
'istable': 0,
|
||||
'max_attachments': None,
|
||||
'menu_index': None,
|
||||
'modified': '2011-03-23 12:37:39',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'Accounts',
|
||||
'name': 'Account Balance',
|
||||
'name_case': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': None,
|
||||
'parent_node': None,
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'print_outline': None,
|
||||
'read_only': None,
|
||||
'read_only_onload': None,
|
||||
'search_fields': 'account, period, fiscal_year, balance',
|
||||
'section_style': 'Simple',
|
||||
'server_code': None,
|
||||
'server_code_compiled': None,
|
||||
'server_code_core': None,
|
||||
'server_code_error': ' ',
|
||||
'show_in_menu': 0,
|
||||
'smallicon': None,
|
||||
'use_template': None,
|
||||
'version': 28
|
||||
},
|
||||
{
|
||||
'amend': 0,
|
||||
'cancel': 0,
|
||||
'create': 0,
|
||||
'creation': '2011-05-09 10:50:48',
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocPerm',
|
||||
'execute': None,
|
||||
'idx': None,
|
||||
'match': None,
|
||||
'modified': '2011-05-09 10:50:48',
|
||||
'modified_by': 'Administrator',
|
||||
'name': '000000174',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Account Balance',
|
||||
'parentfield': 'permissions',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': None,
|
||||
'read': 1,
|
||||
'role': 'Accounts User',
|
||||
'submit': 0,
|
||||
'write': 0
|
||||
},
|
||||
{
|
||||
'amend': 0,
|
||||
'cancel': 0,
|
||||
'create': 0,
|
||||
'creation': '2011-05-09 10:50:48',
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocPerm',
|
||||
'execute': None,
|
||||
'idx': None,
|
||||
'match': None,
|
||||
'modified': '2011-05-09 10:50:48',
|
||||
'modified_by': 'Administrator',
|
||||
'name': '000000175',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Account Balance',
|
||||
'parentfield': 'permissions',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': None,
|
||||
'read': 1,
|
||||
'role': 'Accounts Manager',
|
||||
'submit': 0,
|
||||
'write': 0
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2011-05-09 10:50:48',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'account',
|
||||
'fieldtype': 'Link',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 1,
|
||||
'in_filter': 1,
|
||||
'label': 'Account',
|
||||
'modified': '2011-05-09 10:50:48',
|
||||
'modified_by': 'Administrator',
|
||||
'name': '000000176',
|
||||
'no_copy': None,
|
||||
'oldfieldname': None,
|
||||
'oldfieldtype': None,
|
||||
'options': 'Account',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Account Balance',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': 1,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:08:51',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'period',
|
||||
'fieldtype': 'Link',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 2,
|
||||
'in_filter': 1,
|
||||
'label': 'Period',
|
||||
'modified': '2011-05-09 10:50:48',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL00458',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'period',
|
||||
'oldfieldtype': 'Link',
|
||||
'options': 'Period',
|
||||
'owner': 'nabin@webnotestech.com',
|
||||
'parent': 'Account Balance',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': 1,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:08:51',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'opening',
|
||||
'fieldtype': 'Currency',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 3,
|
||||
'in_filter': None,
|
||||
'label': 'Opening',
|
||||
'modified': '2011-05-09 10:50:48',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL00462',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'opening',
|
||||
'oldfieldtype': 'Currency',
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Account Balance',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': None,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-10-26 09:43:49',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'debit',
|
||||
'fieldtype': 'Currency',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 4,
|
||||
'in_filter': None,
|
||||
'label': 'Debit',
|
||||
'modified': '2011-05-09 10:50:48',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL04062',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'debit',
|
||||
'oldfieldtype': 'Currency',
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Account Balance',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': None,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-10-26 09:43:49',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'credit',
|
||||
'fieldtype': 'Currency',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 5,
|
||||
'in_filter': None,
|
||||
'label': 'Credit',
|
||||
'modified': '2011-05-09 10:50:48',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL04063',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'credit',
|
||||
'oldfieldtype': 'Currency',
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Account Balance',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': None,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:08:51',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'balance',
|
||||
'fieldtype': 'Currency',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 6,
|
||||
'in_filter': None,
|
||||
'label': 'Balance',
|
||||
'modified': '2011-05-09 10:50:48',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL00463',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'balance',
|
||||
'oldfieldtype': 'Currency',
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Account Balance',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': None,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:08:51',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'fiscal_year',
|
||||
'fieldtype': 'Link',
|
||||
'hidden': 1,
|
||||
'icon': None,
|
||||
'idx': 7,
|
||||
'in_filter': 1,
|
||||
'label': 'Fiscal Year',
|
||||
'modified': '2011-05-09 10:50:48',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL00459',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'fiscal_year',
|
||||
'oldfieldtype': 'Link',
|
||||
'options': 'Fiscal Year',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Account Balance',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': 1,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:08:51',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'start_date',
|
||||
'fieldtype': 'Date',
|
||||
'hidden': 1,
|
||||
'icon': None,
|
||||
'idx': 8,
|
||||
'in_filter': None,
|
||||
'label': 'Start Date',
|
||||
'modified': '2011-05-09 10:50:48',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL00460',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'start_date',
|
||||
'oldfieldtype': 'Date',
|
||||
'options': None,
|
||||
'owner': 'nabin@webnotestech.com',
|
||||
'parent': 'Account Balance',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': 1,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:08:51',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'end_date',
|
||||
'fieldtype': 'Date',
|
||||
'hidden': 1,
|
||||
'icon': None,
|
||||
'idx': 9,
|
||||
'in_filter': None,
|
||||
'label': 'End Date',
|
||||
'modified': '2011-05-09 10:50:48',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL00461',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'end_date',
|
||||
'oldfieldtype': 'Date',
|
||||
'options': None,
|
||||
'owner': 'nabin@webnotestech.com',
|
||||
'parent': 'Account Balance',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': 1,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
}
|
||||
]
|
||||
0
accounts/doctype/accounts_setup/__init__.py
Normal file
0
accounts/doctype/accounts_setup/__init__.py
Normal file
3
accounts/doctype/accounts_setup/accounts_setup.js
Normal file
3
accounts/doctype/accounts_setup/accounts_setup.js
Normal file
@@ -0,0 +1,3 @@
|
||||
cur_frm.cscript['Repost GL'] = function(doc,dt,dn) {
|
||||
$c_obj('GL Control','repost_gl','',function(r,rt) {alert('Done')});
|
||||
}
|
||||
43
accounts/doctype/accounts_setup/accounts_setup.py
Normal file
43
accounts/doctype/accounts_setup/accounts_setup.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# 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
|
||||
|
||||
def get_bal(self,arg):
|
||||
msgprint(arg)
|
||||
bal = sql("select balance,debit_or_credit from tabAccount where name=%s", arg)
|
||||
msgprint(bal)
|
||||
return fmt_money(flt(bal[0][0])) + ' ' + bal[0][1]
|
||||
|
||||
def on_update(self):
|
||||
set_default('fiscal_year', self.doc.current_fiscal_year)
|
||||
ysd = sql("select year_start_date from `tabFiscal Year` where name=%s", self.doc.current_fiscal_year)[0][0]
|
||||
set_default('year_start_date', ysd.strftime('%Y-%m-%d'))
|
||||
set_default('year_end_date', get_last_day(get_first_day(ysd,0,11)).strftime('%Y-%m-%d'))
|
||||
|
||||
def get_bank_defaults(self, arg):
|
||||
return {
|
||||
'def_bv_type': self.doc.default_bank_voucher_type,
|
||||
'def_bv_series': self.doc.default_bank_voucher_series,
|
||||
'def_bank_account': self.doc.default_bank_account,
|
||||
'bank_balance': self.get_bal(self.doc.default_bank_account),
|
||||
'acc_balance': self.get_bal(arg),
|
||||
}
|
||||
1
accounts/doctype/accounts_setup/accounts_setup.txt
Normal file
1
accounts/doctype/accounts_setup/accounts_setup.txt
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
[{'section_style': 'Tray', 'is_transaction_doc': None, 'creation': '2009-05-22 14:56:16', 'search_fields': None, 'module': 'Accounts', 'doctype': 'DocType', 'change_log': None, 'print_outline': '', 'owner': 'Administrator', 'in_dialog': None, 'in_create': None, 'read_only': None, 'allow_email': None, 'dt_template': None, 'hide_heading': None, 'issingle': None, 'allow_rename': None, 'smallicon': None, 'allow_attach': None, 'show_in_menu': 0, 'max_attachments': None, 'version': 24, 'menu_index': None, 'docstatus': 0, 'allow_copy': None, 'istable': 1, 'description': None, 'parent': None, 'server_code': None, 'allow_trash': None, 'allow_print': None, 'autoname': None, 'client_script_core': None, 'client_string': None, 'use_template': None, 'modified_by': 'nabin@webnotestech.com', 'document_type': None, 'name': 'Advance Adjustment Detail', 'idx': None, 'hide_toolbar': None, 'colour': 'White:FFF', 'client_script': None, 'modified': '2010-09-20 14:06:57', 'server_code_error': ' ', 'name_case': '', 'parenttype': None, 'read_only_onload': None, 'server_code_core': None, 'server_code_compiled': None, 'parent_node': None, 'parentfield': None}, {'no_copy': 1, 'oldfieldtype': 'Link', 'creation': '2009-05-22 14:56:16', 'doctype': 'DocField', 'oldfieldname': 'journal_voucher', 'owner': 'Administrator', 'reqd': None, 'in_filter': None, 'print_hide': None, 'modified_by': 'nabin@webnotestech.com', 'label': 'Journal Voucher', 'width': '250px', 'trigger': None, 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 1, 'description': None, 'parent': 'Advance Adjustment Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL02126', 'idx': 1, 'default': None, 'colour': None, 'modified': '2009-12-15 14:34:41', 'parenttype': 'DocType', 'fieldname': 'journal_voucher', 'fieldtype': 'Link', 'options': 'Journal Voucher', 'report_hide': None, 'parentfield': 'fields'}, {'no_copy': 1, 'oldfieldtype': 'Data', 'creation': '2009-05-28 12:21:27', 'doctype': 'DocField', 'oldfieldname': 'jv_detail_no', 'owner': 'Administrator', 'reqd': None, 'in_filter': None, 'print_hide': 1, 'modified_by': 'nabin@webnotestech.com', 'label': 'Journal Voucher Detail No', 'width': '120px', 'trigger': None, 'depends_on': None, 'docstatus': 0, 'hidden': 1, 'permlevel': 1, 'description': None, 'parent': 'Advance Adjustment Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL02226', 'idx': 2, 'default': None, 'colour': None, 'modified': '2009-12-15 14:34:41', 'parenttype': 'DocType', 'fieldname': 'jv_detail_no', 'fieldtype': 'Data', 'options': None, 'report_hide': None, 'parentfield': 'fields'}, {'no_copy': 1, 'oldfieldtype': 'Currency', 'creation': '2009-05-22 14:56:16', 'doctype': 'DocField', 'oldfieldname': 'advance_amount', 'owner': 'Administrator', 'reqd': None, 'in_filter': None, 'print_hide': None, 'modified_by': 'nabin@webnotestech.com', 'label': 'Advance amount', 'width': '120px', 'trigger': None, 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 1, 'description': None, 'parent': 'Advance Adjustment Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL02127', 'idx': 3, 'default': None, 'colour': None, 'modified': '2009-12-15 14:34:41', 'parenttype': 'DocType', 'fieldname': 'advance_amount', 'fieldtype': 'Currency', 'options': None, 'report_hide': None, 'parentfield': 'fields'}, {'no_copy': 1, 'oldfieldtype': 'Currency', 'creation': '2009-05-28 12:22:02', 'doctype': 'DocField', 'oldfieldname': 'allocated_amount', 'owner': 'Administrator', 'reqd': None, 'in_filter': None, 'print_hide': None, 'modified_by': 'nabin@webnotestech.com', 'label': 'Allocated amount', 'width': '120px', 'trigger': 'Client', 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 0, 'description': None, 'parent': 'Advance Adjustment Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL02227', 'idx': 4, 'default': None, 'colour': None, 'modified': '2009-12-15 14:34:41', 'parenttype': 'DocType', 'fieldname': 'allocated_amount', 'fieldtype': 'Currency', 'options': None, 'report_hide': None, 'parentfield': 'fields'}, {'no_copy': 1, 'oldfieldtype': 'Small Text', 'creation': '2009-05-28 14:19:30', 'doctype': 'DocField', 'oldfieldname': 'remarks', 'owner': 'Administrator', 'reqd': None, 'in_filter': None, 'print_hide': None, 'modified_by': 'nabin@webnotestech.com', 'label': 'Remarks', 'width': '150px', 'trigger': None, 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 1, 'description': None, 'parent': 'Advance Adjustment Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL02231', 'idx': 5, 'default': None, 'colour': None, 'modified': '2009-12-15 14:34:41', 'parenttype': 'DocType', 'fieldname': 'remarks', 'fieldtype': 'Small Text', 'options': None, 'report_hide': None, 'parentfield': 'fields'}]
|
||||
File diff suppressed because one or more lines are too long
0
accounts/doctype/bank_reconciliation/__init__.py
Normal file
0
accounts/doctype/bank_reconciliation/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
cur_frm.cscript.onload = function(doc, cdt, cdn){
|
||||
// add page head
|
||||
var ph = new PageHeader(cur_frm.fields_dict['Head HTML'].wrapper, 'Bank Reconciliation', '');
|
||||
}
|
||||
49
accounts/doctype/bank_reconciliation/bank_reconciliation.py
Normal file
49
accounts/doctype/bank_reconciliation/bank_reconciliation.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# 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
|
||||
|
||||
def get_details(self):
|
||||
if not (self.doc.bank_account and self.doc.from_date and self.doc.to_date):
|
||||
msgprint("Bank Account, From Date and To Date are Mandatory")
|
||||
return
|
||||
|
||||
dl = sql("select t1.name, t1.cheque_no, t1.cheque_date, t2.debit, t2.credit, t1.posting_date, t2.against_account from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2 where t2.parent = t1.name and t2.account = %s and (clearance_date is null or clearance_date = '0000-00-00' or clearance_date = '') and (t1.cheque_no is not null or t1.cheque_no != '') and t1.posting_date >= %s and t1.posting_date <= %s and t1.docstatus=1", (self.doc.bank_account, self.doc.from_date, self.doc.to_date))
|
||||
|
||||
self.doc.clear_table(self.doclist, 'entries')
|
||||
self.doc.total_amount = 0.0
|
||||
|
||||
for d in dl:
|
||||
nl = addchild(self.doc, 'entries', 'Bank Reconciliation Detail', 1, self.doclist)
|
||||
nl.posting_date = str(d[5])
|
||||
nl.voucher_id = str(d[0])
|
||||
nl.cheque_number = str(d[1])
|
||||
nl.cheque_date = str(d[2])
|
||||
nl.debit = flt(d[3])
|
||||
nl.credit = flt(d[4])
|
||||
nl.against_account = d[6]
|
||||
self.doc.total_amount += flt(flt(d[4]) - flt(d[3]))
|
||||
|
||||
def update_details(self):
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
if d.clearance_date:
|
||||
sql("update `tabJournal Voucher` set clearance_date = %s where name=%s", (d.clearance_date, d.voucher_id))
|
||||
msgprint("Updated")
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
0
accounts/doctype/budget_control/__init__.py
Normal file
0
accounts/doctype/budget_control/__init__.py
Normal file
59
accounts/doctype/budget_control/budget_control.js
Normal file
59
accounts/doctype/budget_control/budget_control.js
Normal file
@@ -0,0 +1,59 @@
|
||||
class DocType:
|
||||
def __init__(self,d,dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
|
||||
# Get monthly budget
|
||||
#-------------------
|
||||
def get_monthly_budget(self, distribution_id, cfy, st_date, post_dt, budget_allocated):
|
||||
|
||||
# get month_list
|
||||
st_date, post_dt = getdate(st_date), getdate(post_dt)
|
||||
|
||||
if distribution_id:
|
||||
if st_date.month <= post_dt.month:
|
||||
tot_per_allocated = sql("select ifnull(sum(percentage_allocation),0) from `tabBudget Distribution Detail` where parent='%s' and idx between '%s' and '%s'" % (distribution_id, st_date.month, post_dt.month))[0][0]
|
||||
|
||||
if st_date.month > post_dt.month:
|
||||
|
||||
tot_per_allocated = flt(sql("select ifnull(sum(percentage_allocation),0) from `tabBudget Distribution Detail` where parent='%s' and idx between '%s' and '%s'" % (distribution_id, st_date.month, 12 ))[0][0])
|
||||
tot_per_allocated = flt(tot_per_allocated) + flt(sql("select ifnull(sum(percentage_allocation),0) from `tabBudget Distribution Detail` where parent='%s' and idx between '%s' and '%s'" % (distribution_id, 1, post_dt.month))[0][0])
|
||||
|
||||
return (flt(budget_allocated) * flt(tot_per_allocated)) / 100
|
||||
period_diff = sql("select PERIOD_DIFF('%s','%s')" % (post_dt.strftime('%Y%m'), st_date.strftime('%Y%m')))
|
||||
|
||||
return (flt(budget_allocated) * (flt(period_diff[0][0]) + 1)) / 12
|
||||
|
||||
def validate_budget(self, acct, cost_center, actual, budget, action):
|
||||
# action if actual exceeds budget
|
||||
if flt(actual) > flt(budget):
|
||||
msgprint("Your monthly expense "+ cstr((action == 'stop') and "will exceed" or "has exceeded") +" budget for <b>Account - "+cstr(acct)+" </b> under <b>Cost Center - "+ cstr(cost_center) + "</b>"+cstr((action == 'Stop') and ", you can not have this transaction." or "."))
|
||||
if action == 'Stop': raise Exception
|
||||
|
||||
def check_budget(self,le_list,cancel):
|
||||
# get value from record
|
||||
acct, cost_center, debit, credit, post_dt, cfy, company = le_list
|
||||
|
||||
# get allocated budget
|
||||
bgt = sql("select t1.budget_allocated, t1.actual, t2.distribution_id from `tabBudget Detail` t1, `tabCost Center` t2 where t1.account='%s' and t1.parent=t2.name and t2.name = '%s' and t1.fiscal_year='%s'" % (acct,cost_center,cfy), as_dict =1)
|
||||
curr_amt = ((cancel and -1 or 1) * flt(debit)) + ((cancel and 1 or -1) * flt(credit))
|
||||
|
||||
if bgt and bgt[0]['budget_allocated']:
|
||||
# check budget flag in Company
|
||||
bgt_flag = sql("select yearly_bgt_flag, monthly_bgt_flag from `tabCompany` where name = '%s'" % company, as_dict =1)
|
||||
|
||||
if bgt_flag and bgt_flag[0]['monthly_bgt_flag'] in ['Stop', 'Warn']:
|
||||
# get start date and last date
|
||||
st_date = get_value('Fiscal Year', cfy, 'year_start_date').strftime('%Y-%m-%d')
|
||||
lt_date = sql("select LAST_DAY('%s')" % post_dt)
|
||||
|
||||
# get Actual
|
||||
actual = get_obj('GL Control').get_period_difference(acct + '~~~' + cstr(st_date) + '~~~' + cstr(lt_date[0][0]), cost_center)
|
||||
|
||||
# Get Monthly budget
|
||||
budget = self.get_monthly_budget(bgt and bgt[0]['distribution_id'] or '' , cfy, st_date, post_dt, bgt[0]['budget_allocated'])
|
||||
|
||||
# validate monthly budget
|
||||
self.validate_budget(acct, cost_center, flt(actual) + flt(curr_amt), budget, 'monthly_bgt_flag')
|
||||
|
||||
# update actual against budget allocated in cost center
|
||||
sql("update `tabBudget Detail` set actual = ifnull(actual,0) + %s where account = '%s' and fiscal_year = '%s' and parent = '%s'" % (curr_amt,cstr(acct),cstr(cfy),cstr(cost_center)))
|
||||
78
accounts/doctype/budget_control/budget_control.py
Normal file
78
accounts/doctype/budget_control/budget_control.py
Normal file
@@ -0,0 +1,78 @@
|
||||
# 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
|
||||
|
||||
# Get monthly budget
|
||||
#-------------------
|
||||
def get_monthly_budget(self, distribution_id, cfy, st_date, post_dt, budget_allocated):
|
||||
|
||||
# get month_list
|
||||
st_date, post_dt = getdate(st_date), getdate(post_dt)
|
||||
|
||||
if distribution_id:
|
||||
if st_date.month <= post_dt.month:
|
||||
tot_per_allocated = sql("select ifnull(sum(percentage_allocation),0) from `tabBudget Distribution Detail` where parent='%s' and idx between '%s' and '%s'" % (distribution_id, st_date.month, post_dt.month))[0][0]
|
||||
|
||||
if st_date.month > post_dt.month:
|
||||
|
||||
tot_per_allocated = flt(sql("select ifnull(sum(percentage_allocation),0) from `tabBudget Distribution Detail` where parent='%s' and idx between '%s' and '%s'" % (distribution_id, st_date.month, 12 ))[0][0])
|
||||
tot_per_allocated = flt(tot_per_allocated) + flt(sql("select ifnull(sum(percentage_allocation),0) from `tabBudget Distribution Detail` where parent='%s' and idx between '%s' and '%s'" % (distribution_id, 1, post_dt.month))[0][0])
|
||||
|
||||
return (flt(budget_allocated) * flt(tot_per_allocated)) / 100
|
||||
period_diff = sql("select PERIOD_DIFF('%s','%s')" % (post_dt.strftime('%Y%m'), st_date.strftime('%Y%m')))
|
||||
|
||||
return (flt(budget_allocated) * (flt(period_diff[0][0]) + 1)) / 12
|
||||
|
||||
def validate_budget(self, acct, cost_center, actual, budget, action):
|
||||
# action if actual exceeds budget
|
||||
if flt(actual) > flt(budget):
|
||||
msgprint("Your monthly expense "+ cstr((action == 'stop') and "will exceed" or "has exceeded") +" budget for <b>Account - "+cstr(acct)+" </b> under <b>Cost Center - "+ cstr(cost_center) + "</b>"+cstr((action == 'Stop') and ", you can not have this transaction." or "."))
|
||||
if action == 'Stop': raise Exception
|
||||
|
||||
def check_budget(self,le_list,cancel):
|
||||
# get value from record
|
||||
acct, cost_center, debit, credit, post_dt, cfy, company = le_list
|
||||
|
||||
# get allocated budget
|
||||
bgt = sql("select t1.budget_allocated, t1.actual, t2.distribution_id from `tabBudget Detail` t1, `tabCost Center` t2 where t1.account='%s' and t1.parent=t2.name and t2.name = '%s' and t1.fiscal_year='%s'" % (acct,cost_center,cfy), as_dict =1)
|
||||
curr_amt = ((cancel and -1 or 1) * flt(debit)) + ((cancel and 1 or -1) * flt(credit))
|
||||
|
||||
if bgt and bgt[0]['budget_allocated']:
|
||||
# check budget flag in Company
|
||||
bgt_flag = sql("select yearly_bgt_flag, monthly_bgt_flag from `tabCompany` where name = '%s'" % company, as_dict =1)
|
||||
|
||||
if bgt_flag and bgt_flag[0]['monthly_bgt_flag'] in ['Stop', 'Warn']:
|
||||
# get start date and last date
|
||||
st_date = get_value('Fiscal Year', cfy, 'year_start_date').strftime('%Y-%m-%d')
|
||||
lt_date = sql("select LAST_DAY('%s')" % post_dt)
|
||||
|
||||
# get Actual
|
||||
actual = get_obj('GL Control').get_period_difference(acct + '~~~' + cstr(st_date) + '~~~' + cstr(lt_date[0][0]), cost_center)
|
||||
|
||||
# Get Monthly budget
|
||||
budget = self.get_monthly_budget(bgt and bgt[0]['distribution_id'] or '' , cfy, st_date, post_dt, bgt[0]['budget_allocated'])
|
||||
|
||||
# validate monthly budget
|
||||
self.validate_budget(acct, cost_center, flt(actual) + flt(curr_amt), budget, 'monthly_bgt_flag')
|
||||
|
||||
# update actual against budget allocated in cost center
|
||||
sql("update `tabBudget Detail` set actual = ifnull(actual,0) + %s where account = '%s' and fiscal_year = '%s' and parent = '%s'" % (curr_amt,cstr(acct),cstr(cfy),cstr(cost_center)))
|
||||
1
accounts/doctype/budget_control/budget_control.txt
Normal file
1
accounts/doctype/budget_control/budget_control.txt
Normal file
@@ -0,0 +1 @@
|
||||
[{'section_style': 'Simple', 'is_transaction_doc': None, 'creation': '2010-03-04 14:18:59', 'search_fields': None, 'module': 'Accounts', 'doctype': 'DocType', 'change_log': None, 'print_outline': '', 'owner': 'nabin@webnotestech.com', 'in_dialog': None, 'in_create': None, 'read_only': None, 'allow_email': None, 'dt_template': None, 'hide_heading': None, 'issingle': 1, 'allow_rename': None, 'smallicon': None, 'allow_attach': None, 'show_in_menu': 0, 'max_attachments': None, 'version': 24, 'menu_index': None, 'docstatus': 0, 'allow_copy': None, 'istable': None, 'description': None, 'parent': None, 'server_code': None, 'allow_trash': None, 'allow_print': None, 'autoname': None, 'client_script_core': None, 'client_string': None, 'use_template': None, 'modified_by': 'nabin@webnotestech.com', 'document_type': None, 'name': 'Budget Control', 'idx': None, 'hide_toolbar': None, 'colour': 'White:FFF', 'client_script': None, 'modified': '2010-09-20 14:06:57', 'server_code_error': ' ', 'name_case': '', 'parenttype': None, 'read_only_onload': None, 'server_code_core': None, 'server_code_compiled': None, 'parent_node': None, 'parentfield': None}]
|
||||
0
accounts/doctype/budget_detail/__init__.py
Normal file
0
accounts/doctype/budget_detail/__init__.py
Normal file
1
accounts/doctype/budget_detail/budget_detail.txt
Normal file
1
accounts/doctype/budget_detail/budget_detail.txt
Normal file
@@ -0,0 +1 @@
|
||||
[{'section_style': 'Tray', 'is_transaction_doc': None, 'creation': '2009-06-05 16:50:56', 'search_fields': None, 'module': 'Accounts', 'doctype': 'DocType', 'change_log': None, 'print_outline': '', 'owner': 'Administrator', 'in_dialog': None, 'in_create': None, 'read_only': None, 'allow_email': None, 'dt_template': None, 'hide_heading': None, 'issingle': None, 'allow_rename': None, 'smallicon': '', 'allow_attach': None, 'show_in_menu': 0, 'max_attachments': None, 'version': 6, 'menu_index': None, 'docstatus': 0, 'allow_copy': None, 'istable': 1, 'description': None, 'parent': None, 'server_code': None, 'allow_trash': None, 'allow_print': None, 'autoname': 'CBD/.######', 'client_script_core': None, 'client_string': None, 'use_template': None, 'modified_by': 'harshada@webnotestech.com', 'document_type': None, 'name': 'Budget Detail', 'idx': None, 'hide_toolbar': None, 'colour': 'White:FFF', 'client_script': None, 'modified': '2010-09-20 14:06:57', 'server_code_error': None, 'name_case': '', 'parenttype': None, 'read_only_onload': None, 'server_code_core': None, 'server_code_compiled': None, 'parent_node': None, 'parentfield': None}, {'no_copy': None, 'oldfieldtype': 'Link', 'creation': '2009-06-05 16:50:56', 'doctype': 'DocField', 'oldfieldname': 'account', 'owner': 'Administrator', 'reqd': 1, 'in_filter': 1, 'print_hide': None, 'modified_by': 'harshada@webnotestech.com', 'label': 'Account', 'width': None, 'trigger': 'Client', 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 0, 'description': None, 'parent': 'Budget Detail', 'search_index': 1, 'allow_on_submit': None, 'icon': None, 'name': 'FL02268', 'idx': 1, 'default': None, 'colour': None, 'modified': '2010-07-28 13:18:00', 'parenttype': 'DocType', 'fieldname': 'account', 'fieldtype': 'Link', 'options': 'Account', 'report_hide': None, 'parentfield': 'fields'}, {'no_copy': None, 'oldfieldtype': 'Currency', 'creation': '2009-06-05 16:50:56', 'doctype': 'DocField', 'oldfieldname': 'budget_allocated', 'owner': 'Administrator', 'reqd': 1, 'in_filter': None, 'print_hide': None, 'modified_by': 'harshada@webnotestech.com', 'label': 'Budget Allocated', 'width': None, 'trigger': None, 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 0, 'description': None, 'parent': 'Budget Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL02269', 'idx': 2, 'default': None, 'colour': None, 'modified': '2010-07-28 13:18:00', 'parenttype': 'DocType', 'fieldname': 'budget_allocated', 'fieldtype': 'Currency', 'options': None, 'report_hide': None, 'parentfield': 'fields'}, {'no_copy': None, 'oldfieldtype': 'Currency', 'creation': '2009-06-05 16:50:56', 'doctype': 'DocField', 'oldfieldname': 'actual', 'owner': 'Administrator', 'reqd': None, 'in_filter': None, 'print_hide': None, 'modified_by': 'harshada@webnotestech.com', 'label': 'Actual', 'width': None, 'trigger': None, 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 1, 'description': None, 'parent': 'Budget Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL02270', 'idx': 3, 'default': None, 'colour': None, 'modified': '2010-07-28 13:18:00', 'parenttype': 'DocType', 'fieldname': 'actual', 'fieldtype': 'Currency', 'options': None, 'report_hide': None, 'parentfield': 'fields'}, {'no_copy': None, 'oldfieldtype': 'Select', 'creation': '2009-06-05 16:50:56', 'doctype': 'DocField', 'oldfieldname': 'fiscal_year', 'owner': 'Administrator', 'reqd': 1, 'in_filter': 1, 'print_hide': None, 'modified_by': 'harshada@webnotestech.com', 'label': 'Fiscal Year', 'width': None, 'trigger': None, 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 0, 'description': None, 'parent': 'Budget Detail', 'search_index': 1, 'allow_on_submit': None, 'icon': None, 'name': 'FL02272', 'idx': 4, 'default': None, 'colour': None, 'modified': '2010-07-28 13:18:00', 'parenttype': 'DocType', 'fieldname': 'fiscal_year', 'fieldtype': 'Select', 'options': 'link:Fiscal Year', 'report_hide': None, 'parentfield': 'fields'}]
|
||||
0
accounts/doctype/budget_distribution/__init__.py
Normal file
0
accounts/doctype/budget_distribution/__init__.py
Normal file
@@ -0,0 +1,9 @@
|
||||
cur_frm.cscript.onload = function(doc,cdt,cdn){
|
||||
if(doc.__islocal){
|
||||
var callback1 = function(r,rt){
|
||||
refresh_field('budget_distribution_details');
|
||||
}
|
||||
|
||||
$c('runserverobj',args={'method' : 'get_months', 'docs' : compress_doclist([doc])},callback1);
|
||||
}
|
||||
}
|
||||
42
accounts/doctype/budget_distribution/budget_distribution.py
Normal file
42
accounts/doctype/budget_distribution/budget_distribution.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# 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,doc,doclist=[]):
|
||||
self.doc,self.doclist = doc,doclist
|
||||
|
||||
def get_months(self):
|
||||
month_list = ['January','February','March','April','May','June','July','August','September','October','November','December']
|
||||
idx =1
|
||||
for m in month_list:
|
||||
mnth = addchild(self.doc,'budget_distribution_details','Budget Distribution Detail',1,self.doclist)
|
||||
mnth.month = m or ''
|
||||
mnth.idx = idx
|
||||
idx += 1
|
||||
|
||||
def validate(self):
|
||||
total = 0
|
||||
for d in getlist(self.doclist,'budget_distribution_details'):
|
||||
total = flt(total) + flt(d.percentage_allocation)
|
||||
if total > 100:
|
||||
msgprint("Percentage Allocation should not exceed 100%.")
|
||||
raise Exception
|
||||
elif total < 100:
|
||||
msgprint("Percentage Allocation should not recede 100%.")
|
||||
raise Exception
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
[{'section_style': 'Tray', 'is_transaction_doc': None, 'creation': '2009-06-05 17:42:48', 'search_fields': None, 'module': 'Accounts', 'doctype': 'DocType', 'change_log': None, 'print_outline': '', 'owner': 'Administrator', 'in_dialog': None, 'in_create': None, 'read_only': None, 'allow_email': None, 'dt_template': None, 'hide_heading': None, 'issingle': None, 'allow_rename': None, 'smallicon': None, 'allow_attach': None, 'show_in_menu': 0, 'max_attachments': None, 'version': 6, 'menu_index': None, 'docstatus': 0, 'allow_copy': None, 'istable': 1, 'description': None, 'parent': None, 'server_code': None, 'allow_trash': None, 'allow_print': None, 'autoname': 'BDD/.#####', 'client_script_core': None, 'client_string': None, 'use_template': None, 'modified_by': 'Administrator', 'document_type': None, 'name': 'Budget Distribution Detail', 'idx': None, 'hide_toolbar': None, 'colour': 'White:FFF', 'client_script': None, 'modified': '2010-09-20 14:06:57', 'server_code_error': None, 'name_case': '', 'parenttype': None, 'read_only_onload': None, 'server_code_core': None, 'server_code_compiled': None, 'parent_node': None, 'parentfield': None}, {'no_copy': None, 'oldfieldtype': 'Data', 'creation': '2009-06-05 17:42:48', 'doctype': 'DocField', 'oldfieldname': 'month', 'owner': 'Administrator', 'reqd': 1, 'in_filter': None, 'print_hide': None, 'modified_by': 'Administrator', 'label': 'Month', 'width': None, 'trigger': None, 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 2, 'description': None, 'parent': 'Budget Distribution Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL02276', 'idx': 1, 'default': None, 'colour': None, 'modified': '2010-03-19 15:53:59', 'parenttype': 'DocType', 'fieldname': 'month', 'fieldtype': 'Data', 'options': None, 'report_hide': None, 'parentfield': 'fields'}, {'no_copy': None, 'oldfieldtype': 'Currency', 'creation': '2009-06-05 17:42:48', 'doctype': 'DocField', 'oldfieldname': 'percentage_allocation', 'owner': 'Administrator', 'reqd': None, 'in_filter': None, 'print_hide': None, 'modified_by': 'Administrator', 'label': 'Percentage Allocation', 'width': None, 'trigger': None, 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 0, 'description': None, 'parent': 'Budget Distribution Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL02277', 'idx': 2, 'default': None, 'colour': None, 'modified': '2010-03-19 15:53:59', 'parenttype': 'DocType', 'fieldname': 'percentage_allocation', 'fieldtype': 'Currency', 'options': None, 'report_hide': None, 'parentfield': 'fields'}, {'no_copy': None, 'oldfieldtype': 'Currency', 'creation': '2009-06-09 15:31:58', 'doctype': 'DocField', 'oldfieldname': 'aggregate_percentage', 'owner': 'Administrator', 'reqd': None, 'in_filter': None, 'print_hide': None, 'modified_by': 'Administrator', 'label': 'Aggregate Percentage', 'width': None, 'trigger': None, 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 2, 'description': None, 'parent': 'Budget Distribution Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL02290', 'idx': 3, 'default': None, 'colour': None, 'modified': '2010-03-19 15:53:59', 'parenttype': 'DocType', 'fieldname': 'aggregate_percentage', 'fieldtype': 'Currency', 'options': None, 'report_hide': None, 'parentfield': 'fields'}]
|
||||
0
accounts/doctype/cost_center/__init__.py
Normal file
0
accounts/doctype/cost_center/__init__.py
Normal file
39
accounts/doctype/cost_center/cost_center.js
Normal file
39
accounts/doctype/cost_center/cost_center.js
Normal file
@@ -0,0 +1,39 @@
|
||||
$import(Tips Common)
|
||||
|
||||
//Account filtering for cost center
|
||||
cur_frm.fields_dict['budget_details'].grid.get_field('account').get_query = function(doc) {
|
||||
var mydoc = locals[this.doctype][this.docname];
|
||||
return 'SELECT DISTINCT `tabAccount`.`name`,`tabAccount`.debit_or_credit,`tabAccount`.group_or_ledger FROM `tabAccount` WHERE `tabAccount`.`company` = "' + doc.company_name + '" AND `tabAccount`.docstatus != 2 AND `tabAccount`.`is_pl_account` = "Yes" AND `tabAccount`.debit_or_credit = "Debit" AND `tabAccount`.`group_or_ledger` != "Group" AND `tabAccount`.`group_or_ledger` is not NULL AND `tabAccount`.`name` LIKE "%s" ORDER BY `tabAccount`.`name` LIMIT 50';
|
||||
}
|
||||
|
||||
cur_frm.fields_dict['parent_cost_center'].get_query = function(doc){
|
||||
return 'SELECT DISTINCT `tabCost Center`.name FROM `tabCost Center` WHERE `tabCost Center`.group_or_ledger="Group" AND `tabCost Center`.docstatus != 2 AND `tabCost Center`.company_name="'+ doc.company_name+'" AND `tabCost Center`.company_name is not NULL AND `tabCost Center`.name LIKE "%s" ORDER BY `tabCost Center`.name LIMIT 50';
|
||||
}
|
||||
|
||||
//parent cost center
|
||||
cur_frm.cscript.parent_cost_center = function(doc,cdt,cdn){
|
||||
if(!doc.company_name){
|
||||
alert('Please enter company name first');
|
||||
}
|
||||
}
|
||||
|
||||
//company abbr
|
||||
cur_frm.cscript.company_name = function(doc,cdt,cdn){
|
||||
get_server_fields('get_abbr','','',doc,cdt,cdn,1);
|
||||
}
|
||||
|
||||
//onload if cost center is group
|
||||
cur_frm.cscript.onload = function(doc, cdt, cdn) {
|
||||
cur_frm.cscript.get_tips(doc, cdt, cdn);
|
||||
if(!doc.__islocal && doc.docstatus == 0){
|
||||
get_field(doc.doctype,'group_or_ledger',doc.name).permlevel = 1;
|
||||
refresh_field('group_or_ledger');
|
||||
get_field(doc.doctype,'company_name',doc.name).permlevel = 1;
|
||||
refresh_field('company_name');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
||||
cur_frm.cscript.get_tips(doc, cdt, cdn);
|
||||
}
|
||||
58
accounts/doctype/cost_center/cost_center.py
Normal file
58
accounts/doctype/cost_center/cost_center.py
Normal file
@@ -0,0 +1,58 @@
|
||||
# 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.nsm_parent_field = 'parent_cost_center'
|
||||
|
||||
def autoname(self):
|
||||
#company_abbr = sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0]
|
||||
self.doc.name = self.doc.cost_center_name + ' - ' + self.doc.company_abbr
|
||||
|
||||
|
||||
def get_abbr(self):
|
||||
abbr = sql("select abbr from tabCompany where company_name='%s'"%(self.doc.company_name))[0][0] or ''
|
||||
ret = {
|
||||
'company_abbr' : abbr
|
||||
}
|
||||
return cstr(ret)
|
||||
|
||||
def validate(self):
|
||||
|
||||
# Cost Center name must be unique
|
||||
# ---------------------------
|
||||
|
||||
if (self.doc.__islocal or (not self.doc.name)) and sql("select name from `tabCost Center` where cost_center_name = %s and company_name=%s", (self.doc.cost_center_name, self.doc.company_name)):
|
||||
msgprint("Cost Center Name already exists, please rename")
|
||||
raise Exception
|
||||
|
||||
check_acc_list = []
|
||||
for d in getlist(self.doclist, 'budget_details'):
|
||||
if [d.account, d.fiscal_year] in check_acc_list:
|
||||
msgprint("Account " + cstr(d.account) + "has been entered more than once for fiscal year " + cstr(d.fiscal_year))
|
||||
raise Exception
|
||||
if [d.account, d.fiscal_year] not in check_acc_list: check_acc_list.append([d.account, d.fiscal_year])
|
||||
|
||||
def on_update(self):
|
||||
# update Node Set Model
|
||||
import webnotes
|
||||
import webnotes.utils.nestedset
|
||||
# update Node Set Model
|
||||
webnotes.utils.nestedset.update_nsm(self)
|
||||
1
accounts/doctype/cost_center/cost_center.txt
Normal file
1
accounts/doctype/cost_center/cost_center.txt
Normal file
File diff suppressed because one or more lines are too long
0
accounts/doctype/fiscal_year/__init__.py
Normal file
0
accounts/doctype/fiscal_year/__init__.py
Normal file
10
accounts/doctype/fiscal_year/fiscal_year.js
Normal file
10
accounts/doctype/fiscal_year/fiscal_year.js
Normal file
@@ -0,0 +1,10 @@
|
||||
$import(Tips Common)
|
||||
|
||||
//--------- ONLOAD -------------
|
||||
cur_frm.cscript.onload = function(doc, cdt, cdn) {
|
||||
cur_frm.cscript.get_tips(doc, cdt, cdn);
|
||||
}
|
||||
|
||||
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
||||
cur_frm.cscript.get_tips(doc, cdt, cdn);
|
||||
}
|
||||
188
accounts/doctype/fiscal_year/fiscal_year.py
Normal file
188
accounts/doctype/fiscal_year/fiscal_year.py
Normal file
@@ -0,0 +1,188 @@
|
||||
# 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
|
||||
|
||||
def repost(self):
|
||||
if not in_transaction:
|
||||
sql("start transaction")
|
||||
|
||||
self.clear_account_balances()
|
||||
self.create_account_balances()
|
||||
self.update_opening()
|
||||
self.post_entries()
|
||||
sql("commit")
|
||||
msgprint("Account balance reposted")
|
||||
|
||||
def clear_account_balances(self):
|
||||
# balances clear - `tabAccount Balance` for fiscal year
|
||||
sql("update `tabAccount Balance` set opening=0, balance=0, debit=0, credit=0 where fiscal_year=%s", self.doc.name)
|
||||
|
||||
def create_account_balances(self):
|
||||
# get periods
|
||||
period_list = self.get_period_list()
|
||||
cnt = 0
|
||||
|
||||
# get accounts
|
||||
al = sql("select name from tabAccount")
|
||||
|
||||
for a in al:
|
||||
# check
|
||||
if sql("select count(*) from `tabAccount Balance` where fiscal_year=%s and account=%s", (self.doc.name, a[0]))[0][0] < 13:
|
||||
for p in period_list:
|
||||
# check if missing
|
||||
if not sql("select name from `tabAccount Balance` where period=%s and account=%s and fiscal_year=%s", (p[0], a[0], self.doc.name)):
|
||||
d = Document('Account Balance')
|
||||
d.account = a[0]
|
||||
d.period = p[0]
|
||||
d.start_date = p[1].strftime('%Y-%m-%d')
|
||||
d.end_date = p[2].strftime('%Y-%m-%d')
|
||||
d.fiscal_year = p[3]
|
||||
d.debit = 0
|
||||
d.credit = 0
|
||||
d.opening = 0
|
||||
d.balance = 0
|
||||
d.save(1)
|
||||
cnt += 1
|
||||
if cnt % 100 == 0:
|
||||
sql("commit")
|
||||
sql("start transaction")
|
||||
return cnt
|
||||
|
||||
# Get periods(month and year)
|
||||
#=================================
|
||||
def get_period_list(self):
|
||||
periods = []
|
||||
pl = sql("SELECT name, start_date, end_date, fiscal_year FROM tabPeriod WHERE fiscal_year = '%s' and period_type in ('Month', 'Year') order by start_date ASC, end_date DESC" % self.doc.name)
|
||||
for p in pl:
|
||||
periods.append([p[0], p[1], p[2], p[3]])
|
||||
return periods
|
||||
|
||||
# ====================================================================================
|
||||
def update_opening(self):
|
||||
# set opening from last year closing
|
||||
abl = sql("select t1.account, t1.balance from `tabAccount Balance` t1, tabAccount t2 where t1.period=%s and t2.company=%s and ifnull(t2.is_pl_account, 'No') = 'No' and t1.account = t2.name for update", (self.doc.past_year, self.doc.company))
|
||||
|
||||
cnt = 0
|
||||
for ab in abl:
|
||||
if cnt % 100 == 0:
|
||||
sql("commit")
|
||||
sql("start transaction")
|
||||
|
||||
sql("update `tabAccount Balance` set opening=%s where period=%s and account=%s", (ab[1], self.doc.name, ab[0]))
|
||||
sql("update `tabAccount Balance` set balance=%s where fiscal_year=%s and account=%s", (ab[1], self.doc.name, ab[0]))
|
||||
cnt += 1
|
||||
|
||||
return cnt
|
||||
|
||||
def get_account_details(self, account):
|
||||
return sql("select debit_or_credit, lft, rgt, is_pl_account from tabAccount where name=%s", account)[0]
|
||||
|
||||
# ====================================================================================
|
||||
def post_entries(self):
|
||||
sql("LOCK TABLE `tabGL Entry` WRITE")
|
||||
# post each gl entry (batch or complete)
|
||||
gle = sql("select name, account, debit, credit, is_opening, posting_date from `tabGL Entry` where fiscal_year=%s and ifnull(is_cancelled,'No')='No' and company=%s", (self.doc.name, self.doc.company))
|
||||
account_details = {}
|
||||
|
||||
cnt = 0
|
||||
for entry in gle:
|
||||
# commit in batches of 100
|
||||
if cnt % 100 == 0:
|
||||
sql("commit")
|
||||
sql("start transaction")
|
||||
cnt += 1
|
||||
#print cnt
|
||||
|
||||
if not account_details.has_key(entry[1]):
|
||||
account_details[entry[1]] = self.get_account_details(entry[1])
|
||||
|
||||
det = account_details[entry[1]]
|
||||
diff = flt(entry[2])-flt(entry[3])
|
||||
if det[0]=='Credit': diff = -diff
|
||||
|
||||
# build dict
|
||||
p = {
|
||||
'debit': flt(entry[2])
|
||||
,'credit':flt(entry[3])
|
||||
,'opening': entry[4]=='Yes' and diff or 0
|
||||
|
||||
# end date conditino only if it is not opening
|
||||
,'end_date_condition':(entry[4]!='Yes' and ("and ab.end_date >= '"+entry[5].strftime('%Y-%m-%d')+"'") or '')
|
||||
,'diff': diff
|
||||
,'lft': det[1]
|
||||
,'rgt': det[2]
|
||||
,'posting_date': entry[5]
|
||||
,'fiscal_year': self.doc.name
|
||||
}
|
||||
|
||||
sql("""update `tabAccount Balance` ab, `tabAccount` a
|
||||
set
|
||||
ab.debit = ifnull(ab.debit,0) + %(debit)s
|
||||
,ab.credit = ifnull(ab.credit,0) + %(credit)s
|
||||
,ab.opening = ifnull(ab.opening,0) + %(opening)s
|
||||
,ab.balance = ifnull(ab.balance,0) + %(diff)s
|
||||
where
|
||||
a.lft <= %(lft)s
|
||||
and a.rgt >= %(rgt)s
|
||||
and ab.account = a.name
|
||||
%(end_date_condition)s
|
||||
and ab.fiscal_year = '%(fiscal_year)s' """ % p)
|
||||
|
||||
sql("UNLOCK TABLES")
|
||||
|
||||
|
||||
|
||||
# Clear PV/RV outstanding
|
||||
# ====================================================================================
|
||||
def clear_outstanding(self):
|
||||
# clear o/s of current year
|
||||
sql("update `tabPayable Voucher` set outstanding_amount = 0 where fiscal_year=%s and company=%s", (self.doc.name, self.doc.company))
|
||||
sql("update `tabReceivable Voucher` set outstanding_amount = 0 where fiscal_year=%s and company=%s", (self.doc.name, self.doc.company))
|
||||
|
||||
# Update Voucher Outstanding
|
||||
def update_voucher_outstanding(self):
|
||||
# Clear outstanding
|
||||
self.clear_outstanding()
|
||||
sql("LOCK TABLE `tabGL Entry` WRITE")
|
||||
against_voucher = sql("select against_voucher, against_voucher_type from `tabGL Entry` where fiscal_year=%s and is_cancelled='No' and company=%s group by against_voucher, against_voucher_type for update", (self.doc.name, self.doc.company))
|
||||
for d in against_voucher:
|
||||
# get voucher balance
|
||||
bal = sql("select sum(debit)-sum(credit) from `tabGL Entry` where against_voucher=%s and against_voucher_type=%s", (d[0], d[1]))
|
||||
bal = bal and flt(bal[0][0]) or 0.0
|
||||
if d[1] == 'Payable Voucher':
|
||||
bal = -bal
|
||||
# set voucher balance
|
||||
sql("update `tab%s` set outstanding_amount=%s where name='%s'"% (d[1], bal, d[0]))
|
||||
sql("UNLOCK TABLES")
|
||||
|
||||
# ====================================================================================
|
||||
# Generate periods
|
||||
def create_periods(self):
|
||||
get_obj('Period Control').generate_periods(self.doc.name)
|
||||
|
||||
# on update
|
||||
def on_update(self):
|
||||
if not self.doc.is_fiscal_year_closed:
|
||||
self.is_fiscal_year_closed = 'No'
|
||||
self.doc.save()
|
||||
self.create_periods()
|
||||
self.create_account_balances()
|
||||
1
accounts/doctype/fiscal_year/fiscal_year.txt
Normal file
1
accounts/doctype/fiscal_year/fiscal_year.txt
Normal file
File diff suppressed because one or more lines are too long
0
accounts/doctype/form_16a/__init__.py
Normal file
0
accounts/doctype/form_16a/__init__.py
Normal file
32
accounts/doctype/form_16a/form_16a.js
Normal file
32
accounts/doctype/form_16a/form_16a.js
Normal file
@@ -0,0 +1,32 @@
|
||||
cur_frm.cscript.onload = function(doc,cdt,cdn){
|
||||
if(doc.company)get_server_fields('get_registration_details','','',doc,cdt,cdn,1);
|
||||
}
|
||||
|
||||
cur_frm.cscript.company = function(doc,cdt,cdn){
|
||||
if(doc.company)get_server_fields('get_registration_details','','',doc,cdt,cdn);
|
||||
}
|
||||
|
||||
cur_frm.fields_dict['party_name'].get_query = function(doc, cdt, cdn) {
|
||||
return 'SELECT `tabAccount`.name FROM `tabAccount` WHERE `tabAccount`.master_type = "Supplier" AND `tabAccount`.docstatus != 2 AND `tabAccount`.group_or_ledger = "Ledger" AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name ASC LIMIT 50';
|
||||
}
|
||||
|
||||
cur_frm.cscript.party_name = function(doc,cdt,cdn){
|
||||
if(doc.party_name)get_server_fields('get_party_det','','',doc,cdt,cdn);
|
||||
}
|
||||
|
||||
// Date validation
|
||||
cur_frm.cscript.to_date = function(doc,cdt,cdn){
|
||||
if((doc.from_date) && (doc.to_date) && (doc.from_date>doc.to_date)){
|
||||
alert("From date can not be greater than To date");
|
||||
doc.to_date='';
|
||||
refresh_field('to_date');
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript.from_date = function(doc,cdt,cdn){
|
||||
if((doc.from_date) && (doc.to_date) && (doc.from_date>doc.to_date)){
|
||||
alert("From date can not be greater than To date");
|
||||
doc.from_date='';
|
||||
refresh_field('from_date');
|
||||
}
|
||||
}
|
||||
106
accounts/doctype/form_16a/form_16a.py
Normal file
106
accounts/doctype/form_16a/form_16a.py
Normal file
@@ -0,0 +1,106 @@
|
||||
# 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
|
||||
|
||||
def autoname(self):
|
||||
self.doc.name = make_autoname('Form 16A' + '/.#####')
|
||||
|
||||
# Get pan no and tan no from company
|
||||
#-------------------------------------
|
||||
def get_registration_details(self):
|
||||
comp_det=sql("Select address,registration_details from `tabCompany` where name = '%s'"%(self.doc.company))
|
||||
if not comp_det:
|
||||
msgprint("Registration Details is not mentioned in comapny")
|
||||
ret = {
|
||||
'company_address':'',
|
||||
'registration_details': ''
|
||||
}
|
||||
else:
|
||||
ret = {
|
||||
'company_address': cstr(comp_det[0][0]),
|
||||
'registration_details': cstr(comp_det[0][1])
|
||||
}
|
||||
return cstr(ret)
|
||||
|
||||
# Get party details
|
||||
#------------------
|
||||
def get_party_det(self):
|
||||
party_det=sql("Select pan_number, address from `tabAccount` where name = '%s'" % self.doc.party_name)
|
||||
ret = {
|
||||
'pan_number': cstr(party_det[0][0]) ,
|
||||
'party_address': cstr(party_det[0][1])
|
||||
}
|
||||
return cstr(ret)
|
||||
|
||||
# Get TDS Return acknowledgement
|
||||
#-------------------------------
|
||||
def get_return_ack_details(self):
|
||||
self.doc.clear_table(self.doclist, 'form_16A_ack_details')
|
||||
if not (self.doc.from_date and self.doc.to_date):
|
||||
msgprint("Please enter From Date, To Date")
|
||||
else:
|
||||
ack = sql("select quarter, acknowledgement_no from `tabTDS Return Acknowledgement` where date_of_receipt>='%s' and date_of_receipt<='%s' and tds_category = '%s' order by date_of_receipt ASC" % (self.doc.from_date, self.doc.to_date, self.doc.tds_category))
|
||||
for d in ack:
|
||||
ch = addchild(self.doc, 'form_16A_ack_details', 'Form 16A Ack Detail', 1, self.doclist)
|
||||
ch.quarter = d[0]
|
||||
ch.ack_no = d[1]
|
||||
|
||||
# Get tds payment details
|
||||
#-------------------------------
|
||||
def get_tds(self):
|
||||
self.doc.clear_table(self.doclist,'form_16A_tax_details')
|
||||
import datetime
|
||||
if self.doc.from_date and self.doc.to_date and self.doc.tds_category:
|
||||
tot=0.0
|
||||
party_tds_list=sql("select t2.amount_paid,t2.date_of_payment,t2.tds_amount,t2.cess_on_tds, t2.total_tax_amount, t1.cheque_no, t1.bsr_code, t1.date_of_receipt, t1.challan_no from `tabTDS Payment` t1, `tabTDS Payment Detail` t2 where t1.tds_category='%s' and t2.party_name='%s' and t1.from_date >= '%s' and t1.to_date <= '%s' and t2.total_tax_amount>0 and t2.parent=t1.name and t1.docstatus=1" % (self.doc.tds_category,self.doc.party_name,self.doc.from_date,self.doc.to_date))
|
||||
for s in party_tds_list:
|
||||
child = addchild(self.doc, 'form_16A_tax_details', 'Form 16A Tax Detail', 1, self.doclist)
|
||||
child.amount_paid = s and flt(s[0]) or ''
|
||||
child.date_of_payment =s and s[1].strftime('%Y-%m-%d') or ''
|
||||
child.tds_main = s and flt(s[2]) or ''
|
||||
child.surcharge = 0
|
||||
child.cess_on_tds = s and flt(s[3]) or ''
|
||||
child.total_tax_deposited = s and flt(s[4]) or ''
|
||||
child.cheque_no = s and s[5] or ''
|
||||
child.bsr_code = s and s[6] or ''
|
||||
child.tax_deposited_date = s and s[7].strftime('%Y-%m-%d') or ''
|
||||
child.challan_no = s and s[8] or ''
|
||||
tot=flt(tot)+flt(s[4])
|
||||
self.doc.total_amount = flt(tot)
|
||||
else:
|
||||
msgprint("Plaese enter from date, to date and TDS category")
|
||||
|
||||
|
||||
# validate
|
||||
#----------------
|
||||
def validate(self):
|
||||
tot=0.0
|
||||
for d in getlist(self.doclist,'form_16A_tax_details'):
|
||||
tot=flt(tot)+flt(d.total_tax_deposited)
|
||||
|
||||
self.doc.total_amount = flt(tot)
|
||||
|
||||
# on update
|
||||
def on_update(self):
|
||||
obj = get_obj('Feed Control', 'Feed Control')
|
||||
|
||||
obj.make_feed(self.doc)
|
||||
1
accounts/doctype/form_16a/form_16a.txt
Normal file
1
accounts/doctype/form_16a/form_16a.txt
Normal file
File diff suppressed because one or more lines are too long
0
accounts/doctype/form_16a_ack_detail/__init__.py
Normal file
0
accounts/doctype/form_16a_ack_detail/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
[{'section_style': 'Tray', 'is_transaction_doc': None, 'creation': '2009-05-28 10:54:48', 'search_fields': None, 'module': 'Accounts', 'doctype': 'DocType', 'change_log': None, 'print_outline': '', 'owner': 'Administrator', 'in_dialog': None, 'in_create': None, 'read_only': None, 'allow_email': None, 'dt_template': None, 'hide_heading': None, 'issingle': None, 'allow_rename': None, 'smallicon': None, 'allow_attach': None, 'show_in_menu': 0, 'max_attachments': None, 'version': 1, 'menu_index': None, 'docstatus': 0, 'allow_copy': None, 'istable': 1, 'description': None, 'parent': None, 'server_code': None, 'allow_trash': None, 'allow_print': None, 'autoname': None, 'client_script_core': None, 'client_string': None, 'use_template': None, 'modified_by': 'Administrator', 'document_type': None, 'name': 'Form 16A Ack Detail', 'idx': None, 'hide_toolbar': None, 'colour': 'White:FFF', 'client_script': None, 'modified': '2010-09-20 14:06:57', 'server_code_error': None, 'name_case': '', 'parenttype': None, 'read_only_onload': None, 'server_code_core': None, 'server_code_compiled': None, 'parent_node': None, 'parentfield': None}, {'no_copy': None, 'oldfieldtype': 'Select', 'creation': '2009-05-28 10:54:48', 'doctype': 'DocField', 'oldfieldname': 'quarter', 'owner': 'Administrator', 'reqd': None, 'in_filter': None, 'print_hide': None, 'modified_by': 'Administrator', 'label': 'Quarter', 'width': None, 'trigger': None, 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 0, 'description': None, 'parent': 'Form 16A Ack Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL02217', 'idx': 1, 'default': None, 'colour': None, 'modified': '2009-05-28 10:54:48', 'parenttype': 'DocType', 'fieldname': 'quarter', 'fieldtype': 'Select', 'options': '\nApr-Jun\nJul-Sept\nOct-Dec\nJan-Mar', 'report_hide': None, 'parentfield': 'fields'}, {'no_copy': None, 'oldfieldtype': 'Data', 'creation': '2009-05-28 10:54:48', 'doctype': 'DocField', 'oldfieldname': 'ack_no', 'owner': 'Administrator', 'reqd': None, 'in_filter': None, 'print_hide': None, 'modified_by': 'Administrator', 'label': 'Acknowledgement No.', 'width': None, 'trigger': None, 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 0, 'description': None, 'parent': 'Form 16A Ack Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL02218', 'idx': 2, 'default': None, 'colour': None, 'modified': '2009-05-28 10:54:48', 'parenttype': 'DocType', 'fieldname': 'ack_no', 'fieldtype': 'Data', 'options': None, 'report_hide': None, 'parentfield': 'fields'}]
|
||||
0
accounts/doctype/form_16a_tax_detail/__init__.py
Normal file
0
accounts/doctype/form_16a_tax_detail/__init__.py
Normal file
File diff suppressed because one or more lines are too long
0
accounts/doctype/gl_control/__init__.py
Normal file
0
accounts/doctype/gl_control/__init__.py
Normal file
367
accounts/doctype/gl_control/gl_control.js
Normal file
367
accounts/doctype/gl_control/gl_control.js
Normal file
@@ -0,0 +1,367 @@
|
||||
class DocType:
|
||||
def __init__(self,d,dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
self.entries = []
|
||||
|
||||
# Get Company List
|
||||
# ----------------
|
||||
def get_companies(self,arg=''):
|
||||
d = get_defaults()
|
||||
ret = sql("select name, abbr from tabCompany where docstatus != 2")
|
||||
pl = {}
|
||||
for r in ret:
|
||||
inc = get_value('Account','Income - '+r[1], 'balance')
|
||||
exp = get_value('Account','Expenses - '+r[1], 'balance')
|
||||
pl[r[0]] = flt(flt(inc) - flt(exp))
|
||||
return {'cl':[r[0] for r in ret], 'pl':pl}
|
||||
|
||||
# Get current balance
|
||||
# --------------------
|
||||
def get_bal(self,arg):
|
||||
ac, fy = arg.split('~~~')
|
||||
det = sql("select t1.balance, t2.debit_or_credit from `tabAccount Balance` t1, `tabAccount` t2 where t1.period = %s and t2.name=%s and t1.parent = t2.name", (fy, ac))
|
||||
bal = det and flt(det[0][0]) or 0
|
||||
dr_or_cr = det and flt(det[0][1]) or ''
|
||||
return fmt_money(bal) + ' ' + dr_or_cr
|
||||
|
||||
def get_period_balance(self,arg):
|
||||
acc, f, t = arg.split('~~~')
|
||||
c, fy = '', get_defaults()['fiscal_year']
|
||||
|
||||
det = sql("select debit_or_credit, lft, rgt, is_pl_account from tabAccount where name=%s", acc)
|
||||
if f: c += (' and t1.posting_date >= "%s"' % f)
|
||||
if t: c += (' and t1.posting_date <= "%s"' % t)
|
||||
bal = sql("select sum(ifnull(t1.debit,0))-sum(ifnull(t1.credit,0)) from `tabGL Entry` t1 where t1.account='%s' and ifnull(is_opening, 'No') = 'No' %s" % (acc, c))
|
||||
bal = bal and flt(bal[0][0]) or 0
|
||||
|
||||
if det[0][0] != 'Debit':
|
||||
bal = (-1) * bal
|
||||
|
||||
# add opening for balance sheet accounts
|
||||
if det[0][3] == 'No':
|
||||
opening = flt(sql("select opening from `tabAccount Balance` where parent=%s and period=%s", (acc, fy))[0][0])
|
||||
bal = bal + opening
|
||||
|
||||
return flt(bal)
|
||||
|
||||
|
||||
def get_period_difference(self,arg, cost_center =''):
|
||||
# used in General Ledger Page Report
|
||||
# used for Budget where cost center passed as extra argument
|
||||
acc, f, t = arg.split('~~~')
|
||||
c, fy = '', get_defaults()['fiscal_year']
|
||||
|
||||
det = sql("select debit_or_credit, lft, rgt, is_pl_account from tabAccount where name=%s", acc)
|
||||
if f: c += (' and t1.posting_date >= "%s"' % f)
|
||||
if t: c += (' and t1.posting_date <= "%s"' % t)
|
||||
if cost_center: c += (' and t1.cost_center = "%s"' % cost_center)
|
||||
bal = sql("select sum(ifnull(t1.debit,0))-sum(ifnull(t1.credit,0)) from `tabGL Entry` t1 where t1.account='%s' %s" % (acc, c))
|
||||
bal = bal and flt(bal[0][0]) or 0
|
||||
|
||||
if det[0][0] != 'Debit':
|
||||
bal = (-1) * bal
|
||||
|
||||
return flt(bal)
|
||||
|
||||
# Get Children (for tree)
|
||||
# -----------------------
|
||||
def get_cl(self, arg):
|
||||
fy = get_defaults()['fiscal_year']
|
||||
parent, parent_acc_name, company, type = arg.split(',')
|
||||
|
||||
# get children account details
|
||||
if type=='Account':
|
||||
if parent=='Root':
|
||||
cl = sql("select t1.name, t1.group_or_ledger, t1.debit_or_credit, t2.balance, t1.account_name from tabAccount t1, `tabAccount Balance` t2 where t1.parent_account is NULL or t1.parent_account='' and t1.docstatus != 2 and t1.company=%s and t1.name = t2.parent and t2.period = %s order by t1.name asc", (company, fy),as_dict=1)
|
||||
else:
|
||||
cl = sql("select t1.name, t1.group_or_ledger, t1.debit_or_credit, t2.balance, t1.account_name from tabAccount t1, `tabAccount Balance` t2 where t1.parent_account=%s and t1.docstatus != 2 and t1.company=%s and t1.name = t2.parent and t2.period = %s order by t1.name asc",(parent, company, fy) ,as_dict=1)
|
||||
|
||||
# remove Decimals
|
||||
for c in cl: c['balance'] = flt(c['balance'])
|
||||
|
||||
# get children cost center details
|
||||
elif type=='Cost Center':
|
||||
if parent=='Root':
|
||||
cl = sql("select name,group_or_ledger, cost_center_name from `tabCost Center` where parent_cost_center is NULL or parent_cost_center='' and docstatus != 2 and company_name=%s order by name asc",(company),as_dict=1)
|
||||
else:
|
||||
cl = sql("select name,group_or_ledger,cost_center_name from `tabCost Center` where parent_cost_center=%s and docstatus != 2 and company_name=%s order by name asc",(parent,company),as_dict=1)
|
||||
|
||||
return {'parent':parent, 'parent_acc_name':parent_acc_name, 'cl':cl}
|
||||
|
||||
# Add a new account
|
||||
# -----------------
|
||||
def add_ac(self,arg):
|
||||
arg = eval(arg)
|
||||
ac = Document('Account')
|
||||
for d in arg.keys():
|
||||
ac.fields[d] = arg[d]
|
||||
ac.old_parent = ''
|
||||
ac_obj = get_obj(doc=ac)
|
||||
ac_obj.validate()
|
||||
ac_obj.doc.save(1)
|
||||
ac_obj.on_update()
|
||||
|
||||
return ac_obj.doc.name
|
||||
|
||||
# Add a new cost center
|
||||
#----------------------
|
||||
def add_cc(self,arg):
|
||||
arg = eval(arg)
|
||||
cc = Document('Cost Center')
|
||||
# map fields
|
||||
for d in arg.keys():
|
||||
cc.fields[d] = arg[d]
|
||||
# map company abbr
|
||||
other_info = sql("select company_abbr from `tabCost Center` where name='%s'"%arg['parent_cost_center'])
|
||||
cc.company_abbr = other_info and other_info[0][0] or arg['company_abbr']
|
||||
|
||||
cc_obj = get_obj(doc=cc)
|
||||
cc_obj.validate()
|
||||
cc_obj.doc.save(1)
|
||||
cc_obj.on_update()
|
||||
|
||||
return cc_obj.doc.name
|
||||
|
||||
|
||||
|
||||
# Get field values from the voucher
|
||||
#------------------------------------------
|
||||
def get_val(self, src, d, parent=None):
|
||||
if not src:
|
||||
return None
|
||||
if src.startswith('parent:'):
|
||||
return parent.fields[src.split(':')[1]]
|
||||
elif src.startswith('value:'):
|
||||
return eval(src.split(':')[1])
|
||||
elif src:
|
||||
return d.fields.get(src)
|
||||
|
||||
def check_if_in_list(self, le):
|
||||
for e in self.entries:
|
||||
if e.account == le.account and (cstr(e.against_voucher)==cstr(le.against_voucher)) and (cstr(e.against_voucher_type)==cstr(le.against_voucher_type)) and (cstr(e.cost_center)==cstr(le.cost_center)):
|
||||
return [e]
|
||||
return 0
|
||||
|
||||
# Make a dictionary(le) for every gl entry and append to a list(self.entries)
|
||||
#----------------------------------------------------------------------------
|
||||
def make_single_entry(self,parent,d,le_map,cancel):
|
||||
if self.get_val(le_map['account'], d, parent) and (self.get_val(le_map['debit'], d, parent) or self.get_val(le_map['credit'], d, parent)):
|
||||
flist = ['account','cost_center','against','debit','credit','remarks','voucher_type','voucher_no','transaction_date','posting_date','fiscal_year','against_voucher','against_voucher_type','company','is_opening', 'aging_date']
|
||||
|
||||
# Check budget before gl entry
|
||||
#check budget only if account is expense account
|
||||
is_expense_acct = sql("select name from tabAccount where is_pl_account='Yes' and debit_or_credit='Debit' and name=%s",self.get_val(le_map['account'], d, parent))
|
||||
if is_expense_acct and self.get_val(le_map['cost_center'], d, parent):
|
||||
get_obj('Budget Control').check_budget([self.get_val(le_map[k], d, parent) for k in flist if k in ['account','cost_center','debit','credit','posting_date','fiscal_year','company']],cancel)
|
||||
|
||||
# Create new GL entry object and map values
|
||||
le = Document('GL Entry')
|
||||
for k in flist:
|
||||
le.fields[k] = self.get_val(le_map[k], d, parent)
|
||||
|
||||
# if there is already an entry in this account then just add it to that entry
|
||||
same_head = self.check_if_in_list(le)
|
||||
if same_head:
|
||||
same_head = same_head[0]
|
||||
same_head.debit = flt(same_head.debit) + flt(le.debit)
|
||||
same_head.credit = flt(same_head.credit) + flt(le.credit)
|
||||
else:
|
||||
self.entries.append(le)
|
||||
|
||||
# Save GL Entries
|
||||
# ----------------
|
||||
def save_entries(self, cancel, adv_adj):
|
||||
for le in self.entries:
|
||||
# cancel
|
||||
if cancel:
|
||||
tmp=le.debit
|
||||
le.debit, le.credit = le.credit, tmp
|
||||
|
||||
le_obj = get_obj(doc=le)
|
||||
# validate except on_cancel
|
||||
if not cancel:
|
||||
le_obj.validate()
|
||||
|
||||
# save
|
||||
le.save(1)
|
||||
le_obj.on_update(adv_adj)
|
||||
|
||||
# update total debit / credit
|
||||
self.td += flt(le.debit)
|
||||
self.tc += flt(le.credit)
|
||||
|
||||
# Make Multiple Entries
|
||||
# ---------------------
|
||||
def make_gl_entries(self, doc, doclist, cancel=0, adv_adj = 0):
|
||||
# get entries
|
||||
le_map_list = sql("select * from `tabGL Mapper Detail` where parent = %s", doc.doctype, as_dict=1)
|
||||
|
||||
self.td, self.tc = 0.0, 0.0
|
||||
|
||||
for le_map in le_map_list:
|
||||
if le_map['table_field']:
|
||||
for d in getlist(doclist,le_map['table_field']):
|
||||
# purchase_tax_details is the table of other charges in purchase cycle
|
||||
if le_map['table_field'] != 'purchase_tax_details' or (le_map['table_field'] == 'purchase_tax_details' and d.fields.get('category') != 'For Valuation'):
|
||||
self.make_single_entry(doc,d,le_map,cancel)
|
||||
else:
|
||||
self.make_single_entry(None,doc,le_map,cancel)
|
||||
|
||||
# save entries
|
||||
self.save_entries(cancel,adv_adj)
|
||||
|
||||
# check total debit / credit
|
||||
# Due to old wrong entries (total debit != total credit) some voucher could be cancelled
|
||||
if abs(self.td - self.tc) > 0.001 and not cancel:
|
||||
msgprint("Debit and Credit not equal for this voucher: Diff (Debit) is %s" % (self.td-self.tc))
|
||||
raise Exception
|
||||
|
||||
# set as cancelled
|
||||
if cancel:
|
||||
vt, vn = self.get_val(le_map['voucher_type'], doc, doc), self.get_val(le_map['voucher_no'], doc, doc)
|
||||
sql("update `tabGL Entry` set is_cancelled='Yes' where voucher_type=%s and voucher_no=%s", (vt, vn))
|
||||
|
||||
# Get account balance on any date
|
||||
# -------------------------------
|
||||
|
||||
def get_as_on_balance(self, account_name, fiscal_year, as_on, credit_or_debit, is_pl, lft, rgt, ysd):
|
||||
# get total transaction value for the current year
|
||||
bal = bal = sql("select SUM(t1.debit), SUM(t1.credit) from `tabGL Entry` t1, `tabAccount` t2 WHERE t1.posting_date >= %s AND t1.posting_date <= %s and t1.is_opening = 'No' AND t1.account = t2.name AND t2.lft >= %s AND t2.rgt <= %s and t1.is_cancelled = 'No'", (ysd,as_on,lft, rgt))
|
||||
bal = bal and (flt(bal[0][0]) - flt(bal[0][1])) or 0
|
||||
|
||||
if credit_or_debit == 'Credit' and bal:
|
||||
bal = -bal
|
||||
|
||||
# Add opening balance with the transaction value
|
||||
if is_pl=='No':
|
||||
op = sql("select opening from `tabAccount Balance` where parent=%s and period=%s", (account_name, fiscal_year))
|
||||
op = op and op[0][0] or 0
|
||||
bal += flt(op)
|
||||
return flt(bal)
|
||||
|
||||
# ADVANCE ALLOCATION
|
||||
#-------------------
|
||||
def get_advances(self, obj, account_head, table_name,table_field_name, dr_or_cr):
|
||||
jv_detail = sql("select t1.name, t1.remark, t2.%s, t2.name, t1.ded_amount from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2 where t1.name = t2.parent and (t2.against_voucher is null or t2.against_voucher = '') and (t2.against_invoice is null or t2.against_invoice = '') and t2.account = '%s' and t2.is_advance = 'Yes' and t1.docstatus = 1 order by t1.voucher_date " % (dr_or_cr,account_head))
|
||||
# clear advance table
|
||||
obj.doc.clear_table(obj.doclist,table_field_name)
|
||||
# Create advance table
|
||||
for d in jv_detail:
|
||||
add = addchild(obj.doc, table_field_name, table_name, 1, obj.doclist)
|
||||
add.journal_voucher = d[0]
|
||||
add.jv_detail_no = d[3]
|
||||
add.remarks = d[1]
|
||||
add.advance_amount = flt(d[2])
|
||||
add.allocate_amount = 0
|
||||
if table_name == 'Advance Allocation Detail':
|
||||
add.tds_amount = flt(d[4])
|
||||
|
||||
# Clear rows which is not adjusted
|
||||
#-------------------------------------
|
||||
def clear_advances(self, obj,table_name,table_field_name):
|
||||
for d in getlist(obj.doclist,table_field_name):
|
||||
if not flt(d.allocated_amount):
|
||||
sql("update `tab%s` set parent = '' where name = '%s' and parent = '%s'" % (table_name, d.name, d.parent))
|
||||
d.parent = ''
|
||||
|
||||
# Update aginst document in journal voucher
|
||||
#------------------------------------------
|
||||
def update_against_document_in_jv(self, obj, table_field_name, against_document_no, against_document_doctype, account_head, dr_or_cr,doctype):
|
||||
for d in getlist(obj.doclist, table_field_name):
|
||||
self.validate_jv_entry(d, account_head, dr_or_cr)
|
||||
if flt(d.advance_amount) == flt(d.allocated_amount):
|
||||
# cancel JV
|
||||
jv_obj = get_obj('Journal Voucher', d.journal_voucher, with_children=1)
|
||||
get_obj(dt='GL Control').make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel =1, adv_adj =1)
|
||||
|
||||
# update ref in JV Detail
|
||||
sql("update `tabJournal Voucher Detail` set %s = '%s' where name = '%s'" % (doctype=='Payable Voucher' and 'against_voucher' or 'against_invoice', cstr(against_document_no), d.jv_detail_no))
|
||||
|
||||
# re-submit JV
|
||||
jv_obj = get_obj('Journal Voucher', d.journal_voucher, with_children =1)
|
||||
get_obj(dt='GL Control').make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel = 0, adv_adj =1)
|
||||
|
||||
elif flt(d.advance_amount) > flt(d.allocated_amount):
|
||||
# cancel JV
|
||||
jv_obj = get_obj('Journal Voucher', d.journal_voucher, with_children=1)
|
||||
get_obj(dt='GL Control').make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel =1, adv_adj = 1)
|
||||
|
||||
# add extra entries
|
||||
self.add_extra_entry(jv_obj, d.journal_voucher, d.jv_detail_no, flt(d.allocated_amount), account_head, doctype, dr_or_cr, against_document_no)
|
||||
|
||||
# re-submit JV
|
||||
jv_obj = get_obj('Journal Voucher', d.journal_voucher, with_children =1)
|
||||
get_obj(dt='GL Control').make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel = 0, adv_adj = 1)
|
||||
else:
|
||||
msgprint("Allocation amount cannot be greater than advance amount")
|
||||
raise Exception
|
||||
|
||||
# Add extra row in jv detail for unadjusted amount
|
||||
#--------------------------------------------------
|
||||
def add_extra_entry(self,jv_obj,jv,jv_detail_no, allocate, account_head, doctype, dr_or_cr, against_document_no):
|
||||
# get old entry details
|
||||
|
||||
jvd = sql("select %s, cost_center, balance, against_account from `tabJournal Voucher Detail` where name = '%s'" % (dr_or_cr,jv_detail_no))
|
||||
advance = jvd and flt(jvd[0][0]) or 0
|
||||
balance = flt(advance) - flt(allocate)
|
||||
|
||||
# update old entry
|
||||
sql("update `tabJournal Voucher Detail` set %s = '%s', %s = '%s' where name = '%s'" % (dr_or_cr, flt(allocate), doctype == "Payable Voucher" and 'against_voucher' or 'against_invoice',cstr(against_document_no), jv_detail_no))
|
||||
|
||||
# new entry with balance amount
|
||||
add = addchild(jv_obj.doc, 'entries', 'Journal Voucher Detail', 1, jv_obj.doclist)
|
||||
add.account = account_head
|
||||
add.cost_center = cstr(jvd[0][1])
|
||||
add.balance = cstr(jvd[0][2])
|
||||
add.fields[dr_or_cr] = balance
|
||||
add.against_account = cstr(jvd[0][3])
|
||||
add.is_advance = 'Yes'
|
||||
add.save(1)
|
||||
|
||||
# check if advance entries are still valid
|
||||
# ----------------------------------------
|
||||
def validate_jv_entry(self, d, account_head, dr_or_cr):
|
||||
# 1. check if there is already a voucher reference
|
||||
# 2. check if amount is same
|
||||
# 3. check if is_advance is 'Yes'
|
||||
# 4. check if jv is submitted
|
||||
ret = sql("select t2.%s from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2 where t1.name = t2.parent and (t2.against_voucher = '' || t2.against_voucher is null) and (t2.against_invoice = '' || t2.against_invoice is null) and t2.account = '%s' and t1.name = '%s' and t2.name = '%s' and t2.is_advance = 'Yes' and t1.docstatus=1 and t2.%s = %s" % ( dr_or_cr, account_head, d.journal_voucher, d.jv_detail_no, dr_or_cr, d.advance_amount))
|
||||
if (not ret):
|
||||
msgprint("Please click on 'Get Advances Paid' button as the advance entries have been changed.")
|
||||
raise Exception
|
||||
return
|
||||
|
||||
##############################################################################
|
||||
# Repair Outstanding Amount
|
||||
##############################################################################
|
||||
def repair_voucher_outstanding(self, voucher_obj):
|
||||
msg = []
|
||||
|
||||
# Get Balance from GL Entries
|
||||
bal = sql("select sum(debit)-sum(credit) from `tabGL Entry` where against_voucher=%s and against_voucher_type=%s", (voucher_obj.doc.name , voucher_obj.doc.doctype))
|
||||
bal = bal and flt(bal[0][0]) or 0.0
|
||||
if cstr(voucher_obj.doc.doctype) == 'Payable Voucher':
|
||||
bal = -bal
|
||||
|
||||
# Check outstanding Amount
|
||||
if flt(voucher_obj.doc.outstanding_amount) != flt(bal):
|
||||
msgprint('<div style="color: RED"> Difference found in Outstanding Amount of %s : %s (Before : %s; After : %s) </div>' % (voucher_obj.doc.doctype, voucher_obj.doc.name, voucher_obj.doc.outstanding_amount, bal))
|
||||
msg.append('<div style="color: RED"> Difference found in Outstanding Amount of %s : %s (Before : %s; After : %s) </div>' % (voucher_obj.doc.doctype, voucher_obj.doc.name, voucher_obj.doc.outstanding_amount, bal))
|
||||
|
||||
# set voucher balance
|
||||
#sql("update `tab%s` set outstanding_amount=%s where name='%s'" % (voucher_obj.doc.doctype, bal, voucher_obj.doc.name))
|
||||
set(voucher_obj.doc, 'outstanding_amount', flt(bal))
|
||||
|
||||
# Send Mail
|
||||
if msg:
|
||||
email_msg = """ Dear Administrator,
|
||||
|
||||
In Account := %s User := %s has Repaired Outstanding Amount For %s : %s and following was found:-
|
||||
|
||||
%s
|
||||
|
||||
""" % (get_value('Control Panel', None,'account_id'), session['user'], voucher_obj.doc.doctype, voucher_obj.doc.name, '\n'.join(msg))
|
||||
|
||||
sendmail(['jai@webnotestech.com'], subject='Repair Outstanding Amount', parts = [('text/plain', email_msg)])
|
||||
# Acknowledge User
|
||||
msgprint(cstr(voucher_obj.doc.doctype) + " : " + cstr(voucher_obj.doc.name) + " has been checked" + cstr(msg and " and repaired successfully." or ". No changes Found."))
|
||||
399
accounts/doctype/gl_control/gl_control.py
Normal file
399
accounts/doctype/gl_control/gl_control.py
Normal file
@@ -0,0 +1,399 @@
|
||||
# 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.entries = []
|
||||
|
||||
# Get Company List
|
||||
# ----------------
|
||||
def get_companies(self,arg=''):
|
||||
#d = get_defaults()
|
||||
ret = sql("select name, abbr from tabCompany where docstatus != 2")
|
||||
#pl = {}
|
||||
#for r in ret:
|
||||
# inc = get_value('Account','Income - '+r[1], 'balance')
|
||||
# exp = get_value('Account','Expenses - '+r[1], 'balance')
|
||||
# pl[r[0]] = flt(flt(inc) - flt(exp))
|
||||
|
||||
return {'cl':[r[0] for r in ret]}#, 'pl':pl}
|
||||
|
||||
# Get current balance
|
||||
# --------------------
|
||||
def get_bal(self,arg):
|
||||
ac, fy = arg.split('~~~')
|
||||
det = sql("select t1.balance, t2.debit_or_credit from `tabAccount Balance` t1, `tabAccount` t2 where t1.period = %s and t2.name=%s and t1.account = t2.name", (fy, ac))
|
||||
bal = det and flt(det[0][0]) or 0
|
||||
dr_or_cr = det and flt(det[0][1]) or ''
|
||||
return fmt_money(bal) + ' ' + dr_or_cr
|
||||
|
||||
def get_period_balance(self,arg):
|
||||
acc, f, t = arg.split('~~~')
|
||||
c, fy = '', get_defaults()['fiscal_year']
|
||||
|
||||
det = sql("select debit_or_credit, lft, rgt, is_pl_account from tabAccount where name=%s", acc)
|
||||
if f: c += (' and t1.posting_date >= "%s"' % f)
|
||||
if t: c += (' and t1.posting_date <= "%s"' % t)
|
||||
bal = sql("select sum(ifnull(t1.debit,0))-sum(ifnull(t1.credit,0)) from `tabGL Entry` t1 where t1.account='%s' and ifnull(is_opening, 'No') = 'No' %s" % (acc, c))
|
||||
bal = bal and flt(bal[0][0]) or 0
|
||||
|
||||
if det[0][0] != 'Debit':
|
||||
bal = (-1) * bal
|
||||
|
||||
# add opening for balance sheet accounts
|
||||
if det[0][3] == 'No':
|
||||
opening = flt(sql("select opening from `tabAccount Balance` where account=%s and period=%s", (acc, fy))[0][0])
|
||||
bal = bal + opening
|
||||
|
||||
return flt(bal)
|
||||
|
||||
|
||||
def get_period_difference(self,arg, cost_center =''):
|
||||
# used in General Ledger Page Report
|
||||
# used for Budget where cost center passed as extra argument
|
||||
acc, f, t = arg.split('~~~')
|
||||
c, fy = '', get_defaults()['fiscal_year']
|
||||
|
||||
det = sql("select debit_or_credit, lft, rgt, is_pl_account from tabAccount where name=%s", acc)
|
||||
if f: c += (' and t1.posting_date >= "%s"' % f)
|
||||
if t: c += (' and t1.posting_date <= "%s"' % t)
|
||||
if cost_center: c += (' and t1.cost_center = "%s"' % cost_center)
|
||||
bal = sql("select sum(ifnull(t1.debit,0))-sum(ifnull(t1.credit,0)) from `tabGL Entry` t1 where t1.account='%s' %s" % (acc, c))
|
||||
bal = bal and flt(bal[0][0]) or 0
|
||||
|
||||
if det[0][0] != 'Debit':
|
||||
bal = (-1) * bal
|
||||
|
||||
return flt(bal)
|
||||
|
||||
# Get Children (for tree)
|
||||
# -----------------------
|
||||
def get_cl(self, arg):
|
||||
|
||||
fy = get_defaults()['fiscal_year']
|
||||
parent, parent_acc_name, company, type = arg.split(',')
|
||||
|
||||
# get children account details
|
||||
if type=='Account':
|
||||
|
||||
if parent=='Root Node':
|
||||
|
||||
cl = sql("select t1.name, t1.group_or_ledger, t1.debit_or_credit, t2.balance, t1.account_name from tabAccount t1, `tabAccount Balance` t2 where ifnull(t1.parent_account, '') = '' and t1.docstatus != 2 and t1.company=%s and t1.name = t2.account and t2.period = %s order by t1.name asc", (company, fy),as_dict=1)
|
||||
else:
|
||||
cl = sql("select t1.name, t1.group_or_ledger, t1.debit_or_credit, t2.balance, t1.account_name from tabAccount t1, `tabAccount Balance` t2 where ifnull(t1.parent_account, '')=%s and t1.docstatus != 2 and t1.company=%s and t1.name = t2.account and t2.period = %s order by t1.name asc",(parent, company, fy) ,as_dict=1)
|
||||
|
||||
# remove Decimals
|
||||
for c in cl: c['balance'] = flt(c['balance'])
|
||||
|
||||
# get children cost center details
|
||||
elif type=='Cost Center':
|
||||
if parent=='Root Node':
|
||||
cl = sql("select name,group_or_ledger, cost_center_name from `tabCost Center` where ifnull(parent_cost_center, '')='' and docstatus != 2 and company_name=%s order by name asc",(company),as_dict=1)
|
||||
else:
|
||||
cl = sql("select name,group_or_ledger,cost_center_name from `tabCost Center` where ifnull(parent_cost_center, '')=%s and docstatus != 2 and company_name=%s order by name asc",(parent,company),as_dict=1)
|
||||
return {'parent':parent, 'parent_acc_name':parent_acc_name, 'cl':cl}
|
||||
|
||||
# Add a new account
|
||||
# -----------------
|
||||
def add_ac(self,arg):
|
||||
arg = eval(arg)
|
||||
ac = Document('Account')
|
||||
for d in arg.keys():
|
||||
ac.fields[d] = arg[d]
|
||||
ac.old_parent = ''
|
||||
ac_obj = get_obj(doc=ac)
|
||||
ac_obj.validate()
|
||||
ac_obj.doc.save(1)
|
||||
ac_obj.on_update()
|
||||
|
||||
return ac_obj.doc.name
|
||||
|
||||
# Add a new cost center
|
||||
#----------------------
|
||||
def add_cc(self,arg):
|
||||
arg = eval(arg)
|
||||
cc = Document('Cost Center')
|
||||
# map fields
|
||||
for d in arg.keys():
|
||||
cc.fields[d] = arg[d]
|
||||
# map company abbr
|
||||
other_info = sql("select company_abbr from `tabCost Center` where name='%s'"%arg['parent_cost_center'])
|
||||
cc.company_abbr = other_info and other_info[0][0] or arg['company_abbr']
|
||||
|
||||
cc_obj = get_obj(doc=cc)
|
||||
cc_obj.validate()
|
||||
cc_obj.doc.save(1)
|
||||
cc_obj.on_update()
|
||||
|
||||
return cc_obj.doc.name
|
||||
|
||||
|
||||
# Get field values from the voucher
|
||||
#------------------------------------------
|
||||
def get_val(self, src, d, parent=None):
|
||||
if not src:
|
||||
return None
|
||||
if src.startswith('parent:'):
|
||||
return parent.fields[src.split(':')[1]]
|
||||
elif src.startswith('value:'):
|
||||
return eval(src.split(':')[1])
|
||||
elif src:
|
||||
return d.fields.get(src)
|
||||
|
||||
def check_if_in_list(self, le):
|
||||
for e in self.entries:
|
||||
if e.account == le.account and (cstr(e.against_voucher)==cstr(le.against_voucher)) and (cstr(e.against_voucher_type)==cstr(le.against_voucher_type)) and (cstr(e.cost_center)==cstr(le.cost_center)):
|
||||
return [e]
|
||||
return 0
|
||||
|
||||
# Make a dictionary(le) for every gl entry and append to a list(self.entries)
|
||||
#----------------------------------------------------------------------------
|
||||
def make_single_entry(self,parent,d,le_map,cancel, merge_entries):
|
||||
if self.get_val(le_map['account'], d, parent) and (self.get_val(le_map['debit'], d, parent) or self.get_val(le_map['credit'], d, parent)):
|
||||
flist = ['account','cost_center','against','debit','credit','remarks','voucher_type','voucher_no','transaction_date','posting_date','fiscal_year','against_voucher','against_voucher_type','company','is_opening', 'aging_date']
|
||||
|
||||
# Check budget before gl entry
|
||||
#check budget only if account is expense account
|
||||
is_expense_acct = sql("select name from tabAccount where is_pl_account='Yes' and debit_or_credit='Debit' and name=%s",self.get_val(le_map['account'], d, parent))
|
||||
if is_expense_acct and self.get_val(le_map['cost_center'], d, parent):
|
||||
get_obj('Budget Control').check_budget([self.get_val(le_map[k], d, parent) for k in flist if k in ['account','cost_center','debit','credit','posting_date','fiscal_year','company']],cancel)
|
||||
|
||||
# Create new GL entry object and map values
|
||||
le = Document('GL Entry')
|
||||
for k in flist:
|
||||
le.fields[k] = self.get_val(le_map[k], d, parent)
|
||||
|
||||
# if there is already an entry in this account then just add it to that entry
|
||||
same_head = self.check_if_in_list(le)
|
||||
if same_head and merge_entries:
|
||||
same_head = same_head[0]
|
||||
same_head.debit = flt(same_head.debit) + flt(le.debit)
|
||||
same_head.credit = flt(same_head.credit) + flt(le.credit)
|
||||
else:
|
||||
self.entries.append(le)
|
||||
|
||||
# Save GL Entries
|
||||
# ----------------
|
||||
def save_entries(self, cancel, adv_adj, update_outstanding):
|
||||
for le in self.entries:
|
||||
# cancel
|
||||
if cancel or flt(le.debit) < 0 or flt(le.credit) < 0:
|
||||
tmp=le.debit
|
||||
le.debit, le.credit = abs(flt(le.credit)), abs(flt(tmp))
|
||||
|
||||
|
||||
le_obj = get_obj(doc=le)
|
||||
# validate except on_cancel
|
||||
if not cancel:
|
||||
le_obj.validate()
|
||||
|
||||
# save
|
||||
le.save(1)
|
||||
le_obj.on_update(adv_adj, cancel, update_outstanding)
|
||||
|
||||
# update total debit / credit
|
||||
self.td += flt(le.debit)
|
||||
self.tc += flt(le.credit)
|
||||
|
||||
# Make Multiple Entries
|
||||
# ---------------------
|
||||
def make_gl_entries(self, doc, doclist, cancel=0, adv_adj = 0, use_mapper='', merge_entries = 1, update_outstanding='Yes'):
|
||||
# get entries
|
||||
le_map_list = sql("select * from `tabGL Mapper Detail` where parent = %s", use_mapper or doc.doctype, as_dict=1)
|
||||
self.td, self.tc = 0.0, 0.0
|
||||
for le_map in le_map_list:
|
||||
if le_map['table_field']:
|
||||
for d in getlist(doclist,le_map['table_field']):
|
||||
# purchase_tax_details is the table of other charges in purchase cycle
|
||||
if le_map['table_field'] != 'purchase_tax_details' or (le_map['table_field'] == 'purchase_tax_details' and d.fields.get('category') != 'For Valuation'):
|
||||
self.make_single_entry(doc,d,le_map,cancel, merge_entries)
|
||||
else:
|
||||
self.make_single_entry(None,doc,le_map,cancel, merge_entries)
|
||||
|
||||
# save entries
|
||||
self.save_entries(cancel, adv_adj, update_outstanding)
|
||||
|
||||
# check total debit / credit
|
||||
# Due to old wrong entries (total debit != total credit) some voucher could be cancelled
|
||||
if abs(self.td - self.tc) > 0.001 and not cancel:
|
||||
msgprint("Debit and Credit not equal for this voucher: Diff (Debit) is %s" % (self.td-self.tc))
|
||||
raise Exception
|
||||
|
||||
# set as cancelled
|
||||
if cancel:
|
||||
vt, vn = self.get_val(le_map['voucher_type'], doc, doc), self.get_val(le_map['voucher_no'], doc, doc)
|
||||
sql("update `tabGL Entry` set is_cancelled='Yes' where voucher_type=%s and voucher_no=%s", (vt, vn))
|
||||
|
||||
# Get account balance on any date
|
||||
# -------------------------------
|
||||
def get_as_on_balance(self, account_name, fiscal_year, as_on, credit_or_debit, lft, rgt):
|
||||
# initialization
|
||||
det = sql("select start_date, opening from `tabAccount Balance` where period = %s and account = %s", (fiscal_year, account_name))
|
||||
from_date, opening, debit_bal, credit_bal, closing_bal = det and det[0][0] or getdate(nowdate()), det and flt(det[0][1]) or 0, 0, 0, det and flt(det[0][1]) or 0
|
||||
|
||||
# prev month closing
|
||||
prev_month_det = sql("select end_date, debit, credit, balance from `tabAccount Balance` where account = %s and end_date <= %s and fiscal_year = %s order by end_date desc limit 1", (account_name, as_on, fiscal_year))
|
||||
if prev_month_det:
|
||||
from_date = getdate(add_days(prev_month_det[0][0].strftime('%Y-%m-%d'), 1))
|
||||
opening = 0
|
||||
debit_bal = flt(prev_month_det[0][1])
|
||||
credit_bal = flt(prev_month_det[0][2])
|
||||
closing_bal = flt(prev_month_det[0][3])
|
||||
|
||||
# curr month transaction
|
||||
if getdate(as_on) >= from_date:
|
||||
curr_month_bal = sql("select SUM(t1.debit), SUM(t1.credit) from `tabGL Entry` t1, `tabAccount` t2 WHERE t1.posting_date >= %s AND t1.posting_date <= %s and ifnull(t1.is_opening, 'No') = 'No' AND t1.account = t2.name AND t2.lft >= %s AND t2.rgt <= %s and ifnull(t1.is_cancelled, 'No') = 'No'", (from_date, as_on, lft, rgt))
|
||||
curr_debit_amt, curr_credit_amt = flt(curr_month_bal[0][0]), flt(curr_month_bal[0][1])
|
||||
debit_bal = curr_month_bal and debit_bal + curr_debit_amt or debit_bal
|
||||
credit_bal = curr_month_bal and credit_bal + curr_credit_amt or credit_bal
|
||||
|
||||
if credit_or_debit == 'Credit':
|
||||
curr_debit_amt, curr_credit_amt = -1*flt(curr_month_bal[0][0]), -1*flt(curr_month_bal[0][1])
|
||||
closing_bal = closing_bal + curr_debit_amt - curr_credit_amt
|
||||
|
||||
return flt(debit_bal), flt(credit_bal), flt(closing_bal)
|
||||
|
||||
|
||||
# ADVANCE ALLOCATION
|
||||
#-------------------
|
||||
def get_advances(self, obj, account_head, table_name,table_field_name, dr_or_cr):
|
||||
jv_detail = sql("select t1.name, t1.remark, t2.%s, t2.name, t1.ded_amount from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2 where t1.name = t2.parent and (t2.against_voucher is null or t2.against_voucher = '') and (t2.against_invoice is null or t2.against_invoice = '') and (t2.against_jv is null or t2.against_jv = '') and t2.account = '%s' and t2.is_advance = 'Yes' and t1.docstatus = 1 order by t1.voucher_date " % (dr_or_cr,account_head))
|
||||
# clear advance table
|
||||
obj.doc.clear_table(obj.doclist,table_field_name)
|
||||
# Create advance table
|
||||
for d in jv_detail:
|
||||
add = addchild(obj.doc, table_field_name, table_name, 1, obj.doclist)
|
||||
add.journal_voucher = d[0]
|
||||
add.jv_detail_no = d[3]
|
||||
add.remarks = d[1]
|
||||
add.advance_amount = flt(d[2])
|
||||
add.allocate_amount = 0
|
||||
if table_name == 'Advance Allocation Detail':
|
||||
add.tds_amount = flt(d[4])
|
||||
|
||||
# Clear rows which is not adjusted
|
||||
#-------------------------------------
|
||||
def clear_advances(self, obj,table_name,table_field_name):
|
||||
for d in getlist(obj.doclist,table_field_name):
|
||||
if not flt(d.allocated_amount):
|
||||
sql("update `tab%s` set parent = '' where name = '%s' and parent = '%s'" % (table_name, d.name, d.parent))
|
||||
d.parent = ''
|
||||
|
||||
# Update aginst document in journal voucher
|
||||
#------------------------------------------
|
||||
def update_against_document_in_jv(self, obj, table_field_name, against_document_no, against_document_doctype, account_head, dr_or_cr,doctype):
|
||||
for d in getlist(obj.doclist, table_field_name):
|
||||
self.validate_jv_entry(d, account_head, dr_or_cr)
|
||||
if flt(d.advance_amount) == flt(d.allocated_amount):
|
||||
# cancel JV
|
||||
jv_obj = get_obj('Journal Voucher', d.journal_voucher, with_children=1)
|
||||
get_obj(dt='GL Control').make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel =1, adv_adj =1)
|
||||
|
||||
# update ref in JV Detail
|
||||
sql("update `tabJournal Voucher Detail` set %s = '%s' where name = '%s'" % (doctype=='Payable Voucher' and 'against_voucher' or 'against_invoice', cstr(against_document_no), d.jv_detail_no))
|
||||
|
||||
# re-submit JV
|
||||
jv_obj = get_obj('Journal Voucher', d.journal_voucher, with_children =1)
|
||||
get_obj(dt='GL Control').make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel = 0, adv_adj =1)
|
||||
|
||||
elif flt(d.advance_amount) > flt(d.allocated_amount):
|
||||
# cancel JV
|
||||
jv_obj = get_obj('Journal Voucher', d.journal_voucher, with_children=1)
|
||||
get_obj(dt='GL Control').make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel =1, adv_adj = 1)
|
||||
|
||||
# add extra entries
|
||||
self.add_extra_entry(jv_obj, d.journal_voucher, d.jv_detail_no, flt(d.allocated_amount), account_head, doctype, dr_or_cr, against_document_no)
|
||||
|
||||
# re-submit JV
|
||||
jv_obj = get_obj('Journal Voucher', d.journal_voucher, with_children =1)
|
||||
get_obj(dt='GL Control').make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel = 0, adv_adj = 1)
|
||||
else:
|
||||
msgprint("Allocation amount cannot be greater than advance amount")
|
||||
raise Exception
|
||||
|
||||
# Add extra row in jv detail for unadjusted amount
|
||||
#--------------------------------------------------
|
||||
def add_extra_entry(self,jv_obj,jv,jv_detail_no, allocate, account_head, doctype, dr_or_cr, against_document_no):
|
||||
# get old entry details
|
||||
|
||||
jvd = sql("select %s, cost_center, balance, against_account from `tabJournal Voucher Detail` where name = '%s'" % (dr_or_cr,jv_detail_no))
|
||||
advance = jvd and flt(jvd[0][0]) or 0
|
||||
balance = flt(advance) - flt(allocate)
|
||||
|
||||
# update old entry
|
||||
sql("update `tabJournal Voucher Detail` set %s = '%s', %s = '%s' where name = '%s'" % (dr_or_cr, flt(allocate), doctype == "Payable Voucher" and 'against_voucher' or 'against_invoice',cstr(against_document_no), jv_detail_no))
|
||||
|
||||
# new entry with balance amount
|
||||
add = addchild(jv_obj.doc, 'entries', 'Journal Voucher Detail', 1, jv_obj.doclist)
|
||||
add.account = account_head
|
||||
add.cost_center = cstr(jvd[0][1])
|
||||
add.balance = cstr(jvd[0][2])
|
||||
add.fields[dr_or_cr] = balance
|
||||
add.against_account = cstr(jvd[0][3])
|
||||
add.is_advance = 'Yes'
|
||||
add.save(1)
|
||||
|
||||
# check if advance entries are still valid
|
||||
# ----------------------------------------
|
||||
def validate_jv_entry(self, d, account_head, dr_or_cr):
|
||||
# 1. check if there is already a voucher reference
|
||||
# 2. check if amount is same
|
||||
# 3. check if is_advance is 'Yes'
|
||||
# 4. check if jv is submitted
|
||||
ret = sql("select t2.%s from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2 where t1.name = t2.parent and (t2.against_voucher = '' or t2.against_voucher is null) and (t2.against_invoice = '' or t2.against_invoice is null) and t2.account = '%s' and t1.name = '%s' and t2.name = '%s' and t2.is_advance = 'Yes' and t1.docstatus=1 and t2.%s = %s" % ( dr_or_cr, account_head, d.journal_voucher, d.jv_detail_no, dr_or_cr, d.advance_amount))
|
||||
if (not ret):
|
||||
msgprint("Please click on 'Get Advances Paid' button as the advance entries have been changed.")
|
||||
raise Exception
|
||||
return
|
||||
|
||||
##############################################################################
|
||||
# Repair Outstanding Amount
|
||||
##############################################################################
|
||||
def repair_voucher_outstanding(self, voucher_obj):
|
||||
msg = []
|
||||
|
||||
# Get Balance from GL Entries
|
||||
bal = sql("select sum(debit)-sum(credit) from `tabGL Entry` where against_voucher=%s and against_voucher_type=%s", (voucher_obj.doc.name , voucher_obj.doc.doctype))
|
||||
bal = bal and flt(bal[0][0]) or 0.0
|
||||
if cstr(voucher_obj.doc.doctype) == 'Payable Voucher':
|
||||
bal = -bal
|
||||
|
||||
# Check outstanding Amount
|
||||
if flt(voucher_obj.doc.outstanding_amount) != flt(bal):
|
||||
msgprint('<div style="color: RED"> Difference found in Outstanding Amount of %s : %s (Before : %s; After : %s) </div>' % (voucher_obj.doc.doctype, voucher_obj.doc.name, voucher_obj.doc.outstanding_amount, bal))
|
||||
msg.append('<div style="color: RED"> Difference found in Outstanding Amount of %s : %s (Before : %s; After : %s) </div>' % (voucher_obj.doc.doctype, voucher_obj.doc.name, voucher_obj.doc.outstanding_amount, bal))
|
||||
|
||||
# set voucher balance
|
||||
#sql("update `tab%s` set outstanding_amount=%s where name='%s'" % (voucher_obj.doc.doctype, bal, voucher_obj.doc.name))
|
||||
set(voucher_obj.doc, 'outstanding_amount', flt(bal))
|
||||
|
||||
# Send Mail
|
||||
if msg:
|
||||
email_msg = """ Dear Administrator,
|
||||
|
||||
In Account := %s User := %s has Repaired Outstanding Amount For %s : %s and following was found:-
|
||||
|
||||
%s
|
||||
|
||||
""" % (get_value('Control Panel', None,'account_id'), session['user'], voucher_obj.doc.doctype, voucher_obj.doc.name, '\n'.join(msg))
|
||||
|
||||
sendmail(['support@iwebnotes.com'], subject='Repair Outstanding Amount', parts = [('text/plain', email_msg)])
|
||||
# Acknowledge User
|
||||
msgprint(cstr(voucher_obj.doc.doctype) + " : " + cstr(voucher_obj.doc.name) + " has been checked" + cstr(msg and " and repaired successfully." or ". No changes Found."))
|
||||
1
accounts/doctype/gl_control/gl_control.txt
Normal file
1
accounts/doctype/gl_control/gl_control.txt
Normal file
@@ -0,0 +1 @@
|
||||
[{'section_style': 'Simple', 'is_transaction_doc': None, 'creation': '2010-12-06 11:45:17', 'search_fields': None, 'module': 'Accounts', 'doctype': 'DocType', 'change_log': None, 'print_outline': '', 'owner': 'Administrator', 'in_dialog': None, 'in_create': None, 'read_only': None, 'allow_email': None, 'dt_template': None, 'hide_heading': None, 'issingle': 1, 'allow_rename': None, 'smallicon': '', 'allow_attach': None, 'show_in_menu': 0, 'max_attachments': None, 'version': 300, 'menu_index': None, 'docstatus': 0, 'allow_copy': None, 'istable': None, 'description': None, 'parent': None, 'server_code': '', 'allow_trash': None, 'allow_print': None, 'autoname': None, 'client_script_core': None, 'client_string': None, 'use_template': None, 'modified_by': 'Administrator', 'document_type': '', 'name': 'GL Control', 'idx': None, 'hide_toolbar': None, 'colour': 'White:FFF', 'client_script': '', 'modified': '2010-11-18 16:35:29', 'server_code_error': ' ', 'name_case': '', 'parenttype': None, 'read_only_onload': None, 'server_code_core': None, 'server_code_compiled': None, 'parent_node': None, 'parentfield': None}]
|
||||
0
accounts/doctype/gl_entry/__init__.py
Normal file
0
accounts/doctype/gl_entry/__init__.py
Normal file
202
accounts/doctype/gl_entry/gl_entry.js
Normal file
202
accounts/doctype/gl_entry/gl_entry.js
Normal file
@@ -0,0 +1,202 @@
|
||||
class DocType:
|
||||
def __init__(self,d,dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
|
||||
# Validate mandatory
|
||||
#-------------------
|
||||
def check_mandatory(self):
|
||||
# Following fields are mandatory in GL Entry
|
||||
mandatory = ['account','remarks','voucher_type','voucher_no','fiscal_year','company']
|
||||
for k in mandatory:
|
||||
if not self.doc.fields.get(k):
|
||||
msgprint("%s is mandatory for GL Entry" % k)
|
||||
raise Exception
|
||||
|
||||
# Zero value transaction is not allowed
|
||||
if not (flt(self.doc.debit) or flt(self.doc.credit)):
|
||||
msgprint("GL Entry: Debit or Credit amount is mandatory for %s" % self.doc.account)
|
||||
raise Exception
|
||||
|
||||
# Debit and credit can not done at the same time
|
||||
if flt(self.doc.credit) != 0 and flt(self.doc.debit) != 0:
|
||||
msgprint("Sorry you cannot credit and debit under same account head.")
|
||||
raise Exception, "Validation Error."
|
||||
|
||||
# Cost center is required only if transaction made against pl account
|
||||
#--------------------------------------------------------------------
|
||||
def pl_must_have_cost_center(self):
|
||||
if sql("select name from tabAccount where name=%s and is_pl_account='Yes'", self.doc.account):
|
||||
if not self.doc.cost_center and not self.doc.voucher_type != 'Period Closing Entry':
|
||||
msgprint("Error: Cost Center must be specified for PL Account: %s" % self.doc.account_name)
|
||||
raise Exception
|
||||
else: # not pl
|
||||
if self.doc.cost_center:
|
||||
self.doc.cost_center = ''
|
||||
|
||||
# Account must be ledger, active and not freezed
|
||||
#-----------------------------------------------
|
||||
def validate_account_details(self, adv_adj):
|
||||
ret = sql("select group_or_ledger, docstatus, freeze_account, company from tabAccount where name=%s", self.doc.account)
|
||||
|
||||
# 1. Checks whether Account type is group or ledger
|
||||
if ret and ret[0][0]=='Group':
|
||||
msgprint("Error: All accounts must be Ledgers. Account %s is a group" % self.doc.account)
|
||||
raise Exception
|
||||
|
||||
# 2. Checks whether Account is active
|
||||
if ret and ret[0][1]==2:
|
||||
msgprint("Error: All accounts must be Active. Account %s moved to Trash" % self.doc.account)
|
||||
raise Exception
|
||||
|
||||
# 3. Account has been freezed for other users except account manager
|
||||
if ret and ret[0][2]== 'Yes' and not adv_adj and not 'Accounts Manager' in session['data']['roles']:
|
||||
msgprint("Error: Account %s has been freezed. Only Accounts Manager can do transaction against this account." % self.doc.account)
|
||||
raise Exception
|
||||
|
||||
# 4. Check whether account is within the company
|
||||
if ret and ret[0][3] != self.doc.company:
|
||||
msgprint("Account: %s does not belong to the company: %s" % (self.doc.account, self.doc.company))
|
||||
raise Exception
|
||||
|
||||
# Posting date must be in selected fiscal year and fiscal year is active
|
||||
#-------------------------------------------------------------------------
|
||||
def validate_posting_date(self):
|
||||
fy = sql("select docstatus, year_start_date from `tabFiscal Year` where name=%s ", self.doc.fiscal_year)
|
||||
ysd = fy[0][1]
|
||||
yed = get_last_day(get_first_day(ysd,0,11))
|
||||
pd = getdate(self.doc.posting_date)
|
||||
if fy[0][0] == 2:
|
||||
msgprint("Fiscal Year is not active. You can restore it from Trash")
|
||||
raise Exception
|
||||
if pd < ysd or pd > yed:
|
||||
msgprint("Posting date must be in the Selected Financial Year")
|
||||
raise Exception
|
||||
|
||||
|
||||
# Nobody can do GL Entries where posting date is before freezing date except 'Accounts Manager'
|
||||
#----------------------------------------------------------------------------------------------
|
||||
def check_freezing_date(self, adv_adj):
|
||||
if not adv_adj:
|
||||
pd,fd = getdate(self.doc.posting_date),0
|
||||
acc_frozen_upto = get_obj(dt = 'Manage Account').doc.acc_frozen_upto or ''
|
||||
if acc_frozen_upto:
|
||||
fd = getdate(acc_frozen_upto)
|
||||
|
||||
bde_auth_role = get_value( 'Manage Account', None,'bde_auth_role')
|
||||
if fd and pd <= fd and (bde_auth_role and not bde_auth_role in session['data']['roles']):
|
||||
msgprint("Message:You are not authorized to do back dated entries for account: %s before %s." % (self.doc.account, str(fd)))
|
||||
raise Exception
|
||||
|
||||
# create new bal if not exists
|
||||
#-----------------------------
|
||||
def create_new_balances(self, ac_obj, p, amt):
|
||||
ac = addchild(ac_obj.doc, 'account_balances', 'Account Balance', 1)
|
||||
ac.period = p[0]
|
||||
ac.start_date = p[1].strftime('%Y-%m-%d')
|
||||
ac.end_date = p[2].strftime('%Y-%m-%d')
|
||||
ac.fiscal_year = p[3]
|
||||
ac.opening = 0
|
||||
ac.balance = amt
|
||||
ac.save()
|
||||
|
||||
# Post Balance
|
||||
# ------------
|
||||
def post_balance(self, acc):
|
||||
# get details
|
||||
lft = sql("select lft, rgt, debit_or_credit from `tabAccount` where name='%s'" % acc)
|
||||
|
||||
# amount to debit
|
||||
amt = flt(self.doc.debit) - flt(self.doc.credit)
|
||||
if lft[0][2] == 'Credit': amt = -amt
|
||||
|
||||
# get periods
|
||||
periods = self.get_period_list(self.doc.posting_date, self.doc.fiscal_year)
|
||||
|
||||
acc_obj = get_obj('Account', self.doc.account)
|
||||
for p in periods:
|
||||
if not sql("select name from `tabAccount Balance` where parent=%s and period=%s", (self.doc.account, p[0])):
|
||||
self.create_new_balances(acc_obj, p, amt)
|
||||
else:
|
||||
# update current
|
||||
pl = sql("update `tabAccount Balance` t1, `tabAccount` t2 set t1.balance = t1.balance + %s where t2.lft<=%s and t2.rgt>=%s and t1.parent = t2.name and t1.period = '%s'" % (amt, cint(lft[0][0]), cint(lft[0][1]), p[0]))
|
||||
|
||||
# update opening
|
||||
if self.doc.is_opening=='Yes':
|
||||
pl = sql("update `tabAccount Balance` t1, `tabAccount` t2 set t1.opening = ifnull(t1.opening,0) + %s where t2.lft<=%s and t2.rgt>=%s and t1.parent = t2.name and t1.period = '%s'" % (amt, cint(lft[0][0]), cint(lft[0][1]), self.doc.fiscal_year))
|
||||
|
||||
# Get periods(month and year)
|
||||
#-----------------------------
|
||||
def get_period_list(self, dt, fy):
|
||||
pl = sql("SELECT name, start_date, end_date, fiscal_year FROM tabPeriod WHERE end_date >='%s' and fiscal_year = '%s' and period_type in ('Month', 'Year')" % (dt,fy))
|
||||
return pl
|
||||
|
||||
# Voucher Balance
|
||||
# ---------------
|
||||
def update_outstanding_amt(self):
|
||||
# get final outstanding amt
|
||||
bal = flt(sql("select sum(debit)-sum(credit) from `tabGL Entry` where against_voucher=%s and against_voucher_type=%s and ifnull(is_cancelled,'No') = 'No'", (self.doc.against_voucher, self.doc.against_voucher_type))[0][0] or 0.0)
|
||||
tds = 0
|
||||
|
||||
if self.doc.against_voucher_type=='Payable Voucher':
|
||||
# amount to debit
|
||||
bal = -bal
|
||||
|
||||
# Check if tds applicable
|
||||
tds = sql("select total_tds_on_voucher from `tabPayable Voucher` where name = '%s'" % self.doc.against_voucher)
|
||||
tds = tds and flt(tds[0][0]) or 0
|
||||
|
||||
# Validation : Outstanding can not be negative
|
||||
if bal < 0 and not tds and self.doc.is_cancelled == 'No':
|
||||
msgprint("Outstanding for Voucher %s will become %s. Outstanding cannot be less than zero. Please match exact outstanding." % (self.doc.against_voucher, fmt_money(bal)))
|
||||
raise Exception
|
||||
|
||||
# Update outstanding amt on against voucher
|
||||
sql("update `tab%s` set outstanding_amount=%s where name='%s'"% (self.doc.against_voucher_type,bal,self.doc.against_voucher))
|
||||
|
||||
|
||||
# Total outstanding can not be greater than credit limit for any time for any customer
|
||||
#---------------------------------------------------------------------------------------------
|
||||
def check_credit_limit(self):
|
||||
#check for user role Freezed
|
||||
master_type=sql("select master_type from `tabAccount` where name='%s' " %self.doc.account)
|
||||
tot_outstanding = 0 #needed when there is no GL Entry in the system for that acc head
|
||||
if (self.doc.voucher_type=='Journal Voucher' or self.doc.voucher_type=='Receivable Voucher') and (master_type and master_type[0][0]=='Customer'):
|
||||
dbcr=sql("select sum(debit),sum(credit) from `tabGL Entry` where account = '%s' and is_cancelled='No'" % self.doc.account)
|
||||
if dbcr:
|
||||
tot_outstanding = flt(dbcr[0][0])-flt(dbcr[0][1])+flt(self.doc.debit)-flt(self.doc.credit)
|
||||
get_obj('Account',self.doc.account).check_credit_limit(self.doc.account, self.doc.company, tot_outstanding)
|
||||
|
||||
#for opening entry account can not be pl account
|
||||
#-----------------------------------------------
|
||||
def check_pl_account(self):
|
||||
if self.doc.is_opening=='Yes':
|
||||
is_pl_account=sql("select is_pl_account from `tabAccount` where name='%s'"%(self.doc.account))
|
||||
if is_pl_account and is_pl_account[0][0]=='Yes':
|
||||
msgprint("For opening balance entry account can not be a PL account")
|
||||
raise Exception
|
||||
|
||||
# Validate
|
||||
# --------
|
||||
def validate(self): # not called on cancel
|
||||
self.check_mandatory()
|
||||
self.pl_must_have_cost_center()
|
||||
self.validate_posting_date()
|
||||
self.doc.is_cancelled = 'No' # will be reset by GL Control if cancelled
|
||||
self.check_credit_limit()
|
||||
self.check_pl_account()
|
||||
|
||||
# On Update
|
||||
#----------
|
||||
def on_update(self,adv_adj):
|
||||
# Account must be ledger, active and not freezed
|
||||
self.validate_account_details(adv_adj)
|
||||
|
||||
# Posting date must be after freezing date
|
||||
self.check_freezing_date(adv_adj)
|
||||
|
||||
# Update current account balance
|
||||
self.post_balance(self.doc.account)
|
||||
|
||||
# Update outstanding amt on against voucher
|
||||
if self.doc.against_voucher:
|
||||
self.update_outstanding_amt()
|
||||
251
accounts/doctype/gl_entry/gl_entry.py
Normal file
251
accounts/doctype/gl_entry/gl_entry.py
Normal file
@@ -0,0 +1,251 @@
|
||||
# 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
|
||||
|
||||
# Validate mandatory
|
||||
#-------------------
|
||||
def check_mandatory(self):
|
||||
# Following fields are mandatory in GL Entry
|
||||
mandatory = ['account','remarks','voucher_type','voucher_no','fiscal_year','company']
|
||||
for k in mandatory:
|
||||
if not self.doc.fields.get(k):
|
||||
msgprint("%s is mandatory for GL Entry" % k)
|
||||
raise Exception
|
||||
|
||||
# Zero value transaction is not allowed
|
||||
if not (flt(self.doc.debit) or flt(self.doc.credit)):
|
||||
msgprint("GL Entry: Debit or Credit amount is mandatory for %s" % self.doc.account)
|
||||
raise Exception
|
||||
|
||||
# Debit and credit can not done at the same time
|
||||
if flt(self.doc.credit) != 0 and flt(self.doc.debit) != 0:
|
||||
msgprint("Sorry you cannot credit and debit under same account head.")
|
||||
raise Exception, "Validation Error."
|
||||
|
||||
# Cost center is required only if transaction made against pl account
|
||||
#--------------------------------------------------------------------
|
||||
def pl_must_have_cost_center(self):
|
||||
if sql("select name from tabAccount where name=%s and is_pl_account='Yes'", self.doc.account):
|
||||
if not self.doc.cost_center and self.doc.voucher_type != 'Period Closing Voucher':
|
||||
msgprint("Error: Cost Center must be specified for PL Account: %s" % self.doc.account)
|
||||
raise Exception
|
||||
else: # not pl
|
||||
if self.doc.cost_center:
|
||||
self.doc.cost_center = ''
|
||||
|
||||
# Account must be ledger, active and not freezed
|
||||
#-----------------------------------------------
|
||||
def validate_account_details(self, adv_adj):
|
||||
ret = sql("select group_or_ledger, docstatus, freeze_account, company from tabAccount where name=%s", self.doc.account)
|
||||
|
||||
# 1. Checks whether Account type is group or ledger
|
||||
if ret and ret[0][0]=='Group':
|
||||
msgprint("Error: All accounts must be Ledgers. Account %s is a group" % self.doc.account)
|
||||
raise Exception
|
||||
|
||||
# 2. Checks whether Account is active
|
||||
if ret and ret[0][1]==2:
|
||||
msgprint("Error: All accounts must be Active. Account %s moved to Trash" % self.doc.account)
|
||||
raise Exception
|
||||
|
||||
# 3. Account has been freezed for other users except account manager
|
||||
if ret and ret[0][2]== 'Yes' and not adv_adj and not 'Accounts Manager' in webnotes.user.get_roles():
|
||||
msgprint("Error: Account %s has been freezed. Only Accounts Manager can do transaction against this account." % self.doc.account)
|
||||
raise Exception
|
||||
|
||||
# 4. Check whether account is within the company
|
||||
if ret and ret[0][3] != self.doc.company:
|
||||
msgprint("Account: %s does not belong to the company: %s" % (self.doc.account, self.doc.company))
|
||||
raise Exception
|
||||
|
||||
# Posting date must be in selected fiscal year and fiscal year is active
|
||||
#-------------------------------------------------------------------------
|
||||
def validate_posting_date(self):
|
||||
fy = sql("select docstatus, year_start_date from `tabFiscal Year` where name=%s ", self.doc.fiscal_year)
|
||||
ysd = fy[0][1]
|
||||
yed = get_last_day(get_first_day(ysd,0,11))
|
||||
pd = getdate(self.doc.posting_date)
|
||||
if fy[0][0] == 2:
|
||||
msgprint("Fiscal Year is not active. You can restore it from Trash")
|
||||
raise Exception
|
||||
if pd < ysd or pd > yed:
|
||||
msgprint("Posting date must be in the Selected Financial Year")
|
||||
raise Exception
|
||||
|
||||
|
||||
# Nobody can do GL Entries where posting date is before freezing date except authorized person
|
||||
#----------------------------------------------------------------------------------------------
|
||||
def check_freezing_date(self, adv_adj):
|
||||
if not adv_adj:
|
||||
acc_frozen_upto = get_value('Manage Account', None, 'acc_frozen_upto')
|
||||
if acc_frozen_upto:
|
||||
bde_auth_role = get_value( 'Manage Account', None,'bde_auth_role')
|
||||
if getdate(self.doc.posting_date) <= getdate(acc_frozen_upto) and not bde_auth_role in webnotes.user.get_roles():
|
||||
msgprint("You are not authorized to do/modify back dated accounting entries before %s." % getdate(acc_frozen_upto).strftime('%d-%m-%Y'), raise_exception=1)
|
||||
|
||||
# create new bal if not exists
|
||||
#-----------------------------
|
||||
def create_new_balances(self, det):
|
||||
# check
|
||||
if sql("select count(t1.name) from `tabAccount Balance` t1, tabAccount t2 where t1.fiscal_year=%s and t2.lft <= %s and t2.rgt >= %s and t2.name = t1.account", (self.doc.fiscal_year, det[0][0], det[0][1]))[0][0] < 13*(cint(det[0][1]) - cint(det[0][0]) +1)/2:
|
||||
period_list = self.get_period_list()
|
||||
accounts = sql("select name from tabAccount where lft <= %s and rgt >= %s" % (det[0][0], det[0][1]))
|
||||
|
||||
for p in period_list:
|
||||
for a in accounts:
|
||||
# check if missing
|
||||
if not sql("select name from `tabAccount Balance` where period=%s and account=%s and fiscal_year=%s", (p[0], a[0], self.doc.fiscal_year)):
|
||||
d = Document('Account Balance')
|
||||
d.account = a[0]
|
||||
d.period = p[0]
|
||||
d.start_date = p[1].strftime('%Y-%m-%d')
|
||||
d.end_date = p[2].strftime('%Y-%m-%d')
|
||||
d.fiscal_year = self.doc.fiscal_year
|
||||
d.debit = 0
|
||||
d.credit = 0
|
||||
d.opening = 0
|
||||
d.balance = 0
|
||||
d.save(1)
|
||||
|
||||
# Post Balance
|
||||
# ------------
|
||||
def post_balance(self, acc, cancel):
|
||||
# get details
|
||||
det = sql("select lft, rgt, debit_or_credit from `tabAccount` where name='%s'" % acc)
|
||||
|
||||
# amount to debit
|
||||
amt = flt(self.doc.debit) - flt(self.doc.credit)
|
||||
if det[0][2] == 'Credit': amt = -amt
|
||||
if cancel:
|
||||
debit = -1 * flt(self.doc.credit)
|
||||
credit = -1 * flt(self.doc.debit)
|
||||
else:
|
||||
debit = flt(self.doc.debit)
|
||||
credit = flt(self.doc.credit)
|
||||
|
||||
self.create_new_balances(det)
|
||||
|
||||
# build dict
|
||||
p = {
|
||||
'debit': flt(debit)
|
||||
,'credit':flt(credit)
|
||||
,'opening': self.doc.is_opening=='Yes' and amt or 0
|
||||
# end date condition only if it is not opening
|
||||
,'end_date_condition':(self.doc.is_opening!='Yes' and ("and ab.end_date >= '"+self.doc.posting_date+"'") or '')
|
||||
,'diff': amt
|
||||
,'lft': cint(det[0][0])
|
||||
,'rgt': cint(det[0][1])
|
||||
,'posting_date': self.doc.posting_date
|
||||
,'fiscal_year': self.doc.fiscal_year
|
||||
}
|
||||
|
||||
sql("""update `tabAccount Balance` ab, `tabAccount` a
|
||||
set
|
||||
ab.debit = ifnull(ab.debit,0) + %(debit)s
|
||||
,ab.credit = ifnull(ab.credit,0) + %(credit)s
|
||||
,ab.opening = ifnull(ab.opening,0) + %(opening)s
|
||||
,ab.balance = ifnull(ab.balance,0) + %(diff)s
|
||||
where
|
||||
a.lft <= %(lft)s
|
||||
and a.rgt >= %(rgt)s
|
||||
and ab.account = a.name
|
||||
%(end_date_condition)s
|
||||
and ab.fiscal_year = '%(fiscal_year)s' """ % p)
|
||||
|
||||
|
||||
# Get periods(month and year)
|
||||
#-----------------------------
|
||||
def get_period_list(self):
|
||||
pl = sql("SELECT name, start_date, end_date, fiscal_year FROM tabPeriod WHERE fiscal_year = '%s' and period_type in ('Month', 'Year')" % (self.doc.fiscal_year))
|
||||
return pl
|
||||
|
||||
# Voucher Balance
|
||||
# ---------------
|
||||
def update_outstanding_amt(self):
|
||||
# get final outstanding amt
|
||||
|
||||
bal = flt(sql("select sum(debit)-sum(credit) from `tabGL Entry` where against_voucher=%s and against_voucher_type=%s and ifnull(is_cancelled,'No') = 'No'", (self.doc.against_voucher, self.doc.against_voucher_type))[0][0] or 0.0)
|
||||
tds = 0
|
||||
|
||||
if self.doc.against_voucher_type=='Payable Voucher':
|
||||
# amount to debit
|
||||
bal = -bal
|
||||
|
||||
# Check if tds applicable
|
||||
tds = sql("select total_tds_on_voucher from `tabPayable Voucher` where name = '%s'" % self.doc.against_voucher)
|
||||
tds = tds and flt(tds[0][0]) or 0
|
||||
|
||||
# Validation : Outstanding can not be negative
|
||||
if bal < 0 and not tds and self.doc.is_cancelled == 'No':
|
||||
msgprint("Outstanding for Voucher %s will become %s. Outstanding cannot be less than zero. Please match exact outstanding." % (self.doc.against_voucher, fmt_money(bal)))
|
||||
raise Exception
|
||||
|
||||
# Update outstanding amt on against voucher
|
||||
sql("update `tab%s` set outstanding_amount=%s where name='%s'"% (self.doc.against_voucher_type,bal,self.doc.against_voucher))
|
||||
|
||||
|
||||
# Total outstanding can not be greater than credit limit for any time for any customer
|
||||
#---------------------------------------------------------------------------------------------
|
||||
def check_credit_limit(self):
|
||||
#check for user role Freezed
|
||||
master_type=sql("select master_type, master_name from `tabAccount` where name='%s' " %self.doc.account)
|
||||
tot_outstanding = 0 #needed when there is no GL Entry in the system for that acc head
|
||||
if (self.doc.voucher_type=='Journal Voucher' or self.doc.voucher_type=='Receivable Voucher') and (master_type and master_type[0][0]=='Customer' and master_type[0][1]):
|
||||
dbcr = sql("select sum(debit),sum(credit) from `tabGL Entry` where account = '%s' and is_cancelled='No'" % self.doc.account)
|
||||
if dbcr:
|
||||
tot_outstanding = flt(dbcr[0][0])-flt(dbcr[0][1])+flt(self.doc.debit)-flt(self.doc.credit)
|
||||
get_obj('Account',self.doc.account).check_credit_limit(self.doc.account, self.doc.company, tot_outstanding)
|
||||
|
||||
#for opening entry account can not be pl account
|
||||
#-----------------------------------------------
|
||||
def check_pl_account(self):
|
||||
if self.doc.is_opening=='Yes':
|
||||
is_pl_account=sql("select is_pl_account from `tabAccount` where name='%s'"%(self.doc.account))
|
||||
if is_pl_account and is_pl_account[0][0]=='Yes':
|
||||
msgprint("For opening balance entry account can not be a PL account")
|
||||
raise Exception
|
||||
|
||||
# Validate
|
||||
# --------
|
||||
def validate(self): # not called on cancel
|
||||
self.check_mandatory()
|
||||
self.pl_must_have_cost_center()
|
||||
self.validate_posting_date()
|
||||
self.doc.is_cancelled = 'No' # will be reset by GL Control if cancelled
|
||||
self.check_credit_limit()
|
||||
self.check_pl_account()
|
||||
|
||||
# On Update
|
||||
#----------
|
||||
def on_update(self,adv_adj, cancel, update_outstanding = 'Yes'):
|
||||
# Account must be ledger, active and not freezed
|
||||
self.validate_account_details(adv_adj)
|
||||
|
||||
# Posting date must be after freezing date
|
||||
self.check_freezing_date(adv_adj)
|
||||
|
||||
# Update current account balance
|
||||
self.post_balance(self.doc.account, cancel)
|
||||
|
||||
# Update outstanding amt on against voucher
|
||||
if self.doc.against_voucher and self.doc.against_voucher_type not in ('Journal Voucher','POS') and update_outstanding == 'Yes':
|
||||
self.update_outstanding_amt()
|
||||
1
accounts/doctype/gl_entry/gl_entry.txt
Normal file
1
accounts/doctype/gl_entry/gl_entry.txt
Normal file
File diff suppressed because one or more lines are too long
0
accounts/doctype/journal_voucher/__init__.py
Normal file
0
accounts/doctype/journal_voucher/__init__.py
Normal file
158
accounts/doctype/journal_voucher/journal_voucher.js
Normal file
158
accounts/doctype/journal_voucher/journal_voucher.js
Normal file
@@ -0,0 +1,158 @@
|
||||
cur_frm.cscript.onload = function(doc, cdt, cdn) {
|
||||
var cp = locals['Control Panel']['Control Panel'];
|
||||
if(doc.__islocal){
|
||||
doc.clearance_date ='';
|
||||
refresh_field('clearance_date');
|
||||
}
|
||||
|
||||
if (!doc.voucher_date) doc.voucher_date = dateutil.obj_to_str(new Date());
|
||||
|
||||
if(cp.country == 'India') {
|
||||
unhide_field(['tds_applicable','tds_category','Get TDS','tax_code','rate','ded_amount','supplier_account']);
|
||||
}
|
||||
else {
|
||||
hide_field(['tds_applicable','tds_category','Get TDS','tax_code','rate','ded_amount','supplier_account']);
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript.is_opening = function(doc, cdt, cdn) {
|
||||
hide_field('aging_date');
|
||||
if (doc.is_opening == 'Yes') unhide_field('aging_date');
|
||||
|
||||
if(doc.docstatus==1) { unhide_field('View Ledger Entry'); }
|
||||
else hide_field('View Ledger Entry');
|
||||
}
|
||||
|
||||
cur_frm.cscript.refresh = cur_frm.cscript.is_opening;
|
||||
|
||||
cur_frm.fields_dict['entries'].grid.get_field('account').get_query = function(doc) {
|
||||
return "SELECT `tabAccount`.name FROM `tabAccount` WHERE `tabAccount`.company='"+doc.company+"' AND tabAccount.group_or_ledger = 'Ledger' AND tabAccount.docstatus != 2 AND `tabAccount`.%(key)s LIKE '%s' ORDER BY `tabAccount`.name DESC LIMIT 50";
|
||||
}
|
||||
|
||||
cur_frm.fields_dict["entries"].grid.get_field("cost_center").get_query = function(doc, cdt, cdn) {
|
||||
return 'SELECT `tabCost Center`.`name` FROM `tabCost Center` WHERE `tabCost Center`.`company_name` = "' +doc.company+'" AND `tabCost Center`.%(key)s LIKE "%s" AND `tabCost Center`.`group_or_ledger` = "Ledger" AND `tabCost Center`.docstatus != 2 ORDER BY `tabCost Center`.`name` ASC LIMIT 50';
|
||||
}
|
||||
|
||||
// Restrict Voucher based on Account
|
||||
// ---------------------------------
|
||||
cur_frm.fields_dict['entries'].grid.get_field('against_voucher').get_query = function(doc) {
|
||||
var d = locals[this.doctype][this.docname];
|
||||
return "SELECT `tabPayable Voucher`.name, `tabPayable Voucher`.credit_to, `tabPayable Voucher`.outstanding_amount,`tabPayable Voucher`.bill_no, `tabPayable Voucher`.bill_date FROM `tabPayable Voucher` WHERE `tabPayable Voucher`.credit_to='"+d.account+"' AND `tabPayable Voucher`.outstanding_amount > 0 AND `tabPayable Voucher`.docstatus = 1 AND `tabPayable Voucher`.%(key)s LIKE '%s' ORDER BY `tabPayable Voucher`.name DESC LIMIT 200";
|
||||
}
|
||||
|
||||
cur_frm.fields_dict['entries'].grid.get_field('against_invoice').get_query = function(doc) {
|
||||
var d = locals[this.doctype][this.docname];
|
||||
return "SELECT `tabReceivable Voucher`.name, `tabReceivable Voucher`.debit_to, `tabReceivable Voucher`.outstanding_amount FROM `tabReceivable Voucher` WHERE `tabReceivable Voucher`.debit_to='"+d.account+"' AND `tabReceivable Voucher`.outstanding_amount > 0 AND `tabReceivable Voucher`.docstatus = 1 AND `tabReceivable Voucher`.%(key)s LIKE '%s' ORDER BY `tabReceivable Voucher`.name DESC LIMIT 200";
|
||||
}
|
||||
|
||||
// TDS Account Head
|
||||
cur_frm.fields_dict['tax_code'].get_query = function(doc) {
|
||||
return "SELECT `tabTDS Category Account`.account_head FROM `tabTDS Category Account` WHERE `tabTDS Category Account`.parent = '"+doc.tds_category+"' AND `tabTDS Category Account`.company='"+doc.company+"' AND `tabTDS Category Account`.account_head LIKE '%s' ORDER BY `tabTDS Category Account`.account_head DESC LIMIT 50";
|
||||
}
|
||||
|
||||
//Set debit and credit to zero on adding new row
|
||||
//----------------------------------------------
|
||||
cur_frm.fields_dict['entries'].grid.onrowadd = function(doc, cdt, cdn){
|
||||
var d = locals[cdt][cdn];
|
||||
if(d.idx == 1){
|
||||
d.debit = 0;
|
||||
d.credit = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Get Outstanding of Payable & Receivable Voucher
|
||||
// -----------------------------------------------
|
||||
|
||||
cur_frm.cscript.against_voucher = function(doc,cdt,cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
if (d.against_voucher && !flt(d.debit)) {
|
||||
args = {'doctype': 'Payable Voucher', 'docname': d.against_voucher }
|
||||
get_server_fields('get_outstanding',docstring(args),'entries',doc,cdt,cdn,1,function(r,rt) { cur_frm.cscript.update_totals(doc); });
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript.against_invoice = function(doc,cdt,cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
if (d.against_invoice && !flt(d.credit)) {
|
||||
args = {'doctype': 'Receivable Voucher', 'docname': d.against_invoice }
|
||||
get_server_fields('get_outstanding',docstring(args),'entries',doc,cdt,cdn,1,function(r,rt) { cur_frm.cscript.update_totals(doc); });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Update Totals
|
||||
// ---------------
|
||||
cur_frm.cscript.update_totals = function(doc) {
|
||||
var td=0.0; var tc =0.0;
|
||||
var el = getchildren('Journal Voucher Detail', doc.name, 'entries');
|
||||
for(var i in el) {
|
||||
td += flt(el[i].debit);
|
||||
tc += flt(el[i].credit);
|
||||
}
|
||||
var doc = locals[doc.doctype][doc.name];
|
||||
tc += flt(doc.ded_amount)
|
||||
doc.total_debit = td;
|
||||
doc.total_credit = tc;
|
||||
doc.difference = flt(td - tc);
|
||||
refresh_many(['total_debit','total_credit','difference']);
|
||||
}
|
||||
|
||||
cur_frm.cscript.debit = function(doc,dt,dn) { cur_frm.cscript.update_totals(doc); }
|
||||
cur_frm.cscript.credit = function(doc,dt,dn) { cur_frm.cscript.update_totals(doc); }
|
||||
cur_frm.cscript.ded_amount = function(doc,dt,dn) { cur_frm.cscript.update_totals(doc); }
|
||||
cur_frm.cscript.rate = function(doc,dt,dn) {
|
||||
doc.ded_amount = doc.total_debit*doc.rate/100;
|
||||
refresh_field('ded_amount');
|
||||
cur_frm.cscript.update_totals(doc);
|
||||
}
|
||||
cur_frm.cscript['Get Balance'] = function(doc,dt,dn) {
|
||||
cur_frm.cscript.update_totals(doc);
|
||||
$c_obj(make_doclist(dt,dn), 'get_balance', '', function(r, rt){
|
||||
cur_frm.refresh();
|
||||
});
|
||||
}
|
||||
// Get balance
|
||||
// -----------
|
||||
|
||||
cur_frm.cscript.account = function(doc,dt,dn) {
|
||||
var d = locals[dt][dn];
|
||||
$c_obj('GL Control','get_bal',d.account+'~~~'+doc.fiscal_year, function(r,rt) { d.balance = r.message; refresh_field('balance',d.name,'entries'); });
|
||||
}
|
||||
|
||||
cur_frm.cscript.validate = function(doc,cdt,cdn) {
|
||||
cur_frm.cscript.update_totals(doc);
|
||||
}
|
||||
|
||||
// TDS
|
||||
// --------
|
||||
cur_frm.cscript['Get TDS'] = function(doc, dt, dn) {
|
||||
$c_obj(make_doclist(dt,dn), 'get_tds', '', function(r, rt){
|
||||
cur_frm.refresh();
|
||||
cur_frm.cscript.update_totals(doc);
|
||||
});
|
||||
}
|
||||
|
||||
// ***************** Get Print Heading based on Receivable Voucher *****************
|
||||
cur_frm.fields_dict['select_print_heading'].get_query = function(doc, cdt, cdn) {
|
||||
return 'SELECT `tabPrint Heading`.name FROM `tabPrint Heading` WHERE `tabPrint Heading`.docstatus !=2 AND `tabPrint Heading`.name LIKE "%s" ORDER BY `tabPrint Heading`.name ASC LIMIT 50';
|
||||
}
|
||||
|
||||
|
||||
|
||||
cur_frm.cscript.select_print_heading = function(doc,cdt,cdn){
|
||||
if(doc.select_print_heading){
|
||||
// print heading
|
||||
cur_frm.pformat.print_heading = doc.select_print_heading;
|
||||
}
|
||||
else
|
||||
cur_frm.pformat.print_heading = "Journal Voucher";
|
||||
}
|
||||
|
||||
/****************** Get Accounting Entry *****************/
|
||||
cur_frm.cscript['View Ledger Entry'] = function(doc,cdt,cdn){
|
||||
var callback = function(report){
|
||||
report.set_filter('GL Entry', 'Voucher No',doc.name);
|
||||
report.dt.run();
|
||||
}
|
||||
loadreport('GL Entry','General Ledger', callback);
|
||||
}
|
||||
446
accounts/doctype/journal_voucher/journal_voucher.py
Normal file
446
accounts/doctype/journal_voucher/journal_voucher.py
Normal file
@@ -0,0 +1,446 @@
|
||||
# Please edit this list and import only required elements
|
||||
import webnotes
|
||||
|
||||
from webnotes.utils import cint, cstr, flt, fmt_money, formatdate, getTraceback, get_defaults, getdate, has_common, month_name, now, nowdate, 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.master_type = {}
|
||||
self.credit_days_for = {}
|
||||
self.credit_days_global = -1
|
||||
self.is_approving_authority = -1
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
# Autoname
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
def autoname(self):
|
||||
self.doc.name = make_autoname(self.doc.naming_series+'.#####')
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
# Fetch outstanding amount from RV/PV
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
def get_outstanding(self, args):
|
||||
args = eval(args)
|
||||
o_s = sql("select outstanding_amount from `tab%s` where name = '%s'" % (args['doctype'],args['docname']))
|
||||
if args['doctype'] == 'Payable Voucher':
|
||||
return cstr({'debit': o_s and flt(o_s[0][0]) or 0})
|
||||
if args['doctype'] == 'Receivable Voucher':
|
||||
return cstr({'credit': o_s and flt(o_s[0][0]) or 0})
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
# Create remarks
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
def create_remarks(self):
|
||||
r = []
|
||||
if self.doc.cheque_no :
|
||||
if self.doc.cheque_date:
|
||||
r.append('Via cheque #%s dated %s' % (self.doc.cheque_no, formatdate(self.doc.cheque_date)))
|
||||
else :
|
||||
msgprint("Please enter cheque date")
|
||||
raise Exception
|
||||
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
if d.against_invoice and d.credit:
|
||||
currency = sql("select currency from `tabReceivable Voucher` where name = '%s'" % d.against_invoice)
|
||||
currency = currency and currency[0][0] or ''
|
||||
r.append('%s %s against Invoice: %s' % (cstr(currency), fmt_money(flt(d.credit)), d.against_invoice))
|
||||
if d.against_voucher and d.debit:
|
||||
bill_no = sql("select bill_no, bill_date, currency from `tabPayable Voucher` where name=%s", d.against_voucher)
|
||||
if bill_no and bill_no[0][0] and bill_no[0][0].lower().strip() not in ['na', 'not applicable', 'none']:
|
||||
bill_no = bill_no and bill_no[0]
|
||||
r.append('%s %s against Bill %s dated %s' % (bill_no[2] and cstr(bill_no[2]) or '', fmt_money(flt(d.debit)), bill_no[0], bill_no[1] and formatdate(bill_no[1].strftime('%Y-%m-%d')) or ''))
|
||||
if self.doc.ded_amount:
|
||||
r.append("TDS Amount: %s" % self.doc.ded_amount)
|
||||
|
||||
if self.doc.user_remark:
|
||||
r.append("User Remark : %s"%self.doc.user_remark)
|
||||
|
||||
if r:
|
||||
self.doc.remark = ("\n").join(r)
|
||||
|
||||
# --------------------------------------------------------------------------------------------------------
|
||||
# Check user role for approval process
|
||||
# --------------------------------------------------------------------------------------------------------
|
||||
def get_authorized_user(self):
|
||||
if self.is_approving_authority==-1:
|
||||
self.is_approving_authority = 0
|
||||
|
||||
# Fetch credit controller role
|
||||
approving_authority = sql("select value from `tabSingles` where field='credit_controller' and doctype='Manage Account'")
|
||||
approving_authority = approving_authority and approving_authority[0][0] or ''
|
||||
|
||||
# Check logged-in user is authorized
|
||||
if approving_authority in webnotes.user.get_roles():
|
||||
self.is_approving_authority = 1
|
||||
|
||||
return self.is_approving_authority
|
||||
|
||||
# get master type
|
||||
# ---------------
|
||||
def get_master_type(self, ac):
|
||||
if not self.master_type.get(ac):
|
||||
self.master_type[ac] = sql("select master_type from `tabAccount` where name=%s", ac)[0][0] or 'None'
|
||||
return self.master_type[ac]
|
||||
|
||||
# get credit days for
|
||||
# -------------------
|
||||
def get_credit_days_for(self, ac):
|
||||
|
||||
if not self.credit_days_for.has_key(ac):
|
||||
self.credit_days_for[ac] = sql("select credit_days from `tabAccount` where name='%s'" % ac)[0][0] or 0
|
||||
|
||||
if not self.credit_days_for[ac]:
|
||||
if self.credit_days_global==-1:
|
||||
self.credit_days_global = sql("select credit_days from `tabCompany` where name='%s'" % self.doc.company)[0][0] or 0
|
||||
return self.credit_days_global
|
||||
else:
|
||||
return self.credit_days_for[ac]
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------------------------------------
|
||||
# Check Credit Days - Cheque Date can not after (Posting date + Credit Days)
|
||||
# --------------------------------------------------------------------------------------------------------
|
||||
def check_credit_days(self):
|
||||
date_diff = 0
|
||||
if self.doc.cheque_date:
|
||||
date_diff = (getdate(self.doc.cheque_date)-getdate(self.doc.posting_date)).days
|
||||
|
||||
if date_diff <= 0: return
|
||||
|
||||
# Get List of Customer Account
|
||||
acc_list = filter(lambda d: self.get_master_type(d.account)=='Customer', getlist(self.doclist,'entries'))
|
||||
|
||||
for d in acc_list:
|
||||
credit_days = self.get_credit_days_for(d.account)
|
||||
|
||||
# Check credit days
|
||||
if credit_days > 0 and not self.get_authorized_user() and cint(date_diff) > credit_days:
|
||||
msgprint("Credit Not Allowed: Cannot allow a check that is dated more than %s days after the posting date" % credit_days)
|
||||
raise Exception
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
# validation of debit/credit account with Debit To Account(RV) or Credit To Account (PV)
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
def check_account_against_entries(self):
|
||||
for d in getlist(self.doclist,'entries'):
|
||||
if d.against_invoice:
|
||||
acc=sql("select debit_to from `tabReceivable Voucher` where name='%s'"%d.against_invoice)
|
||||
if acc and acc[0][0] != d.account:
|
||||
msgprint("Debit account is not matching with receivable voucher")
|
||||
raise Exception
|
||||
|
||||
if d.against_voucher:
|
||||
acc=sql("select credit_to from `tabPayable Voucher` where name='%s'"%d.against_voucher)
|
||||
if acc and acc[0][0] != d.account:
|
||||
msgprint("Credit account is not matching with payable voucher")
|
||||
raise Exception
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
# Validate Cheque Info: Mandatory for Bank/Contra voucher
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
def validate_cheque_info(self):
|
||||
if self.doc.voucher_type in ['Bank Voucher']:
|
||||
if not self.doc.cheque_no or not self.doc.cheque_date:
|
||||
msgprint("Cheque No & Cheque Date is required for " + cstr(self.doc.voucher_type))
|
||||
raise Exception
|
||||
|
||||
if self.doc.cheque_date and not self.doc.cheque_no:
|
||||
msgprint("Cheque No is mandatory if you entered Cheque Date")
|
||||
raise Exception
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
# Gives reminder for making is_advance = 'Yes' in Advance Entry
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
def validate_entries_for_advance(self):
|
||||
for d in getlist(self.doclist,'entries'):
|
||||
if not d.is_advance and not d.against_voucher and not d.against_invoice and d.against_jv:
|
||||
master_type = self.get_master_type(d.account)
|
||||
if (master_type == 'Customer' and flt(d.credit) > 0) or (master_type == 'Supplier' and flt(d.debit) > 0):
|
||||
msgprint("Message: Please check Is Advance as 'Yes' against Account %s if this is an advance entry." % d.account)
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
# TDS: Validate tds related fields
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
def get_tds_category_account(self):
|
||||
for d in getlist(self.doclist,'entries'):
|
||||
if flt(d.debit) > 0 and not d.against_voucher and d.is_advance == 'Yes':
|
||||
acc = sql("select tds_applicable from `tabAccount` where name = '%s'" % d.account)
|
||||
acc_tds_applicable = acc and acc[0][0] or 'No'
|
||||
if acc_tds_applicable == 'Yes':
|
||||
# TDS applicable field become mandatory for advance payment towards supplier or related party
|
||||
if not self.doc.tds_applicable:
|
||||
msgprint("Please select TDS Applicable or Not")
|
||||
raise Exception
|
||||
|
||||
# If TDS applicable, category and supplier account bocome mandatory
|
||||
elif self.doc.tds_applicable == 'Yes':
|
||||
self.validate_category_account(d.account)
|
||||
if self.doc.ded_amount and not self.doc.tax_code:
|
||||
msgprint("Please enter Tax Code in TDS section")
|
||||
raise Exception
|
||||
|
||||
#If TDS not applicable, all related fields should blank
|
||||
else:
|
||||
self.set_fields_null()
|
||||
|
||||
# If tds amount but tds applicability not mentioned in account master
|
||||
elif self.doc.ded_amount:
|
||||
msgprint("Please select TDS Applicable = 'Yes' in account head: '%s' if you want to deduct TDS." % self.doc.supplier_account)
|
||||
raise Exception
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
# If TDS applicable , TDS category and supplier account should be mandatory
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
def validate_category_account(self, credit_account):
|
||||
if not self.doc.tds_category:
|
||||
msgprint("Please select TDS Category")
|
||||
raise Exception
|
||||
|
||||
if not self.doc.supplier_account:
|
||||
self.doc.supplier_account = credit_account
|
||||
elif self.doc.supplier_account and self.doc.supplier_account != credit_account:
|
||||
msgprint("Supplier Account is not matching with the account mentioned in the table. Please select proper Supplier Account and click on 'Get TDS' button.")
|
||||
raise Exception
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
# If TDS is not applicable , all related fields should blank
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
def set_fields_null(self):
|
||||
self.doc.ded_amount = 0
|
||||
self.doc.rate = 0
|
||||
self.doc.tax_code = ''
|
||||
self.doc.tds_category = ''
|
||||
self.doc.supplier_account = ''
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
# Get TDS amount
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
def get_tds(self):
|
||||
if cstr(self.doc.is_opening) != 'Yes':
|
||||
if self.doc.total_debit > 0:
|
||||
self.get_tds_category_account()
|
||||
if self.doc.supplier_account and self.doc.tds_category:
|
||||
get_obj('TDS Control').get_tds_amount(self)
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
# Insert new row to balance total debit and total credit
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
def get_balance(self):
|
||||
if not getlist(self.doclist,'entries'):
|
||||
msgprint("Please enter atleast 1 entry in 'GL Entries' table")
|
||||
else:
|
||||
flag, self.doc.total_debit, self.doc.total_credit = 0,0,0
|
||||
diff = flt(self.doc.difference)
|
||||
|
||||
# If any row without amount, set the diff on that row
|
||||
for d in getlist(self.doclist,'entries'):
|
||||
if (d.credit==0 or d.credit is None) and (d.debit==0 or d.debit is None) and (flt(diff) != 0):
|
||||
if diff>0:
|
||||
d.credit = flt(diff)
|
||||
elif diff<0:
|
||||
d.debit = flt(diff)
|
||||
flag = 1
|
||||
|
||||
# Set the diff in a new row
|
||||
if flag == 0 and (flt(diff) != 0):
|
||||
jd = addchild(self.doc, 'entries', 'Journal Voucher Detail', 1, self.doclist)
|
||||
if diff>0:
|
||||
jd.credit = flt(diff)
|
||||
elif diff<0:
|
||||
jd.debit = flt(diff)
|
||||
|
||||
# Set the total debit, total credit and difference
|
||||
for d in getlist(self.doclist,'entries'):
|
||||
self.doc.total_debit += flt(d.debit)
|
||||
self.doc.total_credit += flt(d.credit)
|
||||
|
||||
if self.doc.tds_applicable == 'Yes':
|
||||
self.doc.total_credit = flt(self.doc.total_credit) + flt(self.doc.ded_amount)
|
||||
|
||||
self.doc.difference = flt(self.doc.total_debit) - flt(self.doc.total_credit)
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
# Set against account
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
def get_against_account(self):
|
||||
# Debit = Credit
|
||||
debit, credit = 0.0, 0.0
|
||||
debit_list, credit_list = [], []
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
debit += flt(d.debit)
|
||||
credit += flt(d.credit)
|
||||
if flt(d.debit)>0 and (d.account not in debit_list): debit_list.append(d.account)
|
||||
if flt(d.credit)>0 and (d.account not in credit_list): credit_list.append(d.account)
|
||||
|
||||
self.doc.total_debit = debit
|
||||
if self.doc.tds_applicable == 'Yes':
|
||||
self.doc.total_credit = credit + flt(self.doc.ded_amount)
|
||||
else:
|
||||
self.doc.total_credit = credit
|
||||
|
||||
if abs(self.doc.total_debit-self.doc.total_credit) > 0.001:
|
||||
msgprint("Debit must be equal to Credit. The difference is %s" % (self.doc.total_debit-self.doc.total_credit))
|
||||
raise Exception
|
||||
|
||||
# update against account
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
if flt(d.debit) > 0: d.against_account = ', '.join(credit_list)
|
||||
if flt(d.credit) > 0: d.against_account = ', '.join(debit_list)
|
||||
|
||||
|
||||
# set aging date
|
||||
#---------------
|
||||
def set_aging_date(self):
|
||||
if self.doc.is_opening != 'Yes':
|
||||
self.doc.aging_date = self.doc.posting_date
|
||||
else:
|
||||
# check account type whether supplier or customer
|
||||
exists = ''
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
exists = sql("select name from tabAccount where account_type in ('Supplier', 'Customer') and name = '%s'" % d.account)
|
||||
if exists:
|
||||
break
|
||||
|
||||
# If cus/supp aging dt is mandatory
|
||||
if exists and not self.doc.aging_date:
|
||||
msgprint("Aging Date is mandatory for opening entry")
|
||||
raise Exception
|
||||
# otherwise aging dt = posting dt
|
||||
else:
|
||||
self.doc.aging_date = self.doc.posting_date
|
||||
|
||||
# ------------------------
|
||||
# set print format fields
|
||||
# ------------------------
|
||||
def set_print_format_fields(self):
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
chk_type = sql("select master_type, account_type from `tabAccount` where name='%s'" % d.account)
|
||||
master_type, acc_type = chk_type and cstr(chk_type[0][0]) or '', chk_type and cstr(chk_type[0][1]) or ''
|
||||
if master_type in ['Supplier', 'Customer']:
|
||||
if not self.doc.pay_to_recd_from:
|
||||
self.doc.pay_to_recd_from = get_value(master_type, ' - '.join(d.account.split(' - ')[:-1]), master_type == 'Customer' and 'customer_name' or 'supplier_name')
|
||||
|
||||
if acc_type == 'Bank or Cash':
|
||||
amt = cint(d.debit) and d.debit or d.credit
|
||||
self.doc.total_amount = get_defaults()['currency']+'. '+ cstr(amt)
|
||||
self.doc.total_amount_in_words = get_obj('Sales Common').get_total_in_words(get_defaults()['currency'], cstr(amt))
|
||||
|
||||
|
||||
# --------------------------------
|
||||
# get outstanding invoices values
|
||||
# --------------------------------
|
||||
def get_values(self):
|
||||
cond = (flt(self.doc.write_off_amount) > 0) and ' and outstanding_amount <= '+self.doc.write_off_amount or ''
|
||||
if self.doc.write_off_based_on == 'Accounts Receivable':
|
||||
return sql("select name, debit_to, outstanding_amount from `tabReceivable Voucher` where docstatus = 1 and company = '%s' and outstanding_amount > 0 %s" % (self.doc.company, cond))
|
||||
elif self.doc.write_off_based_on == 'Accounts Payable':
|
||||
return sql("select name, credit_to, outstanding_amount from `tabPayable Voucher` where docstatus = 1 and company = '%s' and outstanding_amount > 0 %s" % (self.doc.company, cond))
|
||||
|
||||
|
||||
# -------------------------
|
||||
# get outstanding invoices
|
||||
# -------------------------
|
||||
def get_outstanding_invoices(self):
|
||||
self.doc.clear_table(self.doclist, 'entries')
|
||||
total = 0
|
||||
for d in self.get_values():
|
||||
total += flt(d[2])
|
||||
jd = addchild(self.doc, 'entries', 'Journal Voucher Detail', 1, self.doclist)
|
||||
jd.account = cstr(d[1])
|
||||
if self.doc.write_off_based_on == 'Accounts Receivable':
|
||||
jd.credit = flt(d[2])
|
||||
jd.against_invoice = cstr(d[0])
|
||||
elif self.doc.write_off_based_on == 'Accounts Payable':
|
||||
jd.debit = flt(d[2])
|
||||
jd.against_voucher = cstr(d[0])
|
||||
jd.save(1)
|
||||
jd = addchild(self.doc, 'entries', 'Journal Voucher Detail', 1, self.doclist)
|
||||
if self.doc.write_off_based_on == 'Accounts Receivable':
|
||||
jd.debit = total
|
||||
elif self.doc.write_off_based_on == 'Accounts Payable':
|
||||
jd.credit = total
|
||||
jd.save(1)
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
# VALIDATE
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
def validate(self):
|
||||
if not self.doc.is_opening:
|
||||
self.doc.is_opening='No'
|
||||
self.get_against_account()
|
||||
self.validate_cheque_info()
|
||||
self.create_remarks()
|
||||
# tds
|
||||
get_obj('TDS Control').validate_first_entry(self)
|
||||
self.get_tds_category_account()
|
||||
|
||||
self.validate_entries_for_advance()
|
||||
self.set_aging_date()
|
||||
|
||||
self.validate_against_jv()
|
||||
self.set_print_format_fields()
|
||||
|
||||
#FY and Date validation
|
||||
get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.posting_date,'Posting Date')
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
# On Update - Update Feed
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
def on_update(self):
|
||||
pass
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
# On submit
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
def on_submit(self):
|
||||
if self.doc.voucher_type in ['Bank Voucher', 'Contra Voucher', 'Journal Entry']:
|
||||
self.check_credit_days()
|
||||
self.check_account_against_entries()
|
||||
get_obj(dt='GL Control').make_gl_entries(self.doc, self.doclist)
|
||||
|
||||
|
||||
# validate against jv no
|
||||
def validate_against_jv(self):
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
if d.against_jv:
|
||||
if d.against_jv == self.doc.name:
|
||||
msgprint("You can not enter current voucher in 'Against JV' column")
|
||||
raise Exception
|
||||
elif not sql("select name from `tabJournal Voucher Detail` where account = '%s' and docstatus = 1 and parent = '%s'" % (d.account, d.against_jv)):
|
||||
msgprint("Against JV: "+ d.against_jv + " is not valid. Please check")
|
||||
raise Exception
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
# On cancel reverse gl entry
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
def on_cancel(self):
|
||||
self.check_tds_payment_voucher()
|
||||
get_obj(dt='GL Control').make_gl_entries(self.doc, self.doclist, cancel=1)
|
||||
|
||||
# Check whether tds payment voucher has been created against this voucher
|
||||
#---------------------------------------------------------------------------
|
||||
def check_tds_payment_voucher(self):
|
||||
tdsp = sql("select parent from `tabTDS Payment Detail` where voucher_no = '%s' and docstatus = 1 and parent not like 'old%'")
|
||||
if tdsp:
|
||||
msgprint("TDS Payment voucher '%s' has been made against this voucher. Please cancel the payment voucher to proceed." % (tdsp and tdsp[0][0] or ''))
|
||||
raise Exception
|
||||
2022
accounts/doctype/journal_voucher/journal_voucher.txt
Normal file
2022
accounts/doctype/journal_voucher/journal_voucher.txt
Normal file
File diff suppressed because it is too large
Load Diff
0
accounts/doctype/journal_voucher_detail/__init__.py
Normal file
0
accounts/doctype/journal_voucher_detail/__init__.py
Normal file
File diff suppressed because one or more lines are too long
0
accounts/doctype/ledger_balance_export/__init__.py
Executable file
0
accounts/doctype/ledger_balance_export/__init__.py
Executable file
@@ -0,0 +1,2 @@
|
||||
|
||||
cur_frm.cscript['Export Report']=function(doc,cdt,cdn){$c_obj_csv(make_doclist(cdt,cdn),'get_report_data','');}
|
||||
3
accounts/doctype/ledger_balance_export/ledger_balance_export.js
Executable file
3
accounts/doctype/ledger_balance_export/ledger_balance_export.js
Executable file
@@ -0,0 +1,3 @@
|
||||
cur_frm.cscript['Export Report'] = function(doc, cdt, cdn) {
|
||||
$c_obj_csv(make_doclist(cdt, cdn), 'get_report_data', '');
|
||||
}
|
||||
63
accounts/doctype/ledger_balance_export/ledger_balance_export.py
Executable file
63
accounts/doctype/ledger_balance_export/ledger_balance_export.py
Executable file
@@ -0,0 +1,63 @@
|
||||
import webnotes
|
||||
from webnotes.utils import add_days, cint, cstr, flt, getdate
|
||||
from webnotes.model.doclist import getlist
|
||||
from webnotes.model.code import get_obj
|
||||
from webnotes import session, form, is_testing, msgprint, errprint
|
||||
|
||||
sql = webnotes.conn.sql
|
||||
get_value = webnotes.conn.get_value
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
class DocType:
|
||||
def __init__(self, doc, doclist=[]):
|
||||
self.doc = doc
|
||||
self.doclist = doclist
|
||||
|
||||
# Get fiscal year based on date
|
||||
def get_year(self, dt):
|
||||
yr = sql("select name from `tabFiscal Year` where %s between year_start_date and date_sub(date_add(year_start_date,interval 1 year), interval 1 day)",dt)
|
||||
return yr and yr[0][0] or ''
|
||||
|
||||
# Get gl entries for the period and account
|
||||
def get_gl_entries(self, lft, rgt):
|
||||
gle = sql("select t1.posting_date, t1.voucher_type, t1.voucher_no, t1.debit, t1.credit, t1.remarks from `tabGL Entry` t1, `tabAccount` t2 WHERE t1.posting_date >= %s AND t1.posting_date <= %s and ifnull(t1.is_opening, 'No') = 'No' AND t1.account = t2.name AND t2.lft >= %s AND t2.rgt <= %s and ifnull(t1.is_cancelled, 'No') = 'No'", (self.doc.from_date, self.doc.to_date, lft, rgt), as_dict=1)
|
||||
entries, dr, cr = [], 0, 0
|
||||
for d in gle:
|
||||
dr, cr = dr + flt(d['debit']), cr + flt(d['credit'])
|
||||
entries.append(['', d['posting_date'], d['voucher_type'], d['voucher_no'], d['debit'], d['credit'], d['remarks']])
|
||||
return entries, dr, cr
|
||||
|
||||
# Get Report Data
|
||||
def get_report_data(self):
|
||||
from_date_year = self.get_year(add_days(self.doc.from_date, -1))
|
||||
to_date_year = self.get_year(self.doc.to_date)
|
||||
|
||||
# result initiatlization
|
||||
header = 'Ledger Balances Between ' + getdate(self.doc.from_date).strftime('%d-%m-%Y') + ' and ' + getdate(self.doc.to_date).strftime('%d-%m-%Y')
|
||||
res = [[header], ['Account', 'Posting Date', 'Voucher Type', 'Voucher No', 'Debit', 'Credit', 'Remarks']]
|
||||
glc = get_obj('GL Control')
|
||||
|
||||
for d in getlist(self.doclist, 'ledger_details'):
|
||||
# Fetch acc details
|
||||
acc_det = sql("select debit_or_credit, is_pl_account, lft, rgt from tabAccount where name = '%s'" % d.account, as_dict=1)[0]
|
||||
|
||||
# Opening
|
||||
opening = glc.get_as_on_balance(d.account, from_date_year, add_days(self.doc.from_date, -1), acc_det['debit_or_credit'], acc_det['lft'], acc_det['rgt'])[2]
|
||||
if acc_det['debit_or_credit'] == 'Credit':
|
||||
opening = -1*opening
|
||||
|
||||
# GL Entries
|
||||
gle, debit, credit = self.get_gl_entries(acc_det['lft'], acc_det['rgt'])
|
||||
|
||||
# Closing
|
||||
closing = opening + debit - credit
|
||||
|
||||
# Append to result
|
||||
res.append([d.account])
|
||||
res += gle
|
||||
res.append(['', '', '', 'Total Debit/Credit', debit, credit])
|
||||
res.append(['', '', '', 'Opening Balance', opening])
|
||||
res.append(['', '', '', 'Closing Balance', closing])
|
||||
|
||||
return res
|
||||
321
accounts/doctype/ledger_balance_export/ledger_balance_export.txt
Executable file
321
accounts/doctype/ledger_balance_export/ledger_balance_export.txt
Executable file
@@ -0,0 +1,321 @@
|
||||
[
|
||||
{
|
||||
'_last_update': '1306229235',
|
||||
'_user_tags': None,
|
||||
'allow_attach': None,
|
||||
'allow_copy': 1,
|
||||
'allow_email': 1,
|
||||
'allow_print': 1,
|
||||
'allow_rename': None,
|
||||
'allow_trash': None,
|
||||
'autoname': None,
|
||||
'change_log': None,
|
||||
'client_script': None,
|
||||
'client_script_core': None,
|
||||
'client_string': None,
|
||||
'colour': 'White:FFF',
|
||||
'creation': '2011-05-25 10:54:06',
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocType',
|
||||
'document_type': 'Other',
|
||||
'dt_template': None,
|
||||
'hide_heading': 0,
|
||||
'hide_toolbar': None,
|
||||
'idx': None,
|
||||
'in_create': None,
|
||||
'in_dialog': None,
|
||||
'is_transaction_doc': None,
|
||||
'issingle': 1,
|
||||
'istable': None,
|
||||
'max_attachments': None,
|
||||
'menu_index': None,
|
||||
'modified': '2011-05-24 15:22:43',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'Accounts',
|
||||
'name': 'Ledger Balance Export',
|
||||
'name_case': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': None,
|
||||
'parent_node': None,
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'print_outline': None,
|
||||
'read_only': None,
|
||||
'read_only_onload': None,
|
||||
'search_fields': None,
|
||||
'section_style': 'Simple',
|
||||
'server_code': None,
|
||||
'server_code_compiled': None,
|
||||
'server_code_core': None,
|
||||
'server_code_error': None,
|
||||
'show_in_menu': 0,
|
||||
'smallicon': None,
|
||||
'subject': None,
|
||||
'tag_fields': None,
|
||||
'use_template': None,
|
||||
'version': 9
|
||||
},
|
||||
{
|
||||
'amend': None,
|
||||
'cancel': None,
|
||||
'create': 1,
|
||||
'creation': '2011-05-25 10:54:06',
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocPerm',
|
||||
'execute': None,
|
||||
'idx': 1,
|
||||
'match': None,
|
||||
'modified': '2011-05-25 10:54:06',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'PERM00866',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Ledger Balance Export',
|
||||
'parentfield': 'permissions',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'read': 1,
|
||||
'role': 'Accounts Manager',
|
||||
'submit': None,
|
||||
'write': 1
|
||||
},
|
||||
{
|
||||
'amend': None,
|
||||
'cancel': None,
|
||||
'create': 1,
|
||||
'creation': '2011-05-25 10:54:06',
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocPerm',
|
||||
'execute': None,
|
||||
'idx': 2,
|
||||
'match': None,
|
||||
'modified': '2011-05-25 10:54:06',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'PERM00867',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Ledger Balance Export',
|
||||
'parentfield': 'permissions',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'read': 1,
|
||||
'role': 'Accounts User',
|
||||
'submit': None,
|
||||
'write': 1
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2011-05-25 11:02:00',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': None,
|
||||
'fieldtype': 'Column Break',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 1,
|
||||
'in_filter': None,
|
||||
'label': 'Select Date Range',
|
||||
'modified': '2011-05-25 11:02:00',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL05003',
|
||||
'no_column': None,
|
||||
'no_copy': None,
|
||||
'oldfieldname': None,
|
||||
'oldfieldtype': None,
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Ledger Balance Export',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': None,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2011-05-25 10:54:06',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'from_date',
|
||||
'fieldtype': 'Date',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 2,
|
||||
'in_filter': None,
|
||||
'label': 'From Date',
|
||||
'modified': '2011-05-25 11:02:00',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL04997',
|
||||
'no_column': None,
|
||||
'no_copy': None,
|
||||
'oldfieldname': None,
|
||||
'oldfieldtype': None,
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Ledger Balance Export',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': 1,
|
||||
'search_index': None,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2011-05-25 10:54:06',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'to_date',
|
||||
'fieldtype': 'Date',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 3,
|
||||
'in_filter': None,
|
||||
'label': 'To Date',
|
||||
'modified': '2011-05-25 11:02:00',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL04998',
|
||||
'no_column': None,
|
||||
'no_copy': None,
|
||||
'oldfieldname': None,
|
||||
'oldfieldtype': None,
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Ledger Balance Export',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': 1,
|
||||
'search_index': None,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2011-05-25 11:02:00',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': None,
|
||||
'fieldtype': 'Column Break',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 4,
|
||||
'in_filter': None,
|
||||
'label': 'Select ledgers',
|
||||
'modified': '2011-05-25 11:02:00',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL05004',
|
||||
'no_column': None,
|
||||
'no_copy': None,
|
||||
'oldfieldname': None,
|
||||
'oldfieldtype': None,
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Ledger Balance Export',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': None,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2011-05-25 10:54:06',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'ledger_details',
|
||||
'fieldtype': 'Table',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 5,
|
||||
'in_filter': None,
|
||||
'label': 'Ledger Details',
|
||||
'modified': '2011-05-25 11:02:00',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL05000',
|
||||
'no_column': None,
|
||||
'no_copy': None,
|
||||
'oldfieldname': None,
|
||||
'oldfieldtype': None,
|
||||
'options': 'Ledger Detail',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Ledger Balance Export',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': None,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': 'White:FFF',
|
||||
'creation': '2011-05-25 10:54:06',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': None,
|
||||
'fieldtype': 'Button',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 6,
|
||||
'in_filter': None,
|
||||
'label': 'Export Report',
|
||||
'modified': '2011-05-25 11:02:00',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL05001',
|
||||
'no_column': None,
|
||||
'no_copy': None,
|
||||
'oldfieldname': None,
|
||||
'oldfieldtype': None,
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Ledger Balance Export',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': None,
|
||||
'trigger': 'Client',
|
||||
'width': None
|
||||
}
|
||||
]
|
||||
0
accounts/doctype/ledger_detail/__init__.py
Executable file
0
accounts/doctype/ledger_detail/__init__.py
Executable file
95
accounts/doctype/ledger_detail/ledger_detail.txt
Executable file
95
accounts/doctype/ledger_detail/ledger_detail.txt
Executable file
@@ -0,0 +1,95 @@
|
||||
[
|
||||
{
|
||||
'_last_update': None,
|
||||
'_user_tags': None,
|
||||
'allow_attach': None,
|
||||
'allow_copy': None,
|
||||
'allow_email': None,
|
||||
'allow_print': None,
|
||||
'allow_rename': None,
|
||||
'allow_trash': None,
|
||||
'autoname': None,
|
||||
'change_log': None,
|
||||
'client_script': None,
|
||||
'client_script_core': None,
|
||||
'client_string': None,
|
||||
'colour': 'White:FFF',
|
||||
'creation': '2011-05-25 10:54:06',
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocType',
|
||||
'document_type': None,
|
||||
'dt_template': None,
|
||||
'hide_heading': None,
|
||||
'hide_toolbar': None,
|
||||
'idx': None,
|
||||
'in_create': None,
|
||||
'in_dialog': None,
|
||||
'is_transaction_doc': None,
|
||||
'issingle': None,
|
||||
'istable': 1,
|
||||
'max_attachments': None,
|
||||
'menu_index': None,
|
||||
'modified': '2011-05-24 15:24:03',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'Accounts',
|
||||
'name': 'Ledger Detail',
|
||||
'name_case': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': None,
|
||||
'parent_node': None,
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'print_outline': None,
|
||||
'read_only': None,
|
||||
'read_only_onload': None,
|
||||
'search_fields': None,
|
||||
'section_style': 'Simple',
|
||||
'server_code': None,
|
||||
'server_code_compiled': None,
|
||||
'server_code_core': None,
|
||||
'server_code_error': None,
|
||||
'show_in_menu': 0,
|
||||
'smallicon': None,
|
||||
'subject': None,
|
||||
'tag_fields': None,
|
||||
'use_template': None,
|
||||
'version': 3
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2011-05-25 10:54:06',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'account',
|
||||
'fieldtype': 'Link',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 1,
|
||||
'in_filter': None,
|
||||
'label': 'Account',
|
||||
'modified': '2011-05-25 10:54:06',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL05002',
|
||||
'no_column': None,
|
||||
'no_copy': None,
|
||||
'oldfieldname': None,
|
||||
'oldfieldtype': None,
|
||||
'options': 'Account',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'Ledger Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': 1,
|
||||
'search_index': None,
|
||||
'trigger': None,
|
||||
'width': '300px'
|
||||
}
|
||||
]
|
||||
0
accounts/doctype/mode_of_payment/__init__.py
Normal file
0
accounts/doctype/mode_of_payment/__init__.py
Normal file
10
accounts/doctype/mode_of_payment/mode_of_payment.js
Normal file
10
accounts/doctype/mode_of_payment/mode_of_payment.js
Normal file
@@ -0,0 +1,10 @@
|
||||
$import(Tips Common)
|
||||
|
||||
//--------- ONLOAD -------------
|
||||
cur_frm.cscript.onload = function(doc, cdt, cdn) {
|
||||
cur_frm.cscript.get_tips(doc, cdt, cdn);
|
||||
}
|
||||
|
||||
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
||||
cur_frm.cscript.get_tips(doc, cdt, cdn);
|
||||
}
|
||||
1
accounts/doctype/mode_of_payment/mode_of_payment.txt
Normal file
1
accounts/doctype/mode_of_payment/mode_of_payment.txt
Normal file
@@ -0,0 +1 @@
|
||||
[{'section_style': 'Simple', 'is_transaction_doc': None, 'creation': '2010-05-04 12:05:50', 'search_fields': None, 'module': 'Accounts', 'doctype': 'DocType', 'change_log': None, 'print_outline': '', 'owner': 'harshada@webnotestech.com', 'in_dialog': None, 'in_create': None, 'read_only': None, 'allow_email': None, 'dt_template': None, 'hide_heading': None, 'issingle': None, 'allow_rename': None, 'smallicon': None, 'allow_attach': None, 'show_in_menu': None, 'max_attachments': None, 'version': 4, 'menu_index': None, 'docstatus': 0, 'allow_copy': None, 'istable': None, 'description': None, 'parent': None, 'server_code': None, 'allow_trash': None, 'allow_print': None, 'autoname': 'field:mode_of_payment', 'client_script_core': None, 'client_string': None, 'use_template': None, 'modified_by': 'ashwini@webnotestech.com', 'document_type': 'Master', 'name': 'Mode of Payment', 'idx': None, 'hide_toolbar': None, 'colour': 'White:FFF', 'client_script': None, 'modified': '2010-09-20 14:06:57', 'server_code_error': ' ', 'name_case': '', 'parenttype': None, 'read_only_onload': None, 'server_code_core': None, 'server_code_compiled': None, 'parent_node': None, 'parentfield': None}, {'cancel': None, 'amend': None, 'execute': None, 'modified_by': 'ashwini@webnotestech.com', 'name': 'PERM00997', 'parent': 'Mode of Payment', 'read': 1, 'create': 1, 'creation': '2010-05-04 12:05:50', 'modified': '2010-09-20 09:51:10', 'submit': None, 'doctype': 'DocPerm', 'write': 1, 'idx': 1, 'parenttype': 'DocType', 'role': 'Accounts Manager', 'owner': 'harshada@webnotestech.com', 'docstatus': 0, 'permlevel': 0, 'match': None, 'parentfield': 'permissions'}, {'no_copy': None, 'oldfieldtype': 'Data', 'creation': '2010-05-04 12:05:50', 'doctype': 'DocField', 'oldfieldname': 'mode_of_payment', 'owner': 'harshada@webnotestech.com', 'reqd': 1, 'in_filter': None, 'print_hide': None, 'modified_by': 'ashwini@webnotestech.com', 'label': 'Mode of Payment', 'width': None, 'trigger': None, 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 0, 'description': None, 'parent': 'Mode of Payment', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL04973', 'idx': 1, 'default': None, 'colour': None, 'modified': '2010-09-20 09:51:10', 'parenttype': 'DocType', 'fieldname': 'mode_of_payment', 'fieldtype': 'Data', 'options': None, 'report_hide': None, 'parentfield': 'fields'}]
|
||||
0
accounts/doctype/payable_voucher/__init__.py
Normal file
0
accounts/doctype/payable_voucher/__init__.py
Normal file
450
accounts/doctype/payable_voucher/payable_voucher.js
Normal file
450
accounts/doctype/payable_voucher/payable_voucher.js
Normal file
@@ -0,0 +1,450 @@
|
||||
cur_frm.cscript.tname = "PV Detail";
|
||||
cur_frm.cscript.fname = "entries";
|
||||
cur_frm.cscript.other_fname = "purchase_tax_details";
|
||||
$import(Purchase Other Charges)
|
||||
$import(Purchase Common)
|
||||
|
||||
// On Load
|
||||
// --------
|
||||
cur_frm.cscript.onload = function(doc,dt,dn) {
|
||||
var cp = locals['Control Panel']['Control Panel'];
|
||||
|
||||
if(!doc.voucher_date) set_multiple(dt,dn,{voucher_date:get_today()});
|
||||
if(!doc.posting_date) set_multiple(dt,dn,{posting_date:get_today()});
|
||||
|
||||
if(cp.country == 'India') {
|
||||
unhide_field(['TDS','tds_applicable','tds_category','Get TDS','tax_code','rate','ded_amount','total_tds_on_voucher','tds_amount_on_advance']);
|
||||
}
|
||||
else {
|
||||
hide_field(['TDS','tds_applicable','tds_category','Get TDS','tax_code','rate','ded_amount','total_tds_on_voucher','tds_amount_on_advance']);
|
||||
}
|
||||
|
||||
if(doc.__islocal){
|
||||
if(doc.supplier) {cur_frm.cscript.supplier(doc,dt,dn)}
|
||||
hide_field(['supplier_address','contact_person','supplier_name','address_display','contact_display','contact_mobile','contact_email']);
|
||||
}
|
||||
|
||||
|
||||
if(doc.supplier) unhide_field(['supplier_address','contact_person','supplier_name','address_display','contact_display','contact_mobile','contact_email']);
|
||||
}
|
||||
|
||||
// Refresh
|
||||
// --------
|
||||
cur_frm.cscript.refresh = function(doc, dt, dn) {
|
||||
|
||||
cur_frm.clear_custom_buttons();
|
||||
|
||||
// Show / Hide button
|
||||
if(doc.docstatus==1 && doc.outstanding_amount > 0)
|
||||
cur_frm.add_custom_button('Make Payment Entry', cur_frm.cscript['Make Bank Voucher']);
|
||||
|
||||
if(doc.docstatus==1) {
|
||||
unhide_field(['Repair Outstanding Amt']);
|
||||
cur_frm.add_custom_button('View Ledger', cur_frm.cscript['View Ledger Entry']);
|
||||
} else hide_field(['Repair Outstanding Amt']);
|
||||
|
||||
cur_frm.cscript.is_opening(doc, dt, dn);
|
||||
}
|
||||
|
||||
|
||||
//Supplier
|
||||
cur_frm.cscript.supplier = function(doc,dt,dn) {
|
||||
|
||||
var callback = function(r,rt) {
|
||||
var doc = locals[cur_frm.doctype][cur_frm.docname];
|
||||
get_server_fields('get_credit_to','','',doc, dt, dn, 0, callback2);
|
||||
}
|
||||
|
||||
var callback2 = function(r,rt){
|
||||
var doc = locals[cur_frm.doctype][cur_frm.docname];
|
||||
var el = getchildren('PV Detail',doc.name,'entries');
|
||||
for(var i in el){
|
||||
if(el[i].item_code && (!el[i].expense_head || !el[i].cost_center)){
|
||||
args = "{'item_code':'" + el[i].item_code + "','expense_head':'" + el[i].expense_head + "','cost_center':'" + el[i].cost_center + "'}";
|
||||
get_server_fields('get_default_values', args, 'entries', doc, el[i].doctype, el[i].name, 1);
|
||||
}
|
||||
}
|
||||
cur_frm.cscript.calc_total(doc);
|
||||
}
|
||||
|
||||
if(doc.supplier) get_server_fields('get_default_supplier_address', JSON.stringify({supplier: doc.supplier}),'', doc, dt, dn, 1,callback);
|
||||
if(doc.supplier) unhide_field(['supplier_address','contact_person','supplier_name','address_display','contact_display','contact_mobile','contact_email']);
|
||||
}
|
||||
|
||||
cur_frm.cscript.supplier_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {
|
||||
if(doc.supplier) get_server_fields('get_supplier_address', JSON.stringify({supplier: doc.supplier, address: doc.supplier_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
|
||||
}
|
||||
|
||||
cur_frm.fields_dict['supplier_address'].get_query = function(doc, cdt, cdn) {
|
||||
return 'SELECT name,address_line1,city FROM tabAddress WHERE supplier = "'+ doc.supplier +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50';
|
||||
}
|
||||
|
||||
cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
|
||||
return 'SELECT name,CONCAT(first_name," ",ifnull(last_name,"")) As FullName,department,designation FROM tabContact WHERE supplier = "'+ doc.supplier +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50';
|
||||
}
|
||||
|
||||
|
||||
cur_frm.fields_dict.supplier_address.on_new = function(dn) {
|
||||
locals['Address'][dn].supplier = locals[cur_frm.doctype][cur_frm.docname].supplier;
|
||||
locals['Address'][dn].supplier_name = locals[cur_frm.doctype][cur_frm.docname].supplier_name;
|
||||
}
|
||||
|
||||
cur_frm.fields_dict.contact_person.on_new = function(dn) {
|
||||
locals['Contact'][dn].supplier = locals[cur_frm.doctype][cur_frm.docname].supplier;
|
||||
locals['Contact'][dn].supplier_name = locals[cur_frm.doctype][cur_frm.docname].supplier_name;
|
||||
}
|
||||
|
||||
|
||||
cur_frm.cscript.credit_to = function(doc,dt,dn) {
|
||||
|
||||
var callback = function(r,rt) {
|
||||
var doc = locals[cur_frm.doctype][cur_frm.docname];
|
||||
if(doc.supplier) get_server_fields('get_default_supplier_address', JSON.stringify({supplier: doc.supplier}),'', doc, dt, dn, 1);
|
||||
if(doc.supplier) unhide_field(['supplier_address','contact_person','supplier_name','address_display','contact_display','contact_mobile','contact_email']);
|
||||
cur_frm.refresh();
|
||||
}
|
||||
|
||||
get_server_fields('get_cust','','',doc,dt,dn,1,callback);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Get Print Heading
|
||||
cur_frm.fields_dict['select_print_heading'].get_query = function(doc, cdt, cdn) {
|
||||
return 'SELECT `tabPrint Heading`.name FROM `tabPrint Heading` WHERE `tabPrint Heading`.docstatus !=2 AND `tabPrint Heading`.name LIKE "%s" ORDER BY `tabPrint Heading`.name ASC LIMIT 50';
|
||||
}
|
||||
|
||||
|
||||
//Set expense_head and cost center on adding new row
|
||||
//----------------------------------------------
|
||||
cur_frm.fields_dict['entries'].grid.onrowadd = function(doc, cdt, cdn){
|
||||
|
||||
cl = getchildren('PV Detail', doc.name, cur_frm.cscript.fname, doc.doctype);
|
||||
acc = '';
|
||||
cc = '';
|
||||
|
||||
for(var i = 0; i<cl.length; i++) {
|
||||
if (cl[i].idx == 1){
|
||||
acc = cl[i].expense_head;
|
||||
cc = cl[i].cost_center;
|
||||
}
|
||||
else{
|
||||
if (! cl[i].expense_head) { cl[i].expense_head = acc; refresh_field('expense_head', cl[i].name, 'entries');}
|
||||
if (! cl[i].cost_center) {cl[i].cost_center = cc; refresh_field('cost_center', cl[i].name, 'entries');}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript.is_opening = function(doc, dt, dn) {
|
||||
hide_field('aging_date');
|
||||
if (doc.is_opening == 'Yes') unhide_field('aging_date');
|
||||
}
|
||||
|
||||
/* ******************************** TRIGGERS **************************************** */
|
||||
/*
|
||||
// Supplier
|
||||
// ---------
|
||||
cur_frm.cscript.supplier = function(doc,cdt,cdn){
|
||||
get_server_fields('get_credit_to','','',doc,cdt,cdn);
|
||||
}
|
||||
*/
|
||||
|
||||
// Conversion Rate
|
||||
// ----------------
|
||||
cur_frm.cscript.conversion_rate = function(doc,cdt,cdn) {
|
||||
cur_frm.cscript.calc_total(doc,cdt,cdn);
|
||||
}
|
||||
|
||||
// Recalculate Button
|
||||
// -------------------
|
||||
cur_frm.cscript['Recalculate'] = function(doc, dt, dn) {
|
||||
cur_frm.cscript.calc_total(doc, cdt, cdn);
|
||||
calc_total_advance(doc,cdt,cdn);
|
||||
}
|
||||
|
||||
// Get Items Button
|
||||
// -----------------
|
||||
cur_frm.cscript['Get Items'] = function(doc, dt, dn) {
|
||||
var callback = function(r,rt) {
|
||||
unhide_field(['supplier_address','contact_person','supplier_name','address_display','contact_display','contact_mobile','contact_email']);
|
||||
refresh_many(['credit_to','supplier','supplier_address','contact_person','supplier_name','address_display','contact_display','contact_mobile','contact_email','entries','purchase_receipt_main','purchase_order_main']);
|
||||
}
|
||||
get_server_fields('pull_details','','',doc, dt, dn,1,callback);
|
||||
}
|
||||
|
||||
|
||||
// ========== PV Details Table ============
|
||||
|
||||
// Item Code
|
||||
// ----------
|
||||
cur_frm.cscript.item_code = function(doc,cdt,cdn){
|
||||
var d = locals[cdt][cdn];
|
||||
if(d.item_code){
|
||||
get_server_fields('get_item_details',d.item_code,'entries',doc,cdt,cdn,1);
|
||||
}
|
||||
}
|
||||
|
||||
// Quantity
|
||||
// ---------
|
||||
cur_frm.cscript.qty = function(doc,dt,dn) { cur_frm.cscript.calc_exp_row(doc,dt,dn); }
|
||||
|
||||
// Import Rate
|
||||
// ------------
|
||||
cur_frm.cscript.import_rate = function(doc,dt,dn) {
|
||||
var d = locals[dt][dn];
|
||||
set_multiple('PV Detail', d.name, {'rate': flt(d.import_rate) * flt(doc.conversion_rate) }, 'entries');
|
||||
cur_frm.cscript.calc_exp_row(doc,dt,dn)
|
||||
}
|
||||
|
||||
|
||||
// ============== TDS ===============
|
||||
|
||||
// Rate in Deduct Taxes (TDS)
|
||||
// --------------------------
|
||||
cur_frm.cscript.rate = function(doc,dt,dn) {
|
||||
//This is done as Purchase tax detail and PV detail both contain the same fieldname 'rate'
|
||||
if(dt != 'Purchase Tax Detail') cur_frm.cscript.calc_exp_row(doc,dt,dn);
|
||||
}
|
||||
|
||||
// Amount
|
||||
// -------
|
||||
cur_frm.cscript.ded_amount = function(doc,dt,dn) { cur_frm.cscript.calc_total(doc); }
|
||||
|
||||
// Get TDS Button
|
||||
// ---------------
|
||||
cur_frm.cscript['Get TDS'] = function(doc, dt, dn) {
|
||||
var callback = function(r,rt) {
|
||||
cur_frm.refresh();
|
||||
refresh_field('ded_amount');
|
||||
cur_frm.cscript.calc_total(locals[dt][dn]);
|
||||
}
|
||||
$c_obj(make_doclist(dt,dn), 'get_tds', '', callback);
|
||||
}
|
||||
|
||||
// ===================== Advance Allocation ==================
|
||||
cur_frm.cscript.allocated_amount = function(doc,cdt,cdn){
|
||||
var d = locals[cdt][cdn];
|
||||
if (d.allocated_amount && d.tds_amount){
|
||||
d.tds_allocated=flt(d.tds_amount*(d.allocated_amount/d.advance_amount))
|
||||
refresh_field('tds_allocated', d.name, 'advance_allocation_details');
|
||||
}
|
||||
tot_tds=0
|
||||
el = getchildren('Advance Allocation Detail',doc.name,'advance_allocation_details')
|
||||
for(var i in el){
|
||||
tot_tds += el[i].tds_allocated
|
||||
}
|
||||
doc.tds_amount_on_advance = tot_tds
|
||||
refresh_field('tds_amount_on_advance');
|
||||
|
||||
calc_total_advance(doc, cdt, cdn);
|
||||
}
|
||||
|
||||
|
||||
// Make Journal Voucher
|
||||
// --------------------
|
||||
cur_frm.cscript['Make Bank Voucher'] = function(doc, dt, dn) {
|
||||
cur_frm.cscript.make_jv(cur_frm.doc);
|
||||
}
|
||||
|
||||
|
||||
/* ***************************** GET QUERY Functions *************************** */
|
||||
|
||||
// Item Code
|
||||
// ----------
|
||||
cur_frm.fields_dict['entries'].grid.get_field("item_code").get_query = function(doc, cdt, cdn) {
|
||||
return 'SELECT tabItem.name, tabItem.description FROM tabItem WHERE tabItem.is_purchase_item="Yes" AND (IFNULL(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` ="0000-00-00" OR `tabItem`.`end_of_life` > NOW()) AND tabItem.%(key)s LIKE "%s" LIMIT 50'
|
||||
}
|
||||
|
||||
// Credit To
|
||||
// ----------
|
||||
cur_frm.fields_dict['credit_to'].get_query = function(doc) {
|
||||
return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Credit" AND tabAccount.is_pl_account="No" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus != 2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"'
|
||||
}
|
||||
|
||||
|
||||
// Purchase Order
|
||||
// ---------------
|
||||
cur_frm.fields_dict['purchase_order_main'].get_query = function(doc) {
|
||||
if (doc.supplier){
|
||||
return 'SELECT `tabPurchase Order`.`name` FROM `tabPurchase Order` WHERE `tabPurchase Order`.`docstatus` = 1 AND `tabPurchase Order`.supplier = "'+ doc.supplier +'" AND `tabPurchase Order`.`status` != "Stopped" AND ifnull(`tabPurchase Order`.`per_billed`,0) < 100 AND `tabPurchase Order`.`company` = "' + doc.company + '" AND `tabPurchase Order`.%(key)s LIKE "%s" ORDER BY `tabPurchase Order`.`name` DESC LIMIT 50'
|
||||
} else {
|
||||
return 'SELECT `tabPurchase Order`.`name` FROM `tabPurchase Order` WHERE `tabPurchase Order`.`docstatus` = 1 AND `tabPurchase Order`.`status` != "Stopped" AND ifnull(`tabPurchase Order`.`per_billed`, 0) < 100 AND `tabPurchase Order`.`company` = "' + doc.company + '" AND `tabPurchase Order`.%(key)s LIKE "%s" ORDER BY `tabPurchase Order`.`name` DESC LIMIT 50'
|
||||
}
|
||||
}
|
||||
|
||||
// Purchase Receipt
|
||||
// -----------------
|
||||
cur_frm.fields_dict['purchase_receipt_main'].get_query = function(doc) {
|
||||
if (doc.supplier){
|
||||
return 'SELECT `tabPurchase Receipt`.`name` FROM `tabPurchase Receipt` WHERE `tabPurchase Receipt`.`docstatus` = 1 AND `tabPurchase Receipt`.supplier = "'+ doc.supplier +'" AND `tabPurchase Receipt`.`status` != "Stopped" AND ifnull(`tabPurchase Receipt`.`per_billed`, 0) < 100 AND `tabPurchase Receipt`.`company` = "' + doc.company + '" AND `tabPurchase Receipt`.%(key)s LIKE "%s" ORDER BY `tabPurchase Receipt`.`name` DESC LIMIT 50'
|
||||
} else {
|
||||
return 'SELECT `tabPurchase Receipt`.`name` FROM `tabPurchase Receipt` WHERE `tabPurchase Receipt`.`docstatus` = 1 AND `tabPurchase Receipt`.`status` != "Stopped" AND ifnull(`tabPurchase Receipt`.`per_billed`, 0) < 100 AND `tabPurchase Receipt`.`company` = "' + doc.company + '" AND `tabPurchase Receipt`.%(key)s LIKE "%s" ORDER BY `tabPurchase Receipt`.`name` DESC LIMIT 50'
|
||||
}
|
||||
}
|
||||
|
||||
// ================== PV Details Table ===================
|
||||
// Expense Head
|
||||
// -------------
|
||||
cur_frm.fields_dict['entries'].grid.get_field("expense_head").get_query = function(doc) {
|
||||
return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Debit" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus != 2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"';
|
||||
}
|
||||
cur_frm.cscript.expense_head = function(doc, cdt, cdn){
|
||||
var d = locals[cdt][cdn];
|
||||
if(d.idx == 1 && d.expense_head){
|
||||
var cl = getchildren('PV Detail', doc.name, 'entries', doc.doctype);
|
||||
for(var i = 0; i < cl.length; i++){
|
||||
if(!cl[i].expense_head) cl[i].expense_head = d.expense_head;
|
||||
}
|
||||
}
|
||||
refresh_field('entries');
|
||||
}
|
||||
|
||||
|
||||
// Cost Center
|
||||
//-------------
|
||||
cur_frm.fields_dict['entries'].grid.get_field("cost_center").get_query = function(doc) {
|
||||
return 'SELECT `tabCost Center`.`name` FROM `tabCost Center` WHERE `tabCost Center`.`company_name` = "' +doc.company+'" AND `tabCost Center`.%(key)s LIKE "%s" AND `tabCost Center`.`group_or_ledger` = "Ledger" AND `tabCost Center`.docstatus != 2 ORDER BY `tabCost Center`.`name` ASC LIMIT 50';
|
||||
}
|
||||
|
||||
cur_frm.cscript.cost_center = function(doc, cdt, cdn){
|
||||
var d = locals[cdt][cdn];
|
||||
if(d.idx == 1 && d.cost_center){
|
||||
var cl = getchildren('PV Detail', doc.name, 'entries', doc.doctype);
|
||||
for(var i = 0; i < cl.length; i++){
|
||||
if(!cl[i].cost_center) cl[i].cost_center = d.cost_center;
|
||||
}
|
||||
}
|
||||
refresh_field('entries');
|
||||
}
|
||||
|
||||
|
||||
// TDS Account Head
|
||||
cur_frm.fields_dict['tax_code'].get_query = function(doc) {
|
||||
return "SELECT `tabTDS Category Account`.account_head FROM `tabTDS Category Account` WHERE `tabTDS Category Account`.parent = '"+doc.tds_category+"' AND `tabTDS Category Account`.company='"+doc.company+"' AND `tabTDS Category Account`.account_head LIKE '%s' ORDER BY `tabTDS Category Account`.account_head DESC LIMIT 50";
|
||||
}
|
||||
|
||||
cur_frm.cscript.tax_code = function(doc, dt, dn) {
|
||||
get_server_fields('get_tds_rate','','',doc, dt, dn, 0);
|
||||
}
|
||||
|
||||
/* ***************************** UTILITY FUNCTIONS ************************ */
|
||||
|
||||
// Calculate
|
||||
// ---------
|
||||
cur_frm.cscript.calc_total = function(doc) {
|
||||
|
||||
// expense
|
||||
var t_exp = 0.0;
|
||||
var el = getchildren('PV Detail',doc.name,'entries');
|
||||
for(var i in el) {
|
||||
if (flt(el[i].import_rate) > 0){
|
||||
set_multiple('PV Detail', el[i].name, {'rate': flt(doc.conversion_rate) * flt(el[i].import_rate) }, 'entries');
|
||||
set_multiple('PV Detail', el[i].name, {'import_amount': flt(el[i].qty) * flt(el[i].import_rate) }, 'entries');
|
||||
}
|
||||
set_multiple('PV Detail', el[i].name, {'amount': flt(el[i].qty) * flt(el[i].rate) }, 'entries')
|
||||
t_exp += flt(el[i].amount);
|
||||
}
|
||||
doc.net_total = flt(t_exp);
|
||||
refresh_field('net_total');
|
||||
cur_frm.cscript.val_cal_charges(doc, cdt, cdn, cur_frm.cscript.tname, cur_frm.cscript.fname, cur_frm.cscript.other_fname);
|
||||
}
|
||||
|
||||
|
||||
// Calculate Advance
|
||||
// ------------------
|
||||
var calc_total_advance = function(doc,cdt,cdn) {
|
||||
var doc = locals[doc.doctype][doc.name];
|
||||
var el = getchildren('Advance Allocation Detail',doc.name,'advance_allocation_details')
|
||||
var tot_tds=0;
|
||||
var total_advance = 0;
|
||||
for(var i in el) {
|
||||
if (! el[i].allocated_amount == 0) {
|
||||
total_advance += flt(el[i].allocated_amount);
|
||||
tot_tds += flt(el[i].tds_allocated)
|
||||
}
|
||||
}
|
||||
doc.total_amount_to_pay = flt(doc.grand_total) - flt(doc.ded_amount);
|
||||
doc.tds_amount_on_advance = flt(tot_tds);
|
||||
doc.total_advance = flt(total_advance);
|
||||
doc.outstanding_amount = flt(doc.total_amount_to_pay) - flt(total_advance);
|
||||
refresh_many(['total_advance','outstanding_amount','tds_amount_on_advance', 'total_amount_to_pay']);
|
||||
}
|
||||
|
||||
|
||||
cur_frm.cscript.calc_exp_row = function(doc,dt,dn) {
|
||||
var d = locals[dt][dn];
|
||||
d.amount = flt(d.qty * d.rate);
|
||||
refresh_field('amount',dn,'entries');
|
||||
|
||||
if (!doc.conversion_rate){ doc.conversion_rate = 1; refresh_field('conversion_rate'); }
|
||||
|
||||
set_multiple('PV Detail', dn, {'import_rate': flt(d.rate) / flt(doc.conversion_rate) }, 'entries');
|
||||
set_multiple('PV Detail', dn, {'import_amount': flt(d.qty) * flt(d.rate) / flt(doc.conversion_rate) }, 'entries');
|
||||
|
||||
cur_frm.cscript.calc_total(doc)
|
||||
}
|
||||
|
||||
|
||||
// Make JV
|
||||
// --------
|
||||
cur_frm.cscript.make_jv = function(doc, dt, dn, det) {
|
||||
var jv = LocalDB.create('Journal Voucher');
|
||||
jv = locals['Journal Voucher'][jv];
|
||||
jv.voucher_type = 'Bank Voucher';
|
||||
//jv.voucher_series = det.def_bv_series;
|
||||
//jv.voucher_date = doc.voucher_date;
|
||||
//jv.posting_date = doc.posting_date;
|
||||
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 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries');
|
||||
d1.account = doc.credit_to;
|
||||
d1.debit = doc.outstanding_amount;
|
||||
//d1.balance = det.acc_balance;
|
||||
d1.against_voucher = doc.name;
|
||||
|
||||
// credit to bank
|
||||
var d1 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries');
|
||||
//d1.account = det.def_bank_account;
|
||||
//d1.balance = det.bank_balance;
|
||||
d1.credit = doc.outstanding_amount;
|
||||
|
||||
loaddoc('Journal Voucher', jv.name);
|
||||
}
|
||||
|
||||
// ***************** Get project name *****************
|
||||
cur_frm.fields_dict['project_name'].get_query = function(doc, cdt, cdn) {
|
||||
return 'SELECT `tabProject`.name FROM `tabProject` WHERE `tabProject`.status = "Open" AND `tabProject`.name LIKE "%s" ORDER BY `tabProject`.name ASC LIMIT 50';
|
||||
}
|
||||
|
||||
|
||||
cur_frm.cscript.select_print_heading = function(doc,cdt,cdn){
|
||||
if(doc.select_print_heading){
|
||||
// print heading
|
||||
cur_frm.pformat.print_heading = doc.select_print_heading;
|
||||
}
|
||||
else
|
||||
cur_frm.pformat.print_heading = "Purchase Invoice";
|
||||
}
|
||||
|
||||
/* *********************** Client Side Validation **************************** */
|
||||
// Validate
|
||||
// ---------
|
||||
cur_frm.cscript.validate = function(doc, cdt, cdn) {
|
||||
is_item_table(doc,cdt,cdn);
|
||||
cur_frm.cscript.calc_total(doc, cdt, cdn);
|
||||
calc_total_advance(doc, cdt, cdn);
|
||||
}
|
||||
|
||||
/****************** Get Accounting Entry *****************/
|
||||
cur_frm.cscript['View Ledger Entry'] = function(){
|
||||
var callback = function(report){
|
||||
report.set_filter('GL Entry', 'Voucher No',cur_frm.doc.name);
|
||||
report.dt.run();
|
||||
}
|
||||
loadreport('GL Entry','General Ledger', callback);
|
||||
}
|
||||
507
accounts/doctype/payable_voucher/payable_voucher.py
Normal file
507
accounts/doctype/payable_voucher/payable_voucher.py
Normal file
@@ -0,0 +1,507 @@
|
||||
# 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
|
||||
|
||||
# -----------------------------------------------------------------------------------------
|
||||
|
||||
from utilities.transaction_base import TransactionBase
|
||||
|
||||
class DocType(TransactionBase):
|
||||
def __init__(self,d,dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
self.tname = 'PV Detail'
|
||||
self.fname = 'entries'
|
||||
|
||||
# Autoname
|
||||
# ---------
|
||||
def autoname(self):
|
||||
self.doc.name = make_autoname(self.doc.naming_series+'.####')
|
||||
|
||||
|
||||
# ************************** Trigger Functions ****************************
|
||||
|
||||
# Credit To
|
||||
# ----------
|
||||
def get_credit_to(self):
|
||||
acc_head = sql("select name, credit_days from `tabAccount` where name = %s", (cstr(self.doc.supplier) + " - " + self.get_company_abbr()))
|
||||
#supp_detail = sql("select supplier_name,address from `tabSupplier` where name = %s", self.doc.supplier, as_dict =1)
|
||||
#ret = {
|
||||
# 'supplier_name' : supp_detail and supp_detail[0]['supplier_name'] or '',
|
||||
# 'supplier_address': supp_detail and supp_detail[0]['address'] or ''
|
||||
#}
|
||||
ret = {}
|
||||
if acc_head and acc_head[0][0]:
|
||||
ret['credit_to'] = acc_head[0][0]
|
||||
if not self.doc.due_date:
|
||||
ret['due_date'] = add_days(cstr(self.doc.posting_date), acc_head and cint(acc_head[0][1]) or 0)
|
||||
elif not acc_head:
|
||||
msgprint("%s does not have an Account Head in %s. You must first create it from the Supplier Master" % (self.doc.supplier, self.doc.company))
|
||||
return cstr(ret)
|
||||
|
||||
def get_cust(self):
|
||||
ret = {}
|
||||
if self.doc.credit_to:
|
||||
ret['supplier'] = get_value('Account',self.doc.credit_to,'master_name')
|
||||
|
||||
return cstr(ret)
|
||||
|
||||
|
||||
# Get Default Cost Center and Expense Head from Item Master
|
||||
# ----------------------------------------------------------
|
||||
def get_default_values(self,args):
|
||||
args = eval(args)
|
||||
ret = {}
|
||||
if sql("select name from `tabItem` where name = '%s'" % args['item_code']):
|
||||
if not args['expense_head'] or args['expense_head'] == 'undefined':
|
||||
expense_head = sql("select name from `tabAccount` where account_name in (select purchase_account from `tabItem` where name = '%s')" % args['item_code'])
|
||||
ret['expense_head'] = expense_head and expense_head[0][0] or ''
|
||||
if not args['cost_center'] or args['cost_center'] == 'undefined':
|
||||
cost_center = sql("select cost_center from `tabItem` where name = '%s'" % args['item_code'])
|
||||
ret['cost_center'] = cost_center and cost_center[0][0] or ''
|
||||
return cstr(ret)
|
||||
|
||||
|
||||
# Get Items based on PO or PR
|
||||
# ----------------------------
|
||||
def pull_details(self):
|
||||
if self.doc.purchase_receipt_main:
|
||||
self.validate_duplicate_docname('purchase_receipt')
|
||||
self.doclist = get_obj('DocType Mapper', 'Purchase Receipt-Payable Voucher').dt_map('Purchase Receipt', 'Payable Voucher', self.doc.purchase_receipt_main, self.doc, self.doclist, "[['Purchase Receipt', 'Payable Voucher'],['Purchase Receipt Detail', 'PV Detail']]")
|
||||
|
||||
elif self.doc.purchase_order_main:
|
||||
self.validate_duplicate_docname('purchase_order')
|
||||
self.doclist = get_obj('DocType Mapper', 'Purchase Order-Payable Voucher').dt_map('Purchase Order', 'Payable Voucher', self.doc.purchase_order_main, self.doc, self.doclist, "[['Purchase Order', 'Payable Voucher'],['PO Detail', 'PV Detail']]")
|
||||
|
||||
ret = eval(self.get_credit_to())
|
||||
#self.doc.supplier_name = ret['supplier_name']
|
||||
#self.doc.supplier_address = ret['supplier_address']
|
||||
|
||||
#self.doc.cst_no =ret['cst_no']
|
||||
#self.doc.bst_no = ret['bst_no']
|
||||
#self.doc.vat_tin_no = ret['vat_tin_no']
|
||||
|
||||
if ret.has_key('credit_to'):
|
||||
self.doc.credit_to = ret['credit_to']
|
||||
|
||||
|
||||
# Get Item Details
|
||||
# -----------------
|
||||
def get_item_details(self,arg):
|
||||
item_det = sql("select item_name, brand, description, item_group,purchase_account,cost_center from tabItem where name=%s",arg,as_dict=1)
|
||||
tax = sql("select tax_type, tax_rate from `tabItem Tax` where parent = %s" , arg)
|
||||
t = {}
|
||||
for x in tax: t[x[0]] = flt(x[1])
|
||||
ret = {
|
||||
'item_name' : item_det and item_det[0]['item_name'] or '',
|
||||
'brand' : item_det and item_det[0]['brand'] or '',
|
||||
'description' : item_det and item_det[0]['description'] or '',
|
||||
'item_group' : item_det and item_det[0]['item_group'] or '',
|
||||
'rate' : 0.00,
|
||||
'qty' : 0.00,
|
||||
'amount' : 0.00,
|
||||
'expense_head' : item_det and item_det[0]['purchase_account'] or '',
|
||||
'cost_center' : item_det and item_det[0]['cost_center'] or '',
|
||||
'item_tax_rate' : str(t)
|
||||
}
|
||||
return cstr(ret)
|
||||
|
||||
# Advance Allocation
|
||||
# -------------------
|
||||
def get_advances(self):
|
||||
get_obj('GL Control').get_advances( self, self.doc.credit_to, 'Advance Allocation Detail','advance_allocation_details','debit')
|
||||
|
||||
|
||||
# ============= OTHER CHARGES ====================
|
||||
|
||||
# Get Tax rate if account type is TAX
|
||||
# ------------------------------------
|
||||
def get_rate(self,arg):
|
||||
return get_obj('Purchase Common').get_rate(arg,self)
|
||||
|
||||
# Pull details from other charges master (Get Other Charges)
|
||||
# -----------------------------------------------------------
|
||||
def get_purchase_tax_details(self):
|
||||
return get_obj('Purchase Common').get_purchase_tax_details(self)
|
||||
|
||||
|
||||
def get_rate1(self,acc):
|
||||
rate = sql("select tax_rate from `tabAccount` where name='%s'"%(acc))
|
||||
ret={'add_tax_rate' :rate and flt(rate[0][0]) or 0 }
|
||||
return cstr(ret)
|
||||
|
||||
|
||||
# *************************** Server Utility Functions *****************************
|
||||
# Get Company abbr
|
||||
# -----------------
|
||||
def get_company_abbr(self):
|
||||
return sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0]
|
||||
|
||||
# Check whether PO or PR is already fetched
|
||||
# ------------------------------------------
|
||||
def validate_duplicate_docname(self,doctype):
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
if doctype == 'purchase_receipt' and cstr(self.doc.purchase_receipt_main) == cstr(d.purchase_receipt):
|
||||
msgprint(cstr(self.doc.purchase_receipt_main) + " purchase receipt details have already been pulled.")
|
||||
raise Exception , " Validation Error. "
|
||||
|
||||
if doctype == 'purchase_order' and cstr(self.doc.purchase_order_main) == cstr(d.purchase_order) and not d.purchase_receipt:
|
||||
msgprint(cstr(self.doc.purchase_order_main) + " purchase order details have already been pulled.")
|
||||
raise Exception , " Validation Error. "
|
||||
|
||||
|
||||
# **************************** VALIDATE ********************************
|
||||
|
||||
# Check for Item.is_Purchase_item = 'Yes' and Item is active
|
||||
# ------------------------------------------------------------------
|
||||
def check_active_purchase_items(self):
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
if d.item_code: # extra condn coz item_code is not mandatory in PV
|
||||
valid_item = sql("select docstatus,is_purchase_item from tabItem where name = %s",d.item_code)
|
||||
if valid_item[0][0] == 2:
|
||||
msgprint("Item : '%s' is Inactive, you can restore it from Trash" %(d.item_code))
|
||||
raise Exception
|
||||
if not valid_item[0][1] == 'Yes':
|
||||
msgprint("Item : '%s' is not Purchase Item"%(d.item_code))
|
||||
raise Exception
|
||||
|
||||
# Check Conversion Rate
|
||||
# ----------------------
|
||||
def check_conversion_rate(self):
|
||||
default_currency = get_obj('Manage Account').doc.default_currency
|
||||
if not default_currency:
|
||||
msgprint('Message: Please enter default currency in Manage Account')
|
||||
raise Exception
|
||||
if (self.doc.currency == default_currency and flt(self.doc.conversion_rate) != 1.00) or not self.doc.conversion_rate or (self.doc.currency != default_currency and flt(self.doc.conversion_rate) == 1.00):
|
||||
msgprint("Message: Please Enter Appropriate Conversion Rate.")
|
||||
raise Exception
|
||||
|
||||
# 1. Check whether bill is already booked against this bill no. or not
|
||||
# 2. Add Remarks
|
||||
# ---------------------------------------------------------------------
|
||||
def validate_bill_no(self):
|
||||
if self.doc.bill_no and self.doc.bill_no.lower().strip() not in ['na', 'not applicable', 'none']:
|
||||
b_no = sql("select bill_no, name, ifnull(is_opening,'') from `tabPayable Voucher` where bill_no = '%s' and credit_to = '%s' and docstatus = 1 and name != '%s' " % (self.doc.bill_no, self.doc.credit_to, self.doc.name))
|
||||
if b_no and cstr(b_no[0][2]) == cstr(self.doc.is_opening):
|
||||
msgprint("Please check you have already booked expense against Bill No. %s in Purchase Invoice %s" % (cstr(b_no[0][0]), cstr(b_no[0][1])))
|
||||
raise Exception , "Validation Error"
|
||||
if not self.doc.remarks:
|
||||
self.doc.remarks = (self.doc.remarks or '') + "\n" + ("Against Bill %s dated %s" % (self.doc.bill_no, formatdate(self.doc.bill_date)))
|
||||
if self.doc.ded_amount:
|
||||
self.doc.remarks = (self.doc.remarks or '') + "\n" + ("Grand Total: %s, Tax Deduction Amount: %s" %(self.doc.grand_total, self.doc.ded_amount))
|
||||
else:
|
||||
if not self.doc.remarks:
|
||||
self.doc.remarks = "No Remarks"
|
||||
|
||||
# Validate Bill No Date
|
||||
# ---------------------
|
||||
def validate_bill_no_date(self):
|
||||
if self.doc.bill_no and not self.doc.bill_date and self.doc.bill_no.lower().strip() not in ['na', 'not applicable', 'none']:
|
||||
msgprint("Please enter Bill Date")
|
||||
raise Exception
|
||||
|
||||
|
||||
|
||||
# Clear Advances
|
||||
# ---------------
|
||||
def clear_advances(self):
|
||||
get_obj('GL Control').clear_advances( self, 'Advance Allocation Detail','advance_allocation_details')
|
||||
|
||||
|
||||
# 1. Credit To Account Exists
|
||||
# 2. Is a Credit Account
|
||||
# 3. Is not a PL Account
|
||||
# ----------------------------
|
||||
def validate_credit_acc(self):
|
||||
acc = sql("select debit_or_credit, is_pl_account from tabAccount where name = '%s'" % self.doc.credit_to)
|
||||
if not acc:
|
||||
msgprint("Account: "+ self.doc.credit_to + "does not exist")
|
||||
raise Exception
|
||||
elif acc[0][0] and acc[0][0] != 'Credit':
|
||||
msgprint("Account: "+ self.doc.credit_to + "is not a credit account")
|
||||
raise Exception
|
||||
elif acc[0][1] and acc[0][1] != 'No':
|
||||
msgprint("Account: "+ self.doc.credit_to + "is a pl account")
|
||||
raise Exception
|
||||
|
||||
# Validate Acc Head of Supplier and Credit To Account entered
|
||||
# ------------------------------------------------------------
|
||||
def check_for_acc_head_of_supplier(self):
|
||||
acc_head = sql("select name from `tabAccount` where name = %s", (cstr(self.doc.supplier) + " - " + self.get_company_abbr()))
|
||||
if self.doc.supplier:
|
||||
if acc_head and acc_head[0][0]:
|
||||
if not cstr(acc_head[0][0]) == cstr(self.doc.credit_to):
|
||||
msgprint("Credit To: %s do not match with Supplier: %s for Company: %s i.e. %s" %(self.doc.credit_to,self.doc.supplier,self.doc.company,cstr(acc_head[0][0])))
|
||||
raise Exception, "Validation Error "
|
||||
if not acc_head:
|
||||
msgprint("Supplier %s does not have an Account Head in %s. You must first create it from the Supplier Master" % (self.doc.supplier, self.doc.company))
|
||||
raise Exception, "Validation Error "
|
||||
|
||||
# Check for Stopped PO
|
||||
# ---------------------
|
||||
def check_for_stopped_status(self):
|
||||
check_list = []
|
||||
for d in getlist(self.doclist,'entries'):
|
||||
if d.purchase_order and not d.purchase_order in check_list and not d.purchase_receipt:
|
||||
check_list.append(d.purhcase_order)
|
||||
stopped = sql("select name from `tabPurchase Order` where status = 'Stopped' and name = '%s'" % d.purchase_order)
|
||||
if stopped:
|
||||
msgprint("One cannot do any transaction against 'Purchase Order' : %s, it's status is 'Stopped'" % (d.purhcase_order))
|
||||
raise Exception
|
||||
|
||||
# Validate Supplier
|
||||
# -----------------
|
||||
def validate_supplier(self, d):
|
||||
supplier = ''
|
||||
if d.purchase_order and not d.purchase_order in self.po_list:
|
||||
supplier = sql("select supplier from `tabPurchase Order` where name = '%s'" % d.purchase_order)[0][0]
|
||||
doctype = 'purchase order'
|
||||
doctype_no = cstr(d.purchase_order)
|
||||
if supplier and not cstr(self.doc.supplier) == cstr(supplier):
|
||||
msgprint("Supplier name %s do not match with supplier name of %s %s." %(self.doc.supplier,doctype,doctype_no))
|
||||
raise Exception , " Validation Error "
|
||||
|
||||
if d.purchase_receipt and not d.purchase_receipt in self.pr_list:
|
||||
supplier = sql("select supplier from `tabPurchase Receipt` where name = '%s'" % d.purchase_receipt)[0][0]
|
||||
doctype = 'purchase receipt'
|
||||
doctype_no = cstr(d.purchase_receipt)
|
||||
if supplier and not cstr(self.doc.supplier) == cstr(supplier):
|
||||
msgprint("Supplier name %s do not match with supplier name of %s %s." %(self.doc.supplier,doctype,doctype_no))
|
||||
raise Exception , " Validation Error "
|
||||
|
||||
# Validate values with reference document
|
||||
#----------------------------------------
|
||||
def validate_reference_value(self):
|
||||
get_obj('DocType Mapper', 'Purchase Order-Payable Voucher', with_children = 1).validate_reference_value(self, self.doc.name)
|
||||
|
||||
|
||||
# Validate PO and PR
|
||||
# -------------------
|
||||
def validate_po_pr(self, d):
|
||||
# check po / pr for qty and rates and currency and conversion rate
|
||||
|
||||
# always import_rate must be equal to import_rate of purchase order
|
||||
if d.purchase_order and not d.purchase_order in self.po_list:
|
||||
# currency
|
||||
currency = cstr(sql("select currency from `tabPurchase Order` where name = '%s'" % d.purchase_order)[0][0])
|
||||
if not cstr(currency) == cstr(self.doc.currency):
|
||||
msgprint("Purchase Order: " + cstr(d.purchase_order) + " currency : " + cstr(currency) + " does not match with currency of current document.")
|
||||
raise Exception
|
||||
# import_rate
|
||||
rate = flt(sql('select import_rate from `tabPO Detail` where item_code=%s and parent=%s and name = %s', (d.item_code, d.purchase_order, d.po_detail))[0][0])
|
||||
if abs(rate - flt(d.import_rate)) > 1:
|
||||
msgprint("Import Rate for %s in the Purchase Order is %s. Rate must be same as Purchase Order Rate" % (d.item_code,rate))
|
||||
raise Exception
|
||||
|
||||
if d.purchase_receipt and not d.purchase_receipt in self.pr_list:
|
||||
# currency , conversion_rate
|
||||
data = sql("select currency, conversion_rate from `tabPurchase Receipt` where name = '%s'" % d.purchase_receipt, as_dict = 1)
|
||||
if not cstr(data[0]['currency']) == cstr(self.doc.currency):
|
||||
msgprint("Purchase Receipt: " + cstr(d.purchase_receipt) + " currency : " + cstr(data[0]['currency']) + " does not match with currency of current document.")
|
||||
raise Exception
|
||||
if not flt(data[0]['conversion_rate']) == flt(self.doc.conversion_rate):
|
||||
msgprint("Purchase Receipt: " + cstr(d.purchase_receipt) + " conversion_rate : " + cstr(data[0]['conversion_rate']) + " does not match with conversion_rate of current document.")
|
||||
raise Exception
|
||||
|
||||
# Build tds table if applicable
|
||||
#------------------------------
|
||||
def get_tds(self):
|
||||
if cstr(self.doc.is_opening) != 'Yes':
|
||||
if not self.doc.credit_to:
|
||||
msgprint("Please Enter Credit To account first")
|
||||
raise Exception
|
||||
else:
|
||||
tds_applicable = sql("select tds_applicable from tabAccount where name = '%s'" % self.doc.credit_to)
|
||||
if tds_applicable and cstr(tds_applicable[0][0]) == 'Yes':
|
||||
if not self.doc.tds_applicable:
|
||||
msgprint("Please enter whether TDS Applicable or not")
|
||||
raise Exception
|
||||
if self.doc.tds_applicable == 'Yes':
|
||||
if not self.doc.tds_category:
|
||||
msgprint("Please select TDS Category")
|
||||
raise Exception
|
||||
else:
|
||||
get_obj('TDS Control').get_tds_amount(self)
|
||||
self.doc.total_tds_on_voucher = self.doc.ded_amount
|
||||
self.doc.total_amount_to_pay=flt(self.doc.grand_total)-flt(self.doc.ded_amount)-flt(self.doc.other_tax_deducted)
|
||||
elif self.doc.tds_applicable == 'No':
|
||||
self.doc.tds_category = ''
|
||||
self.doc.tax_code = ''
|
||||
self.doc.rate = 0
|
||||
self.doc.ded_amount = 0
|
||||
self.doc.total_tds_on_voucher = 0
|
||||
|
||||
# get tds rate
|
||||
# -------------
|
||||
def get_tds_rate(self):
|
||||
return str({'rate' : flt(get_value('Account', self.doc.tax_code, 'tax_rate'))})
|
||||
|
||||
# set aging date
|
||||
#-------------------
|
||||
def set_aging_date(self):
|
||||
if self.doc.is_opening != 'Yes':
|
||||
self.doc.aging_date = self.doc.posting_date
|
||||
elif not self.doc.aging_date:
|
||||
msgprint("Aging Date is mandatory for opening entry")
|
||||
raise Exception
|
||||
|
||||
|
||||
# Set against account for debit to account
|
||||
#------------------------------------------
|
||||
def set_against_expense_account(self):
|
||||
against_acc = []
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
if d.expense_account not in against_acc:
|
||||
against_acc.append(d.expense_account)
|
||||
self.doc.against_expense_account = ','.join(against_acc)
|
||||
|
||||
#check in manage account if purchase order required or not.
|
||||
# ====================================================================================
|
||||
def po_required(self):
|
||||
res = sql("select value from `tabSingles` where doctype = 'Manage Account' and field = 'po_required'")
|
||||
if res and res[0][0] == 'Yes':
|
||||
for d in getlist(self.doclist,'entries'):
|
||||
if not d.purchase_order:
|
||||
msgprint("Purchse Order No. required against item %s"%d.item_code)
|
||||
raise Exception
|
||||
|
||||
#check in manage account if purchase receipt required or not.
|
||||
# ====================================================================================
|
||||
def pr_required(self):
|
||||
res = sql("select value from `tabSingles` where doctype = 'Manage Account' and field = 'pr_required'")
|
||||
if res and res[0][0] == 'Yes':
|
||||
for d in getlist(self.doclist,'entries'):
|
||||
if not d.purchase_receipt:
|
||||
msgprint("Purchase Receipt No. required against item %s"%d.item_code)
|
||||
raise Exception
|
||||
|
||||
# VALIDATE
|
||||
# ====================================================================================
|
||||
def validate(self):
|
||||
self.po_required()
|
||||
self.pr_required()
|
||||
self.check_active_purchase_items()
|
||||
self.check_conversion_rate()
|
||||
self.validate_bill_no_date()
|
||||
self.validate_bill_no()
|
||||
self.validate_reference_value()
|
||||
self.clear_advances()
|
||||
self.validate_credit_acc()
|
||||
self.check_for_acc_head_of_supplier()
|
||||
self.check_for_stopped_status()
|
||||
|
||||
self.po_list, self.pr_list = [], []
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
self.validate_supplier(d)
|
||||
self.validate_po_pr(d)
|
||||
if not d.purchase_order in self.po_list:
|
||||
self.po_list.append(d.purchase_order)
|
||||
if not d.purhcase_receipt in self.pr_list:
|
||||
self.pr_list.append(d.purchase_receipt)
|
||||
# tds
|
||||
get_obj('TDS Control').validate_first_entry(self)
|
||||
if not flt(self.doc.ded_amount):
|
||||
self.get_tds()
|
||||
self.doc.save()
|
||||
|
||||
if not self.doc.is_opening:
|
||||
self.doc.is_opening = 'No'
|
||||
|
||||
self.set_aging_date()
|
||||
|
||||
#set against account for credit to
|
||||
self.set_against_expense_account()
|
||||
|
||||
#FY validation
|
||||
get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.posting_date,'Posting Date')
|
||||
|
||||
#get Purchase Common Obj
|
||||
pc_obj = get_obj(dt='Purchase Common')
|
||||
|
||||
# get total in words
|
||||
self.doc.in_words = pc_obj.get_total_in_words('Rs', self.doc.grand_total)
|
||||
self.doc.in_words_import = pc_obj.get_total_in_words(self.doc.currency, self.doc.grand_total_import)
|
||||
# ***************************** SUBMIT *****************************
|
||||
# Check Ref Document docstatus
|
||||
# -----------------------------
|
||||
def check_prev_docstatus(self):
|
||||
for d in getlist(self.doclist,'entries'):
|
||||
if d.purchase_order:
|
||||
submitted = sql("select name from `tabPurchase Order` where docstatus = 1 and name = '%s'" % d.purchase_order)
|
||||
if not submitted:
|
||||
msgprint("Purchase Order : "+ cstr(d.purchase_order) +" is not submitted")
|
||||
raise Exception , "Validation Error."
|
||||
if d.purchase_receipt:
|
||||
submitted = sql("select name from `tabPurchase Receipt` where docstatus = 1 and name = '%s'" % d.purchase_receipt)
|
||||
if not submitted:
|
||||
msgprint("Purchase Receipt : "+ cstr(d.purchase_receipt) +" is not submitted")
|
||||
raise Exception , "Validation Error."
|
||||
|
||||
def update_against_document_in_jv(self, against_document_no, against_document_doctype):
|
||||
get_obj('GL Control').update_against_document_in_jv( self,'advance_allocation_details', against_document_no, against_document_doctype, self.doc.credit_to, 'debit',self.doc.doctype)
|
||||
|
||||
# On Submit
|
||||
# ----------
|
||||
def on_submit(self):
|
||||
self.check_prev_docstatus()
|
||||
|
||||
# Check for Approving Authority
|
||||
get_obj('Authorization Control').validate_approving_authority(self.doc.doctype,self.doc.company, self.doc.grand_total)
|
||||
|
||||
|
||||
# this sequence because outstanding may get -negative
|
||||
get_obj(dt='GL Control').make_gl_entries(self.doc, self.doclist)
|
||||
self.update_against_document_in_jv(self.doc.name, self.doc.doctype)
|
||||
get_obj(dt = 'Purchase Common').update_prevdoc_detail(self, is_submit = 1)
|
||||
|
||||
|
||||
|
||||
# ********************************* CANCEL *********************************
|
||||
# Check Next Document's docstatus
|
||||
# --------------------------------
|
||||
def check_next_docstatus(self):
|
||||
submit_jv = sql("select t1.name from `tabJournal Voucher` t1,`tabJournal Voucher Detail` t2 where t1.name = t2.parent and t2.against_voucher = '%s' and t1.docstatus = 1" % (self.doc.name))
|
||||
if submit_jv:
|
||||
msgprint("Journal Voucher : " + cstr(submit_jv[0][0]) + " has been created against " + cstr(self.doc.doctype) + ". So " + cstr(self.doc.doctype) + " cannot be Cancelled.")
|
||||
raise Exception, "Validation Error."
|
||||
|
||||
# On Cancel
|
||||
# ----------
|
||||
def on_cancel(self):
|
||||
self.check_next_docstatus()
|
||||
|
||||
# Check whether tds payment voucher has been created against this voucher
|
||||
self.check_tds_payment_voucher()
|
||||
|
||||
get_obj(dt='GL Control').make_gl_entries(self.doc, self.doclist, cancel=1)
|
||||
get_obj(dt = 'Purchase Common').update_prevdoc_detail(self, is_submit = 0)
|
||||
|
||||
|
||||
# Check whether tds payment voucher has been created against this voucher
|
||||
#---------------------------------------------------------------------------
|
||||
def check_tds_payment_voucher(self):
|
||||
tdsp = sql("select parent from `tabTDS Payment Detail` where voucher_no = '%s' and docstatus = 1 and parent not like 'old%'")
|
||||
if tdsp:
|
||||
msgprint("TDS Payment voucher '%s' has been made against this voucher. Please cancel the payment voucher to proceed." % (tdsp and tdsp[0][0] or ''))
|
||||
raise Exception
|
||||
|
||||
# on update
|
||||
def on_update(self):
|
||||
pass
|
||||
|
||||
########################################################################
|
||||
# Repair Outstanding
|
||||
#######################################################################
|
||||
def repair_pv_outstanding(self):
|
||||
get_obj(dt = 'GL Control').repair_voucher_outstanding(self)
|
||||
3172
accounts/doctype/payable_voucher/payable_voucher.txt
Normal file
3172
accounts/doctype/payable_voucher/payable_voucher.txt
Normal file
File diff suppressed because it is too large
Load Diff
0
accounts/doctype/period_closing_voucher/__init__.py
Normal file
0
accounts/doctype/period_closing_voucher/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
//========================== On Load =================================================
|
||||
cur_frm.cscript.onload = function(doc, cdt, cdn) {
|
||||
if (!doc.transaction_date) doc.transaction_date = dateutil.obj_to_str(new Date());
|
||||
}
|
||||
|
||||
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
||||
hide_field('Repost Account Balances');
|
||||
hide_field('next_fiscal_year');
|
||||
hide_field('Repost');
|
||||
|
||||
if (doc.docstatus == 1) {
|
||||
unhide_field('Repost Account Balances');
|
||||
unhide_field('next_fiscal_year');
|
||||
unhide_field('Repost');
|
||||
}
|
||||
}
|
||||
|
||||
// ***************** Get Account Head *****************
|
||||
cur_frm.fields_dict['closing_account_head'].get_query = function(doc, cdt, cdn) {
|
||||
return 'SELECT `tabAccount`.name FROM `tabAccount` WHERE `tabAccount`.is_pl_account = "No" AND `tabAccount`.debit_or_credit = "Credit" AND `tabAccount`.company = "'+ cstr(doc.company) +'" AND `tabAccount`.freeze_account = "No" AND `tabAccount`.group_or_ledger = "Ledger" AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name ASC LIMIT 50';
|
||||
}
|
||||
|
||||
cur_frm.cscript.acc_help = function(doc,dt,dn){
|
||||
show_chart_browser('Accounts Browser','Account');
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
# 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.td, self.tc = 0, 0
|
||||
self.year_start_date = ''
|
||||
self.year_end_date = ''
|
||||
|
||||
|
||||
# Validate Account Head
|
||||
#============================================================
|
||||
def validate_account_head(self):
|
||||
acc_det = sql("select debit_or_credit, is_pl_account, group_or_ledger, company from `tabAccount` where name = '%s'" % (self.doc.closing_account_head))
|
||||
|
||||
# Account should be under liability
|
||||
if cstr(acc_det[0][0]) != 'Credit' or cstr(acc_det[0][1]) != 'No':
|
||||
msgprint("Account: %s must be created under 'Source of Funds'" % self.doc.closing_account_head)
|
||||
raise Exception
|
||||
|
||||
# Account must be a ledger
|
||||
if cstr(acc_det[0][2]) != 'Ledger':
|
||||
msgprint("Account %s must be a ledger" % self.doc.closing_account_head)
|
||||
raise Exception
|
||||
|
||||
# Account should belong to company selected
|
||||
if cstr(acc_det[0][3]) != self.doc.company:
|
||||
msgprint("Account %s does not belong to Company %s ." % (self.doc.closing_account_head, self.doc.company))
|
||||
raise Exception
|
||||
|
||||
# validate posting date
|
||||
#=============================================================
|
||||
def validate_posting_date(self):
|
||||
yr = sql("select start_date, end_date from `tabPeriod` where period_name = '%s'" % (self.doc.fiscal_year))
|
||||
self.year_start_date = yr and yr[0][0] or ''
|
||||
self.year_end_date = yr and yr[0][1] or ''
|
||||
|
||||
# Posting Date should be within closing year
|
||||
if getdate(self.doc.posting_date) < self.year_start_date or getdate(self.doc.posting_date) > self.year_end_date:
|
||||
msgprint("Posting Date should be within Closing Fiscal Year")
|
||||
raise Exception
|
||||
|
||||
# Period Closing Entry
|
||||
pce = sql("select name from `tabPeriod Closing Voucher` where posting_date > '%s' and fiscal_year = '%s' and docstatus = 1" % (self.doc.posting_date, self.doc.fiscal_year))
|
||||
if pce and pce[0][0]:
|
||||
msgprint("Another Period Closing Entry: %s has been made after posting date: %s" % (cstr(pce[0][0]), self.doc.posting_date))
|
||||
raise Exception
|
||||
|
||||
# Validate closing entry requirement
|
||||
#==========================================================
|
||||
def validate_pl_balances(self):
|
||||
income_bal = sql("select sum(ifnull(t1.debit,0))-sum(ifnull(t1.credit,0)) from `tabGL Entry` t1, tabAccount t2 where t1.account = t2.name and t1.posting_date between '%s' and '%s' and t2.debit_or_credit = 'Credit' and t2.group_or_ledger = 'Ledger' and ifnull(t2.freeze_account, 'No') = 'No' and t2.is_pl_account = 'Yes' and t2.docstatus < 2 and t2.company = '%s'" % (self.year_start_date, self.doc.posting_date, self.doc.company))
|
||||
expense_bal = sql("select sum(ifnull(t1.debit,0))-sum(ifnull(t1.credit,0)) from `tabGL Entry` t1, tabAccount t2 where t1.account = t2.name and t1.posting_date between '%s' and '%s' and t2.debit_or_credit = 'Debit' and t2.group_or_ledger = 'Ledger' and ifnull(t2.freeze_account, 'No') = 'No' and t2.is_pl_account = 'Yes' and t2.docstatus < 2 and t2.company = '%s'" % (self.year_start_date, self.doc.posting_date, self.doc.company))
|
||||
|
||||
income_bal = income_bal and income_bal[0][0] or 0
|
||||
expense_bal = expense_bal and expense_bal[0][0] or 0
|
||||
|
||||
if not income_bal and not expense_bal:
|
||||
msgprint("Both Income and Expense balances are zero. No Need to make Period Closing Entry.")
|
||||
raise Exception
|
||||
|
||||
# Get account (pl) specific balance
|
||||
#===========================================================
|
||||
def get_pl_balances(self, d_or_c):
|
||||
acc_bal = sql("select t1.account, sum(ifnull(t1.debit,0))-sum(ifnull(t1.credit,0)) from `tabGL Entry` t1, `tabAccount` t2 where t1.account = t2.name and t2.group_or_ledger = 'Ledger' and ifnull(t2.freeze_account, 'No') = 'No' and t2.is_pl_account = 'Yes' and t2.debit_or_credit = '%s' and t2.docstatus < 2 and t2.company = '%s' and t1.posting_date between '%s' and '%s' group by t1.account " % (d_or_c, self.doc.company, self.year_start_date, self.doc.posting_date))
|
||||
return acc_bal
|
||||
|
||||
|
||||
# Makes GL Entries
|
||||
# ==========================================================
|
||||
def make_gl_entries(self, acc_det):
|
||||
for a in acc_det:
|
||||
if flt(a[1]):
|
||||
fdict = {
|
||||
'account': a[0],
|
||||
'cost_center': '',
|
||||
'against': '',
|
||||
'debit': flt(a[1]) < 0 and -1*flt(a[1]) or 0,
|
||||
'credit': flt(a[1]) > 0 and flt(a[1]) or 0,
|
||||
'remarks': self.doc.remarks,
|
||||
'voucher_type': self.doc.doctype,
|
||||
'voucher_no': self.doc.name,
|
||||
'transaction_date': self.doc.transaction_date,
|
||||
'posting_date': self.doc.posting_date,
|
||||
'fiscal_year': self.doc.fiscal_year,
|
||||
'against_voucher': '',
|
||||
'against_voucher_type': '',
|
||||
'company': self.doc.company,
|
||||
'is_opening': 'No',
|
||||
'aging_date': self.doc.posting_date
|
||||
}
|
||||
|
||||
self.save_entry(fdict)
|
||||
|
||||
|
||||
# Save GL Entry
|
||||
# ==========================================================
|
||||
def save_entry(self, fdict, is_cancel = 'No'):
|
||||
# Create new GL entry object and map values
|
||||
le = Document('GL Entry')
|
||||
for k in fdict:
|
||||
le.fields[k] = fdict[k]
|
||||
|
||||
le_obj = get_obj(doc=le)
|
||||
# validate except on_cancel
|
||||
if is_cancel == 'No':
|
||||
le_obj.validate()
|
||||
|
||||
# update total debit / credit except on_cancel
|
||||
self.td += flt(le.credit)
|
||||
self.tc += flt(le.debit)
|
||||
|
||||
# save
|
||||
le.save(1)
|
||||
le_obj.on_update(adv_adj = '')
|
||||
|
||||
|
||||
# Reposting Balances
|
||||
# ==========================================================
|
||||
def repost_account_balances(self):
|
||||
# Get Next Fiscal Year
|
||||
fy = sql("select name, is_fiscal_year_closed from `tabFiscal Year` where name = '%s' and past_year = '%s'" % (self.doc.next_fiscal_year, self.doc.fiscal_year))
|
||||
if not fy:
|
||||
msgprint("There is no Fiscal Year with Name " + cstr(self.doc.next_fiscal_year) + " and Past Year " + cstr(self.doc.fiscal_year))
|
||||
raise Exception
|
||||
|
||||
if fy and fy[0][1] == 'Yes':
|
||||
msgprint("Fiscal Year %s has been closed." % cstr(fy[1]))
|
||||
raise Exception
|
||||
|
||||
# Repost Balances
|
||||
get_obj('Fiscal Year', fy[0][0]).repost()
|
||||
|
||||
|
||||
# Validation
|
||||
# ===========================================================
|
||||
def validate(self):
|
||||
|
||||
# validate account head
|
||||
self.validate_account_head()
|
||||
|
||||
# validate posting date
|
||||
self.validate_posting_date()
|
||||
|
||||
# check if pl balance:
|
||||
self.validate_pl_balances()
|
||||
|
||||
|
||||
# On Submit
|
||||
# ===========================================================
|
||||
def on_submit(self):
|
||||
|
||||
# Makes closing entries for Expense Account
|
||||
in_acc_det = self.get_pl_balances('Credit')
|
||||
self.make_gl_entries(in_acc_det)
|
||||
|
||||
# Makes closing entries for Expense Account
|
||||
ex_acc_det = self.get_pl_balances('Debit')
|
||||
self.make_gl_entries(ex_acc_det)
|
||||
|
||||
|
||||
# Makes Closing entry for Closing Account Head
|
||||
bal = self.tc - self.td
|
||||
self.make_gl_entries([[self.doc.closing_account_head, flt(bal)]])
|
||||
|
||||
|
||||
# On Cancel
|
||||
# =============================================================
|
||||
def on_cancel(self):
|
||||
# get all submit entries of current closing entry voucher
|
||||
gl_entries = sql("select account, debit, credit from `tabGL Entry` where voucher_type = 'Period Closing Voucher' and voucher_no = '%s'" % (self.doc.name))
|
||||
|
||||
# Swap Debit & Credit Column and make gl entry
|
||||
for gl in gl_entries:
|
||||
fdict = {'account': gl[0], 'cost_center': '', 'against': '', 'debit': flt(gl[2]), 'credit' : flt(gl[1]), 'remarks': self.doc.cancel_reason, 'voucher_type': self.doc.doctype, 'voucher_no': self.doc.name, 'transaction_date': self.doc.transaction_date, 'posting_date': self.doc.posting_date, 'fiscal_year': self.doc.fiscal_year, 'against_voucher': '', 'against_voucher_type': '', 'company': self.doc.company, 'is_opening': 'No', 'aging_date': 'self.doc.posting_date'}
|
||||
self.save_entry(fdict, is_cancel = 'Yes')
|
||||
|
||||
# Update is_cancelled = 'Yes' to all gl entries for current voucher
|
||||
sql("update `tabGL Entry` set is_cancelled = 'Yes' where voucher_type = '%s' and voucher_no = '%s'" % (self.doc.doctype, self.doc.name))
|
||||
File diff suppressed because one or more lines are too long
0
accounts/doctype/pos_setting/__init__.py
Normal file
0
accounts/doctype/pos_setting/__init__.py
Normal file
38
accounts/doctype/pos_setting/pos_setting.js
Executable file
38
accounts/doctype/pos_setting/pos_setting.js
Executable file
@@ -0,0 +1,38 @@
|
||||
cur_frm.cscript.onload = function(doc,cdt,cdn){
|
||||
$c_obj(make_doclist(cdt,cdn),'get_series','',function(r,rt){
|
||||
if(r.message) set_field_options('naming_series', r.message);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
//cash bank account
|
||||
//------------------------------------
|
||||
cur_frm.fields_dict['cash_bank_account'].get_query = function(doc,cdt,cdn) {
|
||||
return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Debit" AND tabAccount.is_pl_account = "No" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"'
|
||||
}
|
||||
|
||||
// Income Account
|
||||
// --------------------------------
|
||||
cur_frm.fields_dict['income_account'].get_query = function(doc,cdt,cdn) {
|
||||
return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Credit" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.account_type ="Income Account" AND tabAccount.%(key)s LIKE "%s"'
|
||||
}
|
||||
|
||||
|
||||
// Cost Center
|
||||
// -----------------------------
|
||||
cur_frm.fields_dict['cost_center'].get_query = function(doc,cdt,cdn) {
|
||||
return 'SELECT `tabCost Center`.`name` FROM `tabCost Center` WHERE `tabCost Center`.`company_name` = "' +doc.company+'" AND `tabCost Center`.%(key)s LIKE "%s" AND `tabCost Center`.`group_or_ledger` = "Ledger" AND `tabCost Center`.`docstatus`!= 2 ORDER BY `tabCost Center`.`name` ASC LIMIT 50';
|
||||
}
|
||||
|
||||
//get query select Territory
|
||||
//=================================================================
|
||||
cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) {
|
||||
return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50';
|
||||
}
|
||||
|
||||
|
||||
// ------------------ Get Print Heading ------------------------------------
|
||||
cur_frm.fields_dict['select_print_heading'].get_query = function(doc, cdt, cdn) {
|
||||
return 'SELECT `tabPrint Heading`.name FROM `tabPrint Heading` WHERE `tabPrint Heading`.docstatus !=2 AND `tabPrint Heading`.name LIKE "%s" ORDER BY `tabPrint Heading`.name ASC LIMIT 50';
|
||||
}
|
||||
35
accounts/doctype/pos_setting/pos_setting.py
Executable file
35
accounts/doctype/pos_setting/pos_setting.py
Executable file
@@ -0,0 +1,35 @@
|
||||
# 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,doc,doclist=[]):
|
||||
self.doc, self.doclist = doc,doclist
|
||||
|
||||
#--------------------get naming series from sales invoice-----------------
|
||||
def get_series(self):
|
||||
res = sql("select options from `tabDocField` where parent='Receivable Voucher' and fieldname = 'naming_series'")
|
||||
return res and cstr(res[0][0]) or ''
|
||||
|
||||
def validate(self):
|
||||
res = sql("select name, user from `tabPOS Setting` where ifnull(user, '') = '%s' and name != '%s' and company = '%s'" % (self.doc.user, self.doc.name, self.doc.company))
|
||||
if res:
|
||||
if res[0][1]:
|
||||
msgprint("POS Setting '%s' already created for user: '%s' and company: '%s'"%(res[0][0], res[0][1], self.doc.company), raise_exception=1)
|
||||
else:
|
||||
msgprint("Global POS Setting already created - %s for this company: '%s'" % (res[0][0], self.doc.company), raise_exception=1)
|
||||
1
accounts/doctype/pos_setting/pos_setting.txt
Executable file
1
accounts/doctype/pos_setting/pos_setting.txt
Executable file
File diff suppressed because one or more lines are too long
0
accounts/doctype/purchase_tax_detail/__init__.py
Normal file
0
accounts/doctype/purchase_tax_detail/__init__.py
Normal file
File diff suppressed because one or more lines are too long
0
accounts/doctype/pv_add_tax_detail/__init__.py
Normal file
0
accounts/doctype/pv_add_tax_detail/__init__.py
Normal file
1
accounts/doctype/pv_add_tax_detail/pv_add_tax_detail.txt
Normal file
1
accounts/doctype/pv_add_tax_detail/pv_add_tax_detail.txt
Normal file
@@ -0,0 +1 @@
|
||||
[{'section_style': 'Tray', 'is_transaction_doc': None, 'creation': '2009-03-12 12:09:22', 'search_fields': None, 'module': 'Accounts', 'doctype': 'DocType', 'change_log': None, 'print_outline': '', 'owner': 'Administrator', 'in_dialog': None, 'in_create': None, 'read_only': None, 'allow_email': None, 'dt_template': None, 'hide_heading': None, 'issingle': None, 'allow_rename': None, 'smallicon': None, 'allow_attach': None, 'show_in_menu': 0, 'max_attachments': None, 'version': 1, 'menu_index': None, 'docstatus': 0, 'allow_copy': None, 'istable': 1, 'description': None, 'parent': None, 'server_code': '', 'allow_trash': None, 'allow_print': None, 'autoname': 'EXPTD.######', 'client_script_core': None, 'client_string': None, 'use_template': None, 'modified_by': 'Administrator', 'document_type': None, 'name': 'PV Add Tax Detail', 'idx': None, 'hide_toolbar': None, 'colour': 'White:FFF', 'client_script': '', 'modified': '2010-09-20 14:06:57', 'server_code_error': None, 'name_case': '', 'parenttype': None, 'read_only_onload': None, 'server_code_core': None, 'server_code_compiled': None, 'parent_node': None, 'parentfield': None}, {'no_copy': None, 'oldfieldtype': 'Link', 'creation': '2009-03-12 12:09:22', 'doctype': 'DocField', 'oldfieldname': 'add_tax_code', 'owner': 'Administrator', 'reqd': 1, 'in_filter': None, 'print_hide': None, 'modified_by': 'Administrator', 'label': 'Tax Code', 'width': '200px', 'trigger': 'Client', 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 0, 'description': None, 'parent': 'PV Add Tax Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL00442', 'idx': 1, 'default': None, 'colour': None, 'modified': '2009-07-09 14:29:26', 'parenttype': 'DocType', 'fieldname': 'add_tax_code', 'fieldtype': 'Link', 'options': 'Account', 'report_hide': None, 'parentfield': 'fields'}, {'no_copy': None, 'oldfieldtype': 'Link', 'creation': '2009-04-23 11:13:34', 'doctype': 'DocField', 'oldfieldname': 'cost_center', 'owner': 'Administrator', 'reqd': None, 'in_filter': None, 'print_hide': None, 'modified_by': 'Administrator', 'label': 'Cost Center', 'width': None, 'trigger': None, 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 0, 'description': None, 'parent': 'PV Add Tax Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL01926', 'idx': 2, 'default': None, 'colour': None, 'modified': '2009-07-09 14:29:26', 'parenttype': 'DocType', 'fieldname': 'cost_center', 'fieldtype': 'Link', 'options': 'Cost Center', 'report_hide': None, 'parentfield': 'fields'}, {'no_copy': None, 'oldfieldtype': 'Currency', 'creation': '2009-03-12 12:09:22', 'doctype': 'DocField', 'oldfieldname': 'add_tax_rate', 'owner': 'Administrator', 'reqd': None, 'in_filter': None, 'print_hide': None, 'modified_by': 'Administrator', 'label': 'Rate', 'width': None, 'trigger': 'Client', 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 0, 'description': None, 'parent': 'PV Add Tax Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL00443', 'idx': 3, 'default': None, 'colour': None, 'modified': '2009-07-09 14:29:26', 'parenttype': 'DocType', 'fieldname': 'add_tax_rate', 'fieldtype': 'Currency', 'options': None, 'report_hide': None, 'parentfield': 'fields'}, {'no_copy': None, 'oldfieldtype': 'Currency', 'creation': '2009-03-12 12:09:22', 'doctype': 'DocField', 'oldfieldname': 'add_amount', 'owner': 'Administrator', 'reqd': 1, 'in_filter': None, 'print_hide': None, 'modified_by': 'Administrator', 'label': 'Amount', 'width': None, 'trigger': 'Client', 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 0, 'description': None, 'parent': 'PV Add Tax Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL00444', 'idx': 4, 'default': None, 'colour': None, 'modified': '2009-07-09 14:29:26', 'parenttype': 'DocType', 'fieldname': 'add_amount', 'fieldtype': 'Currency', 'options': None, 'report_hide': None, 'parentfield': 'fields'}]
|
||||
0
accounts/doctype/pv_ded_tax_detail/__init__.py
Normal file
0
accounts/doctype/pv_ded_tax_detail/__init__.py
Normal file
1
accounts/doctype/pv_ded_tax_detail/pv_ded_tax_detail.txt
Normal file
1
accounts/doctype/pv_ded_tax_detail/pv_ded_tax_detail.txt
Normal file
@@ -0,0 +1 @@
|
||||
[{'section_style': 'Tray', 'is_transaction_doc': None, 'creation': '2009-03-12 12:09:22', 'search_fields': None, 'module': 'Accounts', 'doctype': 'DocType', 'change_log': None, 'print_outline': '', 'owner': 'Administrator', 'in_dialog': None, 'in_create': None, 'read_only': None, 'allow_email': None, 'dt_template': None, 'hide_heading': None, 'issingle': None, 'allow_rename': None, 'smallicon': None, 'allow_attach': None, 'show_in_menu': 0, 'max_attachments': None, 'version': 4, 'menu_index': None, 'docstatus': 0, 'allow_copy': None, 'istable': 1, 'description': None, 'parent': None, 'server_code': '', 'allow_trash': None, 'allow_print': None, 'autoname': 'TDD.######', 'client_script_core': None, 'client_string': None, 'use_template': None, 'modified_by': 'nabin@webnotestech.com', 'document_type': None, 'name': 'PV Ded Tax Detail', 'idx': None, 'hide_toolbar': None, 'colour': 'White:FFF', 'client_script': '', 'modified': '2010-09-20 14:06:57', 'server_code_error': None, 'name_case': '', 'parenttype': None, 'read_only_onload': None, 'server_code_core': None, 'server_code_compiled': None, 'parent_node': None, 'parentfield': None}, {'no_copy': None, 'oldfieldtype': 'Select', 'creation': '2009-05-25 16:21:06', 'doctype': 'DocField', 'oldfieldname': 'tds_type', 'owner': 'Administrator', 'reqd': None, 'in_filter': None, 'print_hide': 1, 'modified_by': 'nabin@webnotestech.com', 'label': 'TDS Type', 'width': None, 'trigger': None, 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 0, 'description': None, 'parent': 'PV Ded Tax Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL02152', 'idx': 1, 'default': None, 'colour': None, 'modified': '2009-12-15 12:02:13', 'parenttype': 'DocType', 'fieldname': 'tds_type', 'fieldtype': 'Select', 'options': '\nMain\nSurcharge\nEdu Cess\nSH Edu Cess\nNot Applicable', 'report_hide': None, 'parentfield': 'fields'}, {'no_copy': None, 'oldfieldtype': 'Link', 'creation': '2009-03-12 12:09:22', 'doctype': 'DocField', 'oldfieldname': 'tax_code', 'owner': 'Administrator', 'reqd': 1, 'in_filter': None, 'print_hide': None, 'modified_by': 'nabin@webnotestech.com', 'label': 'Tax Code', 'width': '200px', 'trigger': '', 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 0, 'description': None, 'parent': 'PV Ded Tax Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL00445', 'idx': 2, 'default': None, 'colour': None, 'modified': '2009-12-15 12:02:13', 'parenttype': 'DocType', 'fieldname': 'tax_code', 'fieldtype': 'Link', 'options': 'Account', 'report_hide': None, 'parentfield': 'fields'}, {'no_copy': None, 'oldfieldtype': 'Float', 'creation': '2009-03-12 12:09:22', 'doctype': 'DocField', 'oldfieldname': 'tax_rate', 'owner': 'Administrator', 'reqd': None, 'in_filter': None, 'print_hide': None, 'modified_by': 'nabin@webnotestech.com', 'label': 'Rate', 'width': None, 'trigger': 'Client', 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 0, 'description': None, 'parent': 'PV Ded Tax Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL00446', 'idx': 3, 'default': None, 'colour': None, 'modified': '2009-12-15 12:02:13', 'parenttype': 'DocType', 'fieldname': 'tax_rate', 'fieldtype': 'Float', 'options': None, 'report_hide': None, 'parentfield': 'fields'}, {'no_copy': None, 'oldfieldtype': 'Currency', 'creation': '2009-03-12 12:09:22', 'doctype': 'DocField', 'oldfieldname': 'ded_amount', 'owner': 'Administrator', 'reqd': 1, 'in_filter': None, 'print_hide': None, 'modified_by': 'nabin@webnotestech.com', 'label': 'Amount', 'width': None, 'trigger': 'Client', 'depends_on': None, 'docstatus': 0, 'hidden': None, 'permlevel': 0, 'description': None, 'parent': 'PV Ded Tax Detail', 'search_index': None, 'allow_on_submit': None, 'icon': None, 'name': 'FL00447', 'idx': 4, 'default': None, 'colour': None, 'modified': '2009-12-15 12:02:13', 'parenttype': 'DocType', 'fieldname': 'ded_amount', 'fieldtype': 'Currency', 'options': None, 'report_hide': None, 'parentfield': 'fields'}]
|
||||
0
accounts/doctype/pv_detail/__init__.py
Normal file
0
accounts/doctype/pv_detail/__init__.py
Normal file
686
accounts/doctype/pv_detail/pv_detail.txt
Normal file
686
accounts/doctype/pv_detail/pv_detail.txt
Normal file
@@ -0,0 +1,686 @@
|
||||
[
|
||||
{
|
||||
'_last_update': None,
|
||||
'allow_attach': None,
|
||||
'allow_copy': None,
|
||||
'allow_email': None,
|
||||
'allow_print': None,
|
||||
'allow_rename': None,
|
||||
'allow_trash': None,
|
||||
'autoname': 'EVD.######',
|
||||
'change_log': None,
|
||||
'client_script': None,
|
||||
'client_script_core': None,
|
||||
'client_string': None,
|
||||
'colour': 'White:FFF',
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocType',
|
||||
'document_type': None,
|
||||
'dt_template': None,
|
||||
'hide_heading': None,
|
||||
'hide_toolbar': None,
|
||||
'idx': None,
|
||||
'in_create': None,
|
||||
'in_dialog': None,
|
||||
'is_transaction_doc': None,
|
||||
'issingle': None,
|
||||
'istable': 1,
|
||||
'max_attachments': None,
|
||||
'menu_index': None,
|
||||
'modified': '2011-03-30 11:23:38',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'Accounts',
|
||||
'name': 'PV Detail',
|
||||
'name_case': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': None,
|
||||
'parent_node': None,
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'print_outline': None,
|
||||
'read_only': None,
|
||||
'read_only_onload': None,
|
||||
'search_fields': None,
|
||||
'section_style': 'Tray',
|
||||
'server_code': None,
|
||||
'server_code_compiled': None,
|
||||
'server_code_core': None,
|
||||
'server_code_error': ' ',
|
||||
'show_in_menu': 0,
|
||||
'smallicon': None,
|
||||
'use_template': None,
|
||||
'version': 26
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'item_code',
|
||||
'fieldtype': 'Link',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 1,
|
||||
'in_filter': 1,
|
||||
'label': 'Item',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL02571',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'item_code',
|
||||
'oldfieldtype': 'Link',
|
||||
'options': 'Item',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': 1,
|
||||
'report_hide': None,
|
||||
'reqd': 0,
|
||||
'search_index': 1,
|
||||
'trigger': 'Client',
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'item_name',
|
||||
'fieldtype': 'Data',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 2,
|
||||
'in_filter': 0,
|
||||
'label': 'Item Name',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL02572',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'item_name',
|
||||
'oldfieldtype': 'Data',
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': 1,
|
||||
'search_index': 0,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'brand',
|
||||
'fieldtype': 'Data',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 3,
|
||||
'in_filter': None,
|
||||
'label': 'Brand',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL02573',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'brand',
|
||||
'oldfieldtype': 'Data',
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': 1,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': None,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'description',
|
||||
'fieldtype': 'Text',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 4,
|
||||
'in_filter': None,
|
||||
'label': 'Description',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL02574',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'description',
|
||||
'oldfieldtype': 'Text',
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': None,
|
||||
'trigger': None,
|
||||
'width': '200px'
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'item_group',
|
||||
'fieldtype': 'Link',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 5,
|
||||
'in_filter': 1,
|
||||
'label': 'Item Group',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL02575',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'item_group',
|
||||
'oldfieldtype': 'Link',
|
||||
'options': 'Item Group',
|
||||
'owner': 'jai@webnotestech.com',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 1,
|
||||
'print_hide': 1,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': 1,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'rate',
|
||||
'fieldtype': 'Currency',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 6,
|
||||
'in_filter': None,
|
||||
'label': 'Rate (Default Curr.)',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL02576',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'rate',
|
||||
'oldfieldtype': 'Currency',
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': 1,
|
||||
'report_hide': None,
|
||||
'reqd': 1,
|
||||
'search_index': None,
|
||||
'trigger': 'Client',
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'import_rate',
|
||||
'fieldtype': 'Currency',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 7,
|
||||
'in_filter': None,
|
||||
'label': 'Rate',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL02578',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'import_rate',
|
||||
'oldfieldtype': 'Currency',
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': 0,
|
||||
'report_hide': None,
|
||||
'reqd': 1,
|
||||
'search_index': None,
|
||||
'trigger': 'Client',
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'qty',
|
||||
'fieldtype': 'Currency',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 8,
|
||||
'in_filter': None,
|
||||
'label': 'Qty',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL02577',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'qty',
|
||||
'oldfieldtype': 'Currency',
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': 0,
|
||||
'report_hide': None,
|
||||
'reqd': 1,
|
||||
'search_index': None,
|
||||
'trigger': 'Client',
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'amount',
|
||||
'fieldtype': 'Currency',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 9,
|
||||
'in_filter': None,
|
||||
'label': 'Amount (Default Curr.)',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL02579',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'amount',
|
||||
'oldfieldtype': 'Currency',
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 1,
|
||||
'print_hide': 1,
|
||||
'report_hide': None,
|
||||
'reqd': 1,
|
||||
'search_index': None,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'import_amount',
|
||||
'fieldtype': 'Currency',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 10,
|
||||
'in_filter': None,
|
||||
'label': 'Amount',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL02580',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'import_amount',
|
||||
'oldfieldtype': 'Currency',
|
||||
'options': None,
|
||||
'owner': 'jai@webnotestech.com',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 1,
|
||||
'print_hide': None,
|
||||
'report_hide': None,
|
||||
'reqd': 1,
|
||||
'search_index': None,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': 'White:FFF',
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'expense_head',
|
||||
'fieldtype': 'Link',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 11,
|
||||
'in_filter': None,
|
||||
'label': 'Expense Head',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL02581',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'expense_head',
|
||||
'oldfieldtype': 'Link',
|
||||
'options': 'Account',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': 1,
|
||||
'report_hide': None,
|
||||
'reqd': 1,
|
||||
'search_index': None,
|
||||
'trigger': 'Client',
|
||||
'width': '120px'
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': 'White:FFF',
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'cost_center',
|
||||
'fieldtype': 'Link',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 12,
|
||||
'in_filter': None,
|
||||
'label': 'Cost Center',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL02582',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'cost_center',
|
||||
'oldfieldtype': 'Link',
|
||||
'options': 'Cost Center',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': 1,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': None,
|
||||
'trigger': 'Client',
|
||||
'width': '120px'
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'purchase_order',
|
||||
'fieldtype': 'Link',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 13,
|
||||
'in_filter': 1,
|
||||
'label': 'Pur Order',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL02583',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'purchase_order',
|
||||
'oldfieldtype': 'Link',
|
||||
'options': 'Purchase Order',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 1,
|
||||
'print_hide': 1,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': 1,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'po_detail',
|
||||
'fieldtype': 'Data',
|
||||
'hidden': 1,
|
||||
'icon': None,
|
||||
'idx': 14,
|
||||
'in_filter': 1,
|
||||
'label': 'PO Detail',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL02584',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'po_detail',
|
||||
'oldfieldtype': 'Data',
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 1,
|
||||
'print_hide': 1,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': 1,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'purchase_receipt',
|
||||
'fieldtype': 'Link',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 15,
|
||||
'in_filter': 1,
|
||||
'label': 'Pur Receipt',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL02585',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'purchase_receipt',
|
||||
'oldfieldtype': 'Link',
|
||||
'options': 'Purchase Receipt',
|
||||
'owner': 'Administrator',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 1,
|
||||
'print_hide': 1,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': 1,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'pr_detail',
|
||||
'fieldtype': 'Data',
|
||||
'hidden': 1,
|
||||
'icon': None,
|
||||
'idx': 16,
|
||||
'in_filter': 1,
|
||||
'label': 'PR Detail',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL02586',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'pr_detail',
|
||||
'oldfieldtype': 'Data',
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 1,
|
||||
'print_hide': 1,
|
||||
'report_hide': None,
|
||||
'reqd': None,
|
||||
'search_index': 1,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': None,
|
||||
'colour': None,
|
||||
'creation': '2010-08-08 17:09:17',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': 'Tax detail table fetched from item master as a string and stored in this field.\nUsed for Purchase Other Charges',
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'item_tax_rate',
|
||||
'fieldtype': 'Small Text',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 17,
|
||||
'in_filter': None,
|
||||
'label': 'Item Tax Rate',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': 'FL02587',
|
||||
'no_copy': None,
|
||||
'oldfieldname': 'item_tax_rate',
|
||||
'oldfieldtype': 'Small Text',
|
||||
'options': None,
|
||||
'owner': 'wasim@webnotestech.com',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 1,
|
||||
'print_hide': 1,
|
||||
'report_hide': 1,
|
||||
'reqd': None,
|
||||
'search_index': None,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
},
|
||||
{
|
||||
'allow_on_submit': 1,
|
||||
'colour': None,
|
||||
'creation': '2011-05-09 11:04:22',
|
||||
'default': None,
|
||||
'depends_on': None,
|
||||
'description': None,
|
||||
'docstatus': 0,
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'page_break',
|
||||
'fieldtype': 'Check',
|
||||
'hidden': None,
|
||||
'icon': None,
|
||||
'idx': 18,
|
||||
'in_filter': None,
|
||||
'label': 'Page Break',
|
||||
'modified': '2011-05-09 11:04:22',
|
||||
'modified_by': 'Administrator',
|
||||
'name': '000000371',
|
||||
'no_copy': 1,
|
||||
'oldfieldname': None,
|
||||
'oldfieldtype': None,
|
||||
'options': None,
|
||||
'owner': 'Administrator',
|
||||
'parent': 'PV Detail',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'print_hide': 1,
|
||||
'report_hide': 1,
|
||||
'reqd': None,
|
||||
'search_index': None,
|
||||
'trigger': None,
|
||||
'width': None
|
||||
}
|
||||
]
|
||||
0
accounts/doctype/receivable_voucher/__init__.py
Normal file
0
accounts/doctype/receivable_voucher/__init__.py
Normal file
419
accounts/doctype/receivable_voucher/receivable_voucher.js
Normal file
419
accounts/doctype/receivable_voucher/receivable_voucher.js
Normal file
@@ -0,0 +1,419 @@
|
||||
cur_frm.cscript.tname = "RV Detail";
|
||||
cur_frm.cscript.fname = "entries";
|
||||
cur_frm.cscript.other_fname = "other_charges";
|
||||
cur_frm.cscript.sales_team_fname = "sales_team";
|
||||
|
||||
// print heading
|
||||
cur_frm.pformat.print_heading = 'Invoice';
|
||||
|
||||
$import(Sales Common)
|
||||
$import(Other Charges)
|
||||
$import(SMS Control)
|
||||
|
||||
// On Load
|
||||
// -------
|
||||
cur_frm.cscript.onload = function(doc,dt,dn) {
|
||||
if(!doc.customer && doc.debit_to) get_field(dt, 'debit_to', dn).print_hide = 0;
|
||||
if (doc.__islocal) {
|
||||
if(!doc.voucher_date) set_multiple(dt,dn,{voucher_date:get_today()});
|
||||
if(!doc.due_date) set_multiple(dt,dn,{due_date:get_today()});
|
||||
if(!doc.posting_date) set_multiple(dt,dn,{posting_date:get_today()});
|
||||
|
||||
//for previously created sales invoice, set required field related to pos
|
||||
if(doc.is_pos ==1) cur_frm.cscript.is_pos(doc, dt, dn);
|
||||
|
||||
hide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']);
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript.onload_post_render = function(doc, dt, dn) {
|
||||
if(doc.customer && doc.__islocal) {
|
||||
// called from mapper, update the account names for items and customer
|
||||
$c_obj(make_doclist(doc.doctype,doc.name),
|
||||
'load_default_accounts','',
|
||||
function(r,rt) {
|
||||
refresh_field('entries');
|
||||
refresh_field('debit_to');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if(!doc.customer && doc.__islocal) {
|
||||
// new -- load default taxes
|
||||
cur_frm.cscript.load_taxes(doc, cdt, cdn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Hide Fields
|
||||
// ------------
|
||||
cur_frm.cscript.hide_fields = function(doc, cdt, cdn) {
|
||||
if(cint(doc.is_pos) == 1)
|
||||
hide_field(['project_name', 'due_date', 'posting_time', 'sales_order_main', 'delivery_note_main', 'Get Items']);
|
||||
else
|
||||
unhide_field(['project_name', 'due_date', 'posting_time', 'sales_order_main', 'delivery_note_main', 'Get Items']);
|
||||
}
|
||||
|
||||
|
||||
// Refresh
|
||||
// -------
|
||||
cur_frm.cscript.refresh = function(doc, dt, dn) {
|
||||
|
||||
// Show / Hide button
|
||||
cur_frm.clear_custom_buttons();
|
||||
|
||||
if(doc.docstatus==1) {
|
||||
cur_frm.add_custom_button('View Ledger', cur_frm.cscript['View Ledger Entry']);
|
||||
cur_frm.add_custom_button('Send SMS', cur_frm.cscript['Send SMS']);
|
||||
unhide_field('Repair Outstanding Amt');
|
||||
|
||||
if(doc.is_pos==1 && doc.update_stock!=1)
|
||||
cur_frm.add_custom_button('Make Delivery', cur_frm.cscript['Make Delivery Note']);
|
||||
|
||||
if(doc.outstanding_amount!=0)
|
||||
cur_frm.add_custom_button('Make Payment Entry', cur_frm.cscript['Make Bank Voucher']);
|
||||
}
|
||||
else
|
||||
hide_field('Repair Outstanding Amt');
|
||||
cur_frm.cscript.is_opening(doc, dt, dn);
|
||||
cur_frm.cscript.hide_fields(doc, cdt, cdn);
|
||||
}
|
||||
|
||||
//fetch retail transaction related fields
|
||||
//--------------------------------------------
|
||||
cur_frm.cscript.is_pos = function(doc,dt,dn){
|
||||
cur_frm.cscript.hide_fields(doc, cdt, cdn);
|
||||
if(doc.is_pos == 1){
|
||||
if (!doc.company) {
|
||||
msgprint("Please select company to proceed");
|
||||
doc.is_pos = 0;
|
||||
refresh_field('is_pos');
|
||||
}
|
||||
else {
|
||||
var callback = function(r,rt){
|
||||
cur_frm.refresh();
|
||||
}
|
||||
$c_obj(make_doclist(dt,dn),'set_pos_fields','',callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cur_frm.cscript.warehouse = function(doc, cdt , cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
if (!d.item_code) {alert("please enter item code first"); return};
|
||||
if (d.warehouse) {
|
||||
arg = "{'item_code':'" + d.item_code + "','warehouse':'" + d.warehouse +"'}";
|
||||
get_server_fields('get_actual_qty',arg,'entries',doc,cdt,cdn,1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Customer
|
||||
cur_frm.cscript.customer = function(doc,dt,dn) {
|
||||
|
||||
var callback = function(r,rt) {
|
||||
var doc = locals[cur_frm.doctype][cur_frm.docname];
|
||||
get_server_fields('get_debit_to','','',doc, dt, dn, 0);
|
||||
cur_frm.refresh();
|
||||
}
|
||||
|
||||
if(doc.customer) $c_obj(make_doclist(doc.doctype, doc.name), 'get_default_customer_address', '', callback);
|
||||
if(doc.customer) unhide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']);
|
||||
}
|
||||
|
||||
cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {
|
||||
if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
|
||||
}
|
||||
|
||||
cur_frm.fields_dict.customer_address.on_new = function(dn) {
|
||||
locals['Address'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer;
|
||||
locals['Address'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name;
|
||||
}
|
||||
|
||||
cur_frm.fields_dict.contact_person.on_new = function(dn) {
|
||||
locals['Contact'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer;
|
||||
locals['Contact'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name;
|
||||
}
|
||||
|
||||
cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) {
|
||||
return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50';
|
||||
}
|
||||
|
||||
cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
|
||||
return 'SELECT name,CONCAT(first_name," ",ifnull(last_name,"")) As FullName,department,designation FROM tabContact WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50';
|
||||
}
|
||||
|
||||
|
||||
// Set Due Date = posting date + credit days
|
||||
cur_frm.cscript.debit_to = function(doc,dt,dn) {
|
||||
|
||||
var callback2 = function(r,rt) {
|
||||
var doc = locals[cur_frm.doctype][cur_frm.docname];
|
||||
cur_frm.refresh();
|
||||
}
|
||||
|
||||
var callback = function(r,rt) {
|
||||
var doc = locals[cur_frm.doctype][cur_frm.docname];
|
||||
if(doc.customer) $c_obj(make_doclist(dt,dn), 'get_default_customer_address', '', callback2);
|
||||
if(doc.customer) unhide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']);
|
||||
cur_frm.refresh();
|
||||
}
|
||||
|
||||
if(doc.debit_to && doc.posting_date){
|
||||
get_server_fields('get_cust_and_due_date','','',doc,dt,dn,1,callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//refresh advance amount
|
||||
//-------------------------------------------------
|
||||
|
||||
cur_frm.cscript.paid_amount = function(doc,dt,dn){
|
||||
doc.outstanding_amount = flt(doc.grand_total) - flt(doc.paid_amount) - flt(doc.write_off_amount);
|
||||
refresh_field('outstanding_amount');
|
||||
}
|
||||
|
||||
|
||||
//---- get customer details ----------------------------
|
||||
cur_frm.cscript.project_name = function(doc,cdt,cdn){
|
||||
$c_obj(make_doclist(doc.doctype, doc.name),'pull_project_customer','', function(r,rt){
|
||||
refresh_many(['customer', 'customer_name','customer_address', 'territory']);
|
||||
});
|
||||
}
|
||||
|
||||
//Set debit and credit to zero on adding new row
|
||||
//----------------------------------------------
|
||||
cur_frm.fields_dict['entries'].grid.onrowadd = function(doc, cdt, cdn){
|
||||
|
||||
cl = getchildren('RV Detail', doc.name, cur_frm.cscript.fname, doc.doctype);
|
||||
acc = '';
|
||||
cc = '';
|
||||
|
||||
for(var i = 0; i<cl.length; i++) {
|
||||
|
||||
if (cl[i].idx == 1){
|
||||
acc = cl[i].income_account;
|
||||
cc = cl[i].cost_center;
|
||||
}
|
||||
else{
|
||||
if (! cl[i].income_account) { cl[i].income_account = acc; refresh_field('income_account', cl[i].name, 'entries');}
|
||||
if (! cl[i].cost_center) {cl[i].cost_center = cc;refresh_field('cost_center', cl[i].name, 'entries');}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript.is_opening = function(doc, dt, dn) {
|
||||
hide_field('aging_date');
|
||||
if (doc.is_opening == 'Yes') unhide_field('aging_date');
|
||||
}
|
||||
|
||||
/* **************************** TRIGGERS ********************************** */
|
||||
|
||||
|
||||
|
||||
// Posting Date
|
||||
// ------------
|
||||
//cur_frm.cscript.posting_date = cur_frm.cscript.debit_to;
|
||||
|
||||
|
||||
// Get Items based on SO or DN Selected
|
||||
cur_frm.cscript['Get Items'] = function(doc, dt, dn) {
|
||||
var callback = function(r,rt) {
|
||||
unhide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']);
|
||||
cur_frm.refresh();
|
||||
}
|
||||
get_server_fields('pull_details','','',doc, dt, dn,1,callback);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Allocated Amount in advances table
|
||||
// -----------------------------------
|
||||
cur_frm.cscript.allocated_amount = function(doc,cdt,cdn){
|
||||
cur_frm.cscript.calc_adjustment_amount(doc,cdt,cdn);
|
||||
}
|
||||
|
||||
//Make Delivery Note Button
|
||||
//-----------------------------
|
||||
|
||||
cur_frm.cscript['Make Delivery Note'] = function() {
|
||||
|
||||
var doc = cur_frm.doc
|
||||
n = createLocal('Delivery Note');
|
||||
$c('dt_map', args={
|
||||
'docs':compress_doclist([locals['Delivery Note'][n]]),
|
||||
'from_doctype':doc.doctype,
|
||||
'to_doctype':'Delivery Note',
|
||||
'from_docname':doc.name,
|
||||
'from_to_list':"[['Receivable Voucher','Delivery Note'],['RV Detail','Delivery Note Detail'],['RV Tax Detail','RV Tax Detail'],['Sales Team','Sales Team']]"
|
||||
}, function(r,rt) {
|
||||
loaddoc('Delivery Note', n);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Make Bank Voucher Button
|
||||
// -------------------------
|
||||
cur_frm.cscript['Make Bank Voucher'] = function(doc, dt, dn) {
|
||||
cur_frm.cscript.make_jv(cur_frm.doc);
|
||||
}
|
||||
|
||||
|
||||
/* ***************************** Get Query Functions ************************** */
|
||||
|
||||
// Debit To
|
||||
// ---------
|
||||
cur_frm.fields_dict.debit_to.get_query = function(doc) {
|
||||
return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Debit" AND tabAccount.is_pl_account = "No" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"'
|
||||
}
|
||||
|
||||
// Cash/bank account
|
||||
//------------------
|
||||
cur_frm.fields_dict.cash_bank_account.get_query = function(doc) {
|
||||
return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Debit" AND tabAccount.is_pl_account = "No" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"'
|
||||
}
|
||||
|
||||
// Write off account
|
||||
//------------------
|
||||
cur_frm.fields_dict.write_off_account.get_query = function(doc) {
|
||||
return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Debit" AND tabAccount.is_pl_account = "Yes" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"'
|
||||
}
|
||||
|
||||
// Write off cost center
|
||||
//-----------------------
|
||||
cur_frm.fields_dict.write_off_cost_center.get_query = function(doc) {
|
||||
return 'SELECT `tabCost Center`.name FROM `tabCost Center` WHERE `tabCost Center`.group_or_ledger="Ledger" AND `tabCost Center`.docstatus!=2 AND `tabCost Center`.company_name="'+doc.company+'" AND `tabCost Center`.%(key)s LIKE "%s"'
|
||||
}
|
||||
|
||||
//project name
|
||||
//--------------------------
|
||||
cur_frm.fields_dict['project_name'].get_query = function(doc, cdt, cdn) {
|
||||
var cond = '';
|
||||
if(doc.customer) cond = '(`tabProject`.customer = "'+doc.customer+'" OR IFNULL(`tabProject`.customer,"")="") AND';
|
||||
return repl('SELECT `tabProject`.name FROM `tabProject` WHERE `tabProject`.status = "Open" AND %(cond)s `tabProject`.name LIKE "%s" ORDER BY `tabProject`.name ASC LIMIT 50', {cond:cond});
|
||||
}
|
||||
|
||||
//Territory
|
||||
//-----------------------------
|
||||
cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) {
|
||||
return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50';
|
||||
}
|
||||
|
||||
// Income Account in Details Table
|
||||
// --------------------------------
|
||||
cur_frm.fields_dict.entries.grid.get_field("income_account").get_query = function(doc) {
|
||||
return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Credit" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus!=2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"';
|
||||
}
|
||||
|
||||
// warehouse in detail table
|
||||
//----------------------------
|
||||
cur_frm.fields_dict['entries'].grid.get_field('warehouse').get_query= function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
return "SELECT `tabBin`.`warehouse`, `tabBin`.`actual_qty` FROM `tabBin` WHERE `tabBin`.`item_code` = '"+ d.item_code +"' AND ifnull(`tabBin`.`actual_qty`,0) > 0 AND `tabBin`.`warehouse` like '%s' ORDER BY `tabBin`.`warehouse` DESC LIMIT 50";
|
||||
}
|
||||
|
||||
// Cost Center in Details Table
|
||||
// -----------------------------
|
||||
cur_frm.fields_dict.entries.grid.get_field("cost_center").get_query = function(doc) {
|
||||
return 'SELECT `tabCost Center`.`name` FROM `tabCost Center` WHERE `tabCost Center`.`company_name` = "' +doc.company+'" AND `tabCost Center`.%(key)s LIKE "%s" AND `tabCost Center`.`group_or_ledger` = "Ledger" AND `tabCost Center`.`docstatus`!= 2 ORDER BY `tabCost Center`.`name` ASC LIMIT 50';
|
||||
}
|
||||
|
||||
// Sales Order
|
||||
// -----------
|
||||
cur_frm.fields_dict.sales_order_main.get_query = function(doc) {
|
||||
if (doc.customer)
|
||||
return 'SELECT DISTINCT `tabSales Order`.`name` FROM `tabSales Order` WHERE `tabSales Order`.company = "' + doc.company + '" and `tabSales Order`.`docstatus` = 1 and `tabSales Order`.`status` != "Stopped" and ifnull(`tabSales Order`.per_billed,0) < 100 and `tabSales Order`.`customer` = "' + doc.customer + '" and `tabSales Order`.%(key)s LIKE "%s" ORDER BY `tabSales Order`.`name` DESC LIMIT 50';
|
||||
else
|
||||
return 'SELECT DISTINCT `tabSales Order`.`name` FROM `tabSales Order` WHERE `tabSales Order`.company = "' + doc.company + '" and `tabSales Order`.`docstatus` = 1 and `tabSales Order`.`status` != "Stopped" and ifnull(`tabSales Order`.per_billed,0) < 100 and `tabSales Order`.%(key)s LIKE "%s" ORDER BY `tabSales Order`.`name` DESC LIMIT 50';
|
||||
}
|
||||
|
||||
// Delivery Note
|
||||
// --------------
|
||||
cur_frm.fields_dict.delivery_note_main.get_query = function(doc) {
|
||||
if (doc.customer)
|
||||
return 'SELECT DISTINCT `tabDelivery Note`.`name` FROM `tabDelivery Note` WHERE `tabDelivery Note`.company = "' + doc.company + '" and `tabDelivery Note`.`docstatus` = 1 and ifnull(`tabDelivery Note`.per_billed,0) < 100 and `tabDelivery Note`.`customer` = "' + doc.customer + '" and `tabDelivery Note`.%(key)s LIKE "%s" ORDER BY `tabDelivery Note`.`name` DESC LIMIT 50';
|
||||
else
|
||||
return 'SELECT DISTINCT `tabDelivery Note`.`name` FROM `tabDelivery Note` WHERE `tabDelivery Note`.company = "' + doc.company + '" and `tabDelivery Note`.`docstatus` = 1 and ifnull(`tabDelivery Note`.per_billed,0) < 100 and `tabDelivery Note`.%(key)s LIKE "%s" ORDER BY `tabDelivery Note`.`name` DESC LIMIT 50';
|
||||
}
|
||||
|
||||
|
||||
|
||||
cur_frm.cscript.income_account = function(doc, cdt, cdn){
|
||||
var d = locals[cdt][cdn];
|
||||
if(d.income_account){
|
||||
var cl = getchildren('RV Detail', doc.name, cur_frm.cscript.fname, doc.doctype);
|
||||
for(var i = 0; i < cl.length; i++){
|
||||
if(!cl[i].income_account) cl[i].income_account = d.income_account;
|
||||
}
|
||||
}
|
||||
refresh_field(cur_frm.cscript.fname);
|
||||
}
|
||||
|
||||
|
||||
cur_frm.cscript.cost_center = function(doc, cdt, cdn){
|
||||
var d = locals[cdt][cdn];
|
||||
if(d.cost_center){
|
||||
var cl = getchildren('RV Detail', doc.name, cur_frm.cscript.fname, doc.doctype);
|
||||
for(var i = 0; i < cl.length; i++){
|
||||
if(!cl[i].cost_center) cl[i].cost_center = d.cost_center;
|
||||
}
|
||||
}
|
||||
refresh_field(cur_frm.cscript.fname);
|
||||
}
|
||||
|
||||
/* **************************************** Utility Functions *************************************** */
|
||||
|
||||
// Details Calculation
|
||||
// --------------------
|
||||
cur_frm.cscript.calc_adjustment_amount = function(doc,cdt,cdn) {
|
||||
var doc = locals[doc.doctype][doc.name];
|
||||
var el = getchildren('Advance Adjustment Detail',doc.name,'advance_adjustment_details');
|
||||
var total_adjustment_amt = 0
|
||||
for(var i in el) {
|
||||
total_adjustment_amt += flt(el[i].allocated_amount)
|
||||
}
|
||||
doc.total_advance = flt(total_adjustment_amt);
|
||||
doc.outstanding_amount = flt(doc.grand_total) - flt(total_adjustment_amt) - flt(doc.paid_amount) - flt(doc.write_off_amount);
|
||||
refresh_many(['total_advance','outstanding_amount']);
|
||||
}
|
||||
|
||||
|
||||
// Make Journal Voucher
|
||||
// --------------------
|
||||
cur_frm.cscript.make_jv = function(doc, dt, dn) {
|
||||
var jv = LocalDB.create('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 = LocalDB.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 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries');
|
||||
d1.debit = doc.outstanding_amount;
|
||||
|
||||
loaddoc('Journal Voucher', jv.name);
|
||||
}
|
||||
|
||||
|
||||
/****************** Get Accounting Entry *****************/
|
||||
cur_frm.cscript['View Ledger Entry'] = function(){
|
||||
var callback = function(report){
|
||||
report.set_filter('GL Entry', 'Voucher No',cur_frm.doc.name);
|
||||
report.dt.run();
|
||||
}
|
||||
loadreport('GL Entry','General Ledger', callback);
|
||||
}
|
||||
618
accounts/doctype/receivable_voucher/receivable_voucher.py
Normal file
618
accounts/doctype/receivable_voucher/receivable_voucher.py
Normal file
@@ -0,0 +1,618 @@
|
||||
# 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
|
||||
|
||||
# -----------------------------------------------------------------------------------------
|
||||
|
||||
from utilities.transaction_base import TransactionBase
|
||||
|
||||
class DocType(TransactionBase):
|
||||
def __init__(self,d,dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
self.log = []
|
||||
self.tname = 'RV Detail'
|
||||
self.fname = 'entries'
|
||||
|
||||
|
||||
# Autoname
|
||||
# ---------
|
||||
def autoname(self):
|
||||
self.doc.name = make_autoname(self.doc.naming_series+ '.#####')
|
||||
|
||||
|
||||
|
||||
# ********************************* Trigger Functions ******************************
|
||||
|
||||
#Set retail related fields from pos settings
|
||||
#-------------------------------------------------------------------------
|
||||
def set_pos_fields(self):
|
||||
pos = sql("select * from `tabPOS Setting` where ifnull(user,'') = '%s' and company = '%s'" % (session['user'], self.doc.company), as_dict=1)
|
||||
if not pos:
|
||||
pos = sql("select * from `tabPOS Setting` where ifnull(user,'') = '' and company = '%s'" % (self.doc.company), as_dict=1)
|
||||
if pos:
|
||||
val = sql("select name from `tabAccount` where name = %s and docstatus != 2", (cstr(self.doc.customer) + " - " + self.get_company_abbr()))
|
||||
val = val and val[0][0] or ''
|
||||
if not val: val = pos and pos[0]['customer_account'] or ''
|
||||
if not self.doc.debit_to:
|
||||
set(self.doc,'debit_to',val)
|
||||
|
||||
lst = ['territory','naming_series','currency','charge','letter_head','tc_name','price_list_name','company','select_print_heading','cash_bank_account']
|
||||
|
||||
for i in lst:
|
||||
val = pos and pos[0][i] or ''
|
||||
set(self.doc,i,val)
|
||||
self.set_pos_item_values()
|
||||
|
||||
val = pos and flt(pos[0]['conversion_rate']) or 0
|
||||
set(self.doc,'conversion_rate',val)
|
||||
|
||||
#fetch terms
|
||||
if self.doc.tc_name: self.get_tc_details()
|
||||
|
||||
#fetch charges
|
||||
if self.doc.charge: self.get_other_charges()
|
||||
|
||||
|
||||
# Set default values related to pos for previously created sales invoice.
|
||||
# --------------------------------------------------------------------------
|
||||
def set_pos_item_values(self):
|
||||
if cint(self.doc.is_pos) ==1:
|
||||
dtl = sql("select income_account, warehouse, cost_center from `tabPOS Setting` where ifnull(user,'') = '%s' and company = '%s'" % (session['user'], self.doc.company), as_dict=1)
|
||||
if not dtl:
|
||||
dtl = sql("select income_account, warehouse, cost_center from `tabPOS Setting` where ifnull(user,'') = '' and company = '%s'" % (self.doc.company), as_dict=1)
|
||||
for d in getlist(self.doclist,'entries'):
|
||||
if dtl and dtl[0]['income_account']: d.income_account = dtl[0]['income_account']
|
||||
if dtl and dtl[0]['cost_center']: d.cost_center = dtl[0]['cost_center']
|
||||
if dtl and dtl[0]['warehouse']: d.warehouse = dtl[0]['warehouse']
|
||||
|
||||
|
||||
# Get Account Head to which amount needs to be Debited based on Customer
|
||||
# ----------------------------------------------------------------------
|
||||
def get_customer_account(self):
|
||||
acc_head = sql("select name from `tabAccount` where name = %s and docstatus != 2", (cstr(self.doc.customer) + " - " + self.get_company_abbr()))
|
||||
if acc_head and acc_head[0][0]:
|
||||
return acc_head[0][0]
|
||||
else:
|
||||
msgprint("%s does not have an Account Head in %s. You must first create it from the Customer Master" % (self.doc.customer, self.doc.company))
|
||||
|
||||
def get_debit_to(self):
|
||||
acc_head = self.get_customer_account()
|
||||
if acc_head:
|
||||
return cstr({ 'debit_to' : acc_head })
|
||||
|
||||
|
||||
# Set Due Date = Posting Date + Credit Days
|
||||
# -----------------------------------------
|
||||
def get_cust_and_due_date(self):
|
||||
credit_days = 0
|
||||
if self.doc.debit_to:
|
||||
credit_days = sql("select credit_days from `tabAccount` where name='%s' and docstatus != 2" % self.doc.debit_to)
|
||||
credit_days = credit_days and cint(credit_days[0][0]) or 0
|
||||
if self.doc.company and not credit_days:
|
||||
credit_days = sql("select credit_days from `tabCompany` where name='%s'" % self.doc.company)
|
||||
credit_days = credit_days and cint(credit_days[0][0]) or 0
|
||||
# Customer has higher priority than company
|
||||
# i.e.if not entered in customer will take credit days from company
|
||||
self.doc.due_date = add_days(cstr(self.doc.posting_date), credit_days)
|
||||
|
||||
if self.doc.debit_to:
|
||||
self.doc.customer = get_value('Account',self.doc.debit_to,'master_name')
|
||||
# get_obj('Sales Common').get_customer_details(self, inv_det_reqd = 0)
|
||||
|
||||
|
||||
# Pull Details of Delivery Note or Sales Order Selected
|
||||
# ------------------------------------------------------
|
||||
def pull_details(self):
|
||||
# Delivery Note
|
||||
if self.doc.delivery_note_main:
|
||||
self.validate_prev_docname('delivery note')
|
||||
self.doc.clear_table(self.doclist,'other_charges')
|
||||
self.doclist = get_obj('DocType Mapper', 'Delivery Note-Receivable Voucher').dt_map('Delivery Note', 'Receivable Voucher', self.doc.delivery_note_main, self.doc, self.doclist, "[['Delivery Note', 'Receivable Voucher'],['Delivery Note Detail', 'RV Detail'],['RV Tax Detail','RV Tax Detail'],['Sales Team','Sales Team']]")
|
||||
self.get_income_account('entries')
|
||||
# Sales Order
|
||||
elif self.doc.sales_order_main:
|
||||
self.validate_prev_docname('sales order')
|
||||
self.doc.clear_table(self.doclist,'other_charges')
|
||||
get_obj('DocType Mapper', 'Sales Order-Receivable Voucher').dt_map('Sales Order', 'Receivable Voucher', self.doc.sales_order_main, self.doc, self.doclist, "[['Sales Order', 'Receivable Voucher'],['Sales Order Detail', 'RV Detail'],['RV Tax Detail','RV Tax Detail'], ['Sales Team', 'Sales Team']]")
|
||||
self.get_income_account('entries')
|
||||
|
||||
ret = eval(self.get_debit_to())
|
||||
if ret.has_key('debit_to'):
|
||||
self.doc.debit_to = ret['debit_to']
|
||||
|
||||
# onload pull income account
|
||||
# --------------------------
|
||||
def load_default_accounts(self):
|
||||
"""
|
||||
Loads default accounts from items, customer when called from mapper
|
||||
"""
|
||||
self.get_income_account('entries')
|
||||
self.doc.debit_to = self.get_customer_account()
|
||||
|
||||
def get_income_account(self,doctype):
|
||||
for d in getlist(self.doclist, doctype):
|
||||
if d.item_code:
|
||||
item = sql("select default_income_account, default_sales_cost_center from tabItem where name = '%s'" %(d.item_code), as_dict=1)
|
||||
d.income_account = item and item[0]['default_income_account'] or ''
|
||||
d.cost_center = item and item[0]['default_sales_cost_center'] or ''
|
||||
|
||||
# Item Details
|
||||
# -------------
|
||||
def get_item_details(self, item_code):
|
||||
ret = get_obj('Sales Common').get_item_details(item_code, self)
|
||||
if item_code and cint(self.doc.is_pos) == 1:
|
||||
dtl = sql("select income_account, warehouse, cost_center from `tabPOS Setting` where user = '%s' and company = '%s'" % (session['user'], self.doc.company), as_dict=1)
|
||||
if not dtl:
|
||||
dtl = sql("select income_account, warehouse, cost_center from `tabPOS Setting` where ifnull(user,'') = '' and company = '%s'" % (self.doc.company), as_dict=1)
|
||||
if dtl and dtl[0]['income_account']: ret['income_account'] = dtl and dtl[0]['income_account']
|
||||
if dtl and dtl[0]['cost_center']: ret['cost_center'] = dtl and dtl[0]['cost_center']
|
||||
if dtl and dtl[0]['warehouse']: ret['warehouse'] = dtl and dtl[0]['warehouse']
|
||||
if ret['warehouse']:
|
||||
actual_qty = sql("select actual_qty from `tabBin` where item_code = '%s' and warehouse = '%s'" % (item_code, ret['warehouse']))
|
||||
ret['actual_qty']= actual_qty and flt(actual_qty[0][0]) or 0
|
||||
return str(ret)
|
||||
|
||||
|
||||
# Get tax rate if account type is tax
|
||||
# ------------------------------------
|
||||
def get_rate(self,arg):
|
||||
get_obj('Sales Common').get_rate(arg)
|
||||
|
||||
|
||||
# Get Commission rate of Sales Partner
|
||||
# -------------------------------------
|
||||
def get_comm_rate(self, sales_partner):
|
||||
return get_obj('Sales Common').get_comm_rate(sales_partner, self)
|
||||
|
||||
|
||||
# GET TERMS & CONDITIONS
|
||||
# -------------------------------------
|
||||
def get_tc_details(self):
|
||||
return get_obj('Sales Common').get_tc_details(self)
|
||||
|
||||
# Load Default Charges
|
||||
# ----------------------------------------------------------
|
||||
def load_default_taxes(self):
|
||||
return get_obj('Sales Common').load_default_taxes(self)
|
||||
|
||||
# Get Other Charges Details
|
||||
# --------------------------
|
||||
def get_other_charges(self):
|
||||
return get_obj('Sales Common').get_other_charges(self)
|
||||
|
||||
|
||||
# Get Advances
|
||||
# -------------
|
||||
def get_advances(self):
|
||||
get_obj('GL Control').get_advances(self, self.doc.debit_to, 'Advance Adjustment Detail', 'advance_adjustment_details', 'credit')
|
||||
|
||||
#pull project customer
|
||||
#-------------------------
|
||||
def pull_project_customer(self):
|
||||
res = sql("select customer from `tabProject` where name = '%s'"%self.doc.project_name)
|
||||
if res:
|
||||
get_obj('DocType Mapper', 'Project-Receivable Voucher').dt_map('Project', 'Receivable Voucher', self.doc.project_name, self.doc, self.doclist, "[['Project', 'Receivable Voucher']]")
|
||||
|
||||
# ********************************** Server Utility Functions ******************************
|
||||
|
||||
# Get Company Abbr.
|
||||
# ------------------
|
||||
def get_company_abbr(self):
|
||||
return sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0]
|
||||
|
||||
|
||||
# Check whether sales order / delivery note items already pulled
|
||||
#----------------------------------------------------------------
|
||||
def validate_prev_docname(self,doctype):
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
if doctype == 'delivery note' and self.doc.delivery_note_main == d.delivery_note:
|
||||
msgprint(cstr(self.doc.delivery_note_main) + " delivery note details have already been pulled.")
|
||||
raise Exception , "Validation Error. Delivery note details have already been pulled."
|
||||
elif doctype == 'sales order' and self.doc.sales_order_main == d.sales_order and not d.delivery_note:
|
||||
msgprint(cstr(self.doc.sales_order_main) + " sales order details have already been pulled.")
|
||||
raise Exception , "Validation Error. Sales order details have already been pulled."
|
||||
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
# ADVANCE ALLOCATION
|
||||
#-----------------------------------------------------------------
|
||||
def update_against_document_in_jv(self,against_document_no, against_document_doctype):
|
||||
get_obj('GL Control').update_against_document_in_jv( self, 'advance_adjustment_details', against_document_no, against_document_doctype, self.doc.debit_to, 'credit', self.doc.doctype)
|
||||
|
||||
|
||||
|
||||
# ************************************* VALIDATE **********************************************
|
||||
# Get Customer Name and address based on Debit To Account selected
|
||||
# This case arises in case of direct RV where user doesn't enter customer name.
|
||||
# Hence it should be fetched from Account Head.
|
||||
# -----------------------------------------------------------------------------
|
||||
#def get_customer_details(self):
|
||||
# get_obj('Sales Common').get_customer_details(self, inv_det_reqd = 1)
|
||||
# self.get_cust_and_due_date()
|
||||
|
||||
|
||||
# Validate Customer Name with SO or DN if items are fetched from SO or DN
|
||||
# ------------------------------------------------------------------------
|
||||
def validate_customer(self):
|
||||
for d in getlist(self.doclist,'entries'):
|
||||
customer = ''
|
||||
if d.sales_order:
|
||||
customer = sql("select customer from `tabSales Order` where name = '%s'" % d.sales_order)[0][0]
|
||||
doctype = 'sales order'
|
||||
doctype_no = cstr(d.sales_order)
|
||||
if d.delivery_note:
|
||||
customer = sql("select customer from `tabDelivery Note` where name = '%s'" % d.delivery_note)[0][0]
|
||||
doctype = 'delivery note'
|
||||
doctype_no = cstr(d.delivery_note)
|
||||
if customer and not cstr(self.doc.customer) == cstr(customer):
|
||||
msgprint("Customer %s do not match with customer of %s %s." %(self.doc.customer,doctype,doctype_no))
|
||||
raise Exception , " Validation Error "
|
||||
|
||||
|
||||
# Validates Debit To Account and Customer Matches
|
||||
# ------------------------------------------------
|
||||
def validate_debit_to_acc(self):
|
||||
if self.doc.customer and not cint(self.doc.is_pos):
|
||||
acc_head = sql("select name from `tabAccount` where name = %s and docstatus != 2", (cstr(self.doc.customer) + " - " + self.get_company_abbr()))
|
||||
if acc_head and acc_head[0][0]:
|
||||
if not cstr(acc_head[0][0]) == cstr(self.doc.debit_to):
|
||||
msgprint("Debit To %s do not match with Customer %s for Company %s i.e. %s" %(self.doc.debit_to,self.doc.customer,self.doc.company,cstr(acc_head[0][0])))
|
||||
raise Exception, "Validation Error "
|
||||
if not acc_head:
|
||||
msgprint("%s does not have an Account Head in %s. You must first create it from the Customer Master" % (self.doc.customer, self.doc.company))
|
||||
raise Exception, "Validation Error "
|
||||
|
||||
|
||||
# Validate Debit To Account
|
||||
# 1. Account Exists
|
||||
# 2. Is a Debit Account
|
||||
# 3. Is a PL Account
|
||||
# ---------------------------
|
||||
def validate_debit_acc(self):
|
||||
acc = sql("select debit_or_credit, is_pl_account from tabAccount where name = '%s' and docstatus != 2" % self.doc.debit_to)
|
||||
if not acc:
|
||||
msgprint("Account: "+ self.doc.debit_to + " does not exist")
|
||||
raise Exception
|
||||
elif acc[0][0] and acc[0][0] != 'Debit':
|
||||
msgprint("Account: "+ self.doc.debit_to + " is not a debit account")
|
||||
raise Exception
|
||||
elif acc[0][1] and acc[0][1] != 'No':
|
||||
msgprint("Account: "+ self.doc.debit_to + " is a pl account")
|
||||
raise Exception
|
||||
|
||||
|
||||
# Validate Fixed Asset Account and whether Income Account Entered Exists
|
||||
# -----------------------------------------------------------------------
|
||||
def validate_fixed_asset_account(self):
|
||||
for d in getlist(self.doclist,'entries'):
|
||||
item = sql("select name,is_asset_item,is_sales_item from `tabItem` where name = '%s' and (ifnull(end_of_life,'')='' or end_of_life = '0000-00-00' or end_of_life > now())"% d.item_code)
|
||||
acc = sql("select account_type from `tabAccount` where name = '%s' and docstatus != 2" % d.income_account)
|
||||
if not acc:
|
||||
msgprint("Account: "+d.income_account+" does not exist in the system")
|
||||
raise Exception
|
||||
elif item and item[0][1] == 'Yes' and not acc[0][0] == 'Fixed Asset Account':
|
||||
msgprint("Please select income head with account type 'Fixed Asset Account' as Item %s is an asset item" % d.item_code)
|
||||
raise Exception
|
||||
|
||||
|
||||
|
||||
# Set totals in words
|
||||
#--------------------
|
||||
def set_in_words(self):
|
||||
self.doc.in_words = get_obj('Sales Common').get_total_in_words(get_defaults()['currency'], self.doc.rounded_total)
|
||||
self.doc.in_words_export = get_obj('Sales Common').get_total_in_words(self.doc.currency, self.doc.rounded_total_export)
|
||||
|
||||
# Clear Advances
|
||||
# --------------
|
||||
def clear_advances(self):
|
||||
get_obj('GL Control').clear_advances(self, 'Advance Adjustment Detail','advance_adjustment_details')
|
||||
|
||||
|
||||
# set aging date
|
||||
#-------------------
|
||||
def set_aging_date(self):
|
||||
if self.doc.is_opening != 'Yes':
|
||||
self.doc.aging_date = self.doc.posting_date
|
||||
elif not self.doc.aging_date:
|
||||
msgprint("Aging Date is mandatory for opening entry")
|
||||
raise Exception
|
||||
|
||||
|
||||
# Set against account for debit to account
|
||||
#------------------------------------------
|
||||
def set_against_income_account(self):
|
||||
against_acc = []
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
if d.income_account not in against_acc:
|
||||
against_acc.append(d.income_account)
|
||||
self.doc.against_income_account = ','.join(against_acc)
|
||||
|
||||
def add_remarks(self):
|
||||
if not self.doc.remarks: self.doc.remarks = 'No Remarks'
|
||||
|
||||
#check in manage account if sales order / delivery note required or not.
|
||||
def so_dn_required(self):
|
||||
dict = {'Sales Order':'so_required','Delivery Note':'dn_required'}
|
||||
for i in dict:
|
||||
res = sql("select value from `tabSingles` where doctype = 'Manage Account' and field = '%s'"%dict[i])
|
||||
if res and res[0][0] == 'Yes':
|
||||
for d in getlist(self.doclist,'entries'):
|
||||
if not d.fields[i.lower().replace(' ','_')]:
|
||||
msgprint("%s No. required against item %s"%(i,d.item_code))
|
||||
raise Exception
|
||||
|
||||
#check for does customer belong to same project as entered..
|
||||
#-------------------------------------------------------------------------------------------------
|
||||
def validate_proj_cust(self):
|
||||
if self.doc.project_name and self.doc.customer:
|
||||
res = sql("select name from `tabProject` where name = '%s' and (customer = '%s' or ifnull(customer,'')='')"%(self.doc.project_name, self.doc.customer))
|
||||
if not res:
|
||||
msgprint("Customer - %s does not belong to project - %s. \n\nIf you want to use project for multiple customers then please make customer details blank in that project."%(self.doc.customer,self.doc.project_name))
|
||||
raise Exception
|
||||
|
||||
def validate_pos(self):
|
||||
if not self.doc.cash_bank_account:
|
||||
msgprint("Cash/Bank Account is mandatory for POS entry")
|
||||
raise Exception
|
||||
if (flt(self.doc.paid_amount) + flt(self.doc.write_off_amount) - flt(self.doc.grand_total))>0.001:
|
||||
msgprint("(Paid amount + Write Off Amount) can not be greater than Grand Total")
|
||||
raise Exception
|
||||
|
||||
|
||||
# ********* UPDATE CURRENT STOCK *****************************
|
||||
def update_current_stock(self):
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
bin = sql("select actual_qty from `tabBin` where item_code = %s and warehouse = %s", (d.item_code, d.warehouse), as_dict = 1)
|
||||
d.actual_qty = bin and flt(bin[0]['actual_qty']) or 0
|
||||
|
||||
def validate_item_code(self):
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
if not d.item_code:
|
||||
msgprint("Please enter Item Code at line no : %s to update stock for POS or remove check from Update Stock in Basic Info Tab." % (d.idx))
|
||||
raise Exception
|
||||
|
||||
# Validate Write Off Account
|
||||
# -------------------------------
|
||||
def validate_write_off_account(self):
|
||||
if flt(self.doc.write_off_amount) and not self.doc.write_off_account:
|
||||
msgprint("Please enter Write Off Account", raise_exception=1)
|
||||
|
||||
|
||||
# VALIDATE
|
||||
# ====================================================================================
|
||||
def validate(self):
|
||||
self.so_dn_required()
|
||||
#self.dn_required()
|
||||
self.validate_proj_cust()
|
||||
sales_com_obj = get_obj('Sales Common')
|
||||
sales_com_obj.check_stop_sales_order(self)
|
||||
sales_com_obj.check_active_sales_items(self)
|
||||
sales_com_obj.check_conversion_rate(self)
|
||||
sales_com_obj.validate_max_discount(self, 'entries') #verify whether rate is not greater than tolerance
|
||||
sales_com_obj.get_allocated_sum(self) # this is to verify that the allocated % of sales persons is 100%
|
||||
sales_com_obj.validate_fiscal_year(self.doc.fiscal_year,self.doc.posting_date,'Posting Date')
|
||||
if not self.doc.customer:
|
||||
get_obj('Sales Common').get_customer_details(self, inv_det_reqd = 0)
|
||||
self.validate_customer()
|
||||
self.validate_debit_to_acc()
|
||||
self.validate_debit_acc()
|
||||
self.validate_fixed_asset_account()
|
||||
self.add_remarks()
|
||||
if cint(self.doc.is_pos):
|
||||
self.validate_pos()
|
||||
self.validate_write_off_account()
|
||||
if cint(self.doc.update_stock):
|
||||
get_obj('Stock Ledger').validate_serial_no(self, 'entries')
|
||||
self.validate_item_code()
|
||||
self.update_current_stock()
|
||||
self.set_in_words()
|
||||
if not self.doc.is_opening:
|
||||
self.doc.is_opening = 'No'
|
||||
self.set_aging_date()
|
||||
self.clear_advances()
|
||||
# Set against account
|
||||
self.set_against_income_account()
|
||||
|
||||
|
||||
# *************************************************** ON SUBMIT **********************************************
|
||||
# Check Ref Document's docstatus
|
||||
# -------------------------------
|
||||
def check_prev_docstatus(self):
|
||||
for d in getlist(self.doclist,'entries'):
|
||||
if d.sales_order:
|
||||
submitted = sql("select name from `tabSales Order` where docstatus = 1 and name = '%s'" % d.sales_order)
|
||||
if not submitted:
|
||||
msgprint("Sales Order : "+ cstr(d.sales_order) +" is not submitted")
|
||||
raise Exception , "Validation Error."
|
||||
|
||||
if d.delivery_note:
|
||||
submitted = sql("select name from `tabDelivery Note` where docstatus = 1 and name = '%s'" % d.delivery_note)
|
||||
if not submitted:
|
||||
msgprint("Delivery Note : "+ cstr(d.delivery_note) +" is not submitted")
|
||||
raise Exception , "Validation Error."
|
||||
|
||||
#Set Actual Qty based on item code and warehouse
|
||||
#------------------------------------------------------
|
||||
def set_actual_qty(self):
|
||||
for d in getlist(self.doclist, 'delivery_note_details'):
|
||||
if d.item_code and d.warehouse:
|
||||
actual_qty = sql("select actual_qty from `tabBin` where item_code = '%s' and warehouse = '%s'" % (d.item_code, d.warehouse))
|
||||
d.actual_qty = actual_qty and flt(actual_qty[0][0]) or 0
|
||||
|
||||
# Check qty in stock depends on item code and warehouse
|
||||
#-------------------------------------------------------
|
||||
def check_qty_in_stock(self):
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
is_stock_item = sql("select is_stock_item from `tabItem` where name = '%s'" % d.item_code)[0][0]
|
||||
actual_qty = 0
|
||||
if d.item_code and d.warehouse:
|
||||
actual_qty = sql("select actual_qty from `tabBin` where item_code = '%s' and warehouse = '%s'" % (d.item_code, d.warehouse))
|
||||
actual_qty = actual_qty and flt(actual_qty[0][0]) or 0
|
||||
|
||||
if is_stock_item == 'Yes' and flt(d.qty) > flt(actual_qty):
|
||||
msgprint("For Item: " + cstr(d.item_code) + " at Warehouse: " + cstr(d.warehouse) + " Quantity: " + cstr(d.qty) +" is not Available. (Must be less than or equal to " + cstr(actual_qty) + " )")
|
||||
raise Exception, "Validation Error"
|
||||
|
||||
|
||||
|
||||
# ********************** Make Stock Entry ************************************
|
||||
def make_sl_entry(self, d, wh, qty, in_value, update_stock):
|
||||
st_uom = sql("select stock_uom from `tabItem` where name = '%s'"%d.item_code)
|
||||
self.values.append({
|
||||
'item_code' : d.item_code,
|
||||
'warehouse' : wh,
|
||||
'transaction_date' : self.doc.voucher_date,
|
||||
'posting_date' : self.doc.posting_date,
|
||||
'posting_time' : self.doc.posting_time,
|
||||
'voucher_type' : 'Receivable Voucher',
|
||||
'voucher_no' : cstr(self.doc.name),
|
||||
'voucher_detail_no' : cstr(d.name),
|
||||
'actual_qty' : qty,
|
||||
'stock_uom' : st_uom and st_uom[0][0] or '',
|
||||
'incoming_rate' : in_value,
|
||||
'company' : self.doc.company,
|
||||
'fiscal_year' : self.doc.fiscal_year,
|
||||
'is_cancelled' : (update_stock==1) and 'No' or 'Yes',
|
||||
'batch_no' : cstr(d.batch_no),
|
||||
'serial_no' : d.serial_no
|
||||
})
|
||||
|
||||
|
||||
# UPDATE STOCK LEDGER
|
||||
# ---------------------------------------------------------------------------
|
||||
def update_stock_ledger(self, update_stock, clear = 0):
|
||||
self.values = []
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
stock_item = sql("SELECT is_stock_item, is_sample_item FROM tabItem where name = '%s'"%(d.item_code), as_dict = 1) # stock ledger will be updated only if it is a stock item
|
||||
if stock_item[0]['is_stock_item'] == "Yes":
|
||||
# Reduce actual qty from warehouse
|
||||
self.make_sl_entry( d, d.warehouse, - flt(d.qty) , 0, update_stock)
|
||||
get_obj('Stock Ledger', 'Stock Ledger').update_stock(self.values)
|
||||
|
||||
|
||||
#-------------------POS Stock Updatation Part----------------------------------------------
|
||||
def pos_update_stock(self):
|
||||
self.check_qty_in_stock()
|
||||
self.update_stock_ledger(update_stock = 1)
|
||||
|
||||
# ********** Get Actual Qty of item in warehouse selected *************
|
||||
def get_actual_qty(self,args):
|
||||
args = eval(args)
|
||||
actual_qty = sql("select actual_qty from `tabBin` where item_code = '%s' and warehouse = '%s'" % (args['item_code'], args['warehouse']), as_dict=1)
|
||||
ret = {
|
||||
'actual_qty' : actual_qty and flt(actual_qty[0]['actual_qty']) or 0
|
||||
}
|
||||
return cstr(ret)
|
||||
|
||||
# Make GL Entries
|
||||
# -------------------------
|
||||
def make_gl_entries(self, is_cancel=0):
|
||||
mapper = self.doc.is_pos and self.doc.write_off_account and 'POS with write off' or self.doc.is_pos and not self.doc.write_off_account and 'POS' or ''
|
||||
update_outstanding = self.doc.is_pos and self.doc.write_off_account and 'No' or 'Yes'
|
||||
|
||||
get_obj(dt='GL Control').make_gl_entries(self.doc, self.doclist,cancel = is_cancel, use_mapper = mapper, update_outstanding = update_outstanding, merge_entries = cint(self.doc.is_pos) != 1 and 1 or 0)
|
||||
|
||||
|
||||
# On Submit
|
||||
# ---------
|
||||
def on_submit(self):
|
||||
if cint(self.doc.is_pos) == 1:
|
||||
if cint(self.doc.update_stock) == 1:
|
||||
sl_obj = get_obj("Stock Ledger")
|
||||
sl_obj.validate_serial_no_warehouse(self, 'entries')
|
||||
sl_obj.update_serial_record(self, 'entries', is_submit = 1, is_incoming = 0)
|
||||
self.pos_update_stock()
|
||||
else:
|
||||
self.check_prev_docstatus()
|
||||
get_obj("Sales Common").update_prevdoc_detail(1,self)
|
||||
|
||||
# Check for Approving Authority
|
||||
get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.company, self.doc.grand_total, self)
|
||||
|
||||
# this sequence because outstanding may get -ve
|
||||
self.make_gl_entries()
|
||||
|
||||
if not cint(self.doc.is_pos) == 1:
|
||||
self.update_against_document_in_jv(self.doc.name, self.doc.doctype)
|
||||
|
||||
# on submit notification
|
||||
# get_obj('Notification Control').notify_contact('Sales Invoice', self.doc.doctype,self.doc.name, self.doc.email_id, self.doc.contact_person)
|
||||
|
||||
|
||||
# *************************************************** ON CANCEL **********************************************
|
||||
# Check Next Document's docstatus
|
||||
# --------------------------------
|
||||
def check_next_docstatus(self):
|
||||
submit_jv = sql("select t1.name from `tabJournal Voucher` t1,`tabJournal Voucher Detail` t2 where t1.name = t2.parent and t2.against_invoice = '%s' and t1.docstatus = 1" % (self.doc.name))
|
||||
if submit_jv:
|
||||
msgprint("Journal Voucher : " + cstr(submit_jv[0][0]) + " has been created against " + cstr(self.doc.doctype) + ". So " + cstr(self.doc.doctype) + " cannot be Cancelled.")
|
||||
raise Exception, "Validation Error."
|
||||
|
||||
|
||||
# On Cancel
|
||||
# ----------
|
||||
def on_cancel(self):
|
||||
if cint(self.doc.is_pos) == 1:
|
||||
if cint(self.doc.update_stock) == 1:
|
||||
get_obj('Stock Ledger').update_serial_record(self, 'entries', is_submit = 0, is_incoming = 0)
|
||||
self.update_stock_ledger(update_stock = -1)
|
||||
else:
|
||||
sales_com_obj = get_obj(dt = 'Sales Common')
|
||||
sales_com_obj.check_stop_sales_order(self)
|
||||
self.check_next_docstatus()
|
||||
sales_com_obj.update_prevdoc_detail(0,self)
|
||||
|
||||
self.make_gl_entries(is_cancel=1)
|
||||
|
||||
# Get Warehouse
|
||||
def get_warehouse(self):
|
||||
w = sql("select warehouse from `tabPOS Setting` where ifnull(user,'') = '%s' and company = '%s'" % (session['user'], self.doc.company))
|
||||
if not w:
|
||||
ps = sql("select name, warehouse from `tabPOS Setting` where ifnull(user,'') = '' and company = '%s'" % self.doc.company)
|
||||
if not ps:
|
||||
msgprint("To make POS entry, please create POS Setting from Setup --> Accounts --> POS Setting and refresh the system.")
|
||||
raise Exception
|
||||
elif not ps[0][1]:
|
||||
msgprint("Please enter warehouse in POS Setting")
|
||||
else:
|
||||
w = ps[0][1]
|
||||
return w
|
||||
|
||||
# on update
|
||||
def on_update(self):
|
||||
# Set default warehouse from pos setting
|
||||
#----------------------------------------
|
||||
if cint(self.doc.is_pos) == 1:
|
||||
self.set_actual_qty()
|
||||
w = self.get_warehouse()
|
||||
if w:
|
||||
for d in getlist(self.doclist, 'entries'):
|
||||
if not d.warehouse:
|
||||
d.warehouse = cstr(w)
|
||||
|
||||
if flt(self.doc.paid_amount) == 0:
|
||||
set(self.doc,'paid_amount',(flt(self.doc.grand_total) - flt(self.doc.write_off_amount)))
|
||||
|
||||
else:
|
||||
set(self.doc,'paid_amount',0)
|
||||
|
||||
set(self.doc,'outstanding_amount',flt(self.doc.grand_total) - flt(self.doc.total_advance) - flt(self.doc.paid_amount) - flt(self.doc.write_off_amount))
|
||||
|
||||
|
||||
########################################################################
|
||||
# Repair Outstanding
|
||||
#######################################################################
|
||||
def repair_rv_outstanding(self):
|
||||
get_obj(dt = 'GL Control').repair_voucher_outstanding(self)
|
||||
3640
accounts/doctype/receivable_voucher/receivable_voucher.txt
Normal file
3640
accounts/doctype/receivable_voucher/receivable_voucher.txt
Normal file
File diff suppressed because it is too large
Load Diff
0
accounts/doctype/rv_detail/__init__.py
Normal file
0
accounts/doctype/rv_detail/__init__.py
Normal file
1035
accounts/doctype/rv_detail/rv_detail.txt
Normal file
1035
accounts/doctype/rv_detail/rv_detail.txt
Normal file
File diff suppressed because it is too large
Load Diff
0
accounts/doctype/rv_tax_detail/__init__.py
Normal file
0
accounts/doctype/rv_tax_detail/__init__.py
Normal file
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user