Validation added in c-form

This commit is contained in:
Nabin Hait 2011-12-12 14:16:16 +05:30
parent 7e44f9789b
commit 8a6b3b8713
3 changed files with 36 additions and 3 deletions

View File

@ -1,7 +1,7 @@
//c-form js file
// -----------------------------
cur_frm.fields_dict.invoice_details.grid.get_field("invoice_no").get_query = function(doc) {
return 'SELECT `tabReceivable Voucher`.`name` FROM `tabReceivable Voucher` WHERE `tabReceivable Voucher`.`company` = "' +doc.company+'" AND `tabReceivable Voucher`.%(key)s LIKE "%s" AND `tabReceivable Voucher`.`customer` = "' + doc.customer + '" AND `tabReceivable Voucher`.`docstatus` = 1 and `tabReceivable Voucher`.`c_form_applicable` = "Yes" ORDER BY `tabReceivable Voucher`.`name` ASC LIMIT 50';
return 'SELECT `tabReceivable Voucher`.`name` FROM `tabReceivable Voucher` WHERE `tabReceivable Voucher`.`company` = "' +doc.company+'" AND `tabReceivable Voucher`.%(key)s LIKE "%s" AND `tabReceivable Voucher`.`customer` = "' + doc.customer + '" AND `tabReceivable Voucher`.`docstatus` = 1 and `tabReceivable Voucher`.`c_form_applicable` = "Yes" and ifnull(`tabReceivable Voucher`.c_form_no, "") = "" ORDER BY `tabReceivable Voucher`.`name` ASC LIMIT 50';
}
cur_frm.cscript.invoice_no = function(doc, cdt, cdn) {

View File

@ -17,12 +17,23 @@ class DocType:
def autoname(self):
self.doc.name = make_autoname(self.doc.naming_series + '.#####')
def on_update(self):
inv = "'" + "', '".join([d.invoice_no for d in getlist(self.doclist, 'invoice_details')]) + "'"
sql("""update `tabReceivable Voucher` set c_form_no = '%s', modified ='%s'
""" Update C-Form No on invoices"""
if len(getlist(self.doclist, 'invoice_details')):
inv = "'" + "', '".join([d.invoice_no for d in getlist(self.doclist, 'invoice_details')]) + "'"
sql("""update `tabReceivable Voucher` set c_form_no = '%s', modified ='%s'
where name in (%s)"""%(self.doc.name, self.doc.modified, inv))
sql("""update `tabReceivable Voucher` set c_form_no = '', modified = %s where name not
in (%s) and ifnull(c_form_no, '') = %s""", (self.doc.modified, self.doc.name, inv))
else:
msgprint("Please enter atleast 1 invoice in the table below", raise_exception=1)
def get_invoice_details(self, invoice_no):
""" Pull details from invoices for referrence """
inv = sql("""select posting_date, territory, net_total, grand_total from
`tabReceivable Voucher` where name = %s""", invoice_no)
ret = {
@ -32,3 +43,19 @@ class DocType:
'grand_total' : inv and flt(inv[0][3]) or ''
}
return ret
def validate_invoice(self):
"""Validate invoice that c-form is applicable and no other c-form is
received for that"""
for d in getlist(self.doclist, 'invoice_details'):
inv = sql("""select c_form_applicable, c_form_no from
`tabReceivable Voucher` where name = %s""", invoice_no)
if not inv:
msgprint("Invoice: %s is not exists in the system, please check." % d.invoice_no, raise_exception=1)
elif inv[0][0] != 'Yes':
msgprint("C-form is not applicable for Invoice: %s" % d.invoice_no, raise_exception=1)
elif inv[0][1] and inv[0][1] != self.doc.name:
msgprint("""Invoice %s is tagged in another C-form: %s. \nIf you want to change C-form no for this invoice,
please remove invoice no from the previous c-form and then try again""" % (d.invoice_no, inv[0][1]), raise_exception=1)

View File

@ -67,6 +67,12 @@ cur_frm.cscript.hide_fields = function(doc, cdt, cdn) {
}
}
}
// India related fields
var cp = locals['Control Panel']['Control Panel'];
if (cp.country == 'India') unhide_field(['c_form_applicable', 'c_form_no']);
else hide_field(['c_form_applicable', 'c_form_no']);
}