diff --git a/erpnext/accounts/doctype/gl_control/gl_control.py b/erpnext/accounts/doctype/gl_control/gl_control.py index 2f84a9c7f4b..66a0d65b741 100644 --- a/erpnext/accounts/doctype/gl_control/gl_control.py +++ b/erpnext/accounts/doctype/gl_control/gl_control.py @@ -484,11 +484,13 @@ def manage_recurring_invoices(): Create recurring invoices on specific date by copying the original one and notify the concerned people """ - rv = webnotes.conn.sql("""select name, recurring_id from `tabSales Invoice` where ifnull(convert_into_recurring_invoice, 0) = 1 - and next_date = %s and next_date <= ifnull(end_date, '2199-12-31') and docstatus=1""", nowdate()) + rv = webnotes.conn.sql("""select name, recurring_id from `tabSales Invoice` \ + where ifnull(convert_into_recurring_invoice, 0) = 1 and next_date = %s \ + and next_date <= ifnull(end_date, '2199-12-31') and docstatus=1""", nowdate()) for d in rv: - if not webnotes.conn.sql("""select name from `tabSales Invoice` where posting_date = %s and recurring_id = %s and docstatus=1""", (nowdate(), d[1])): + if not webnotes.conn.sql("""select name from `tabSales Invoice` \ + where posting_date = %s and recurring_id = %s and docstatus=1""", (nowdate(), d[1])): prev_rv = get_obj('Sales Invoice', d[0], with_children=1) new_rv = create_new_invoice(prev_rv) @@ -499,13 +501,16 @@ def create_new_invoice(prev_rv): # clone rv new_rv = clone(prev_rv) + mdict = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12} + mcount = mdict[prev_rv.doc.recurring_type] + # update new rv new_rv.doc.posting_date = new_rv.doc.next_date new_rv.doc.aging_date = new_rv.doc.next_date new_rv.doc.due_date = add_days(new_rv.doc.next_date, cint(date_diff(prev_rv.doc.due_date, prev_rv.doc.posting_date))) - new_rv.doc.invoice_period_from_date = get_next_month_date(new_rv.doc.invoice_period_from_date) - new_rv.doc.invoice_period_to_date = get_next_month_date(new_rv.doc.invoice_period_to_date) + new_rv.doc.invoice_period_from_date = get_next_date(new_rv.doc.invoice_period_from_date, mcount) + new_rv.doc.invoice_period_to_date = get_next_date(new_rv.doc.invoice_period_to_date, mcount) new_rv.doc.owner = prev_rv.doc.owner new_rv.doc.save() @@ -515,13 +520,13 @@ def create_new_invoice(prev_rv): return new_rv -def get_next_month_date(dt): +def get_next_date(dt, mcount): import datetime - m = getdate(dt).month + 1 + m = getdate(dt).month + mcount y = getdate(dt).year d = getdate(dt).day if m > 12: - m, y = 1, y+1 + m, y = m-12, y+1 try: next_month_date = datetime.date(y, m, d) except: diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 7b62684db9a..f07c7b3ffc3 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -686,7 +686,9 @@ class DocType(TransactionBase): def convert_into_recurring(self): if self.doc.convert_into_recurring_invoice: - if not self.doc.invoice_period_from_date or not self.doc.invoice_period_to_date: + if not self.doc.recurring_type: + msgprint("Please select recurring type", raise_exception=1) + elif not self.doc.invoice_period_from_date or not self.doc.invoice_period_to_date: msgprint("Invoice period from date and to date is mandatory for recurring invoice", raise_exception=1) self.set_next_date() if not self.doc.recurring_id: @@ -702,10 +704,11 @@ class DocType(TransactionBase): will be generated e.g. 05, 28 etc.""", raise_exception=1) import datetime - m = getdate(self.doc.posting_date).month + 1 + mcount = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12} + m = getdate(self.doc.posting_date).month + mcount[self.doc.recurring_type] y = getdate(self.doc.posting_date).year if m > 12: - m, y = 1, y+1 + m, y = m-12, y+1 try: next_date = datetime.date(y, m, cint(self.doc.repeat_on_day_of_month)) except: diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt b/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt index d2439c81132..969a7dc6d73 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt @@ -3,9 +3,9 @@ # These values are common in all dictionaries { - 'creation': '2012-04-13 11:56:18', + 'creation': '2012-06-11 12:09:54', 'docstatus': 0, - 'modified': '2012-06-04 14:40:59', + 'modified': '2012-06-17 21:37:40', 'modified_by': u'Administrator', 'owner': u'Administrator' }, @@ -1480,6 +1480,21 @@ 'trigger': u'Client' }, + # DocField + { + 'allow_on_submit': 1, + 'depends_on': u'eval:doc.convert_into_recurring_invoice==1', + 'description': u'Select the period when the invoice will be generated automatically', + 'doctype': u'DocField', + 'fieldname': u'recurring_type', + 'fieldtype': u'Select', + 'label': u'Recurring Type', + 'no_copy': 1, + 'options': u'Monthly\nQuarterly\nHalf-yearly\nYearly', + 'permlevel': 0, + 'print_hide': 1 + }, + # DocField { 'allow_on_submit': 1, diff --git a/erpnext/accounts/search_criteria/purchase_register/purchase_register.py b/erpnext/accounts/search_criteria/purchase_register/purchase_register.py index 0601a62f4ca..bb58d77bbc0 100644 --- a/erpnext/accounts/search_criteria/purchase_register/purchase_register.py +++ b/erpnext/accounts/search_criteria/purchase_register/purchase_register.py @@ -15,6 +15,8 @@ # along with this program. If not, see . # add expense head columns +from webnotes.utils import flt, cint, cstr + expense_acc = [c[0] for c in sql("""select distinct expense_head from `tabPurchase Invoice Item` where parenttype='Purchase Invoice' @@ -39,7 +41,7 @@ tax_acc = [c[0] for c in sql("""select distinct account_head order by account_head asc""")] tax_acc.append('Total Tax') -tax_acc.append('GrandTotal') +tax_acc.append('Grand Total') for c in tax_acc: if c: @@ -58,56 +60,41 @@ for r in res: exp_head_amount = sql("""select expense_head, sum(amount) from `tabPurchase Invoice Item` where parent = %s and parenttype='Purchase Invoice' - group by expense_head""", (r[col_idx['ID']],)) + group by expense_head""", (r[col_idx['ID']])) #convert the result to dictionary for easy retrieval exp_head_amount_dict = {} for e in exp_head_amount: exp_head_amount_dict[e[0]] = e[1] - exp_head_keys = exp_head_amount_dict.keys() - - net_total = 0 - + net_total = 0 # get expense amount for i in expense_acc: - val = 0 - - #check if expense head exists in dict - if i in exp_head_keys: - val = exp_head_amount_dict[i] - val = flt(val and val or 0) + val = exp_head_amount_dict.get(i, 0) net_total += val - r.append(val) - + r.append(val) r.append(net_total) #Get tax for account heads - acc_head_tax = sql("""select account_head, tax_amount + acc_head_tax = sql("""select account_head, sum(tax_amount) from `tabPurchase Taxes and Charges` where parent = '%s' and parenttype = 'Purchase Invoice' and add_deduct_tax = 'Add' - and category in ('For Total', 'For Both')""" %(r[col_idx['ID']],)) + and category in ('For Total', 'For Both') + group by account_head + """ %(r[col_idx['ID']],)) #Convert the result to dictionary for easy retrieval acc_head_tax_dict = {} for a in acc_head_tax: - acc_head_tax_dict[a[0]] = a[1] + acc_head_tax_dict[a[0]] = flt(a[1]) - acc_head_keys = acc_head_tax_dict.keys() - # get tax amount total_tax = 0 - grand_total = 0 - for c in tax_acc: - val = 0 - if c: - #check if account head exists in dict - if c in acc_head_keys: - val = acc_head_tax_dict[c] - val = flt(val and val or 0) - total_tax += val - r.append(val) + for c in tax_acc: + val = acc_head_tax_dict.get(c, 0) + total_tax += val + r.append(val) r.append(total_tax) r.append(flt(total_tax)+ flt(net_total)) # grand total \ No newline at end of file diff --git a/erpnext/accounts/search_criteria/sales_register/sales_register.py b/erpnext/accounts/search_criteria/sales_register/sales_register.py index 9fdfb009619..c99948e3a71 100644 --- a/erpnext/accounts/search_criteria/sales_register/sales_register.py +++ b/erpnext/accounts/search_criteria/sales_register/sales_register.py @@ -15,6 +15,7 @@ # along with this program. If not, see . # add additional columns +from webnotes.utils import flt, cint, cstr cl = [c[0] for c in sql("""select distinct account_head from `tabSales Taxes and Charges` @@ -61,41 +62,30 @@ for r in res: #convert the result to dictionary for easy retrieval income_acc_dict = {} for ia in income_acc_list: - income_acc_dict[ia[0]] = ia[1] + income_acc_dict[ia[0]] = flt(ia[1]) - income_acc_keys = income_acc_dict.keys() - net_total = 0 for i in income_acc: - val = 0 - #check if income account exists in dict - if i in income_acc_keys: - val = income_acc_dict[i] - val = flt(val and val or 0) + val = income_acc_dict.get(i, 0) net_total += val r.append(val) r.append(net_total) #Get tax for account heads - acc_head_tax = sql("""select account_head, tax_amount + acc_head_tax = sql("""select account_head, sum(tax_amount) from `tabSales Taxes and Charges` where parent = '%s' - and parenttype = 'Sales Invoice'""" %(r[col_idx['ID']],)) + and parenttype = 'Sales Invoice' + group by account_head""" %(r[col_idx['ID']],)) #Convert the result to dictionary for easy retrieval acc_head_tax_dict = {} for a in acc_head_tax: - acc_head_tax_dict[a[0]] = a[1] - - acc_head_keys = acc_head_tax_dict.keys() + acc_head_tax_dict[a[0]] = flt(a[1]) total_tax = 0 for c in cl: - val = 0 - #check if account head exists in dict - if c in acc_head_keys: - val = acc_head_tax_dict[c] - val = flt(val and val or 0) + val = acc_head_tax_dict.get(c, 0) total_tax += val r.append(val) r.append(total_tax) diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py index 524e03d78ef..67a2aae44f1 100644 --- a/erpnext/buying/doctype/supplier/supplier.py +++ b/erpnext/buying/doctype/supplier/supplier.py @@ -108,7 +108,7 @@ class DocType: msgprint("Supplier Type is mandatory") raise Exception - if not sql("select name from tabAccount where name=%s", (self.doc.supplier_type + " - " + abbr)): + if not sql("select name from tabAccount where name=%s and debit_or_credit = 'Credit' and ifnull(is_pl_account, 'No') = 'No'", (self.doc.supplier_type + " - " + abbr)): # if not group created , create it self.add_account(self.doc.supplier_type, self.get_payables_group(), abbr) diff --git a/erpnext/patches/june_2012/set_recurring_type.py b/erpnext/patches/june_2012/set_recurring_type.py new file mode 100644 index 00000000000..bfb925c6b8e --- /dev/null +++ b/erpnext/patches/june_2012/set_recurring_type.py @@ -0,0 +1,6 @@ +def execute(): + import webnotes + from webnotes.model.sync import sync + sync('accounts', 'sales_invoice') + + webnotes.conn.sql("update `tabSales Invoice` set recurring_type = 'Monthly' where ifnull(convert_into_recurring_invoice, 0) = 1") \ No newline at end of file diff --git a/erpnext/patches/patch_list.py b/erpnext/patches/patch_list.py index 98c3aff772a..fd734a9a6c2 100644 --- a/erpnext/patches/patch_list.py +++ b/erpnext/patches/patch_list.py @@ -442,4 +442,9 @@ patch_list = [ 'patch_file': 'series_unique_patch', 'description': "add unique constraint to series table's name column" }, + { + 'patch_module': 'patches.june_2012', + 'patch_file': 'set_recurring_type', + 'description': "set recurring type as monthly in old" + }, ] \ No newline at end of file diff --git a/erpnext/selling/doctype/lead/lead.js b/erpnext/selling/doctype/lead/lead.js index 5d434495c01..389dce0db1b 100644 --- a/erpnext/selling/doctype/lead/lead.js +++ b/erpnext/selling/doctype/lead/lead.js @@ -45,15 +45,24 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) { cur_frm.cscript.make_communication_body(); } +cur_frm.cscript.refresh_custom_buttons = function() { + cur_frm.clear_custom_buttons(); + if(!doc.__islocal && !in_list(['Converted', 'Lead Lost'], doc.status)) { + if (doc.source != 'Existing Customer') { + cur_frm.add_custom_button('Create Customer', + cur_frm.cscript['Create Customer']); + } + cur_frm.add_custom_button('Create Opportunity', + cur_frm.cscript['Create Opportunity']); + cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms); + } +} + cur_frm.cscript.refresh = function(doc, cdt, cdn) { // custom buttons //--------------- - cur_frm.clear_custom_buttons() - if(!doc.__islocal && !in_list(['Converted', 'Lead Lost'], doc.status)) { - if (doc.source != 'Existing Customer') cur_frm.add_custom_button('Create Customer', cur_frm.cscript['Create Customer']); - cur_frm.add_custom_button('Create Opportunity', cur_frm.cscript['Create Opportunity']); - cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms); - } + cur_frm.cscript.refresh_custom_buttons(); + erpnext.hide_naming_series(); if (!doc.__islocal) cur_frm.cscript.render_communication_list(doc, cdt, cdn); diff --git a/erpnext/website/doctype/web_page/web_page.py b/erpnext/website/doctype/web_page/web_page.py index d4405b3a106..3f4a39c0a90 100644 --- a/erpnext/website/doctype/web_page/web_page.py +++ b/erpnext/website/doctype/web_page/web_page.py @@ -25,7 +25,7 @@ class DocType: """name from title""" self.doc.name = website.utils.page_name(self.doc.title) - def validate(self): + def on_update(self): """make page for this product""" from jinja2 import Template import os @@ -45,6 +45,9 @@ class DocType: self.doc.content = Template(f.read()).render(doc=self.doc) self.cleanup_temp() + + self.doc.save() + self.if_home_clear_cache() def cleanup_temp(self): diff --git a/public/js/all-app.js b/public/js/all-app.js index 859af21f92e..5e3f8f2db42 100644 --- a/public/js/all-app.js +++ b/public/js/all-app.js @@ -350,7 +350,8 @@ df.original_type=df.fieldtype;df.description='';df.reqd=0;if(fieldtype){df.field if(df.fieldtype=='Check'){df.fieldtype='Select';df.options='No\nYes';}else if(['Text','Text Editor','Code','Link'].indexOf(df.fieldtype)!=-1){df.fieldtype='Data';}},set_default_condition:function(df,fieldtype){if(!fieldtype){if(df.fieldtype=='Data'){this.$w.find('.condition').val('like');}else{this.$w.find('.condition').val('=');}}},get_value:function(){var me=this;var val=me.field.get_value();var cond=me.$w.find('.condition').val();if(me.field.df.original_type=='Check'){val=(val=='Yes'?1:0);} if(cond=='like'){val=val+'%';} return[me.fieldselect.$select.find('option:selected').attr('table'),me.field.df.fieldname,me.$w.find('.condition').val(),cstr(val)];}});wn.ui.FieldSelect=Class.extend({init:function(parent,doctype,filter_fields,with_blank){this.doctype=doctype;this.fields_by_name={};this.with_blank=with_blank;this.$select=$('