From fd3751616519961f337277c7d6e1219047c595bc Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 2 May 2017 18:27:09 +0530 Subject: [PATCH] [fix] Contact not creating if only email id has entered in the POS --- erpnext/accounts/doctype/sales_invoice/pos.py | 25 +++++++++++++++++++ erpnext/accounts/page/pos/pos.js | 1 + 2 files changed, 26 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py index f1f997a7f6..a899cde25d 100644 --- a/erpnext/accounts/doctype/sales_invoice/pos.py +++ b/erpnext/accounts/doctype/sales_invoice/pos.py @@ -325,8 +325,10 @@ def make_customer_and_address(customers): if not frappe.db.exists('Customer', name): name = add_customer(name) data = json.loads(data) + make_contact(data, name) make_address(data, name) customer_list.append(name) + frappe.db.commit() return customer_list def add_customer(name): @@ -340,6 +342,29 @@ def add_customer(name): frappe.db.commit() return customer_doc.name +def make_contact(args,customer): + if args.get('email_id') or args.get('phone'): + name = frappe.db.get_value('Dynamic Link', + {'link_doctype': 'Customer', 'link_name': customer, 'parenttype': 'Contact'}, 'parent') + + args = { + 'email_id': args.get('email_id'), + 'phone': args.get('phone') + } + + doc = frappe.new_doc('Contact') + if name: + doc = frappe.get_doc('Contact', name) + + doc.update(args) + if not name: + doc.first_name = customer + doc.append('links',{ + 'link_doctype': 'Customer', + 'link_name': customer + }) + doc.save(ignore_permissions=True) + def make_address(args, customer): if not args.get('address_line1'): return diff --git a/erpnext/accounts/page/pos/pos.js b/erpnext/accounts/page/pos/pos.js index 9c195f9512..c632e459e3 100644 --- a/erpnext/accounts/page/pos/pos.js +++ b/erpnext/accounts/page/pos/pos.js @@ -866,6 +866,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ this.customer_doc.set_primary_action(__("Save"), function () { me.make_offline_customer(new_customer); me.pos_bill.show(); + me.list_customers.hide(); }); },