diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py index 6856f62d0c6..36c23653577 100644 --- a/erpnext/accounts/doctype/sales_invoice/pos.py +++ b/erpnext/accounts/doctype/sales_invoice/pos.py @@ -92,6 +92,7 @@ def update_pos_profile_data(doc, pos_profile, company_data): doc.customer_group = pos_profile.get('customer_group') or get_root('Customer Group') doc.territory = pos_profile.get('territory') or get_root('Territory') doc.terms = frappe.db.get_value('Terms and Conditions', pos_profile.get('tc_name'), 'terms') or doc.terms or '' + doc.offline_pos_name = '' def get_root(table): root = frappe.db.sql(""" select name from `tab%(table)s` having diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 888520ac769..995a333ebad 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -70,7 +70,6 @@ class SalesInvoice(SellingController): self.clear_unallocated_advances("Sales Invoice Advance", "advances") self.add_remarks() self.validate_write_off_account() - self.validate_duplicate_offline_pos_entry() self.validate_account_for_change_amount() self.validate_fixed_asset() self.set_income_account_for_fixed_assets() @@ -464,12 +463,6 @@ class SalesInvoice(SellingController): if flt(self.write_off_amount) and not self.write_off_account: msgprint(_("Please enter Write Off Account"), raise_exception=1) - def validate_duplicate_offline_pos_entry(self): - if self.is_pos and self.offline_pos_name \ - and frappe.db.get_value('Sales Invoice', - {'offline_pos_name': self.offline_pos_name, 'docstatus': 1}): - frappe.throw(_("Duplicate offline pos sales invoice {0}").format(self.offline_pos_name)) - def validate_account_for_change_amount(self): if flt(self.change_amount) and not self.account_for_change_amount: msgprint(_("Please enter Account for Change Amount"), raise_exception=1) diff --git a/erpnext/accounts/page/pos/pos.js b/erpnext/accounts/page/pos/pos.js index c442062ab6f..6b580335262 100644 --- a/erpnext/accounts/page/pos/pos.js +++ b/erpnext/accounts/page/pos/pos.js @@ -179,41 +179,12 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ } }, - dialog_actions: function () { - var me = this; - - $(this.list_body).find('.list-select-all').click(function () { - me.removed_items = []; - $(me.list_body).find('.list-delete').prop("checked", $(this).is(":checked")) - if ($(this).is(":checked")) { - $.each(me.si_docs, function (index, data) { - for (key in data) { - me.removed_items.push(key) - } - }) - } - - me.toggle_delete_button(); - }) - - $(this.list_body).find('.list-delete').click(function () { - me.name = $(this).parent().parent().attr('invoice-name'); - if ($(this).is(":checked")) { - me.removed_items.push(me.name); - } else { - me.removed_items.pop(me.name) - } - - me.toggle_delete_button(); - }) - }, - edit_record: function () { var me = this; doc_data = this.get_invoice_doc(this.si_docs); if (doc_data) { - this.frm.doc = doc_data[0][this.name]; + this.frm.doc = doc_data[0][this.frm.doc.offline_pos_name]; this.set_missing_values(); this.refresh(false); this.toggle_input_field(); @@ -226,16 +197,15 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ this.validate_list() this.remove_doc_from_localstorage() this.update_localstorage(); - // this.dialog_actions(); this.toggle_delete_button(); }, validate_list: function() { var me = this; this.si_docs = this.get_submitted_invoice() - $.each(this.removed_items, function(index, name){ + $.each(this.removed_items, function(index, pos_name){ $.each(me.si_docs, function(key, data){ - if(me.si_docs[key][name] && me.si_docs[key][name].offline_pos_name == name ){ + if(me.si_docs[key][pos_name] && me.si_docs[key][pos_name].offline_pos_name == pos_name ){ frappe.throw(__("Submitted orders can not be deleted")) } }) @@ -294,7 +264,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ return $.grep(this.si_docs, function (data) { for (key in data) { - return key == me.name + return key == me.frm.doc.offline_pos_name; } }) }, @@ -348,7 +318,6 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ create_new: function () { var me = this; this.frm = {} - this.name = null; this.load_data(true); this.setup(); this.set_default_customer() @@ -362,6 +331,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ if (load_doc) { this.frm.doc = JSON.parse(localStorage.getItem('doc')); + this.frm.doc.offline_pos_name = null; } $.each(this.meta, function (i, data) { @@ -629,6 +599,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ // this.list_customers.empty(); this.si_docs = this.get_doc_from_localstorage(); if (!this.si_docs.length) { + this.list_customers.find('.list-customers-table').html(""); return; } @@ -655,7 +626,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ me.list_customers_btn.toggleClass("view_customer"); me.pos_bill.show(); me.list_customers_btn.show(); - me.name = $(this).parents().attr('invoice-name') + me.frm.doc.offline_pos_name = $(this).parents().attr('invoice-name') me.edit_record(); }) @@ -675,11 +646,11 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ }); $(this.wrapper).find('.list-delete').click(function () { - me.name = $(this).parent().parent().attr('invoice-name'); + me.frm.doc.offline_pos_name = $(this).parent().parent().attr('invoice-name'); if ($(this).is(":checked")) { - me.removed_items.push(me.name); + me.removed_items.push(me.frm.doc.offline_pos_name); } else { - me.removed_items.pop(me.name) + me.removed_items.pop(me.frm.doc.offline_pos_name) } me.toggle_delete_button(); @@ -1435,7 +1406,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ }, update_paid_amount_status: function (update_paid_amount) { - if (this.name) { + if (this.frm.doc.offline_pos_name) { update_paid_amount = update_paid_amount ? false : true; } @@ -1643,18 +1614,17 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ create_invoice: function () { var me = this; - var invoice_data = {} + var invoice_data = {}; this.si_docs = this.get_doc_from_localstorage(); - if (this.name) { - this.update_invoice() + if (this.frm.doc.offline_pos_name) { + this.update_invoice(); } else { - this.name = $.now(); - this.frm.doc.offline_pos_name = this.name; + this.frm.doc.offline_pos_name = $.now(); this.frm.doc.posting_date = frappe.datetime.get_today(); this.frm.doc.posting_time = frappe.datetime.now_time(); this.frm.doc.pos_profile = this.pos_profile_data['name']; - invoice_data[this.name] = this.frm.doc - this.si_docs.push(invoice_data) + invoice_data[this.frm.doc.offline_pos_name] = this.frm.doc; + this.si_docs.push(invoice_data); this.update_localstorage(); this.set_primary_action(); } @@ -1666,12 +1636,12 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ this.si_docs = this.get_doc_from_localstorage(); $.each(this.si_docs, function (index, data) { for (var key in data) { - if (key == me.name) { + if (key == me.frm.doc.offline_pos_name) { me.si_docs[index][key] = me.frm.doc; me.update_localstorage(); } } - }) + }); }, update_localstorage: function () { @@ -1710,6 +1680,8 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ freeze_screen = this.freeze_screen || false; if ((this.si_docs.length || this.email_queue_list || this.customers_list) && !this.freeze) { + this.freeze = true; + frappe.call({ method: "erpnext.accounts.doctype.sales_invoice.pos.make_invoice", freeze: freeze_screen, @@ -1720,17 +1692,19 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ }, callback: function (r) { if (r.message) { + me.freeze = false; me.customers = r.message.synced_customers_list; me.address = r.message.synced_address; me.contacts = r.message.synced_contacts; me.removed_items = r.message.invoice; - me.removed_email = r.message.email_queue - me.removed_customers = r.message.customers + me.removed_email = r.message.email_queue; + me.removed_customers = r.message.customers; me.remove_doc_from_localstorage(); me.remove_email_queue_from_localstorage(); me.remove_customer_from_localstorage(); - me.prepare_customer_mapper() - me.autocomplete_customers() + me.prepare_customer_mapper(); + me.autocomplete_customers(); + me.render_list_customers(); } } })