Validation added in c-form
diff --git a/erpnext/accounts/doctype/c_form/c_form.js b/erpnext/accounts/doctype/c_form/c_form.js
index 4a90a9d..6629de6 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 00016cb..7228f11 100644
--- a/erpnext/accounts/doctype/c_form/c_form.py
+++ b/erpnext/accounts/doctype/c_form/c_form.py
@@ -17,12 +17,23 @@
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 @@
'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 363da2e..12b57d9 100644
--- a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js
+++ b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js
@@ -67,6 +67,12 @@
}
}
}
+
+ // 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']);
+
}