mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 11:49:10 +00:00
Either debit or credit amount should be entered in journal voucher
This commit is contained in:
@@ -42,15 +42,9 @@ class DocType:
|
|||||||
self.credit_days_global = -1
|
self.credit_days_global = -1
|
||||||
self.is_approving_authority = -1
|
self.is_approving_authority = -1
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
# Autoname
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
def autoname(self):
|
def autoname(self):
|
||||||
self.doc.name = make_autoname(self.doc.naming_series+'.#####')
|
self.doc.name = make_autoname(self.doc.naming_series+'.#####')
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
# Fetch outstanding amount from RV/PV
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
def get_outstanding(self, args):
|
def get_outstanding(self, args):
|
||||||
args = eval(args)
|
args = eval(args)
|
||||||
o_s = sql("select outstanding_amount from `tab%s` where name = '%s'" % (args['doctype'],args['docname']))
|
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':
|
if args['doctype'] == 'Sales Invoice':
|
||||||
return {'credit': o_s and flt(o_s[0][0]) or 0}
|
return {'credit': o_s and flt(o_s[0][0]) or 0}
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
# Create remarks
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
def create_remarks(self):
|
def create_remarks(self):
|
||||||
r = []
|
r = []
|
||||||
if self.doc.cheque_no :
|
if self.doc.cheque_no :
|
||||||
@@ -90,9 +81,6 @@ class DocType:
|
|||||||
if r:
|
if r:
|
||||||
self.doc.remark = ("\n").join(r)
|
self.doc.remark = ("\n").join(r)
|
||||||
|
|
||||||
# --------------------------------------------------------------------------------------------------------
|
|
||||||
# Check user role for approval process
|
|
||||||
# --------------------------------------------------------------------------------------------------------
|
|
||||||
def get_authorized_user(self):
|
def get_authorized_user(self):
|
||||||
if self.is_approving_authority==-1:
|
if self.is_approving_authority==-1:
|
||||||
self.is_approving_authority = 0
|
self.is_approving_authority = 0
|
||||||
@@ -107,17 +95,12 @@ class DocType:
|
|||||||
|
|
||||||
return self.is_approving_authority
|
return self.is_approving_authority
|
||||||
|
|
||||||
# get master type
|
|
||||||
# ---------------
|
|
||||||
def get_master_type(self, ac):
|
def get_master_type(self, ac):
|
||||||
if not self.master_type.get(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'
|
self.master_type[ac] = sql("select master_type from `tabAccount` where name=%s", ac)[0][0] or 'None'
|
||||||
return self.master_type[ac]
|
return self.master_type[ac]
|
||||||
|
|
||||||
# get credit days for
|
|
||||||
# -------------------
|
|
||||||
def get_credit_days_for(self, ac):
|
def get_credit_days_for(self, ac):
|
||||||
|
|
||||||
if not self.credit_days_for.has_key(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
|
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:
|
else:
|
||||||
return self.credit_days_for[ac]
|
return self.credit_days_for[ac]
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------------------------------------------
|
|
||||||
# Check Credit Days - Cheque Date can not after (Posting date + Credit Days)
|
|
||||||
# --------------------------------------------------------------------------------------------------------
|
|
||||||
def check_credit_days(self):
|
def check_credit_days(self):
|
||||||
date_diff = 0
|
date_diff = 0
|
||||||
if self.doc.cheque_date:
|
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)
|
msgprint("Credit Not Allowed: Cannot allow a check that is dated more than %s days after the posting date" % credit_days)
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
# validation of debit/credit account with Debit To Account(RV) or Credit To Account (PV)
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
def check_account_against_entries(self):
|
def check_account_against_entries(self):
|
||||||
for d in getlist(self.doclist,'entries'):
|
for d in getlist(self.doclist,'entries'):
|
||||||
if d.against_invoice:
|
if d.against_invoice:
|
||||||
@@ -167,9 +143,6 @@ class DocType:
|
|||||||
msgprint("Credit account is not matching with payable voucher")
|
msgprint("Credit account is not matching with payable voucher")
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
# Validate Cheque Info: Mandatory for Bank/Contra voucher
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
def validate_cheque_info(self):
|
def validate_cheque_info(self):
|
||||||
if self.doc.voucher_type in ['Bank Voucher']:
|
if self.doc.voucher_type in ['Bank Voucher']:
|
||||||
if not self.doc.cheque_no or not self.doc.cheque_date:
|
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")
|
msgprint("Cheque No is mandatory if you entered Cheque Date")
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
# Gives reminder for making is_advance = 'Yes' in Advance Entry
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
def validate_entries_for_advance(self):
|
def validate_entries_for_advance(self):
|
||||||
for d in getlist(self.doclist,'entries'):
|
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:
|
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):
|
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)
|
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):
|
def get_tds_category_account(self):
|
||||||
for d in getlist(self.doclist,'entries'):
|
for d in getlist(self.doclist,'entries'):
|
||||||
if flt(d.debit) > 0 and not d.against_voucher and d.is_advance == 'Yes':
|
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)
|
msgprint("Please select TDS Applicable = 'Yes' in account head: '%s' if you want to deduct TDS." % self.doc.supplier_account)
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
# If TDS applicable , TDS category and supplier account should be mandatory
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
def validate_category_account(self, credit_account):
|
def validate_category_account(self, credit_account):
|
||||||
if not self.doc.tds_category:
|
if not self.doc.tds_category:
|
||||||
msgprint("Please select 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.")
|
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
|
raise Exception
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
# If TDS is not applicable , all related fields should blank
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
def set_fields_null(self):
|
def set_fields_null(self):
|
||||||
self.doc.ded_amount = 0
|
self.doc.ded_amount = 0
|
||||||
self.doc.rate = 0
|
self.doc.rate = 0
|
||||||
@@ -247,9 +205,6 @@ class DocType:
|
|||||||
self.doc.tds_category = ''
|
self.doc.tds_category = ''
|
||||||
self.doc.supplier_account = ''
|
self.doc.supplier_account = ''
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
# Get TDS amount
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
def get_tds(self):
|
def get_tds(self):
|
||||||
if cstr(self.doc.is_opening) != 'Yes':
|
if cstr(self.doc.is_opening) != 'Yes':
|
||||||
if self.doc.total_debit > 0:
|
if self.doc.total_debit > 0:
|
||||||
@@ -257,10 +212,6 @@ class DocType:
|
|||||||
if self.doc.supplier_account and self.doc.tds_category:
|
if self.doc.supplier_account and self.doc.tds_category:
|
||||||
get_obj('TDS Control').get_tds_amount(self)
|
get_obj('TDS Control').get_tds_amount(self)
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
# Insert new row to balance total debit and total credit
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
def get_balance(self):
|
def get_balance(self):
|
||||||
if not getlist(self.doclist,'entries'):
|
if not getlist(self.doclist,'entries'):
|
||||||
msgprint("Please enter atleast 1 entry in 'GL Entries' table")
|
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)
|
self.doc.difference = flt(self.doc.total_debit) - flt(self.doc.total_credit)
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
# Set against account
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
def get_against_account(self):
|
def get_against_account(self):
|
||||||
# Debit = Credit
|
# Debit = Credit
|
||||||
debit, credit = 0.0, 0.0
|
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.debit) > 0: d.against_account = ', '.join(credit_list)
|
||||||
if flt(d.credit) > 0: d.against_account = ', '.join(debit_list)
|
if flt(d.credit) > 0: d.against_account = ', '.join(debit_list)
|
||||||
|
|
||||||
|
|
||||||
# set aging date
|
|
||||||
#---------------
|
|
||||||
def set_aging_date(self):
|
def set_aging_date(self):
|
||||||
if self.doc.is_opening != 'Yes':
|
if self.doc.is_opening != 'Yes':
|
||||||
self.doc.aging_date = self.doc.posting_date
|
self.doc.aging_date = self.doc.posting_date
|
||||||
@@ -345,9 +290,6 @@ class DocType:
|
|||||||
else:
|
else:
|
||||||
self.doc.aging_date = self.doc.posting_date
|
self.doc.aging_date = self.doc.posting_date
|
||||||
|
|
||||||
# ------------------------
|
|
||||||
# set print format fields
|
|
||||||
# ------------------------
|
|
||||||
def set_print_format_fields(self):
|
def set_print_format_fields(self):
|
||||||
for d in getlist(self.doclist, 'entries'):
|
for d in getlist(self.doclist, 'entries'):
|
||||||
#msgprint(self.doc.company)
|
#msgprint(self.doc.company)
|
||||||
@@ -363,10 +305,6 @@ class DocType:
|
|||||||
self.doc.total_amount = dcc +' '+ cstr(amt)
|
self.doc.total_amount = dcc +' '+ cstr(amt)
|
||||||
self.doc.total_amount_in_words = get_obj('Sales Common').get_total_in_words(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):
|
def get_values(self):
|
||||||
cond = (flt(self.doc.write_off_amount) > 0) and ' and outstanding_amount <= '+self.doc.write_off_amount or ''
|
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':
|
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))
|
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):
|
def get_outstanding_invoices(self):
|
||||||
self.doclist = self.doc.clear_table(self.doclist, 'entries')
|
self.doclist = self.doc.clear_table(self.doclist, 'entries')
|
||||||
total = 0
|
total = 0
|
||||||
@@ -399,13 +334,10 @@ class DocType:
|
|||||||
jd.credit = total
|
jd.credit = total
|
||||||
jd.save(1)
|
jd.save(1)
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
# VALIDATE
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
if not self.doc.is_opening:
|
if not self.doc.is_opening:
|
||||||
self.doc.is_opening='No'
|
self.doc.is_opening='No'
|
||||||
|
self.validate_debit_credit()
|
||||||
self.get_against_account()
|
self.get_against_account()
|
||||||
self.validate_cheque_info()
|
self.validate_cheque_info()
|
||||||
self.create_remarks()
|
self.create_remarks()
|
||||||
@@ -420,25 +352,24 @@ class DocType:
|
|||||||
self.set_print_format_fields()
|
self.set_print_format_fields()
|
||||||
|
|
||||||
#FY and Date validation
|
#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):
|
def on_update(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
# On submit
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
if self.doc.voucher_type in ['Bank Voucher', 'Contra Voucher', 'Journal Entry']:
|
if self.doc.voucher_type in ['Bank Voucher', 'Contra Voucher', 'Journal Entry']:
|
||||||
self.check_credit_days()
|
self.check_credit_days()
|
||||||
self.check_account_against_entries()
|
self.check_account_against_entries()
|
||||||
get_obj(dt='GL Control').make_gl_entries(self.doc, self.doclist)
|
get_obj(dt='GL Control').make_gl_entries(self.doc, self.doclist)
|
||||||
|
|
||||||
|
|
||||||
# validate against jv no
|
|
||||||
def validate_against_jv(self):
|
def validate_against_jv(self):
|
||||||
for d in getlist(self.doclist, 'entries'):
|
for d in getlist(self.doclist, 'entries'):
|
||||||
if d.against_jv:
|
if d.against_jv:
|
||||||
@@ -449,15 +380,10 @@ class DocType:
|
|||||||
msgprint("Against JV: "+ d.against_jv + " is not valid. Please check")
|
msgprint("Against JV: "+ d.against_jv + " is not valid. Please check")
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
# On cancel reverse gl entry
|
|
||||||
#--------------------------------------------------------------------------------------------------------
|
|
||||||
def on_cancel(self):
|
def on_cancel(self):
|
||||||
self.check_tds_payment_voucher()
|
self.check_tds_payment_voucher()
|
||||||
get_obj(dt='GL Control').make_gl_entries(self.doc, self.doclist, cancel=1)
|
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):
|
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%'")
|
tdsp = sql("select parent from `tabTDS Payment Detail` where voucher_no = '%s' and docstatus = 1 and parent not like 'old%'")
|
||||||
if tdsp:
|
if tdsp:
|
||||||
|
|||||||
Reference in New Issue
Block a user