|
|
|
|
@@ -23,7 +23,7 @@ from webnotes.model import db_exists
|
|
|
|
|
from webnotes.model.doc import Document, addchild, getchildren, make_autoname
|
|
|
|
|
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, msgprint, errprint
|
|
|
|
|
from webnotes import session, form, is_testing, msgprint, errprint
|
|
|
|
|
|
|
|
|
|
set = webnotes.conn.set
|
|
|
|
|
sql = webnotes.conn.sql
|
|
|
|
|
@@ -42,15 +42,9 @@ class DocType:
|
|
|
|
|
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']))
|
|
|
|
|
@@ -59,9 +53,6 @@ class DocType:
|
|
|
|
|
if args['doctype'] == 'Sales Invoice':
|
|
|
|
|
return {'credit': o_s and flt(o_s[0][0]) or 0}
|
|
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------------------------
|
|
|
|
|
# Create remarks
|
|
|
|
|
#--------------------------------------------------------------------------------------------------------
|
|
|
|
|
def create_remarks(self):
|
|
|
|
|
r = []
|
|
|
|
|
if self.doc.cheque_no :
|
|
|
|
|
@@ -90,9 +81,6 @@ class DocType:
|
|
|
|
|
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
|
|
|
|
|
@@ -107,17 +95,12 @@ class DocType:
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
@@ -128,10 +111,6 @@ class DocType:
|
|
|
|
|
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:
|
|
|
|
|
@@ -150,9 +129,6 @@ class DocType:
|
|
|
|
|
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:
|
|
|
|
|
@@ -167,9 +143,6 @@ class DocType:
|
|
|
|
|
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:
|
|
|
|
|
@@ -180,9 +153,6 @@ class DocType:
|
|
|
|
|
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:
|
|
|
|
|
@@ -190,9 +160,6 @@ class DocType:
|
|
|
|
|
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':
|
|
|
|
|
@@ -220,11 +187,6 @@ class DocType:
|
|
|
|
|
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")
|
|
|
|
|
@@ -236,10 +198,6 @@ class DocType:
|
|
|
|
|
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
|
|
|
|
|
@@ -247,9 +205,6 @@ class DocType:
|
|
|
|
|
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:
|
|
|
|
|
@@ -257,10 +212,6 @@ class DocType:
|
|
|
|
|
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")
|
|
|
|
|
@@ -295,9 +246,6 @@ class DocType:
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
@@ -323,9 +271,6 @@ class DocType:
|
|
|
|
|
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
|
|
|
|
|
@@ -345,9 +290,6 @@ class DocType:
|
|
|
|
|
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'):
|
|
|
|
|
#msgprint(self.doc.company)
|
|
|
|
|
@@ -363,10 +305,6 @@ class DocType:
|
|
|
|
|
self.doc.total_amount = dcc +' '+ cstr(amt)
|
|
|
|
|
self.doc.total_amount_in_words = get_obj('Sales Common').get_total_in_words(dcc, 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':
|
|
|
|
|
@@ -375,9 +313,6 @@ class DocType:
|
|
|
|
|
return sql("select name, credit_to, outstanding_amount from `tabPurchase Invoice` where docstatus = 1 and company = '%s' and outstanding_amount > 0 %s" % (self.doc.company, cond))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# -------------------------
|
|
|
|
|
# get outstanding invoices
|
|
|
|
|
# -------------------------
|
|
|
|
|
def get_outstanding_invoices(self):
|
|
|
|
|
self.doclist = self.doc.clear_table(self.doclist, 'entries')
|
|
|
|
|
total = 0
|
|
|
|
|
@@ -399,13 +334,10 @@ class DocType:
|
|
|
|
|
jd.credit = total
|
|
|
|
|
jd.save(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------------------------
|
|
|
|
|
# VALIDATE
|
|
|
|
|
#--------------------------------------------------------------------------------------------------------
|
|
|
|
|
def validate(self):
|
|
|
|
|
if not self.doc.is_opening:
|
|
|
|
|
self.doc.is_opening='No'
|
|
|
|
|
self.validate_debit_credit()
|
|
|
|
|
self.get_against_account()
|
|
|
|
|
self.validate_cheque_info()
|
|
|
|
|
self.create_remarks()
|
|
|
|
|
@@ -420,25 +352,24 @@ class DocType:
|
|
|
|
|
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')
|
|
|
|
|
get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year, \
|
|
|
|
|
self.doc.posting_date, 'Posting Date')
|
|
|
|
|
|
|
|
|
|
def validate_debit_credit(self):
|
|
|
|
|
for d in getlist(self.doclist, 'entries'):
|
|
|
|
|
if d.debit and d.credit:
|
|
|
|
|
msgprint("You cannot credit and debit same account at the same time.",
|
|
|
|
|
raise_exception=1)
|
|
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------------------------
|
|
|
|
|
# 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:
|
|
|
|
|
@@ -448,18 +379,13 @@ class DocType:
|
|
|
|
|
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
|
|
|
|
|
raise Exception
|