From b719dc53fce60495b5992a6a2be65495dbd13d0d Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 23 Mar 2017 17:04:00 +0530 Subject: [PATCH] [fix] customer edit and numeric keypad visibility issue in the pos --- erpnext/accounts/doctype/sales_invoice/pos.py | 14 +++- erpnext/accounts/page/pos/pos.js | 67 ++++++++++++------- 2 files changed, 55 insertions(+), 26 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py index 49e2f15daa6..59766bd7b2b 100644 --- a/erpnext/accounts/doctype/sales_invoice/pos.py +++ b/erpnext/accounts/doctype/sales_invoice/pos.py @@ -170,6 +170,9 @@ def get_customers_list(pos_profile): def get_customers_address(customers): customer_address = {} + if isinstance(customers, basestring): + customers = [frappe._dict({'name': customers})] + for data in customers: address = frappe.db.sql(""" select name, address_line1, address_line2, city, state, email_id, phone, fax, pincode from `tabAddress` where is_primary_address =1 and name in @@ -292,6 +295,7 @@ def make_invoice(doc_list={}, email_queue_list={}, customers_list={}): if not frappe.db.exists('Sales Invoice', {'offline_pos_name': name}): validate_records(doc) si_doc = frappe.new_doc('Sales Invoice') + si_doc.due_date = doc.get('posting_date') si_doc.offline_pos_name = name si_doc.update(doc) submit_invoice(si_doc, name, doc) @@ -328,10 +332,16 @@ def add_customer(name): customer_doc.flags.ignore_mandatory = True customer_doc.save(ignore_permissions = True) frappe.db.commit() + return customer_doc.name def make_address(args, customer): - if args.get('name'): - address = frappe.get_doc('Address', args.get('name')) + if not args.get('address_line1'): return + + name = args.get('name') or get_customers_address(customer)[customer].get("name") + + if name: + address = frappe.get_doc('Address', name) + frappe.errprint(address) else: address = frappe.new_doc('Address') address.country = frappe.db.get_value('Company', args.get('company'), 'country') diff --git a/erpnext/accounts/page/pos/pos.js b/erpnext/accounts/page/pos/pos.js index 8d9efeaf12d..fb89d7e4527 100644 --- a/erpnext/accounts/page/pos/pos.js +++ b/erpnext/accounts/page/pos/pos.js @@ -475,6 +475,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ this.pos_bill = this.wrapper.find('.pos-bill-wrapper').hide(); this.list_customers = this.wrapper.find('.list-customers'); this.numeric_keypad = this.wrapper.find('.numeric_keypad'); + this.list_customers_btn.addClass("view_customer") me.render_list_customers(); me.toggle_totals_area(false); @@ -495,9 +496,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ me.toggle_totals_area(false); me.toggle_delete_button() me.list_customers.hide(); - if(me.frm.doc.items.length > 0) { - me.numeric_keypad.show(); - } + me.numeric_keypad.show(); } }); this.add_customer_btn.on('click', function() { @@ -694,7 +693,8 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ .get(0); } }); - var customers = this.customers.map(function (c) { + + this.customers_mapper = this.customers.map(function (c) { return { label: c.name, value: c.name, @@ -703,7 +703,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ } }); - customers.push({ + this.customers_mapper.push({ label: "" + " " + __("Create a new Customer") @@ -711,11 +711,11 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ value: 'is_action', action: me.add_customer }); - this.party_field.awesomeplete.list = customers; + this.autocomplete_customers(); this.party_field.$input .on('input', function (e) { - me.party_field.awesomeplete.list = customers; + me.party_field.awesomeplete.list = this.customers_mapper; }) .on('awesomplete-select', function (e) { var customer = me.party_field.awesomeplete @@ -731,6 +731,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ me.update_customer_data(customer); me.refresh(); me.set_focus(); + me.list_customers_btn.removeClass("view_customer"); }) .on('focus', function (e) { $(e.target).val('').trigger('input'); @@ -754,6 +755,10 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ }); }, + autocomplete_customers: function() { + this.party_field.awesomeplete.list = this.customers_mapper; + }, + toggle_edit_button: function(flag) { this.page.wrapper.find('.edit-customer-btn').toggle(flag); }, @@ -768,10 +773,10 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ add_customer: function() { this.frm.doc.customer = ""; - this.update_customer() + this.update_customer(true) }, - update_customer: function () { + update_customer: function (new_customer) { var me = this; if (!this.connection_status) return; @@ -844,14 +849,14 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ this.render_address_data() this.customer_doc.set_primary_action(__("Save"), function () { - me.make_offline_customer(); + me.make_offline_customer(new_customer); me.pos_bill.show(); }); }, render_address_data: function() { var me = this; - this.address_data = this.address[this.frm.doc.customer] || this.get_address_from_localstorage(); + this.address_data = this.address[this.frm.doc.customer]; this.customer_doc.set_values(this.address_data) if(!this.customer_doc.fields_dict.full_name.$input.val()) { @@ -864,20 +869,32 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ return this.address_details[this.frm.doc.customer] }, - make_offline_customer: function() { + make_offline_customer: function(new_customer) { this.frm.doc.customer = this.frm.doc.customer || this.customer_doc.get_values().full_name; this.customer_details = this.get_customers_details(); this.customer_details[this.frm.doc.customer] = this.get_prompt_details(); this.party_field.$input.val(this.frm.doc.customer); - this.customers.push({ - name: this.frm.doc.customer, - customer_name: this.frm.doc.customer - }); + this.update_address_and_customer_list(new_customer) + this.autocomplete_customers(); this.update_customer_in_localstorage() this.update_customer_in_localstorage() this.customer_doc.hide() }, + update_address_and_customer_list: function(new_customer) { + var me = this; + if(new_customer) { + this.customers_mapper.push({ + label: this.frm.doc.customer, + value: this.frm.doc.customer, + customer_group: "", + territory: "" + }); + } + + this.address[this.frm.doc.customer] = this.customer_doc.get_values(); + }, + get_prompt_details: function() { this.prompt_details = this.customer_doc.get_values(); this.prompt_details['country'] = this.pos_profile_data.country; @@ -1072,7 +1089,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ // if form is local then allow this function // $(me.wrapper).find(".pos-item-wrapper").on("click", function () { $(this.wrapper).on("click", ".pos-item-wrapper", function () { - if(me.list_customers_btn.hasClass("view_customer")) return; + if($(me.pos_bill).is(":hidden")) return; me.customer_validate(); if (me.frm.doc.docstatus == 0) { @@ -1221,7 +1238,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ customer_validate: function () { var me = this; - if (!this.frm.doc.customer) { + if (!this.frm.doc.customer || this.party_field.get_value() == "") { frappe.throw(__("Please select customer")) } }, @@ -1458,12 +1475,14 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ sn = data.serial_no.split('\n') if(sn.length) { serial_no_list = me.serial_no_data[data.item_code] - $.each(sn, function(i, serial_no) { - if(in_list(Object.keys(serial_no_list), serial_no)) { - delete serial_no_list[serial_no] - } - }) - me.serial_no_data[data.item_code] = serial_no_list; + if(serial_no_list) { + $.each(sn, function(i, serial_no) { + if(in_list(Object.keys(serial_no_list), serial_no)) { + delete serial_no_list[serial_no] + } + }) + me.serial_no_data[data.item_code] = serial_no_list; + } } }) },