From 9bba9ed4d2119e1f3d4888a6c12c824f8f86f96d Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 4 Mar 2013 17:48:31 +0530 Subject: [PATCH] fixes in cform --- accounts/doctype/c_form/c_form.py | 21 +++++++++++++++------ patches/march_2013/p01_c_form.py | 6 ++++++ patches/patch_list.py | 1 + 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 patches/march_2013/p01_c_form.py diff --git a/accounts/doctype/c_form/c_form.py b/accounts/doctype/c_form/c_form.py index e574708a14..9f89ad5d07 100644 --- a/accounts/doctype/c_form/c_form.py +++ b/accounts/doctype/c_form/c_form.py @@ -34,11 +34,11 @@ class DocType: for d in getlist(self.doclist, 'invoice_details'): if d.invoice_no: inv = webnotes.conn.sql("""select c_form_applicable, c_form_no from - `tabSales Invoice` where name = %s""", d.invoice_no) + `tabSales Invoice` where name = %s and docstatus = 1""", d.invoice_no) if not inv: - webnotes.msgprint("Invoice: %s is not exists in the system, please check." % - d.invoice_no, raise_exception=1) + webnotes.msgprint("""Invoice: %s is not exists in the system or + is not submitted, please check.""" % d.invoice_no, raise_exception=1) elif inv[0][0] != 'Yes': webnotes.msgprint("C-form is not applicable for Invoice: %s" % @@ -52,21 +52,30 @@ class DocType: def on_update(self): """ Update C-Form No on invoices""" + self.set_total_invoiced_amount() + + def on_submit(self): + self.set_cform_in_sales_invoices() + + def before_cancel(self): + # remove cform reference + webnotes.conn.sql("""update `tabSales Invoice` set c_form_no=null + where c_form_no=%s""", self.doc.name) + + def set_cform_in_sales_invoices(self): inv = [d.invoice_no for d in getlist(self.doclist, 'invoice_details')] if inv: webnotes.conn.sql("""update `tabSales Invoice` set c_form_no=%s, modified=%s where name in (%s)""" % ('%s', '%s', ', '.join(['%s'] * len(inv))), tuple([self.doc.name, self.doc.modified] + inv)) - webnotes.conn.sql("""update `tabSales Invoice` set c_form_no = '', modified = %s + webnotes.conn.sql("""update `tabSales Invoice` set c_form_no = null, modified = %s where name not in (%s) and ifnull(c_form_no, '') = %s""" % ('%s', ', '.join(['%s']*len(inv)), '%s'), tuple([self.doc.modified] + inv + [self.doc.name])) else: webnotes.msgprint("Please enter atleast 1 invoice in the table", raise_exception=1) - self.set_total_invoiced_amount() - def set_total_invoiced_amount(self): total = sum([flt(d.grand_total) for d in getlist(self.doclist, 'invoice_details')]) webnotes.conn.set(self.doc, 'total_invoiced_amount', total) diff --git a/patches/march_2013/p01_c_form.py b/patches/march_2013/p01_c_form.py new file mode 100644 index 0000000000..5261d2bc16 --- /dev/null +++ b/patches/march_2013/p01_c_form.py @@ -0,0 +1,6 @@ +import webnotes + +def execute(): + for cform in webnotes.conn.sql("""select name from `tabC-Form` where docstatus=2"""): + webnotes.conn.sql("""update `tabSales Invoice` set c_form_no=null + where c_form_no=%s""", cform[0]) \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index 2bd4ad8f1f..dd7ff06e64 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -204,4 +204,5 @@ patch_list = [ "patches.march_2013.update_po_prevdoc_doctype", "patches.february_2013.p09_timesheets", "execute:(not webnotes.conn.exists('UOM', 'Hour')) and webnotes.doc({'uom_name': 'Hour', 'doctype': 'UOM', 'name': 'Hour'}).insert()", + "patches.march_2013.p01_c_form" ] \ No newline at end of file