diff --git a/erpnext/accounts/doctype/journal_voucher/listview.js b/erpnext/accounts/doctype/journal_voucher/journal_voucher_list.js similarity index 100% rename from erpnext/accounts/doctype/journal_voucher/listview.js rename to erpnext/accounts/doctype/journal_voucher/journal_voucher_list.js diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js index c9b4720c3cb..c6f9e97b51b 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -90,8 +90,15 @@ cur_frm.cscript.supplier = function(doc,dt,dn) { cur_frm.cscript.calc_amount(doc, 1); } - if(doc.supplier) get_server_fields('get_default_supplier_address', JSON.stringify({supplier: doc.supplier}),'', doc, dt, dn, 1,callback); - if(doc.supplier) unhide_field(['supplier_address','contact_person']); + if (doc.supplier) { + get_server_fields('get_default_supplier_address', + JSON.stringify({ supplier: doc.supplier }),'', doc, dt, dn, 1, function(doc, dt, dn) { + cur_frm.refresh(); + callback(doc, dt, dn); + }); + unhide_field(['supplier_address','contact_person']); + } + } cur_frm.cscript.supplier_address = cur_frm.cscript.contact_person = function(doc,dt,dn) { @@ -113,14 +120,19 @@ cur_frm.fields_dict.contact_person.on_new = function(dn) { cur_frm.cscript.credit_to = function(doc,dt,dn) { - var callback = function(r,rt) { - var doc = locals[cur_frm.doctype][cur_frm.docname]; - if(doc.supplier) get_server_fields('get_default_supplier_address', JSON.stringify({supplier: doc.supplier}),'', doc, dt, dn, 1); - if(doc.supplier) unhide_field(['supplier_address','contact_person']); + var callback = function(doc, dt, dn) { + var doc = locals[doc.doctype][doc.name]; + if(doc.supplier) { + get_server_fields('get_default_supplier_address', + JSON.stringify({ supplier: doc.supplier }), '', doc, dt, dn, 1, function() { + cur_frm.refresh(); + }); + unhide_field(['supplier_address','contact_person']); + } cur_frm.refresh(); } - get_server_fields('get_cust','','',doc,dt,dn,1,callback); + get_server_fields('get_cust', '', '', doc, dt, dn, 1, callback); } diff --git a/erpnext/accounts/doctype/purchase_invoice/listview.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice_list.js similarity index 100% rename from erpnext/accounts/doctype/purchase_invoice/listview.js rename to erpnext/accounts/doctype/purchase_invoice/purchase_invoice_list.js diff --git a/erpnext/accounts/doctype/sales_invoice/listview.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice_list.js similarity index 100% rename from erpnext/accounts/doctype/sales_invoice/listview.js rename to erpnext/accounts/doctype/sales_invoice/sales_invoice_list.js diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.js b/erpnext/buying/doctype/purchase_common/purchase_common.js index 0ca29d7341e..82a9953df1f 100644 --- a/erpnext/buying/doctype/purchase_common/purchase_common.js +++ b/erpnext/buying/doctype/purchase_common/purchase_common.js @@ -65,9 +65,6 @@ cur_frm.cscript.update_item_details = function(doc, dt, dn, callback) { } } - - - var set_dynamic_label_par = function(doc, cdt, cdn, base_curr) { //parent flds par_cols_base = {'net_total': 'Net Total', 'total_tax': 'Total Tax', 'grand_total': 'Grand Total', /*'rounded_total': 'Rounded Total',*/ diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js index c3c3a385602..9d500209522 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order.js @@ -68,12 +68,15 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { else $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(false); } - - //Supplier cur_frm.cscript.supplier = function(doc,dt,dn) { - if(doc.supplier) get_server_fields('get_default_supplier_address', JSON.stringify({supplier: doc.supplier}),'', doc, dt, dn, 1); - if(doc.supplier) $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(true); + if (doc.supplier) { + get_server_fields('get_default_supplier_address', + JSON.stringify({ supplier: doc.supplier }),'', doc, dt, dn, 1, function() { + cur_frm.refresh(); + }); + $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(true); + } } cur_frm.cscript.supplier_address = cur_frm.cscript.contact_person = function(doc,dt,dn) { diff --git a/erpnext/buying/doctype/purchase_order/listview.js b/erpnext/buying/doctype/purchase_order/purchase_order_list.js similarity index 100% rename from erpnext/buying/doctype/purchase_order/listview.js rename to erpnext/buying/doctype/purchase_order/purchase_order_list.js diff --git a/erpnext/buying/doctype/purchase_request/listview.js b/erpnext/buying/doctype/purchase_request/purchase_request_list.js similarity index 100% rename from erpnext/buying/doctype/purchase_request/listview.js rename to erpnext/buying/doctype/purchase_request/purchase_request_list.js diff --git a/erpnext/buying/doctype/supplier/supplier.txt b/erpnext/buying/doctype/supplier/supplier.txt index 938633ac671..62c1f5c147e 100644 --- a/erpnext/buying/doctype/supplier/supplier.txt +++ b/erpnext/buying/doctype/supplier/supplier.txt @@ -5,7 +5,7 @@ { 'creation': '2012-05-15 12:14:41', 'docstatus': 0, - 'modified': '2012-05-31 13:18:29', + 'modified': '2012-07-18 17:41:49', 'modified_by': u'Administrator', 'owner': u'Administrator' }, @@ -263,6 +263,19 @@ 'search_index': 0 }, + # DocField + { + 'colour': u'White:FFF', + 'description': u'This currency will get fetched in Purchase transactions of this supplier', + 'doctype': u'DocField', + 'fieldname': u'default_currency', + 'fieldtype': u'Select', + 'label': u'Default Currency', + 'no_copy': 1, + 'options': u'link:Currency', + 'permlevel': 0 + }, + # DocField { 'colour': u'White:FFF', diff --git a/erpnext/buying/doctype/supplier/listview.js b/erpnext/buying/doctype/supplier/supplier_list.js similarity index 100% rename from erpnext/buying/doctype/supplier/listview.js rename to erpnext/buying/doctype/supplier/supplier_list.js diff --git a/erpnext/hr/doctype/appraisal/listview.js b/erpnext/hr/doctype/appraisal/appraisal_list.js similarity index 100% rename from erpnext/hr/doctype/appraisal/listview.js rename to erpnext/hr/doctype/appraisal/appraisal_list.js diff --git a/erpnext/hr/doctype/attendance/listview.js b/erpnext/hr/doctype/attendance/attendance_list.js similarity index 100% rename from erpnext/hr/doctype/attendance/listview.js rename to erpnext/hr/doctype/attendance/attendance_list.js diff --git a/erpnext/hr/doctype/employee/listview.js b/erpnext/hr/doctype/employee/employee_list.js similarity index 100% rename from erpnext/hr/doctype/employee/listview.js rename to erpnext/hr/doctype/employee/employee_list.js diff --git a/erpnext/hr/doctype/expense_claim/listview.js b/erpnext/hr/doctype/expense_claim/expense_claim_list.js similarity index 100% rename from erpnext/hr/doctype/expense_claim/listview.js rename to erpnext/hr/doctype/expense_claim/expense_claim_list.js diff --git a/erpnext/hr/doctype/leave_application/listview.js b/erpnext/hr/doctype/leave_application/leave_application_list.js similarity index 100% rename from erpnext/hr/doctype/leave_application/listview.js rename to erpnext/hr/doctype/leave_application/leave_application_list.js diff --git a/erpnext/hr/doctype/salary_slip/listview.js b/erpnext/hr/doctype/salary_slip/salary_slip_list.js similarity index 100% rename from erpnext/hr/doctype/salary_slip/listview.js rename to erpnext/hr/doctype/salary_slip/salary_slip_list.js diff --git a/erpnext/patches/july_2012/repost_stock_due_to_wrong_packing_list.py b/erpnext/patches/july_2012/repost_stock_due_to_wrong_packing_list.py new file mode 100644 index 00000000000..9e9da7f5ec4 --- /dev/null +++ b/erpnext/patches/july_2012/repost_stock_due_to_wrong_packing_list.py @@ -0,0 +1,76 @@ +def repost_reserved_qty(): + import webnotes + bins = webnotes.conn.sql("select item_code, warehouse, name, reserved_qty from `tabBin`") + for d in bins: + reserved_qty = webnotes.conn.sql(""" + select sum((dnpi.qty/so_item.qty)*(so_item.qty - ifnull(so_item.delivered_qty, 0))), so.transaction_date + + from `tabDelivery Note Packing Item` dnpi, `tabSales Order Item` so_item, `tabSales Order` so + + where dnpi.parent = so.name + and so_item.parent = so.name + and dnpi.parenttype = 'Sales Order' + and dnpi.parent_detail_docname = so_item.name + and dnpi.parent_item = so_item.item_code + and so.docstatus = 1 + and so.status != 'Stopped' + and dnpi.item_code = %s + and dnpi.warehouse = %s + """, (d[0], d[1])) + if flt(d[3]) != flt(reserved_qty[0][0]): + print d, reserved_qty + #webnotes.conn.sql(""" + # update `tabBin` set reserved_qty = %s where name = %s + #""", (reserved_qty and reserved_qty[0][0] or 0, d[2])) + +repost_reserved_qty() + +def cleanup_wrong_sle(): + sle = webnotes.conn.sql(""" + select item_code, warehouse, voucher_no, name + from `tabStock Ledger Entry` sle + where voucher_type = 'Delivery Note' + and not exists( + select name from `tabDelivery Note Packing Item` + where item_code = sle.item_code + and qty = abs(sle.actual_qty) + and parent = sle.voucher_no + ) and not exists ( + select name from `tabDelivery Note Item` + where item_code = sle.item_code + and qty = abs(sle.actual_qty) + and parent = sle.voucher_no + ) + """) + if sle: + print sle + # for d in sle: + # webnotes.conn.sql("update `tabStock Ledger Entry` set is_cancelled = 'Yes' where name = %s", d[3]) + # create_comment(d[3]) + # repost_bin(d[0], d[1]) + +def create_comment(dn): + from webnotes.model.doc import Document + cmt = Document('Comment') + for arg in ['comment', 'comment_by', 'comment_by_fullname', 'comment_doctype', \ + 'comment_docname']: + cmt.fields[arg] = args[arg] + cmt.comment = 'Cancelled by administrator due to wrong entry in packing list' + cmt.comment_by = 'Administrator' + cmt.comment_by_fullname = 'Administrator' + cmt.comment_doctype = 'Stock Ledger Entry' + cmt.comment_docname = dn + cmt.save(1) + + +def repost_bin(item, wh): + from webnotes.model.code import get_obj + bin = webnotes.conn.sql("select name from `tabBin` \ + where item_code = %s and warehouse = %s", (item, wh)) + + get_obj('Bin', bin[0][0]).update_entries_after(posting_date = '2012-07-01', posting_time = '12:05') + + +def execute(): + repost_reserved_qty() + cleanup_wrong_sle() diff --git a/erpnext/production/doctype/bom/listview.js b/erpnext/production/doctype/bom/bom_list.js similarity index 100% rename from erpnext/production/doctype/bom/listview.js rename to erpnext/production/doctype/bom/bom_list.js diff --git a/erpnext/production/doctype/production_order/listview.js b/erpnext/production/doctype/production_order/production_order_list.js similarity index 100% rename from erpnext/production/doctype/production_order/listview.js rename to erpnext/production/doctype/production_order/production_order_list.js diff --git a/erpnext/projects/doctype/project/listview.js b/erpnext/projects/doctype/project/project_list.js similarity index 100% rename from erpnext/projects/doctype/project/listview.js rename to erpnext/projects/doctype/project/project_list.js diff --git a/erpnext/projects/doctype/task/listview.js b/erpnext/projects/doctype/task/task_list.js similarity index 100% rename from erpnext/projects/doctype/task/listview.js rename to erpnext/projects/doctype/task/task_list.js diff --git a/erpnext/projects/doctype/timesheet/listview.js b/erpnext/projects/doctype/timesheet/timesheet_list.js similarity index 100% rename from erpnext/projects/doctype/timesheet/listview.js rename to erpnext/projects/doctype/timesheet/timesheet_list.js diff --git a/erpnext/selling/doctype/customer/customer.txt b/erpnext/selling/doctype/customer/customer.txt index e8f03d02d10..121fa325fcf 100644 --- a/erpnext/selling/doctype/customer/customer.txt +++ b/erpnext/selling/doctype/customer/customer.txt @@ -3,9 +3,9 @@ # These values are common in all dictionaries { - 'creation': '2012-05-15 12:14:51', + 'creation': '2012-07-18 16:07:05', 'docstatus': 0, - 'modified': '2012-05-31 11:41:06', + 'modified': '2012-07-18 17:11:25', 'modified_by': u'Administrator', 'owner': u'Administrator' }, @@ -368,6 +368,19 @@ 'permlevel': 0 }, + # DocField + { + 'colour': u'White:FFF', + 'description': u'This currency will get fetched in Sales transactions of this customer', + 'doctype': u'DocField', + 'fieldname': u'default_currency', + 'fieldtype': u'Select', + 'label': u'Default Currency', + 'no_copy': 1, + 'options': u'link:Currency', + 'permlevel': 0 + }, + # DocField { 'colour': u'White:FFF', diff --git a/erpnext/selling/doctype/customer/listview.js b/erpnext/selling/doctype/customer/customer_list.js similarity index 100% rename from erpnext/selling/doctype/customer/listview.js rename to erpnext/selling/doctype/customer/customer_list.js diff --git a/erpnext/selling/doctype/lead/listview.js b/erpnext/selling/doctype/lead/lead_list.js similarity index 100% rename from erpnext/selling/doctype/lead/listview.js rename to erpnext/selling/doctype/lead/lead_list.js diff --git a/erpnext/selling/doctype/opportunity/listview.js b/erpnext/selling/doctype/opportunity/opportunity_list.js similarity index 100% rename from erpnext/selling/doctype/opportunity/listview.js rename to erpnext/selling/doctype/opportunity/opportunity_list.js diff --git a/erpnext/selling/doctype/quotation/listview.js b/erpnext/selling/doctype/quotation/quotation_list.js similarity index 100% rename from erpnext/selling/doctype/quotation/listview.js rename to erpnext/selling/doctype/quotation/quotation_list.js diff --git a/erpnext/selling/doctype/sales_common/sales_common.py b/erpnext/selling/doctype/sales_common/sales_common.py index a6582095963..4f37d98178e 100644 --- a/erpnext/selling/doctype/sales_common/sales_common.py +++ b/erpnext/selling/doctype/sales_common/sales_common.py @@ -410,7 +410,7 @@ class DocType(TransactionBase): if self.has_sales_bom(d.item_code): for p in getlist(obj.doclist, 'packing_details'): - if p.parent_detail_docname == d.name: + if p.parent_detail_docname == d.name and p.parent_item == d.item_code: # the packing details table's qty is already multiplied with parent's qty il.append({ 'warehouse': p.warehouse, @@ -522,7 +522,9 @@ class DocType(TransactionBase): if [d.item_code, d.name] not in parent_items: parent_items.append([d.item_code, d.name]) - self.cleanup_packing_list(obj, parent_items) + obj.doclist = self.cleanup_packing_list(obj, parent_items) + + return obj.doclist def cleanup_packing_list(self, obj, parent_items): """Remove all those child items which are no longer present in main item table""" @@ -532,7 +534,8 @@ class DocType(TransactionBase): # mark for deletion from doclist delete_list.append(d.name) - if not delete_list: return + if not delete_list: + return obj.doclist # delete from doclist obj.doclist = filter(lambda d: d.name not in delete_list, obj.doclist) @@ -543,6 +546,8 @@ class DocType(TransactionBase): where name in (%s)""" % (", ".join(["%s"] * len(delete_list))), tuple(delete_list)) + + return obj.doclist # Get total in words # ================================================================== diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index f4f1bbc66ba..92fdb5d2176 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -325,7 +325,7 @@ class DocType(TransactionBase): sales_com_obj.validate_max_discount(self,'sales_order_details') # this is to verify that the allocated % of sales persons is 100% sales_com_obj.get_allocated_sum(self) - sales_com_obj.make_packing_list(self,'sales_order_details') + self.doclist = sales_com_obj.make_packing_list(self,'sales_order_details') # get total in words dcc = TransactionBase().get_company_currency(self.doc.company) diff --git a/erpnext/selling/doctype/sales_order/listview.js b/erpnext/selling/doctype/sales_order/sales_order_list.js similarity index 95% rename from erpnext/selling/doctype/sales_order/listview.js rename to erpnext/selling/doctype/sales_order/sales_order_list.js index 3fa63a5d7f8..c15944b0a49 100644 --- a/erpnext/selling/doctype/sales_order/listview.js +++ b/erpnext/selling/doctype/sales_order/sales_order_list.js @@ -34,7 +34,7 @@ wn.doclistviews['Sales Order'] = wn.views.ListView.extend({ if (order_type === 'sales') { me.render_icon(parent, 'icon-tag', data.order_type); - me.render_bar_graph(parent, data, 'per_billed', 'Delivered'); + me.render_bar_graph(parent, data, 'per_delivered', 'Delivered'); } else if (order_type === 'maintenance') { me.render_icon(parent, 'icon-wrench', data.order_type); } diff --git a/erpnext/stock/doctype/batch/listview.js b/erpnext/stock/doctype/batch/batch_list.js similarity index 100% rename from erpnext/stock/doctype/batch/listview.js rename to erpnext/stock/doctype/batch/batch_list.js diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index 490051bcc0c..254229576a6 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -404,9 +404,8 @@ class DocType(TransactionBase): def on_update(self): - get_obj('Sales Common').make_packing_list(self,'delivery_note_details') + self.doclist = get_obj('Sales Common').make_packing_list(self,'delivery_note_details') sl = get_obj('Stock Ledger') sl.scrub_serial_nos(self) sl.scrub_serial_nos(self, 'packing_details') - diff --git a/erpnext/stock/doctype/delivery_note/listview.js b/erpnext/stock/doctype/delivery_note/delivery_note_list.js similarity index 100% rename from erpnext/stock/doctype/delivery_note/listview.js rename to erpnext/stock/doctype/delivery_note/delivery_note_list.js diff --git a/erpnext/stock/doctype/item/listview.js b/erpnext/stock/doctype/item/item_list.js similarity index 100% rename from erpnext/stock/doctype/item/listview.js rename to erpnext/stock/doctype/item/item_list.js diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js index 59c69f66281..eb048ea2082 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js @@ -64,11 +64,15 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { } } - //Supplier cur_frm.cscript.supplier = function(doc,dt,dn) { - if(doc.supplier) get_server_fields('get_default_supplier_address', JSON.stringify({supplier: doc.supplier}),'', doc, dt, dn, 1); - if(doc.supplier) $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(true); + if (doc.supplier) { + get_server_fields('get_default_supplier_address', + JSON.stringify({ supplier: doc.supplier }),'', doc, dt, dn, 1, function() { + cur_frm.refresh(); + }); + $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(true); + } } cur_frm.cscript.supplier_address = cur_frm.cscript.contact_person = function(doc,dt,dn) { diff --git a/erpnext/stock/doctype/purchase_receipt/listview.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt_list.js similarity index 95% rename from erpnext/stock/doctype/purchase_receipt/listview.js rename to erpnext/stock/doctype/purchase_receipt/purchase_receipt_list.js index 915565723b1..ae42eac07d1 100644 --- a/erpnext/stock/doctype/purchase_receipt/listview.js +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt_list.js @@ -6,6 +6,7 @@ wn.doclistviews['Purchase Receipt'] = wn.views.ListView.extend({ "`tabPurchase Receipt`.supplier_name", "group_concat(`tabPurchase Receipt Item`.prevdoc_docname) as purchase_order_no", ]); + this.group_by = "`tabPurchase Receipt`.name"; }, prepare_data: function(data) { this._super(data); diff --git a/erpnext/stock/doctype/serial_no/listview.js b/erpnext/stock/doctype/serial_no/serial_no_list.js similarity index 100% rename from erpnext/stock/doctype/serial_no/listview.js rename to erpnext/stock/doctype/serial_no/serial_no_list.js diff --git a/erpnext/stock/doctype/stock_entry/listview.js b/erpnext/stock/doctype/stock_entry/stock_entry_list.js similarity index 100% rename from erpnext/stock/doctype/stock_entry/listview.js rename to erpnext/stock/doctype/stock_entry/stock_entry_list.js diff --git a/erpnext/stock/doctype/warehouse/listview.js b/erpnext/stock/doctype/warehouse/warehouse_list.js similarity index 100% rename from erpnext/stock/doctype/warehouse/listview.js rename to erpnext/stock/doctype/warehouse/warehouse_list.js diff --git a/erpnext/support/doctype/communication/listview.js b/erpnext/support/doctype/communication/communication_list.js similarity index 100% rename from erpnext/support/doctype/communication/listview.js rename to erpnext/support/doctype/communication/communication_list.js diff --git a/erpnext/support/doctype/customer_issue/listview.js b/erpnext/support/doctype/customer_issue/customer_issue_list.js similarity index 100% rename from erpnext/support/doctype/customer_issue/listview.js rename to erpnext/support/doctype/customer_issue/customer_issue_list.js diff --git a/erpnext/support/doctype/maintenance_schedule/listview.js b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule_list.js similarity index 100% rename from erpnext/support/doctype/maintenance_schedule/listview.js rename to erpnext/support/doctype/maintenance_schedule/maintenance_schedule_list.js diff --git a/erpnext/support/doctype/maintenance_visit/listview.js b/erpnext/support/doctype/maintenance_visit/maintenance_visit_list.js similarity index 100% rename from erpnext/support/doctype/maintenance_visit/listview.js rename to erpnext/support/doctype/maintenance_visit/maintenance_visit_list.js diff --git a/erpnext/support/doctype/support_ticket/listview.js b/erpnext/support/doctype/support_ticket/support_ticket_list.js similarity index 100% rename from erpnext/support/doctype/support_ticket/listview.js rename to erpnext/support/doctype/support_ticket/support_ticket_list.js diff --git a/erpnext/utilities/doctype/address/listview.js b/erpnext/utilities/doctype/address/address_list.js similarity index 100% rename from erpnext/utilities/doctype/address/listview.js rename to erpnext/utilities/doctype/address/address_list.js diff --git a/erpnext/utilities/doctype/contact/listview.js b/erpnext/utilities/doctype/contact/contact_list.js similarity index 100% rename from erpnext/utilities/doctype/contact/listview.js rename to erpnext/utilities/doctype/contact/contact_list.js diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py index 88ed82325ec..3bc78217008 100644 --- a/erpnext/utilities/transaction_base.py +++ b/erpnext/utilities/transaction_base.py @@ -116,22 +116,32 @@ class TransactionBase: contact_mobile = details and details[0]['mobile_no'] or '' return contact_display, contact_name, contact_email, contact_mobile - # Get Customer Details - # ----------------------- - def get_customer_details(self, name): - customer_details = webnotes.conn.sql("select customer_name, customer_group, territory, default_sales_partner, default_commission_rate, default_price_list from tabCustomer where name = '%s' and docstatus != 2" %(name), as_dict = 1) + def get_customer_details(self, name): + """ + Get customer details like name, group, territory + and other such defaults + """ + customer_details = webnotes.conn.sql("""\ + select + customer_name, customer_group, territory, + default_sales_partner, default_commission_rate, default_currency, + default_price_list + from `tabCustomer` + where name = %s and docstatus < 2""", name, as_dict=1) if customer_details: - self.doc.customer_name = customer_details[0]['customer_name'] or '' - self.doc.customer_group = customer_details[0]['customer_group'] or '' - self.doc.territory = customer_details[0]['territory'] or '' - self.doc.sales_partner = customer_details[0]['default_sales_partner'] or '' - self.doc.commission_rate = customer_details[0]['default_commission_rate'] or '' - def_price_list = customer_details[0]['default_price_list'] or '' - if not def_price_list: - cg_price_list = webnotes.conn.sql("select default_price_list from `tabCustomer Group` where name = %s", customer_details[0]['customer_group']) - def_price_list = cg_price_list and cg_price_list[0][0] or '' - self.doc.price_list_name = def_price_list or self.doc.price_list_name + for f in ['customer_name', 'customer_group', 'territory']: + self.doc.fields[f] = customer_details[0][f] or self.doc.fields.get(f) + # fields prepended with default in Customer doctype + for f in ['sales_partner', 'commission_rate', 'currency']: + self.doc.fields[f] = customer_details[0]["default_%s" % f] or self.doc.fields.get(f) + + # optionally fetch default price list from Customer Group + self.doc.price_list_name = (customer_details[0]['default_price_list'] + or webnotes.conn.get_value('Customer Group', self.doc.customer_group, + 'default_price_list') + or self.doc.fields.get('price_list_name')) + # Get Customer Shipping Address # ----------------------- def get_shipping_address(self, name): @@ -194,7 +204,7 @@ class TransactionBase: contact_text, contact_name, contact_email, contact_mobile = self.get_contact_text(contact_name=args['contact']) ret = { 'supplier_address' : address_name, - 'address_display' : address_text, + 'address_display' : address_text, 'contact_person' : contact_name, 'contact_display' : contact_text, 'contact_email' : contact_email, @@ -204,12 +214,20 @@ class TransactionBase: # Get Supplier Details # ----------------------- - def get_supplier_details(self, name): - supplier_details = webnotes.conn.sql("select supplier_name from tabSupplier where name = '%s' and docstatus != 2" %(name), as_dict = 1) - ret = { - 'supplier_name' : supplier_details and supplier_details[0]['supplier_name'] or '' - } - return ret + def get_supplier_details(self, name): + supplier_details = webnotes.conn.sql("""\ + select supplier_name, default_currency + from `tabSupplier` + where name = %s and docstatus < 2""", name, as_dict=1) + if supplier_details: + return { + 'supplier_name': (supplier_details[0]['supplier_name'] + or self.doc.fields.get('supplier_name')), + 'currency': (supplier_details[0]['default_currency'] + or self.doc.fields.get('currency')), + } + else: + return {} # Get Sales Person Details of Customer # ------------------------------------ diff --git a/public/js/all-app.js b/public/js/all-app.js index a1ee5003666..817bef877a4 100644 --- a/public/js/all-app.js +++ b/public/js/all-app.js @@ -972,7 +972,7 @@ this.listview.parent=this;this.wrapper=this.$page.find('.wnlist-area');this.page
\

\ -

',{doctype_label:get_doctype_label(this.doctype),doctype:this.doctype});return no_result_message;},render_row:function(row,data){data.doctype=this.doctype;this.listview.render(row,data,this);},get_query_fields:function(){return this.listview.fields;},get_args:function(){return{doctype:this.doctype,fields:this.get_query_fields(),filters:this.filter_list.get_filters(),docstatus:this.can_submit?$.map(this.$page.find('.show-docstatus :checked'),function(inp){return $(inp).attr('data-docstatus')}):[],order_by:this.listview.order_by||undefined,}},add_delete_option:function(){var me=this;if(this.can_delete){this.add_button('Delete',function(){me.delete_items();},'icon-remove');$('
\ +

',{doctype_label:get_doctype_label(this.doctype),doctype:this.doctype});return no_result_message;},render_row:function(row,data){data.doctype=this.doctype;this.listview.render(row,data,this);},get_query_fields:function(){return this.listview.fields;},get_args:function(){return{doctype:this.doctype,fields:this.get_query_fields(),filters:this.filter_list.get_filters(),docstatus:this.can_submit?$.map(this.$page.find('.show-docstatus :checked'),function(inp){return $(inp).attr('data-docstatus')}):[],order_by:this.listview.order_by||undefined,group_by:this.listview.group_by||undefined,}},add_delete_option:function(){var me=this;if(this.can_delete){this.add_button('Delete',function(){me.delete_items();},'icon-remove');$('
\ Select all
').insertBefore(this.$page.find('.result-list'));this.$page.find('[name="select-all"]').click(function(){me.$page.find('.list-delete').attr('checked',$(this).attr('checked')||false);})}},delete_items:function(){var me=this;var dl=$.map(me.$page.find('.list-delete:checked'),function(e){return $(e).data('name');});if(!dl.length) return;if(!confirm('This is PERMANENT action and you cannot undo. Continue?')){return;} me.set_working(true);wn.call({method:'webnotes.widgets.doclistview.delete_items',args:{items:dl,doctype:me.doctype},callback:function(){me.set_working(false);me.refresh();}})},init_stats:function(){var me=this @@ -1713,7 +1713,7 @@ this.appframe.add_button('Amend',function(){cur_frm.amend_doc()},'icon-pencil'); */ wn.provide('_f');_f.frms={};_f.Frm=function(doctype,parent,in_form){this.docname='';this.doctype=doctype;this.display=0;var me=this;this.is_editable={};this.opendocs={};this.sections=[];this.grids=[];this.cscript={};this.pformat={};this.fetch_dict={};this.parent=parent;this.tinymce_id_list=[];this.setup_meta(doctype);this.in_form=in_form?true:false;var me=this;$(document).bind('rename',function(event,dt,old_name,new_name){if(dt==me.doctype) me.rename_notify(dt,old_name,new_name)});} -_f.Frm.prototype.check_doctype_conflict=function(docname){var me=this;if(this.doctype=='DocType'&&docname=='DocType'){msgprint('Allowing DocType, DocType. Be careful!')}else if(this.doctype=='DocType'){if(wn.views.formview[docname]){msgprint("Cannot open DocType when its instance is open") +_f.Frm.prototype.check_doctype_conflict=function(docname){var me=this;if(this.doctype=='DocType'&&docname=='DocType'){msgprint('Allowing DocType, DocType. Be careful!')}else if(this.doctype=='DocType'){if(wn.views.formview[docname]||wn.pages['List/'+docname]){msgprint("Cannot open DocType when its instance is open") throw'doctype open conflict'}}else{if(wn.views.formview.DocType&&wn.views.formview.DocType.frm.opendocs[this.doctype]){msgprint("Cannot open instance when its DocType is open") throw'doctype open conflict'}}} _f.Frm.prototype.setup=function(){var me=this;this.fields=[];this.fields_dict={};this.wrapper=this.parent;this.setup_print_layout();this.saved_wrapper=$a(this.wrapper,'div');this.setup_std_layout();this.setup_client_script();this.setup_done=true;} @@ -1778,7 +1778,8 @@ return 1} _f.Frm.prototype.refresh=function(docname){if(docname){if(this.docname!=docname&&(!this.meta.in_dialog||this.in_form)&&!this.meta.istable) scroll(0,0);this.docname=docname;} if(!this.meta.istable){cur_frm=this;this.parent.cur_frm=this;} -if(this.docname){if(!this.check_doc_perm())return;this.doc=get_local(this.doctype,this.docname);if(!this.setup_done)this.setup();this.runclientscript('set_perm',this.doctype,this.docname);cur_frm.cscript.is_onload=false;if(!this.opendocs[this.docname]){cur_frm.cscript.is_onload=true;this.setnewdoc(this.docname);} +if(this.docname){if(!this.check_doc_perm())return;if(!this.opendocs[this.docname]){this.check_doctype_conflict(this.docname);} +this.doc=get_local(this.doctype,this.docname);if(!this.setup_done)this.setup();this.runclientscript('set_perm',this.doctype,this.docname);cur_frm.cscript.is_onload=false;if(!this.opendocs[this.docname]){cur_frm.cscript.is_onload=true;this.setnewdoc(this.docname);} if(this.doc.__islocal) this.is_editable[this.docname]=1;this.editable=this.is_editable[this.docname];if(!this.doc.__archived&&(this.editable||(!this.editable&&this.meta.istable))){if(this.print_wrapper){$dh(this.print_wrapper);$ds(this.page_layout.wrapper);} if(!this.meta.istable){this.refresh_header();this.sidebar&&this.sidebar.refresh();} @@ -1799,7 +1800,7 @@ _f.Frm.prototype.refresh_dependency=function(){var me=this;var doc=locals[this.d dep_dict[guardian]=[];dep_dict[guardian][dep_dict[guardian].length]=f;has_dep=true;}} if(!has_dep)return;for(var i=me.fields.length-1;i>=0;i--){var f=me.fields[i];f.guardian_has_value=true;if(f.df.depends_on){var v=doc[f.df.depends_on];if(f.df.depends_on.substr(0,5)=='eval:'){f.guardian_has_value=eval(f.df.depends_on.substr(5));}else if(f.df.depends_on.substr(0,3)=='fn:'){f.guardian_has_value=me.runclientscript(f.df.depends_on.substr(3),me.doctype,me.docname);}else{if(v||(v==0&&!v.substr)){}else{f.guardian_has_value=false;}} if(f.guardian_has_value){if(f.grid)f.grid.show();else $ds(f.wrapper);}else{if(f.grid)f.grid.hide();else $dh(f.wrapper);}}}} -_f.Frm.prototype.setnewdoc=function(docname){this.check_doctype_conflict(docname);if(this.opendocs[docname]){this.docname=docname;return;} +_f.Frm.prototype.setnewdoc=function(docname){if(this.opendocs[docname]){this.docname=docname;return;} Meta.make_local_dt(this.doctype,docname);this.docname=docname;var me=this;var viewname=docname;if(this.meta.issingle)viewname=this.doctype;this.runclientscript('onload',this.doctype,this.docname);this.is_editable[docname]=1;if(this.meta.read_only_onload)this.is_editable[docname]=0;this.opendocs[docname]=true;} _f.Frm.prototype.edit_doc=function(){this.is_editable[this.docname]=true;this.refresh();} _f.Frm.prototype.show_doc=function(dn){this.refresh(dn);}