From 064d2ba16a8b012e1c0fdf55d1f7c2d0952d1c88 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Mon, 30 Dec 2013 19:36:58 +0530 Subject: [PATCH 01/23] fixed sr no in maintenance schedule --- .../maintenance_schedule.js | 118 +++++++------ .../maintenance_schedule.py | 156 ++++++++---------- .../maintenance_schedule_detail.txt | 4 +- 3 files changed, 136 insertions(+), 142 deletions(-) diff --git a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.js b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.js index 75773e07ac..bcb1bf33b6 100644 --- a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.js +++ b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.js @@ -5,107 +5,115 @@ wn.provide("erpnext.support"); // TODO commonify this code erpnext.support.MaintenanceSchedule = wn.ui.form.Controller.extend({ refresh: function() { - if (this.frm.doc.docstatus===0) { - cur_frm.add_custom_button(wn._('From Sales Order'), + if (this.frm.doc.docstatus === 0) { + this.frm.add_custom_button(wn._('From Sales Order'), function() { wn.model.map_current_doc({ method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_schedule", source_doctype: "Sales Order", get_query_filters: { docstatus: 1, - order_type: cur_frm.doc.order_type, - customer: cur_frm.doc.customer || undefined, - company: cur_frm.doc.company + order_type: me.frm.doc.order_type, + customer: me.frm.doc.customer || undefined, + company: me.frm.doc.company } - }) + }); }); - } else if (this.frm.doc.docstatus===1) { - cur_frm.add_custom_button(wn._("Make Maintenance Visit"), function() { + } else if (this.frm.doc.docstatus === 1) { + this.frm.add_custom_button(wn._("Make Maintenance Visit"), function() { wn.model.open_mapped_doc({ method: "erpnext.support.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit", source_name: cur_frm.doc.name }) - }) + }); } }, customer: function() { var me = this; if(this.frm.doc.customer) { return this.frm.call({ - doc: this.frm.doc, + doc: me.frm.doc, method: "set_customer_defaults", }); - } - }, + } + }, }); $.extend(cur_frm.cscript, new erpnext.support.MaintenanceSchedule({frm: cur_frm})); cur_frm.cscript.onload = function(doc, dt, dn) { - if(!doc.status) set_multiple(dt,dn,{status:'Draft'}); - - if(doc.__islocal){ - set_multiple(dt,dn,{transaction_date:get_today()}); - hide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']); - } + if(!doc.status) + set_multiple(dt, dn, { status:'Draft' }); + + if (doc.__islocal) { + set_multiple(dt, dn, { transaction_date:get_today() }); + hide_field(['customer_address', 'contact_person', 'customer_name', 'address_display', + 'contact_display', 'contact_mobile', 'contact_email', 'territory', 'customer_group']); + } } -cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) { - if(doc.customer) return get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1); +cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc, dt, dn) { + if (doc.customer) { + return get_server_fields('get_customer_address', + JSON.stringify({customer: doc.customer, address: doc.customer_address, + contact: doc.contact_person}), '', doc, dt, dn, 1); + } } cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { - return{ - filters:{ 'customer': doc.customer} - } + return { + filters:{ 'customer': doc.customer } + } } cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) { - return{ - filters:{ 'customer': doc.customer} - } + return { + filters:{ 'customer': doc.customer } + } } // cur_frm.fields_dict['item_maintenance_detail'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) { - return{ - filters:{ 'is_service_item': "Yes"} - } + return { + filters:{ 'is_service_item': "Yes" } + } } cur_frm.cscript.item_code = function(doc, cdt, cdn) { - var fname = cur_frm.cscript.fname; - var d = locals[cdt][cdn]; - if (d.item_code) { - return get_server_fields('get_item_details',d.item_code, 'item_maintenance_detail',doc,cdt,cdn,1); - } + var fname = cur_frm.cscript.fname; + var d = locals[cdt][cdn]; + if (d.item_code) { + return get_server_fields('get_item_details', d.item_code, 'item_maintenance_detail', + doc, cdt, cdn, 1); + } } cur_frm.cscript.periodicity = function(doc, cdt, cdn){ - var d = locals[cdt][cdn]; - if(d.start_date && d.end_date){ - arg = {} - arg.start_date = d.start_date; - arg.end_date = d.end_date; - arg.periodicity = d.periodicity; - return get_server_fields('get_no_of_visits',docstring(arg),'item_maintenance_detail',doc, cdt, cdn, 1); - } - else{ - msgprint(wn._("Please enter Start Date and End Date")); - } + var d = locals[cdt][cdn]; + if(d.start_date && d.end_date) { + arg = {} + arg.start_date = d.start_date; + arg.end_date = d.end_date; + arg.periodicity = d.periodicity; + return get_server_fields('get_no_of_visits', docstring(arg), + 'item_maintenance_detail', doc, cdt, cdn, 1); + } else { + msgprint(wn._("Please enter Start Date and End Date")); + } } cur_frm.cscript.generate_schedule = function(doc, cdt, cdn) { - if (!doc.__islocal) { - return $c('runserverobj', args={'method':'generate_schedule', 'docs':wn.model.compress(make_doclist(cdt,cdn))}, - function(r,rt){ - refresh_field('maintenance_schedule_detail'); - } - ); - } else { - alert(wn._("Please save the document before generating maintenance schedule")); - } + if (!doc.__islocal) { + return $c('runserverobj', args={'method':'generate_schedule', + 'docs':wn.model.compress(make_doclist(cdt,cdn))}, + function(r, rt) { + refresh_field('maintenance_schedule_detail'); + }); + } else { + msgprint(wn._("Please save the document before generating maintenance schedule")); + } } cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { - return{ query: "erpnext.controllers.queries.customer_query" } } + return { query: "erpnext.controllers.queries.customer_query" } +} diff --git a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py index 8263b19667..270f954922 100644 --- a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py +++ b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py @@ -7,10 +7,7 @@ import webnotes from webnotes.utils import add_days, cstr, getdate from webnotes.model.doc import addchild from webnotes.model.bean import getlist -from webnotes import msgprint - - - +from webnotes import msgprint, throw, _ from erpnext.utilities.transaction_base import TransactionBase, delete_events class DocType(TransactionBase): @@ -19,7 +16,8 @@ class DocType(TransactionBase): self.doclist = doclist def get_item_details(self, item_code): - item = webnotes.conn.sql("select item_name, description from `tabItem` where name = '%s'" %(item_code), as_dict=1) + item = webnotes.conn.sql("""select item_name, description from `tabItem` + where name=%s""", (item_code), as_dict=1) ret = { 'item_name': item and item[0]['item_name'] or '', 'description' : item and item[0]['description'] or '' @@ -28,13 +26,14 @@ class DocType(TransactionBase): def generate_schedule(self): self.doclist = self.doc.clear_table(self.doclist, 'maintenance_schedule_detail') - count = 0 - webnotes.conn.sql("delete from `tabMaintenance Schedule Detail` where parent='%s'" %(self.doc.name)) + webnotes.conn.sql("""delete from `tabMaintenance Schedule Detail` + where parent=%s""", (self.doc.name)) for d in getlist(self.doclist, 'item_maintenance_detail'): self.validate_maintenance_detail() - s_list =[] + count = 1 + s_list = [] s_list = self.create_schedule_list(d.start_date, d.end_date, d.no_of_visits) - for i in range(d.no_of_visits): + for i in range(d.no_of_visits): child = addchild(self.doc, 'maintenance_schedule_detail', 'Maintenance Schedule Detail', self.doclist) child.item_code = d.item_code @@ -43,7 +42,7 @@ class DocType(TransactionBase): if d.serial_no: child.serial_no = d.serial_no child.idx = count - count = count+1 + count = count + 1 child.incharge_name = d.incharge_name child.save(1) @@ -51,8 +50,7 @@ class DocType(TransactionBase): def on_submit(self): if not getlist(self.doclist, 'maintenance_schedule_detail'): - msgprint("Please click on 'Generate Schedule' to get schedule") - raise Exception + throw("Please click on 'Generate Schedule' to get schedule") self.check_serial_no_added() self.validate_serial_no_warranty() self.validate_schedule() @@ -66,9 +64,9 @@ class DocType(TransactionBase): email_map[d.incharge_name] = webnotes.bean("Sales Person", d.incharge_name).run_method("get_email_id") - scheduled_date =webnotes.conn.sql("select scheduled_date from `tabMaintenance Schedule Detail` \ - where incharge_name='%s' and item_code='%s' and parent='%s' " %(d.incharge_name, \ - d.item_code, self.doc.name), as_dict=1) + scheduled_date =webnotes.conn.sql("""select scheduled_date from + `tabMaintenance Schedule Detail` where incharge_name=%s and item_code=%s and + parent=%s""", (d.incharge_name, d.item_code, self.doc.name), as_dict=1) for key in scheduled_date: if email_map[d.incharge_name]: @@ -91,90 +89,80 @@ class DocType(TransactionBase): #---------------------- def create_schedule_list(self, start_date, end_date, no_of_visit): schedule_list = [] - start_date1 = start_date + start_date_copy = start_date date_diff = (getdate(end_date) - getdate(start_date)).days - add_by = date_diff/no_of_visit - #schedule_list.append(start_date1) - while(getdate(start_date1) < getdate(end_date)): - start_date1 = add_days(start_date1, add_by) + add_by = date_diff / no_of_visit + + while (getdate(start_date_copy) < getdate(end_date)): + start_date_copy = add_days(start_date_copy, add_by) if len(schedule_list) < no_of_visit: - schedule_list.append(getdate(start_date1)) + schedule_list.append(getdate(start_date_copy)) return schedule_list #validate date range and periodicity selected #------------------------------------------------- def validate_period(self, arg): - arg1 = eval(arg) - if getdate(arg1['start_date']) >= getdate(arg1['end_date']): - msgprint("Start date should be less than end date ") - raise Exception - - period = (getdate(arg1['end_date'])-getdate(arg1['start_date'])).days+1 - - if (arg1['periodicity']=='Yearly' or arg1['periodicity']=='Half Yearly' or arg1['periodicity']=='Quarterly') and period<365: - msgprint(cstr(arg1['periodicity'])+ " periodicity can be set for period of atleast 1 year or more only") - raise Exception - elif arg1['periodicity']=='Monthly' and period<30: - msgprint("Monthly periodicity can be set for period of atleast 1 month or more") - raise Exception - elif arg1['periodicity']=='Weekly' and period<7: - msgprint("Weekly periodicity can be set for period of atleast 1 week or more") - raise Exception + args = eval(arg) + if getdate(args['start_date']) >= getdate(args['end_date']): + throw(_("Start date should be less than end date.")) + + period = (getdate(args['end_date']) - getdate(args['start_date'])).days + 1 + + if (args['periodicity'] == 'Yearly' or args['periodicity'] == 'Half Yearly' or + args['periodicity'] == 'Quarterly') and period < 365: + throw(cstr(args['periodicity']) + " periodicity can be set for period of atleast 1 year or more only") + elif args['periodicity'] == 'Monthly' and period < 30: + throw("Monthly periodicity can be set for period of atleast 1 month or more") + elif args['periodicity'] == 'Weekly' and period < 7: + throw("Weekly periodicity can be set for period of atleast 1 week or more") def get_no_of_visits(self, arg): - arg1 = eval(arg) + args = eval(arg) self.validate_period(arg) - period = (getdate(arg1['end_date'])-getdate(arg1['start_date'])).days+1 - - count =0 - if arg1['periodicity'] == 'Weekly': + period = (getdate(args['end_date']) - getdate(args['start_date'])).days + 1 + count = 0 + + if args['periodicity'] == 'Weekly': count = period/7 - elif arg1['periodicity'] == 'Monthly': + elif args['periodicity'] == 'Monthly': count = period/30 - elif arg1['periodicity'] == 'Quarterly': + elif args['periodicity'] == 'Quarterly': count = period/91 - elif arg1['periodicity'] == 'Half Yearly': + elif args['periodicity'] == 'Half Yearly': count = period/182 - elif arg1['periodicity'] == 'Yearly': + elif args['periodicity'] == 'Yearly': count = period/365 - ret = {'no_of_visits':count} + ret = {'no_of_visits' : count} return ret - - def validate_maintenance_detail(self): if not getlist(self.doclist, 'item_maintenance_detail'): - msgprint("Please enter Maintaince Details first") - raise Exception + throw(_("Please enter Maintaince Details first")) for d in getlist(self.doclist, 'item_maintenance_detail'): if not d.item_code: - msgprint("Please select item code") - raise Exception + throw(_("Please select item code")) elif not d.start_date or not d.end_date: - msgprint("Please select Start Date and End Date for item "+d.item_code) - raise Exception + throw(_("Please select Start Date and End Date for item") + " " + d.item_code) elif not d.no_of_visits: - msgprint("Please mention no of visits required") - raise Exception + throw(_("Please mention no of visits required")) elif not d.incharge_name: - msgprint("Please select Incharge Person's name") - raise Exception + throw(_("Please select Incharge Person's name")) if getdate(d.start_date) >= getdate(d.end_date): - msgprint("Start date should be less than end date for item "+d.item_code) - raise Exception + throw(_("Start date should be less than end date for item") + " " + d.item_code) #check if maintenance schedule already created against same sales order #----------------------------------------------------------------------------------- def validate_sales_order(self): for d in getlist(self.doclist, 'item_maintenance_detail'): if d.prevdoc_docname: - chk = webnotes.conn.sql("select t1.name from `tabMaintenance Schedule` t1, `tabMaintenance Schedule Item` t2 where t2.parent=t1.name and t2.prevdoc_docname=%s and t1.docstatus=1", d.prevdoc_docname) + chk = webnotes.conn.sql("""select ms.name from `tabMaintenance Schedule` ms, + `tabMaintenance Schedule Item` msi where msi.parent=ms.name and + msi.prevdoc_docname=%s and ms.docstatus=1""", d.prevdoc_docname) if chk: - msgprint("Maintenance Schedule against "+d.prevdoc_docname+" already exist") - raise Exception + throw("Maintenance Schedule against " + d.prevdoc_docname + " already exist") def validate_serial_no(self): @@ -185,13 +173,13 @@ class DocType(TransactionBase): cur_s_no = cur_serial_no.split(',') for x in cur_s_no: - chk = webnotes.conn.sql("select name, status from `tabSerial No` where docstatus!=2 and name=%s", (x)) + chk = webnotes.conn.sql("""select name, status from `tabSerial No` + where docstatus!=2 and name=%s""", (x)) chk1 = chk and chk[0][0] or '' status = chk and chk[0][1] or '' if not chk1: - msgprint("Serial no "+x+" does not exist in system.") - raise Exception + throw("Serial no " + x + " does not exist in system.") def validate(self): self.validate_maintenance_detail() @@ -208,13 +196,13 @@ class DocType(TransactionBase): cur_s_no = cur_serial_no.split(',') for x in cur_s_no: - dt = webnotes.conn.sql("select delivery_date from `tabSerial No` where name = %s", x) + dt = webnotes.conn.sql("""select delivery_date from `tabSerial No` + where name=%s""", x) dt = dt and dt[0][0] or '' if dt: if dt > getdate(d.start_date): - msgprint("Maintenance start date can not be before delivery date "+dt.strftime('%Y-%m-%d')+" for serial no "+x) - raise Exception + throw("Maintenance start date can not be before delivery date " + dt.strftime('%Y-%m-%d') + " for serial no " + x) #update amc expiry date in serial no #------------------------------------------ @@ -224,7 +212,8 @@ class DocType(TransactionBase): cur_s_no = cur_serial_no.split(',') for x in cur_s_no: - webnotes.conn.sql("update `tabSerial No` set amc_expiry_date = '%s', maintenance_status = 'Under AMC' where name = '%s'"% (amc_end_date,x)) + webnotes.conn.sql("""update `tabSerial No` set amc_expiry_date=%s, + maintenance_status='Under AMC' where name=%s""", (amc_end_date, x)) def on_update(self): webnotes.conn.set(self.doc, 'status', 'Draft') @@ -233,16 +222,16 @@ class DocType(TransactionBase): for d in getlist(self.doclist, 'item_maintenance_detail'): if cstr(d.serial_no).strip(): dt = webnotes.conn.sql("""select warranty_expiry_date, amc_expiry_date - from `tabSerial No` where name = %s""", d.serial_no, as_dict=1) + from `tabSerial No` where name=%s""", d.serial_no, as_dict=1) if dt[0]['warranty_expiry_date'] and dt[0]['warranty_expiry_date'] >= d.start_date: - webnotes.msgprint("""Serial No: %s is already under warranty upto %s. + throw("""Serial No: %s is already under warranty upto %s. Please check AMC Start Date.""" % - (d.serial_no, dt[0]["warranty_expiry_date"]), raise_exception=1) + (d.serial_no, dt[0]["warranty_expiry_date"])) if dt[0]['amc_expiry_date'] and dt[0]['amc_expiry_date'] >= d.start_date: - webnotes.msgprint("""Serial No: %s is already under AMC upto %s. + throw("""Serial No: %s is already under AMC upto %s. Please check AMC Start Date.""" % - (d.serial_no, dt[0]["amc_expiry_date"]), raise_exception=1) + (d.serial_no, dt[0]["amc_expiry_date"])) def validate_schedule(self): item_lst1 =[] @@ -256,13 +245,11 @@ class DocType(TransactionBase): item_lst2.append(m.item_code) if len(item_lst1) != len(item_lst2): - msgprint("Maintenance Schedule is not generated for all the items. Please click on 'Generate Schedule'") - raise Exception + throw("Maintenance Schedule is not generated for all the items. Please click on 'Generate Schedule'") else: for x in item_lst1: if x not in item_lst2: - msgprint("Maintenance Schedule is not generated for item "+x+". Please click on 'Generate Schedule'") - raise Exception + throw("Maintenance Schedule is not generated for item "+x+". Please click on 'Generate Schedule'") #check if serial no present in item maintenance table #----------------------------------------------------------- @@ -275,18 +262,15 @@ class DocType(TransactionBase): for m in getlist(self.doclist, 'maintenance_schedule_detail'): if serial_present: if m.item_code in serial_present and not m.serial_no: - msgprint("Please click on 'Generate Schedule' to fetch serial no added for item "+m.item_code) - raise Exception - - - + throw("Please click on 'Generate Schedule' to fetch serial no added for item "+m.item_code) + def on_cancel(self): for d in getlist(self.doclist, 'item_maintenance_detail'): if d.serial_no: self.update_amc_date(d.serial_no, '') webnotes.conn.set(self.doc, 'status', 'Cancelled') delete_events(self.doc.doctype, self.doc.name) - + def on_trash(self): delete_events(self.doc.doctype, self.doc.name) diff --git a/erpnext/support/doctype/maintenance_schedule_detail/maintenance_schedule_detail.txt b/erpnext/support/doctype/maintenance_schedule_detail/maintenance_schedule_detail.txt index 8b52d8b671..7a79d8d659 100644 --- a/erpnext/support/doctype/maintenance_schedule_detail/maintenance_schedule_detail.txt +++ b/erpnext/support/doctype/maintenance_schedule_detail/maintenance_schedule_detail.txt @@ -2,7 +2,7 @@ { "creation": "2013-02-22 01:28:05", "docstatus": 0, - "modified": "2013-12-20 19:23:20", + "modified": "2013-12-30 19:32:30", "modified_by": "Administrator", "owner": "Administrator" }, @@ -52,6 +52,7 @@ "search_index": 0 }, { + "allow_on_submit": 1, "doctype": "DocField", "fieldname": "scheduled_date", "fieldtype": "Date", @@ -78,6 +79,7 @@ "report_hide": 1 }, { + "allow_on_submit": 1, "doctype": "DocField", "fieldname": "incharge_name", "fieldtype": "Link", From 5c96b75a68a13b346e67e7ed8181c80693672c54 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Tue, 31 Dec 2013 17:45:20 +0530 Subject: [PATCH 02/23] fixed maintenance schedule --- erpnext/hr/doctype/employee/employee.js | 10 +- .../hr/doctype/holiday_list/holiday_list.py | 12 +- erpnext/patches.txt | 3 +- ...to_sales_person_in_maintenance_schedule.py | 9 + erpnext/selling/doctype/lead/lead.js | 8 +- .../authorization_rule/authorization_rule.js | 175 +++++++++--------- .../doctype/sales_person/sales_person.js | 18 +- .../doctype/sales_person/sales_person.py | 7 +- .../maintenance_schedule.js | 6 +- .../maintenance_schedule.py | 52 ++++-- .../maintenance_schedule_detail.txt | 10 +- .../maintenance_schedule_item.txt | 6 +- .../maintenance_schedules.txt | 4 +- 13 files changed, 170 insertions(+), 150 deletions(-) create mode 100644 erpnext/patches/4_0/update_incharge_name_to_sales_person_in_maintenance_schedule.py diff --git a/erpnext/hr/doctype/employee/employee.js b/erpnext/hr/doctype/employee/employee.js index 23d50670fb..7ee88f7068 100644 --- a/erpnext/hr/doctype/employee/employee.js +++ b/erpnext/hr/doctype/employee/employee.js @@ -4,10 +4,10 @@ wn.provide("erpnext.hr"); erpnext.hr.EmployeeController = wn.ui.form.Controller.extend({ setup: function() { - this.frm.fields_dict.user_id.get_query = function(doc,cdt,cdn) { - return { query:"webnotes.core.doctype.profile.profile.profile_query"} } - this.frm.fields_dict.reports_to.get_query = function(doc,cdt,cdn) { - return{ query: "erpnext.controllers.queries.employee_query"} } + this.frm.fields_dict.user_id.get_query = function(doc, cdt, cdn) { + return { query:"webnotes.core.doctype.profile.profile.profile_query"} } + this.frm.fields_dict.reports_to.get_query = function(doc, cdt, cdn) { + return { query: "erpnext.controllers.queries.employee_query"} } }, onload: function() { @@ -93,4 +93,4 @@ erpnext.hr.EmployeeController = wn.ui.form.Controller.extend({ }); }, }); -cur_frm.cscript = new erpnext.hr.EmployeeController({frm: cur_frm}); \ No newline at end of file +cur_frm.cscript = new erpnext.hr.EmployeeController({frm: cur_frm}); diff --git a/erpnext/hr/doctype/holiday_list/holiday_list.py b/erpnext/hr/doctype/holiday_list/holiday_list.py index 1045077e77..9f28e4c6b4 100644 --- a/erpnext/hr/doctype/holiday_list/holiday_list.py +++ b/erpnext/hr/doctype/holiday_list/holiday_list.py @@ -8,9 +8,7 @@ from webnotes.utils import add_days, add_years, cint, getdate from webnotes.model import db_exists from webnotes.model.doc import addchild, make_autoname from webnotes.model.bean import copy_doclist -from webnotes import msgprint - - +from webnotes import msgprint, throw, _ import datetime class DocType: @@ -19,7 +17,7 @@ class DocType: self.doclist = doclist def autoname(self): - self.doc.name = make_autoname(self.doc.fiscal_year +"/"+ self.doc.holiday_list_name+"/.###") + self.doc.name = make_autoname(self.doc.fiscal_year + "/" + self.doc.holiday_list_name + "/.###") def validate(self): self.update_default_holiday_list() @@ -38,11 +36,9 @@ class DocType: def validate_values(self): if not self.doc.fiscal_year: - msgprint("Please select Fiscal Year") - raise Exception + throw(_("Please select Fiscal Year")) if not self.doc.weekly_off: - msgprint("Please select weekly off day") - raise Exception + throw(_("Please select weekly off day")) def get_fy_start_end_dates(self): return webnotes.conn.sql("""select year_start_date, year_end_date diff --git a/erpnext/patches.txt b/erpnext/patches.txt index c1ab098298..051c5c7347 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -1,3 +1,4 @@ erpnext.patches.4_0.update_user_properties erpnext.patches.4_0.move_warehouse_user_to_restrictions -erpnext.patches.4_0.new_permissions \ No newline at end of file +erpnext.patches.4_0.new_permissions +erpnext.patches.4_0.update_incharge_name_to_sales_person_in_maintenance_schedule \ No newline at end of file diff --git a/erpnext/patches/4_0/update_incharge_name_to_sales_person_in_maintenance_schedule.py b/erpnext/patches/4_0/update_incharge_name_to_sales_person_in_maintenance_schedule.py new file mode 100644 index 0000000000..7c81ef5acd --- /dev/null +++ b/erpnext/patches/4_0/update_incharge_name_to_sales_person_in_maintenance_schedule.py @@ -0,0 +1,9 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import webnotes + +def execute(): + webnotes.conn.sql("""update `tabMaintenance Schedule Detail` set sales_person=incharge_name""") + webnotes.conn.sql("""update `tabMaintenance Schedule Item` set sales_person=incharge_name""") \ No newline at end of file diff --git a/erpnext/selling/doctype/lead/lead.js b/erpnext/selling/doctype/lead/lead.js index 41f679e34a..228d790e9e 100644 --- a/erpnext/selling/doctype/lead/lead.js +++ b/erpnext/selling/doctype/lead/lead.js @@ -7,18 +7,18 @@ wn.provide("erpnext"); erpnext.LeadController = wn.ui.form.Controller.extend({ setup: function() { - this.frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { + this.frm.fields_dict.customer.get_query = function(doc, cdt, cdn) { return { query: "erpnext.controllers.queries.customer_query" } } }, onload: function() { if(cur_frm.fields_dict.lead_owner.df.options.match(/^Profile/)) { - cur_frm.fields_dict.lead_owner.get_query = function(doc,cdt,cdn) { + cur_frm.fields_dict.lead_owner.get_query = function(doc, cdt, cdn) { return { query:"webnotes.core.doctype.profile.profile.profile_query" } } } if(cur_frm.fields_dict.contact_by.df.options.match(/^Profile/)) { - cur_frm.fields_dict.contact_by.get_query = function(doc,cdt,cdn) { + cur_frm.fields_dict.contact_by.get_query = function(doc, cdt, cdn) { return { query:"webnotes.core.doctype.profile.profile.profile_query" } } } @@ -90,4 +90,4 @@ erpnext.LeadController = wn.ui.form.Controller.extend({ } }); -$.extend(cur_frm.cscript, new erpnext.LeadController({frm: cur_frm})); \ No newline at end of file +$.extend(cur_frm.cscript, new erpnext.LeadController({frm: cur_frm})); diff --git a/erpnext/setup/doctype/authorization_rule/authorization_rule.js b/erpnext/setup/doctype/authorization_rule/authorization_rule.js index 66b14a85ba..b814965ddd 100644 --- a/erpnext/setup/doctype/authorization_rule/authorization_rule.js +++ b/erpnext/setup/doctype/authorization_rule/authorization_rule.js @@ -1,114 +1,113 @@ // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt - - -//--------- ONLOAD ------------- -cur_frm.cscript.onload = function(doc, cdt, cdn) { - -} - // Settings Module +cur_frm.cscript.refresh = function(doc, cdt, cdn) { + if (doc.based_on == 'Grand Total' || doc.based_on == 'Average Discount' || doc.based_on == 'Not Applicable') + hide_field('master_name'); + else + unhide_field('master_name'); -cur_frm.cscript.refresh = function(doc,cdt,cdn){ - + if (doc.based_on == 'Not Applicable') + hide_field('value'); + else + unhide_field('value'); - if(doc.based_on == 'Grand Total' || doc.based_on == 'Average Discount' || doc.based_on == 'Not Applicable') hide_field('master_name'); - else unhide_field('master_name'); - - if(doc.based_on == 'Not Applicable') hide_field('value'); - else unhide_field('value'); - - if(doc.transaction == 'Appraisal'){ - hide_field(['master_name','system_role', 'system_user']); - unhide_field(['to_emp','to_designation']); - if(doc.transaction == 'Appraisal') hide_field('value'); - else unhide_field('value'); - } - else { - unhide_field(['master_name','system_role', 'system_user','value']); - hide_field(['to_emp','to_designation']); - } + if (doc.transaction == 'Appraisal') { + hide_field(['master_name','system_role', 'system_user']); + unhide_field(['to_emp','to_designation']); + + if (doc.transaction == 'Appraisal') + hide_field('value'); + else + unhide_field('value'); + } + else { + unhide_field(['master_name','system_role', 'system_user','value']); + hide_field(['to_emp','to_designation']); + } } -cur_frm.cscript.based_on = function(doc){ - if(doc.based_on == 'Grand Total' || doc.based_on == 'Average Discount' || doc.based_on == 'Not Applicable'){ - doc.master_name = ''; - refresh_field('master_name'); - hide_field('master_name'); - } - else{ - unhide_field('master_name'); - } - - if(doc.based_on == 'Not Applicable') { - doc.value =0; - refresh_field('value'); - hide_field('value'); - } - else unhide_field('value'); +cur_frm.cscript.based_on = function(doc) { + if (doc.based_on == 'Grand Total' || doc.based_on == 'Average Discount' || doc.based_on == 'Not Applicable') { + doc.master_name = ''; + refresh_field('master_name'); + hide_field('master_name'); + } + else + unhide_field('master_name'); + + if (doc.based_on == 'Not Applicable') { + doc.value =0; + refresh_field('value'); + hide_field('value'); + } + else + unhide_field('value'); } -cur_frm.cscript.transaction = function(doc,cdt,cdn){ - if (doc.transaction == 'Appraisal'){ - doc.master_name = doc.system_role = doc.system_user = ''; - refresh_many(['master_name','system_role', 'system_user']); - hide_field(['master_name','system_role', 'system_user']); - unhide_field(['to_emp','to_designation']); - doc.value =0; - refresh_many('value'); - hide_field('value'); - } - else { - unhide_field(['master_name','system_role', 'system_user','value']); - hide_field(['to_emp','to_designation']); - } - - if(doc.transaction == 'Appraisal') doc.based_on == 'Not Applicable'; +cur_frm.cscript.transaction = function(doc, cdt, cdn){ + if (doc.transaction == 'Appraisal') { + doc.based_on == 'Not Applicable'; + doc.master_name = doc.system_role = doc.system_user = ''; + refresh_many(['master_name','system_role', 'system_user', 'based_on']); + hide_field(['master_name','system_role', 'system_user']); + unhide_field(['to_emp','to_designation']); + doc.value = 0; + refresh_many('value'); + hide_field('value'); + } + else { + unhide_field(['master_name','system_role', 'system_user','value']); + hide_field(['to_emp','to_designation']); + } + } +cur_frm.fields_dict.system_user.get_query = function(doc, cdt, cdn) { + return { query:"webnotes.core.doctype.profile.profile.profile_query" } +} -cur_frm.fields_dict.system_user.get_query = function(doc,cdt,cdn) { - return{ query:"webnotes.core.doctype.profile.profile.profile_query" } } - -cur_frm.fields_dict.approving_user.get_query = function(doc,cdt,cdn) { - return{ query:"webnotes.core.doctype.profile.profile.profile_query" } } +cur_frm.fields_dict.approving_user.get_query = function(doc, cdt, cdn) { + return { query:"webnotes.core.doctype.profile.profile.profile_query" } +} cur_frm.fields_dict['approving_role'].get_query = cur_frm.fields_dict['system_role'].get_query; // System Role Trigger // ----------------------- cur_frm.fields_dict['system_role'].get_query = function(doc) { - return{ - filters:[ - ['Role', 'name', 'not in', 'Administrator, Guest, All'] - ] - } + return { + filters:[ + ['Role', 'name', 'not in', 'Administrator, Guest, All'] + ] + } } // Master Name Trigger // -------------------- -cur_frm.fields_dict['master_name'].get_query = function(doc){ - if(doc.based_on == 'Customerwise Discount') - return { - doctype: "Customer", - filters:[ - ['Customer', 'docstatus', '!=', 2] - ] - } - else if(doc.based_on == 'Itemwise Discount') - return { - doctype: "Item", - query: "erpnext.controllers.queries.item_query" - } - else - return { - filters: [ - ['Item', 'name', '=', 'cheating done to avoid null'] - ] - } +cur_frm.fields_dict['master_name'].get_query = function(doc) { + if (doc.based_on == 'Customerwise Discount') + return { + doctype: "Customer", + filters:[ + ['Customer', 'docstatus', '!=', 2] + ] + } + else if (doc.based_on == 'Itemwise Discount') + return { + doctype: "Item", + query: "erpnext.controllers.queries.item_query" + } + else + return { + filters: [ + ['Item', 'name', '=', 'cheating done to avoid null'] + ] + } } -cur_frm.fields_dict.to_emp.get_query = function(doc,cdt,cdn) { - return{ query: "erpnext.controllers.queries.employee_query" } } \ No newline at end of file +cur_frm.fields_dict.to_emp.get_query = function(doc, cdt, cdn) { + return { query: "erpnext.controllers.queries.employee_query" } +} diff --git a/erpnext/setup/doctype/sales_person/sales_person.js b/erpnext/setup/doctype/sales_person/sales_person.js index 19c13b18a4..22f3f98bf2 100644 --- a/erpnext/setup/doctype/sales_person/sales_person.js +++ b/erpnext/setup/doctype/sales_person/sales_person.js @@ -15,15 +15,10 @@ cur_frm.cscript.set_root_readonly = function(doc) { } } - -cur_frm.cscript.onload = function(){ - -} - //get query select sales person -cur_frm.fields_dict['parent_sales_person'].get_query = function(doc,cdt,cdn) { +cur_frm.fields_dict['parent_sales_person'].get_query = function(doc, cdt, cdn) { return{ - filters:[ + filters: [ ['Sales Person', 'is_group', '=', 'Yes'], ['Sales Person', 'name', '!=', doc.sales_person_name] ] @@ -31,10 +26,11 @@ cur_frm.fields_dict['parent_sales_person'].get_query = function(doc,cdt,cdn) { } cur_frm.fields_dict['target_details'].grid.get_field("item_group").get_query = function(doc, cdt, cdn) { - return{ - filters:{ 'is_group': "No" } + return { + filters: { 'is_group': "No" } } } -cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) { - return{ query: "erpnext.controllers.queries.employee_query" } } +cur_frm.fields_dict.employee.get_query = function(doc, cdt, cdn) { + return { query: "erpnext.controllers.queries.employee_query" } +} \ No newline at end of file diff --git a/erpnext/setup/doctype/sales_person/sales_person.py b/erpnext/setup/doctype/sales_person/sales_person.py index cf20087e04..41a986fc30 100644 --- a/erpnext/setup/doctype/sales_person/sales_person.py +++ b/erpnext/setup/doctype/sales_person/sales_person.py @@ -3,10 +3,8 @@ from __future__ import unicode_literals import webnotes - from webnotes.model.bean import getlist from webnotes.utils import flt - from webnotes.utils.nestedset import DocTypeNestedSet class DocType(DocTypeNestedSet): @@ -18,8 +16,7 @@ class DocType(DocTypeNestedSet): def validate(self): for d in getlist(self.doclist, 'target_details'): if not flt(d.target_qty) and not flt(d.target_amount): - webnotes.msgprint("Either target qty or target amount is mandatory.") - raise Exception + webnotes.throw(_("Either target qty or target amount is mandatory.")) def on_update(self): super(DocType, self).on_update() @@ -28,7 +25,7 @@ class DocType(DocTypeNestedSet): def get_email_id(self): profile = webnotes.conn.get_value("Employee", self.doc.employee, "user_id") if not profile: - webnotes.msgprint("User ID (Profile) no set for Employee %s" % self.doc.employee, + webnotes.msgprint("User ID (Profile) not set for Employee %s" % self.doc.employee, raise_exception=True) else: return webnotes.conn.get_value("Profile", profile, "email") or profile diff --git a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.js b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.js index bcb1bf33b6..2ee8b80e47 100644 --- a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.js +++ b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.js @@ -5,6 +5,8 @@ wn.provide("erpnext.support"); // TODO commonify this code erpnext.support.MaintenanceSchedule = wn.ui.form.Controller.extend({ refresh: function() { + var me = this; + if (this.frm.doc.docstatus === 0) { this.frm.add_custom_button(wn._('From Sales Order'), function() { @@ -23,7 +25,7 @@ erpnext.support.MaintenanceSchedule = wn.ui.form.Controller.extend({ this.frm.add_custom_button(wn._("Make Maintenance Visit"), function() { wn.model.open_mapped_doc({ method: "erpnext.support.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit", - source_name: cur_frm.doc.name + source_name: me.frm.doc.name }) }); } @@ -42,7 +44,7 @@ erpnext.support.MaintenanceSchedule = wn.ui.form.Controller.extend({ $.extend(cur_frm.cscript, new erpnext.support.MaintenanceSchedule({frm: cur_frm})); cur_frm.cscript.onload = function(doc, dt, dn) { - if(!doc.status) + if (!doc.status) set_multiple(dt, dn, { status:'Draft' }); if (doc.__islocal) { diff --git a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py index 270f954922..4fdc9ea37d 100644 --- a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py +++ b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py @@ -32,7 +32,7 @@ class DocType(TransactionBase): self.validate_maintenance_detail() count = 1 s_list = [] - s_list = self.create_schedule_list(d.start_date, d.end_date, d.no_of_visits) + s_list = self.create_schedule_list(d.start_date, d.end_date, d.no_of_visits, d.sales_person) for i in range(d.no_of_visits): child = addchild(self.doc, 'maintenance_schedule_detail', 'Maintenance Schedule Detail', self.doclist) @@ -43,7 +43,7 @@ class DocType(TransactionBase): child.serial_no = d.serial_no child.idx = count count = count + 1 - child.incharge_name = d.incharge_name + child.sales_person = d.sales_person child.save(1) self.on_update() @@ -55,26 +55,26 @@ class DocType(TransactionBase): self.validate_serial_no_warranty() self.validate_schedule() - email_map ={} + email_map = {} for d in getlist(self.doclist, 'item_maintenance_detail'): if d.serial_no: self.update_amc_date(d.serial_no, d.end_date) - if d.incharge_name not in email_map: - email_map[d.incharge_name] = webnotes.bean("Sales Person", - d.incharge_name).run_method("get_email_id") + if d.sales_person not in email_map: + sp = webnotes.bean("Sales Person", d.sales_person).make_controller() + email_map[d.sales_person] = sp.get_email_id() - scheduled_date =webnotes.conn.sql("""select scheduled_date from - `tabMaintenance Schedule Detail` where incharge_name=%s and item_code=%s and - parent=%s""", (d.incharge_name, d.item_code, self.doc.name), as_dict=1) + scheduled_date = webnotes.conn.sql("""select scheduled_date from + `tabMaintenance Schedule Detail` where sales_person=%s and item_code=%s and + parent=%s""", (d.sales_person, d.item_code, self.doc.name), as_dict=1) for key in scheduled_date: - if email_map[d.incharge_name]: + if email_map[d.sales_person]: description = "Reference: %s, Item Code: %s and Customer: %s" % \ (self.doc.name, d.item_code, self.doc.customer) webnotes.bean({ "doctype": "Event", - "owner": email_map[d.incharge_name] or self.doc.owner, + "owner": email_map[d.sales_person] or self.doc.owner, "subject": description, "description": description, "starts_on": key["scheduled_date"] + " 10:00:00", @@ -87,7 +87,7 @@ class DocType(TransactionBase): #get schedule dates #---------------------- - def create_schedule_list(self, start_date, end_date, no_of_visit): + def create_schedule_list(self, start_date, end_date, no_of_visit, sales_person): schedule_list = [] start_date_copy = start_date date_diff = (getdate(end_date) - getdate(start_date)).days @@ -96,9 +96,29 @@ class DocType(TransactionBase): while (getdate(start_date_copy) < getdate(end_date)): start_date_copy = add_days(start_date_copy, add_by) if len(schedule_list) < no_of_visit: - schedule_list.append(getdate(start_date_copy)) + schedule_date = self.validate_schedule_date_for_holiday_list(getdate(start_date_copy), + sales_person) + if schedule_date > getdate(end_date): + schedule_date = getdate(end_date) + schedule_list.append(schedule_date) + return schedule_list - + + def validate_schedule_date_for_holiday_list(self, schedule_date, sales_person): + validated = False + + holiday_list = webnotes.conn.sql_list("""select h.holiday_date from `tabEmployee` emp, + `tabSales Person` sp, `tabHoliday` h where sp.name=%s and emp.name=sp.employee + and h.parent=emp.holiday_list""", sales_person) + + while not validated: + if schedule_date in holiday_list: + schedule_date = add_days(schedule_date, 1) + else: + validated = True + + return schedule_date + #validate date range and periodicity selected #------------------------------------------------- def validate_period(self, arg): @@ -147,7 +167,7 @@ class DocType(TransactionBase): throw(_("Please select Start Date and End Date for item") + " " + d.item_code) elif not d.no_of_visits: throw(_("Please mention no of visits required")) - elif not d.incharge_name: + elif not d.sales_person: throw(_("Please select Incharge Person's name")) if getdate(d.start_date) >= getdate(d.end_date): @@ -297,7 +317,7 @@ def make_maintenance_visit(source_name, target_doclist=None): "field_map": { "parent": "prevdoc_docname", "parenttype": "prevdoc_doctype", - "incharge_name": "service_person" + "sales_person": "service_person" } } }, target_doclist) diff --git a/erpnext/support/doctype/maintenance_schedule_detail/maintenance_schedule_detail.txt b/erpnext/support/doctype/maintenance_schedule_detail/maintenance_schedule_detail.txt index 7a79d8d659..8ed6856d24 100644 --- a/erpnext/support/doctype/maintenance_schedule_detail/maintenance_schedule_detail.txt +++ b/erpnext/support/doctype/maintenance_schedule_detail/maintenance_schedule_detail.txt @@ -2,7 +2,7 @@ { "creation": "2013-02-22 01:28:05", "docstatus": 0, - "modified": "2013-12-30 19:32:30", + "modified": "2013-12-31 12:13:38", "modified_by": "Administrator", "owner": "Administrator" }, @@ -52,7 +52,7 @@ "search_index": 0 }, { - "allow_on_submit": 1, + "allow_on_submit": 0, "doctype": "DocField", "fieldname": "scheduled_date", "fieldtype": "Date", @@ -79,13 +79,13 @@ "report_hide": 1 }, { - "allow_on_submit": 1, + "allow_on_submit": 0, "doctype": "DocField", - "fieldname": "incharge_name", + "fieldname": "sales_person", "fieldtype": "Link", "in_filter": 1, "in_list_view": 1, - "label": "Incharge Name", + "label": "Sales Person", "oldfieldname": "incharge_name", "oldfieldtype": "Link", "options": "Sales Person", diff --git a/erpnext/support/doctype/maintenance_schedule_item/maintenance_schedule_item.txt b/erpnext/support/doctype/maintenance_schedule_item/maintenance_schedule_item.txt index f42b48bf55..43d281d9e6 100644 --- a/erpnext/support/doctype/maintenance_schedule_item/maintenance_schedule_item.txt +++ b/erpnext/support/doctype/maintenance_schedule_item/maintenance_schedule_item.txt @@ -2,7 +2,7 @@ { "creation": "2013-02-22 01:28:05", "docstatus": 0, - "modified": "2013-12-20 19:23:20", + "modified": "2013-12-31 12:08:32", "modified_by": "Administrator", "owner": "Administrator" }, @@ -112,10 +112,10 @@ }, { "doctype": "DocField", - "fieldname": "incharge_name", + "fieldname": "sales_person", "fieldtype": "Link", "in_filter": 1, - "label": "Sales Person Incharge", + "label": "Sales Person", "oldfieldname": "incharge_name", "oldfieldtype": "Link", "options": "Sales Person", diff --git a/erpnext/support/report/maintenance_schedules/maintenance_schedules.txt b/erpnext/support/report/maintenance_schedules/maintenance_schedules.txt index 766eb20151..eec3d7f852 100644 --- a/erpnext/support/report/maintenance_schedules/maintenance_schedules.txt +++ b/erpnext/support/report/maintenance_schedules/maintenance_schedules.txt @@ -2,7 +2,7 @@ { "creation": "2013-05-06 14:25:21", "docstatus": 0, - "modified": "2013-10-09 12:23:27", + "modified": "2013-12-31 12:24:48", "modified_by": "Administrator", "owner": "Administrator" }, @@ -10,7 +10,7 @@ "doctype": "Report", "is_standard": "Yes", "name": "__common__", - "query": "SELECT\n ms_sch.scheduled_date as \"Schedule Date:Date:120\",\n\tms_sch.item_code as \"Item Code:Link/Item:120\",\n\tms_sch.item_name as \"Item Name::120\",\n\tms_sch.serial_no as \"Serial No::120\",\n\tms_sch.incharge_name as \"Incharge::120\",\n\tms.customer_name as \"Customer:Link/Customer:120\",\n\tms.address_display as \"Customer Address::120\",\n\tms_item.prevdoc_docname as \"Sales Order:Link/Sales Order:120\",\n\tms.company as \"Company:Link/Company:120\"\n\t\nFROM\n\t`tabMaintenance Schedule` ms, \n `tabMaintenance Schedule Detail` ms_sch, \n `tabMaintenance Schedule Item` ms_item\nWHERE\n\tms.name = ms_sch.parent and ms.name = ms_item.parent and ms.docstatus = 1\nORDER BY\n\tms_sch.scheduled_date asc, ms_sch.item_code asc", + "query": "SELECT\n ms_sch.scheduled_date as \"Schedule Date:Date:120\",\n\tms_sch.item_code as \"Item Code:Link/Item:120\",\n\tms_sch.item_name as \"Item Name::120\",\n\tms_sch.serial_no as \"Serial No::120\",\n\tms_sch.sales_person as \"Sales Person::120\",\n\tms.customer_name as \"Customer:Link/Customer:120\",\n\tms.address_display as \"Customer Address::120\",\n\tms_item.prevdoc_docname as \"Sales Order:Link/Sales Order:120\",\n\tms.company as \"Company:Link/Company:120\"\n\t\nFROM\n\t`tabMaintenance Schedule` ms, \n `tabMaintenance Schedule Detail` ms_sch, \n `tabMaintenance Schedule Item` ms_item\nWHERE\n\tms.name = ms_sch.parent and ms.name = ms_item.parent and ms.docstatus = 1\nORDER BY\n\tms_sch.scheduled_date asc, ms_sch.item_code asc", "ref_doctype": "Maintenance Schedule", "report_name": "Maintenance Schedules", "report_type": "Query Report" From 5dd92fd5d6759279edc7b66cefd87f1c703ac950 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Fri, 3 Jan 2014 19:14:01 +0530 Subject: [PATCH 03/23] reload doc in maintenance schedule --- ...to_sales_person_in_maintenance_schedule.py | 3 ++ .../maintenance_schedule.py | 34 ++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/erpnext/patches/4_0/update_incharge_name_to_sales_person_in_maintenance_schedule.py b/erpnext/patches/4_0/update_incharge_name_to_sales_person_in_maintenance_schedule.py index 7c81ef5acd..2a488f4c8f 100644 --- a/erpnext/patches/4_0/update_incharge_name_to_sales_person_in_maintenance_schedule.py +++ b/erpnext/patches/4_0/update_incharge_name_to_sales_person_in_maintenance_schedule.py @@ -5,5 +5,8 @@ from __future__ import unicode_literals import webnotes def execute(): + webnotes.reload_doc("support", "doctype", "maintenance_schedule_detail") + webnotes.reload_doc("support", "doctype", "maintenance_schedule_item") + webnotes.conn.sql("""update `tabMaintenance Schedule Detail` set sales_person=incharge_name""") webnotes.conn.sql("""update `tabMaintenance Schedule Item` set sales_person=incharge_name""") \ No newline at end of file diff --git a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py index 4fdc9ea37d..865c21c59b 100644 --- a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py +++ b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py @@ -28,9 +28,9 @@ class DocType(TransactionBase): self.doclist = self.doc.clear_table(self.doclist, 'maintenance_schedule_detail') webnotes.conn.sql("""delete from `tabMaintenance Schedule Detail` where parent=%s""", (self.doc.name)) + count = 1 for d in getlist(self.doclist, 'item_maintenance_detail'): self.validate_maintenance_detail() - count = 1 s_list = [] s_list = self.create_schedule_list(d.start_date, d.end_date, d.no_of_visits, d.sales_person) for i in range(d.no_of_visits): @@ -105,17 +105,33 @@ class DocType(TransactionBase): return schedule_list def validate_schedule_date_for_holiday_list(self, schedule_date, sales_person): + from erpnext.accounts.utils import get_fiscal_year validated = False + fy_details = "" - holiday_list = webnotes.conn.sql_list("""select h.holiday_date from `tabEmployee` emp, - `tabSales Person` sp, `tabHoliday` h where sp.name=%s and emp.name=sp.employee - and h.parent=emp.holiday_list""", sales_person) + try: + fy_details = get_fiscal_year(date=schedule_date, verbose=0) + except Exception: + pass - while not validated: - if schedule_date in holiday_list: - schedule_date = add_days(schedule_date, 1) - else: - validated = True + if fy_details and fy_details[0]: + holiday_list = webnotes.conn.sql_list("""select h.holiday_date from `tabEmployee` emp, + `tabSales Person` sp, `tabHoliday` h, `tabHoliday List` hl + where sp.name=%s and emp.name=sp.employee + and hl.name=emp.holiday_list and + h.parent=hl.name and + hl.fiscal_year=%s""", (sales_person, fy_details[0])) + if not holiday_list: + holiday_list = webnotes.conn.sql("""select h.holiday_date from + `tabHoliday` h, `tabHoliday List` hl + where h.parent=hl.name and ifnull(hl.is_default, 0) = 1 + and hl.fiscal_year=%s""", fy_details[0]) + + while not validated and holiday_list: + if schedule_date in holiday_list: + schedule_date = add_days(schedule_date, -1) + else: + validated = True return schedule_date From 6a749e3a8e2bf98fd1deb39997c70c6de6ebd5fc Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Wed, 15 Jan 2014 11:43:47 +0530 Subject: [PATCH 04/23] removed while loop --- .../maintenance_schedule.py | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py index 865c21c59b..bd928b5268 100644 --- a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py +++ b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import add_days, cstr, getdate +from webnotes.utils import add_days, cstr, getdate, cint from webnotes.model.doc import addchild from webnotes.model.bean import getlist from webnotes import msgprint, throw, _ @@ -93,14 +93,15 @@ class DocType(TransactionBase): date_diff = (getdate(end_date) - getdate(start_date)).days add_by = date_diff / no_of_visit - while (getdate(start_date_copy) < getdate(end_date)): - start_date_copy = add_days(start_date_copy, add_by) - if len(schedule_list) < no_of_visit: - schedule_date = self.validate_schedule_date_for_holiday_list(getdate(start_date_copy), - sales_person) - if schedule_date > getdate(end_date): - schedule_date = getdate(end_date) - schedule_list.append(schedule_date) + for visit in range(0, cint(no_of_visit)): + if (getdate(start_date_copy) < getdate(end_date)): + start_date_copy = add_days(start_date_copy, add_by) + if len(schedule_list) < no_of_visit: + schedule_date = self.validate_schedule_date_for_holiday_list(getdate(start_date_copy), + sales_person) + if schedule_date > getdate(end_date): + schedule_date = getdate(end_date) + schedule_list.append(schedule_date) return schedule_list @@ -115,6 +116,7 @@ class DocType(TransactionBase): pass if fy_details and fy_details[0]: + # check holiday list in employee master holiday_list = webnotes.conn.sql_list("""select h.holiday_date from `tabEmployee` emp, `tabSales Person` sp, `tabHoliday` h, `tabHoliday List` hl where sp.name=%s and emp.name=sp.employee @@ -122,12 +124,13 @@ class DocType(TransactionBase): h.parent=hl.name and hl.fiscal_year=%s""", (sales_person, fy_details[0])) if not holiday_list: + # check global holiday list holiday_list = webnotes.conn.sql("""select h.holiday_date from `tabHoliday` h, `tabHoliday List` hl where h.parent=hl.name and ifnull(hl.is_default, 0) = 1 and hl.fiscal_year=%s""", fy_details[0]) - while not validated and holiday_list: + if not validated and holiday_list: if schedule_date in holiday_list: schedule_date = add_days(schedule_date, -1) else: From 2a79b0070034e73e7fd873b6c941c0999e1f4e72 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Wed, 15 Jan 2014 11:54:05 +0530 Subject: [PATCH 05/23] minor fix --- erpnext/setup/doctype/sales_person/sales_person.py | 3 +-- .../doctype/maintenance_schedule/maintenance_schedule.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/erpnext/setup/doctype/sales_person/sales_person.py b/erpnext/setup/doctype/sales_person/sales_person.py index 41a986fc30..41f461be76 100644 --- a/erpnext/setup/doctype/sales_person/sales_person.py +++ b/erpnext/setup/doctype/sales_person/sales_person.py @@ -25,8 +25,7 @@ class DocType(DocTypeNestedSet): def get_email_id(self): profile = webnotes.conn.get_value("Employee", self.doc.employee, "user_id") if not profile: - webnotes.msgprint("User ID (Profile) not set for Employee %s" % self.doc.employee, - raise_exception=True) + webnotes.throw("User ID (Profile) not set for Employee %s" % self.doc.employee) else: return webnotes.conn.get_value("Profile", profile, "email") or profile \ No newline at end of file diff --git a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py index bd928b5268..8f75247d1f 100644 --- a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py +++ b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py @@ -93,7 +93,7 @@ class DocType(TransactionBase): date_diff = (getdate(end_date) - getdate(start_date)).days add_by = date_diff / no_of_visit - for visit in range(0, cint(no_of_visit)): + for visit in range(cint(no_of_visit)): if (getdate(start_date_copy) < getdate(end_date)): start_date_copy = add_days(start_date_copy, add_by) if len(schedule_list) < no_of_visit: From 8a4111fe0eca17c786c4eb6ea5ad6cd03ea2fa6c Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Fri, 17 Jan 2014 18:50:44 +0530 Subject: [PATCH 06/23] decimal places fixed in item prices report --- stock/report/item_prices/item_prices.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stock/report/item_prices/item_prices.py b/stock/report/item_prices/item_prices.py index e744cc73e4..18228ff64b 100644 --- a/stock/report/item_prices/item_prices.py +++ b/stock/report/item_prices/item_prices.py @@ -15,8 +15,8 @@ def execute(filters=None): bom_rate = get_item_bom_rate() val_rate_map = get_valuation_rate() - precision = get_currency_precision or 2 - + precision = get_currency_precision() or 2 + data = [] for item in sorted(item_map): data.append([item, item_map[item]["item_name"], From 529709e08b08ba51479d6a69a55662107361cc17 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Mon, 20 Jan 2014 16:39:03 +0530 Subject: [PATCH 07/23] patch for enabling all price list --- patches/1401/enable_all_price_list.py | 9 +++++++++ patches/patch_list.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 patches/1401/enable_all_price_list.py diff --git a/patches/1401/enable_all_price_list.py b/patches/1401/enable_all_price_list.py new file mode 100644 index 0000000000..9cf141fe67 --- /dev/null +++ b/patches/1401/enable_all_price_list.py @@ -0,0 +1,9 @@ +# Copyright (c) 2014, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import webnotes + +def execute(): + webnotes.reload_doc("stock", "doctype", "price_list") + webnotes.conn.sql("""update `tabPrice List` set enabled=1""") \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index 5bf730af0b..89e33091bf 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -266,5 +266,5 @@ patch_list = [ "patches.1401.p01_move_related_property_setters_to_custom_field", "patches.1401.p01_make_buying_selling_as_check_box_in_price_list", "patches.1401.update_billing_status_for_zero_value_order", - "execute:webnotes.reload_doc('stock', 'doctype', 'price_list') #2014-01-20", + "patches.1401.enable_all_price_list", ] \ No newline at end of file From afe93d633ca0320d5e57fbb4b2049be71bbc5524 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 20 Jan 2014 18:28:48 +0530 Subject: [PATCH 08/23] Increased remarks width in general ledger --- accounts/report/general_ledger/general_ledger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts/report/general_ledger/general_ledger.py b/accounts/report/general_ledger/general_ledger.py index 2f5716ece3..4b1a63b8b3 100644 --- a/accounts/report/general_ledger/general_ledger.py +++ b/accounts/report/general_ledger/general_ledger.py @@ -34,7 +34,7 @@ def validate_filters(filters, account_details): def get_columns(): return ["Posting Date:Date:100", "Account:Link/Account:200", "Debit:Float:100", "Credit:Float:100", "Voucher Type::120", "Voucher No::160", "Link::20", - "Against Account::120", "Cost Center:Link/Cost Center:100", "Remarks::200"] + "Against Account::120", "Cost Center:Link/Cost Center:100", "Remarks::400"] def get_result(filters, account_details): gl_entries = get_gl_entries(filters) From 872e4d1f3d660355ceec220967983aa4ee19e7f2 Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Mon, 20 Jan 2014 19:51:25 +0600 Subject: [PATCH 09/23] bumped to version 3.6.4 --- config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.json b/config.json index 450e2bca6d..5a916c569b 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,6 @@ { "app_name": "ERPNext", - "app_version": "3.6.3", + "app_version": "3.6.4", "base_template": "app/portal/templates/base.html", "modules": { "Accounts": { @@ -74,5 +74,5 @@ "type": "module" } }, - "requires_framework_version": "==3.7.3" + "requires_framework_version": "==3.7.4" } \ No newline at end of file From b2f2df4c64609fcc3dc6fe0d049886baaf2b688d Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 21 Jan 2014 11:58:17 +0530 Subject: [PATCH 10/23] General ledger: opening balance issue fixed --- accounts/report/general_ledger/general_ledger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts/report/general_ledger/general_ledger.py b/accounts/report/general_ledger/general_ledger.py index 4b1a63b8b3..02e970b39c 100644 --- a/accounts/report/general_ledger/general_ledger.py +++ b/accounts/report/general_ledger/general_ledger.py @@ -138,7 +138,7 @@ def get_accountwise_gle(filters, gl_entries, gle_map): for gle in gl_entries: amount = flt(gle.debit) - flt(gle.credit) if filters.get("account") and (gle.posting_date < filters.from_date - or cstr(gle.is_advance) == "Yes"): + or cstr(gle.is_opening) == "Yes"): gle_map[gle.account].opening += amount opening += amount elif gle.posting_date <= filters.to_date: From f3aba2e536a58427b477c4064847ce38ea06a753 Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Tue, 21 Jan 2014 12:39:31 +0600 Subject: [PATCH 11/23] bumped to version 3.6.5 --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index 5a916c569b..d45459417f 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,6 @@ { "app_name": "ERPNext", - "app_version": "3.6.4", + "app_version": "3.6.5", "base_template": "app/portal/templates/base.html", "modules": { "Accounts": { From 13a9e27320b18883e59f3a69175c064d69ad12ed Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 21 Jan 2014 20:57:39 +0530 Subject: [PATCH 12/23] Fixes in warehouse merge function --- stock/doctype/warehouse/warehouse.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/stock/doctype/warehouse/warehouse.py b/stock/doctype/warehouse/warehouse.py index e1b0ef3cc9..0b2fa840c5 100644 --- a/stock/doctype/warehouse/warehouse.py +++ b/stock/doctype/warehouse/warehouse.py @@ -92,23 +92,19 @@ class DocType: exists for this warehouse.""")) def before_rename(self, olddn, newdn, merge=False): - # Add company abbr if not provided - from setup.doctype.company.company import get_name_with_abbr - new_warehouse = get_name_with_abbr(newdn, self.doc.company) - if merge: if not webnotes.conn.exists("Warehouse", newdn): webnotes.throw(_("Warehouse ") + newdn +_(" does not exists")) - if self.doc.company != webnotes.conn.get_value("Warehouse", new_warehouse, "company"): + if self.doc.company != webnotes.conn.get_value("Warehouse", newdn, "company"): webnotes.throw(_("Both Warehouse must belong to same Company")) webnotes.conn.sql("delete from `tabBin` where warehouse=%s", olddn) from accounts.utils import rename_account_for - rename_account_for("Warehouse", olddn, new_warehouse, merge) + rename_account_for("Warehouse", olddn, newdn, merge) - return new_warehouse + return newdn def after_rename(self, olddn, newdn, merge=False): if merge: From 423932fab2f266efe7a5b443a39fed08289e0449 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 22 Jan 2014 11:52:54 +0530 Subject: [PATCH 13/23] Fixes in general ledger opening --- accounts/report/general_ledger/general_ledger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts/report/general_ledger/general_ledger.py b/accounts/report/general_ledger/general_ledger.py index 02e970b39c..af6a87ca97 100644 --- a/accounts/report/general_ledger/general_ledger.py +++ b/accounts/report/general_ledger/general_ledger.py @@ -51,7 +51,7 @@ def get_gl_entries(filters): gl_entries = webnotes.conn.sql("""select posting_date, account, sum(ifnull(debit, 0)) as debit, sum(ifnull(credit, 0)) as credit, - voucher_type, voucher_no, cost_center, remarks, is_advance, against + voucher_type, voucher_no, cost_center, remarks, is_opening, against from `tabGL Entry` where company=%(company)s {conditions} {group_by_condition} From c7676797e1f6a847a69d05e5fec88b37c3dd5322 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 22 Jan 2014 15:36:44 +0530 Subject: [PATCH 14/23] Dont display old fraction outstanding in AR report --- .../report/accounts_receivable/accounts_receivable.py | 5 ++++- accounts/utils.py | 11 ++++++++++- stock/report/item_prices/item_prices.py | 9 +-------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/accounts/report/accounts_receivable/accounts_receivable.py b/accounts/report/accounts_receivable/accounts_receivable.py index de96abb7d7..c826fcbd13 100644 --- a/accounts/report/accounts_receivable/accounts_receivable.py +++ b/accounts/report/accounts_receivable/accounts_receivable.py @@ -37,12 +37,15 @@ class AccountsReceivableReport(object): return columns def get_data(self, customer_naming_by): + from accounts.utils import get_currency_precision + currency_precision = get_currency_precision() or 2 + data = [] future_vouchers = self.get_entries_after(self.filters.report_date) for gle in self.get_entries_till(self.filters.report_date): if self.is_receivable(gle, future_vouchers): outstanding_amount = self.get_outstanding_amount(gle, self.filters.report_date) - if abs(outstanding_amount) > 0.0: + if abs(outstanding_amount) > 0.1/10**currency_precision: due_date = self.get_due_date(gle) invoiced_amount = gle.debit if (gle.debit > 0) else 0 payment_received = invoiced_amount - outstanding_amount diff --git a/accounts/utils.py b/accounts/utils.py index fdd57b35c2..a3557aed09 100644 --- a/accounts/utils.py +++ b/accounts/utils.py @@ -378,4 +378,13 @@ def get_account_for(account_for_doctype, account_for): account_for_field = "account_type" return webnotes.conn.get_value("Account", {account_for_field: account_for_doctype, - "master_name": account_for}) \ No newline at end of file + "master_name": account_for}) + +def get_currency_precision(currency=None): + if not currency: + currency = webnotes.conn.get_value("Company", + webnotes.conn.get_default("company"), "default_currency") + currency_format = webnotes.conn.get_value("Currency", currency, "number_format") + + from webnotes.utils import get_number_format_info + return get_number_format_info(currency_format)[2] \ No newline at end of file diff --git a/stock/report/item_prices/item_prices.py b/stock/report/item_prices/item_prices.py index c9efd69829..50c923bad4 100644 --- a/stock/report/item_prices/item_prices.py +++ b/stock/report/item_prices/item_prices.py @@ -15,6 +15,7 @@ def execute(filters=None): bom_rate = get_item_bom_rate() val_rate_map = get_valuation_rate() + from accounts.utils import get_currency_precision precision = get_currency_precision() or 2 data = [] for item in sorted(item_map): @@ -29,14 +30,6 @@ def execute(filters=None): ]) return columns, data - -def get_currency_precision(): - company_currency = webnotes.conn.get_value("Company", - webnotes.conn.get_default("company"), "default_currency") - currency_format = webnotes.conn.get_value("Currency", company_currency, "number_format") - - from webnotes.utils import get_number_format_info - return get_number_format_info(currency_format)[2] def get_columns(filters): """return columns based on filters""" From 7395dc996942a9da58660396ae4e85d75649ab5d Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Wed, 22 Jan 2014 16:33:07 +0600 Subject: [PATCH 15/23] bumped to version 3.6.6 --- config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.json b/config.json index d45459417f..f71ed9b572 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,6 @@ { "app_name": "ERPNext", - "app_version": "3.6.5", + "app_version": "3.6.6", "base_template": "app/portal/templates/base.html", "modules": { "Accounts": { @@ -74,5 +74,5 @@ "type": "module" } }, - "requires_framework_version": "==3.7.4" + "requires_framework_version": "==3.7.5" } \ No newline at end of file From 82a21beba04bde8ec5b1ee6402c2812b7cef2ecf Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Wed, 22 Jan 2014 16:55:32 +0530 Subject: [PATCH 16/23] Item List refresh when price list changed in POS --- accounts/doctype/sales_invoice/pos.js | 52 +++++++++++++++------------ 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/accounts/doctype/sales_invoice/pos.js b/accounts/doctype/sales_invoice/pos.js index b71b45e55b..21ccd01eaa 100644 --- a/accounts/doctype/sales_invoice/pos.js +++ b/accounts/doctype/sales_invoice/pos.js @@ -109,6 +109,7 @@ erpnext.POS = Class.extend({ this.party = party; this.price_list = (party == "Customer" ? this.frm.doc.selling_price_list : this.frm.doc.buying_price_list); + this.price_list_field = (party == "Customer" ? "selling_price_list" : "buying_price_list"); this.sales_or_purchase = (party == "Customer" ? "Sales" : "Purchase"); this.net_total = "net_total_" + export_or_import; this.grand_total = "grand_total_" + export_or_import; @@ -324,10 +325,12 @@ erpnext.POS = Class.extend({ } } }); - me.refresh(); + this.refresh(); }, refresh: function() { var me = this; + + this.refresh_item_list(); this.party_field.set_input(this.frm.doc[this.party.toLowerCase()]); this.barcode.set_input(""); @@ -350,6 +353,14 @@ erpnext.POS = Class.extend({ this.make_party(); } }, + refresh_item_list: function() { + var me = this; + // refresh item list on change of price list + if (this.frm.doc[this.price_list_field] != this.price_list) { + this.price_list = this.frm.doc[this.price_list_field]; + this.make_item_list(); + } + }, show_items_in_item_cart: function() { var me = this; var $items = this.wrapper.find("#cart tbody").empty(); @@ -383,9 +394,8 @@ erpnext.POS = Class.extend({ )).appendTo($items); }); - this.wrapper.find(".increase-qty, .decrease-qty").on("click", function() { - var item_code = $(this).closest("tr").attr("id"); - me.selected_item_qty_operation(item_code, $(this).attr("class")); + this.wrapper.find("input.qty").on("focus", function() { + $(this).select(); }); }, show_taxes: function() { @@ -422,10 +432,16 @@ erpnext.POS = Class.extend({ // append quantity to the respective item after change from input box $(this.wrapper).find("input.qty").on("change", function() { - var item_code = $(this).closest("tr")[0].id; + var item_code = $(this).closest("tr").attr("id"); me.update_qty(item_code, $(this).val()); }); + // increase/decrease qty on plus/minus button + $(this.wrapper).find(".increase-qty, .decrease-qty").on("click", function() { + var tr = $(this).closest("tr"); + me.increase_decrease_qty(tr, $(this).attr("class")); + }); + // on td click toggle the highlighting of row $(this.wrapper).find("#cart tbody tr td").on("click", function() { var row = $(this).closest("tr"); @@ -443,6 +459,15 @@ erpnext.POS = Class.extend({ me.refresh_delete_btn(); this.barcode.$input.focus(); }, + increase_decrease_qty: function(tr, operation) { + var item_code = tr.attr("id"); + var item_qty = cint(tr.find("input.qty").val()); + + if (operation == "increase-qty") + this.update_qty(item_code, item_qty + 1); + else if (operation == "decrease-qty" && item_qty != 1) + this.update_qty(item_code, item_qty - 1); + }, disable_text_box_and_button: function() { var me = this; // if form is submitted & cancelled then disable all input box & buttons @@ -518,23 +543,6 @@ erpnext.POS = Class.extend({ this.frm.script_manager.trigger("calculate_taxes_and_totals"); this.refresh(); }, - selected_item_qty_operation: function(item_code, operation) { - var me = this; - var child = wn.model.get_children(this.frm.doctype + " Item", this.frm.doc.name, - this.frm.cscript.fname, this.frm.doctype); - - $.each(child, function(i, d) { - if (d.item_code == item_code) { - if (operation == "increase-qty") - d.qty += 1; - else if (operation == "decrease-qty") - d.qty != 1 ? d.qty -= 1 : d.qty = 1; - - me.frm.script_manager.trigger("qty", d.doctype, d.name); - me.refresh(); - } - }); - }, make_payment: function() { var me = this; var no_of_items = $(this.wrapper).find("#cart tbody tr").length; From 8589b1db2208ea0472480b41614a23066835d178 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Wed, 22 Jan 2014 19:25:51 +0530 Subject: [PATCH 17/23] Use model set_value for updating values from POS --- accounts/doctype/sales_invoice/pos.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/accounts/doctype/sales_invoice/pos.js b/accounts/doctype/sales_invoice/pos.js index 21ccd01eaa..a594f7f941 100644 --- a/accounts/doctype/sales_invoice/pos.js +++ b/accounts/doctype/sales_invoice/pos.js @@ -270,22 +270,17 @@ erpnext.POS = Class.extend({ this.frm.cscript.fname, this.frm.doctype), function(i, d) { if (d.item_code == item_code) { caught = true; - if (serial_no) { - d.serial_no += '\n' + serial_no; - me.frm.script_manager.trigger("serial_no", d.doctype, d.name); - } - else { - d.qty += 1; - me.frm.script_manager.trigger("qty", d.doctype, d.name); - } + if (serial_no) + wn.model.set_value(d.doctype, d.name, "serial_no", d.serial_no + '\n' + serial_no); + else + wn.model.set_value(d.doctype, d.name, "qty", d.qty + 1); } }); } // if item not found then add new item - if (!caught) { + if (!caught) this.add_new_item_to_grid(item_code, serial_no); - } this.refresh(); this.refresh_search_box(); @@ -320,8 +315,7 @@ erpnext.POS = Class.extend({ wn.model.clear_doc(d.doctype, d.name); me.refresh_grid(); } else { - d.qty = qty; - me.frm.script_manager.trigger("qty", d.doctype, d.name); + wn.model.set_value(d.doctype, d.name, "qty", qty); } } }); @@ -539,6 +533,7 @@ erpnext.POS = Class.extend({ this.refresh_grid(); }, refresh_grid: function() { + this.frm.dirty(); this.frm.fields_dict[this.frm.cscript.fname].grid.refresh(); this.frm.script_manager.trigger("calculate_taxes_and_totals"); this.refresh(); From 557abdebe09af858b21d2473af51bf113b0876cd Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 23 Jan 2014 13:25:26 +0530 Subject: [PATCH 18/23] order preview through customer login --- portal/templates/sale.html | 4 ++-- portal/utils.py | 12 +++++++----- selling/doctype/sales_order/templates/pages/order.py | 11 ++++++----- selling/utils/cart.py | 5 +++-- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/portal/templates/sale.html b/portal/templates/sale.html index 5dc72c793b..c0996cc4f1 100644 --- a/portal/templates/sale.html +++ b/portal/templates/sale.html @@ -10,9 +10,9 @@
  • {{ doc.name }}
  • {{ doc.name }}

    - {% if doc.name == "Not Allowed" -%} + {% if session_user == "Guest" -%} - {% else %} + {% elif doc.name != "Not Allowed"%}
    diff --git a/portal/utils.py b/portal/utils.py index 89800f3e1d..e210f1a020 100644 --- a/portal/utils.py +++ b/portal/utils.py @@ -41,21 +41,23 @@ def get_currency_context(): } def get_transaction_context(doctype, name): + context = {"session_user": webnotes.session.user} + customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user}, "customer") bean = webnotes.bean(doctype, name) if bean.doc.customer != customer: - return { - "doc": {"name": "Not Allowed"} - } + context.update({"doc": {"name": "Not Allowed"}}) else: - return { + context.update({ "doc": bean.doc, "doclist": bean.doclist, "webnotes": webnotes, "utils": webnotes.utils - } + }) + + return context @webnotes.whitelist(allow_guest=True) def send_message(subject="Website Query", message="", sender="", status="Open"): diff --git a/selling/doctype/sales_order/templates/pages/order.py b/selling/doctype/sales_order/templates/pages/order.py index d53a8b0f6f..9b4a83ce21 100644 --- a/selling/doctype/sales_order/templates/pages/order.py +++ b/selling/doctype/sales_order/templates/pages/order.py @@ -10,11 +10,12 @@ no_cache = True def get_context(): from portal.utils import get_transaction_context context = get_transaction_context("Sales Order", webnotes.form_dict.name) - modify_status(context.get("doc")) - context.update({ - "parent_link": "orders", - "parent_title": "My Orders" - }) + if context.get("doc").get("name") != "Not Allowed": + modify_status(context.get("doc")) + context.update({ + "parent_link": "orders", + "parent_title": "My Orders" + }) return context def modify_status(doc): diff --git a/selling/utils/cart.py b/selling/utils/cart.py index 3cd7b3c9f1..79046270a9 100644 --- a/selling/utils/cart.py +++ b/selling/utils/cart.py @@ -282,7 +282,7 @@ def apply_cart_settings(party=None, quotation=None): party = get_lead_or_customer() if not quotation: quotation = _get_cart_quotation(party) - + cart_settings = webnotes.get_obj("Shopping Cart Settings") billing_territory = get_address_territory(quotation.doc.customer_address) or \ @@ -310,7 +310,8 @@ def set_price_list_and_rate(quotation, cart_settings, billing_territory): quotation.run_method("set_price_list_and_item_details") # set it in cookies for using in product page - webnotes.local._response.set_cookie("selling_price_list", quotation.doc.selling_price_list) + if quotation.doc.selling_price_list: + webnotes.local._response.set_cookie("selling_price_list", quotation.doc.selling_price_list) def set_taxes(quotation, cart_settings, billing_territory): """set taxes based on billing territory""" From 1cd96a136f203ea9b7de4d9eac4ed7df0527d62a Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 24 Jan 2014 11:10:01 +0530 Subject: [PATCH 19/23] updates for restriction --- erpnext/hr/doctype/appraisal/appraisal.txt | 4 ++-- erpnext/hr/doctype/expense_claim/expense_claim.txt | 4 ++-- erpnext/hr/doctype/leave_allocation/leave_allocation.txt | 4 ++-- erpnext/patches/4_0/update_user_properties.py | 6 +++++- erpnext/projects/doctype/time_log/time_log.txt | 4 ++-- erpnext/selling/page/sales_browser/sales_browser.py | 8 ++++---- erpnext/utilities/doctype/note/note.txt | 5 +++-- 7 files changed, 20 insertions(+), 15 deletions(-) diff --git a/erpnext/hr/doctype/appraisal/appraisal.txt b/erpnext/hr/doctype/appraisal/appraisal.txt index c82f8481bb..da57097b52 100644 --- a/erpnext/hr/doctype/appraisal/appraisal.txt +++ b/erpnext/hr/doctype/appraisal/appraisal.txt @@ -2,7 +2,7 @@ { "creation": "2013-01-10 16:34:12", "docstatus": 0, - "modified": "2014-01-20 17:48:22", + "modified": "2014-01-22 16:05:34", "modified_by": "Administrator", "owner": "ashwini@webnotestech.com" }, @@ -233,7 +233,7 @@ "cancel": 0, "delete": 0, "doctype": "DocPerm", - "match": "owner", + "restricted": 1, "role": "Employee", "submit": 0 }, diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.txt b/erpnext/hr/doctype/expense_claim/expense_claim.txt index 98e1782697..ac7f78861d 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.txt +++ b/erpnext/hr/doctype/expense_claim/expense_claim.txt @@ -2,7 +2,7 @@ { "creation": "2013-01-10 16:34:14", "docstatus": 0, - "modified": "2014-01-20 17:48:44", + "modified": "2014-01-22 16:05:34", "modified_by": "Administrator", "owner": "harshada@webnotestech.com" }, @@ -223,7 +223,7 @@ { "delete": 0, "doctype": "DocPerm", - "match": "owner", + "restricted": 1, "role": "Employee" }, { diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.txt b/erpnext/hr/doctype/leave_allocation/leave_allocation.txt index 41584c97be..60f2523941 100644 --- a/erpnext/hr/doctype/leave_allocation/leave_allocation.txt +++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.txt @@ -2,7 +2,7 @@ { "creation": "2013-02-20 19:10:38", "docstatus": 0, - "modified": "2014-01-20 17:48:54", + "modified": "2014-01-22 16:05:35", "modified_by": "Administrator", "owner": "Administrator" }, @@ -171,7 +171,7 @@ }, { "doctype": "DocPerm", - "match": "owner", + "restricted": 1, "role": "HR User" }, { diff --git a/erpnext/patches/4_0/update_user_properties.py b/erpnext/patches/4_0/update_user_properties.py index 085f2c1883..54aed648a8 100644 --- a/erpnext/patches/4_0/update_user_properties.py +++ b/erpnext/patches/4_0/update_user_properties.py @@ -45,7 +45,11 @@ def update_user_match(): for profile in webnotes.conn.sql_list("""select name from `tabProfile` where enabled=1 and user_type='System User'"""): - perms = webnotes.permissions.get_user_perms(meta, "read", profile) + user_roles = webnotes.get_roles(profile) + + perms = meta.get({"doctype": "DocPerm", "permlevel": 0, + "role": ["in", [["All"] + user_roles]], "read": 1}) + # user does not have required roles if not perms: continue diff --git a/erpnext/projects/doctype/time_log/time_log.txt b/erpnext/projects/doctype/time_log/time_log.txt index 556597a4a7..11fa7d6e6e 100644 --- a/erpnext/projects/doctype/time_log/time_log.txt +++ b/erpnext/projects/doctype/time_log/time_log.txt @@ -2,7 +2,7 @@ { "creation": "2013-04-03 16:38:41", "docstatus": 0, - "modified": "2014-01-20 17:49:34", + "modified": "2014-01-22 16:05:35", "modified_by": "Administrator", "owner": "Administrator" }, @@ -205,7 +205,7 @@ { "create": 1, "doctype": "DocPerm", - "match": "owner", + "restricted": 1, "role": "Projects User" }, { diff --git a/erpnext/selling/page/sales_browser/sales_browser.py b/erpnext/selling/page/sales_browser/sales_browser.py index 6791ecf751..bb1a094e76 100644 --- a/erpnext/selling/page/sales_browser/sales_browser.py +++ b/erpnext/selling/page/sales_browser/sales_browser.py @@ -7,17 +7,17 @@ import webnotes @webnotes.whitelist() def get_children(): - ctype = webnotes.form_dict.get('ctype') - webnotes.form_dict['parent_field'] = 'parent_' + ctype.lower().replace(' ', '_') + ctype = webnotes.local.form_dict.get('ctype') + webnotes.local.form_dict['parent_field'] = 'parent_' + ctype.lower().replace(' ', '_') if not webnotes.form_dict.get('parent'): - webnotes.form_dict['parent'] = '' + webnotes.local.form_dict['parent'] = '' return webnotes.conn.sql("""select name as value, if(is_group='Yes', 1, 0) as expandable from `tab%(ctype)s` where docstatus < 2 and ifnull(%(parent_field)s,'') = "%(parent)s" - order by name""" % webnotes.form_dict, as_dict=1) + order by name""" % webnotes.local.form_dict, as_dict=1) @webnotes.whitelist() def add_node(): diff --git a/erpnext/utilities/doctype/note/note.txt b/erpnext/utilities/doctype/note/note.txt index b7c4f8bab8..94e5a0fbb3 100644 --- a/erpnext/utilities/doctype/note/note.txt +++ b/erpnext/utilities/doctype/note/note.txt @@ -2,7 +2,7 @@ { "creation": "2013-05-24 13:41:00", "docstatus": 0, - "modified": "2014-01-20 17:48:58", + "modified": "2014-01-22 16:05:35", "modified_by": "Administrator", "owner": "Administrator" }, @@ -25,7 +25,7 @@ "permlevel": 0 }, { - "cancel": 1, + "cancel": 0, "create": 1, "delete": 1, "doctype": "DocPerm", @@ -37,6 +37,7 @@ "permlevel": 0, "print": 1, "read": 1, + "restricted": 1, "role": "All", "write": 1 }, From e288e5238af724916fbc34e2a5353b4817a210b2 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 24 Jan 2014 15:33:42 +0530 Subject: [PATCH 20/23] added title_fields for Task, Newsletter --- erpnext/projects/doctype/task/task.txt | 6 ++++-- erpnext/support/doctype/newsletter/newsletter.txt | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/erpnext/projects/doctype/task/task.txt b/erpnext/projects/doctype/task/task.txt index 670eaa18c2..2dce94f921 100644 --- a/erpnext/projects/doctype/task/task.txt +++ b/erpnext/projects/doctype/task/task.txt @@ -2,7 +2,7 @@ { "creation": "2013-01-29 19:25:50", "docstatus": 0, - "modified": "2014-01-20 17:49:32", + "modified": "2014-01-24 13:01:46", "modified_by": "Administrator", "owner": "Administrator" }, @@ -15,7 +15,9 @@ "icon": "icon-check", "max_attachments": 5, "module": "Projects", - "name": "__common__" + "name": "__common__", + "search_fields": "subject", + "title_field": "subject" }, { "doctype": "DocField", diff --git a/erpnext/support/doctype/newsletter/newsletter.txt b/erpnext/support/doctype/newsletter/newsletter.txt index 9482ed712e..0618394f28 100644 --- a/erpnext/support/doctype/newsletter/newsletter.txt +++ b/erpnext/support/doctype/newsletter/newsletter.txt @@ -2,7 +2,7 @@ { "creation": "2013-01-10 16:34:31", "docstatus": 0, - "modified": "2013-12-20 19:24:14", + "modified": "2014-01-24 13:00:11", "modified_by": "Administrator", "owner": "Administrator" }, @@ -13,7 +13,8 @@ "document_type": "Other", "icon": "icon-envelope", "module": "Support", - "name": "__common__" + "name": "__common__", + "title_field": "subject" }, { "doctype": "DocField", @@ -26,6 +27,7 @@ { "cancel": 0, "create": 0, + "delete": 0, "doctype": "DocPerm", "email": 1, "name": "__common__", From d9ba544e09e6ed87216d7a0a3e585d1a31ec2cb0 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 24 Jan 2014 15:59:05 +0530 Subject: [PATCH 21/23] Fix in Item Test Case --- stock/doctype/item/test_item.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stock/doctype/item/test_item.py b/stock/doctype/item/test_item.py index b8f6f9e246..47541749db 100644 --- a/stock/doctype/item/test_item.py +++ b/stock/doctype/item/test_item.py @@ -36,6 +36,7 @@ test_records = [ "stock_uom": "_Test UOM", "default_income_account": "Sales - _TC", "default_warehouse": "_Test Warehouse - _TC", + "purchase_account": "_Test Account Cost for Goods Sold - _TC" }, { "doctype": "Item Reorder", "parentfield": "item_reorder", @@ -64,6 +65,7 @@ test_records = [ "stock_uom": "_Test UOM", "default_income_account": "Sales - _TC", "default_warehouse": "_Test Warehouse - _TC", + "purchase_account": "_Test Account Cost for Goods Sold - _TC" }], [{ "doctype": "Item", @@ -73,6 +75,7 @@ test_records = [ "item_group": "_Test Item Group Desktops", "default_warehouse": "_Test Warehouse - _TC", "default_income_account": "Sales - _TC", + "purchase_account": "_Test Account Cost for Goods Sold - _TC", "is_stock_item": "Yes", "is_asset_item": "No", "has_batch_no": "No", @@ -99,6 +102,7 @@ test_records = [ "item_group": "_Test Item Group Desktops", "default_warehouse": "_Test Warehouse - _TC", "default_income_account": "Sales - _TC", + "purchase_account": "_Test Account Cost for Goods Sold - _TC", "is_stock_item": "Yes", "is_asset_item": "No", "has_batch_no": "No", @@ -119,6 +123,7 @@ test_records = [ "description": "_Test Sales BOM Item", "item_group": "_Test Item Group Desktops", "default_income_account": "Sales - _TC", + "purchase_account": "_Test Account Cost for Goods Sold - _TC", "is_stock_item": "No", "is_asset_item": "No", "has_batch_no": "No", @@ -140,6 +145,7 @@ test_records = [ "is_stock_item": "Yes", "default_warehouse": "_Test Warehouse - _TC", "default_income_account": "Sales - _TC", + "purchase_account": "_Test Account Cost for Goods Sold - _TC", "is_asset_item": "No", "has_batch_no": "No", "has_serial_no": "No", @@ -216,6 +222,7 @@ test_records = [ "item_group": "_Test Item Group Desktops", "default_warehouse": "_Test Warehouse - _TC", "default_income_account": "Sales - _TC", + "purchase_account": "_Test Account Cost for Goods Sold - _TC", "is_stock_item": "Yes", "is_asset_item": "No", "has_batch_no": "No", @@ -238,6 +245,7 @@ test_records = [ "is_stock_item": "Yes", "default_warehouse": "_Test Warehouse - _TC", "default_income_account": "Sales - _TC", + "purchase_account": "_Test Account Cost for Goods Sold - _TC", "is_asset_item": "No", "has_batch_no": "No", "has_serial_no": "No", From fc13b87fd56c6b9fa8ac8b8e9fcbf88f62c8749b Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 24 Jan 2014 18:54:50 +0530 Subject: [PATCH 22/23] Fixes in Make Demo --- accounts/doctype/sales_invoice/sales_invoice.py | 7 ++----- .../requested_items_to_be_ordered.txt | 4 ++-- utilities/demo/demo_docs/Fiscal_Year.csv | 3 ++- utilities/demo/make_demo.py | 15 +++++++++++---- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py index a39702b3fc..1768b9b02f 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.py +++ b/accounts/doctype/sales_invoice/sales_invoice.py @@ -320,12 +320,9 @@ class DocType(SellingController): item = webnotes.conn.sql("select name,is_asset_item,is_sales_item from `tabItem` where name = '%s' and (ifnull(end_of_life,'')='' or end_of_life = '0000-00-00' or end_of_life > now())"% d.item_code) acc = webnotes.conn.sql("select account_type from `tabAccount` where name = '%s' and docstatus != 2" % d.income_account) if not acc: - msgprint("Account: "+d.income_account+" does not exist in the system") - raise Exception + msgprint("Account: "+d.income_account+" does not exist in the system", raise_exception=True) elif item and item[0][1] == 'Yes' and not acc[0][0] == 'Fixed Asset Account': - msgprint("Please select income head with account type 'Fixed Asset Account' as Item %s is an asset item" % d.item_code) - raise Exception - + msgprint("Please select income head with account type 'Fixed Asset Account' as Item %s is an asset item" % d.item_code, raise_exception=True) def validate_with_previous_doc(self): super(DocType, self).validate_with_previous_doc(self.tname, { diff --git a/buying/report/requested_items_to_be_ordered/requested_items_to_be_ordered.txt b/buying/report/requested_items_to_be_ordered/requested_items_to_be_ordered.txt index 49c747854a..4d3558ca68 100644 --- a/buying/report/requested_items_to_be_ordered/requested_items_to_be_ordered.txt +++ b/buying/report/requested_items_to_be_ordered/requested_items_to_be_ordered.txt @@ -2,7 +2,7 @@ { "creation": "2013-05-13 16:10:02", "docstatus": 0, - "modified": "2013-05-13 16:21:07", + "modified": "2014-01-24 18:19:11", "modified_by": "Administrator", "owner": "Administrator" }, @@ -11,7 +11,7 @@ "doctype": "Report", "is_standard": "Yes", "name": "__common__", - "query": "select \n mr.name as \"Material Request:Link/Material Request:120\",\n\tmr.transaction_date as \"Date:Date:100\",\n\tmr_item.item_code as \"Item Code:Link/Item:120\",\n\tmr_item.qty as \"Qty:Float:100\",\n\tmr_item.ordered_qty as \"Ordered Qty:Float:100\", \n\t(mr_item.qty - ifnull(mr_item.ordered_qty, 0)) as \"Qty to Order:Float:100\",\n\tmr_item.item_name as \"Item Name::150\",\n\tmr_item.description as \"Description::200\"\nfrom\n\t`tabMaterial Request` mr, `tabMaterial Request Item` mr_item\nwhere\n\tmr_item.parent = mr.name\n\tand mr.material_request_type = \"Purchase\"\n\tand mr.docstatus = 1\n\tand mr.status != \"Stopped\"\n\tand ifnull(mr_item.ordered_qty, 0) < ifnull(mr_item.qty, 0)\norder by mr.transaction_date asc", + "query": "select \n mr.name as \"Material Request:Link/Material Request:120\",\n\tmr.transaction_date as \"Date:Date:100\",\n\tmr_item.item_code as \"Item Code:Link/Item:120\",\n\tsum(ifnull(mr_item.qty, 0)) as \"Qty:Float:100\",\n\tsum(ifnull(mr_item.ordered_qty, 0)) as \"Ordered Qty:Float:100\", \n\t(sum(mr_item.qty) - sum(ifnull(mr_item.ordered_qty, 0))) as \"Qty to Order:Float:100\",\n\tmr_item.item_name as \"Item Name::150\",\n\tmr_item.description as \"Description::200\"\nfrom\n\t`tabMaterial Request` mr, `tabMaterial Request Item` mr_item\nwhere\n\tmr_item.parent = mr.name\n\tand mr.material_request_type = \"Purchase\"\n\tand mr.docstatus = 1\n\tand mr.status != \"Stopped\"\ngroup by mr.name, mr_item.item_code\nhaving\n\tsum(ifnull(mr_item.ordered_qty, 0)) < sum(ifnull(mr_item.qty, 0))\norder by mr.transaction_date asc", "ref_doctype": "Purchase Order", "report_name": "Requested Items To Be Ordered", "report_type": "Query Report" diff --git a/utilities/demo/demo_docs/Fiscal_Year.csv b/utilities/demo/demo_docs/Fiscal_Year.csv index d56b1b9b94..1a06e872b8 100644 --- a/utilities/demo/demo_docs/Fiscal_Year.csv +++ b/utilities/demo/demo_docs/Fiscal_Year.csv @@ -20,4 +20,5 @@ Info:,,,,,"One of: No, Yes" Start entering data below this line,,,, ,,2009,01-01-2009,31-12-2009,No ,,2010,01-01-2010,31-12-2010,No -,,2011,01-01-2011,31-12-2011,No \ No newline at end of file +,,2011,01-01-2011,31-12-2011,No +,,2012,01-01-2012,31-12-2012,No \ No newline at end of file diff --git a/utilities/demo/make_demo.py b/utilities/demo/make_demo.py index b98fd7ac9c..99c3e8b7e8 100644 --- a/utilities/demo/make_demo.py +++ b/utilities/demo/make_demo.py @@ -19,7 +19,7 @@ company_abbr = "WP" country = "United States" currency = "USD" time_zone = "America/New_York" -start_date = '2013-01-01' +start_date = '2014-01-01' bank_name = "Citibank" runs_for = None prob = { @@ -105,6 +105,10 @@ def run_accounts(current_date): for so in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Sales Invoice")]: si = webnotes.bean(make_sales_invoice(so)) si.doc.posting_date = current_date + for d in si.doclist.get({"parentfield": "entries"}): + if not d.income_account: + d.income_account = "Sales - {}".format(company_abbr) + si.insert() si.submit() webnotes.conn.commit() @@ -170,6 +174,9 @@ def run_stock(current_date): dn = webnotes.bean(make_delivery_note(so)) dn.doc.posting_date = current_date dn.doc.fiscal_year = current_date.year + for d in dn.doclist.get({"parentfield": "delivery_note_details"}): + d.expense_account = "Cost of Goods Sold - {}".format(company_abbr) + dn.insert() try: dn.submit() @@ -236,7 +243,7 @@ def run_manufacturing(current_date): ppt = webnotes.bean("Production Planning Tool", "Production Planning Tool") ppt.doc.company = company ppt.doc.use_multi_level_bom = 1 - ppt.doc.purchase_request_for_warehouse = "Stores - WP" + ppt.doc.purchase_request_for_warehouse = "Stores - {}".format(company_abbr) ppt.run_method("get_open_sales_orders") ppt.run_method("get_items_from_so") ppt.run_method("raise_production_order") @@ -380,8 +387,8 @@ def complete_setup(): setup_account({ "first_name": "Test", "last_name": "User", - "fy_start_date": "2013-01-01", - "fy_end_date": "2013-12-31", + "fy_start_date": "2014-01-01", + "fy_end_date": "2014-12-31", "industry": "Manufacturing", "company_name": company, "company_abbr": company_abbr, From 3f8f4ff6cdd56d764522d953a4d5fbaf2953a178 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 24 Jan 2014 21:47:01 +0530 Subject: [PATCH 23/23] BugFix: Production Planning Tool - get_raw_materials --- .../production_planning_tool.py | 4 ++-- .../stock/doctype/material_request/material_request.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py index 3b529cbe10..ac4b0fab3f 100644 --- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py +++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py @@ -243,10 +243,10 @@ class DocType: "item_code": [qty_required, description, stock_uom, min_order_qty] } """ - bom_wise_item_details = {} item_list = [] - + for bom, so_wise_qty in bom_dict.items(): + bom_wise_item_details = {} if self.doc.use_multi_level_bom: # get all raw materials with sub assembly childs for d in webnotes.conn.sql("""select fb.item_code, diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py index 28ec5084e0..d3262c5888 100644 --- a/erpnext/stock/doctype/material_request/material_request.py +++ b/erpnext/stock/doctype/material_request/material_request.py @@ -37,16 +37,16 @@ class DocType(BuyingController): for so_no in so_items.keys(): for item in so_items[so_no].keys(): - already_indented = webnotes.conn.sql("""select sum(qty) from `tabMaterial Request Item` + already_indented = webnotes.conn.sql("""select sum(ifnull(qty, 0)) + from `tabMaterial Request Item` where item_code = %s and sales_order_no = %s and docstatus = 1 and parent != %s""", (item, so_no, self.doc.name)) already_indented = already_indented and flt(already_indented[0][0]) or 0 - actual_so_qty = webnotes.conn.sql("""select sum(qty) from `tabSales Order Item` - where parent = %s and item_code = %s and docstatus = 1 - group by parent""", (so_no, item)) + actual_so_qty = webnotes.conn.sql("""select sum(ifnull(qty, 0)) from `tabSales Order Item` + where parent = %s and item_code = %s and docstatus = 1""", (so_no, item)) actual_so_qty = actual_so_qty and flt(actual_so_qty[0][0]) or 0 - + if actual_so_qty and (flt(so_items[so_no][item]) + already_indented > actual_so_qty): webnotes.throw("You can raise indent of maximum qty: %s for item: %s against sales order: %s\ \n Anyway, you can add more qty in new row for the same item."