From 8a6b3b871379376764e64722ba100f895319f880 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 12 Dec 2011 14:16:16 +0530 Subject: [PATCH] Validation added in c-form --- erpnext/accounts/doctype/c_form/c_form.js | 2 +- erpnext/accounts/doctype/c_form/c_form.py | 31 +++++++++++++++++-- .../receivable_voucher/receivable_voucher.js | 6 ++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/c_form/c_form.js b/erpnext/accounts/doctype/c_form/c_form.js index 4a90a9d1d6..6629de6f3b 100644 --- a/erpnext/accounts/doctype/c_form/c_form.js +++ b/erpnext/accounts/doctype/c_form/c_form.js @@ -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) { diff --git a/erpnext/accounts/doctype/c_form/c_form.py b/erpnext/accounts/doctype/c_form/c_form.py index 00016cb053..7228f11a4f 100644 --- a/erpnext/accounts/doctype/c_form/c_form.py +++ b/erpnext/accounts/doctype/c_form/c_form.py @@ -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) diff --git a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js index 363da2ec57..12b57d9454 100644 --- a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js +++ b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js @@ -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']); + }