From 539e913b464fbb096b680916600d06aaec9c6174 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 7 Jul 2016 16:44:40 +0530 Subject: [PATCH] [Fix] Access is pos from sales invoice form. --- erpnext/accounts/doctype/sales_invoice/pos.py | 4 +-- .../doctype/sales_invoice/sales_invoice.js | 35 ++++++++++++++++++- .../doctype/sales_invoice/sales_invoice.json | 4 +-- .../doctype/sales_invoice/sales_invoice.py | 5 +++ erpnext/accounts/page/pos/pos.js | 7 ++-- 5 files changed, 46 insertions(+), 9 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py index ec0e50c378..c6191da9f0 100644 --- a/erpnext/accounts/doctype/sales_invoice/pos.py +++ b/erpnext/accounts/doctype/sales_invoice/pos.py @@ -30,6 +30,7 @@ def get_pos_data(): return { 'doc': doc, + 'default_customer': pos_profile.get('customer'), 'items': get_items(doc, pos_profile), 'customers': get_customers(pos_profile, doc), 'pricing_rules': get_pricing_rules(doc), @@ -122,9 +123,6 @@ def get_items(doc, pos_profile): def get_customers(pos_profile, doc): filters = {'disabled': 0} customer_list = [] - if pos_profile.get('customer'): - filters.update({'name': pos_profile.customer}) - customers = frappe.get_all("Customer", fields=["*"], filters = filters) for customer in customers: diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 4bc634a323..f39c983887 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -239,6 +239,32 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte } }) } + }, + + is_pos: function(frm){ + if(this.frm.doc.is_pos) { + if(!this.frm.doc.company) { + this.frm.set_value("is_pos", 0); + msgprint(__("Please specify Company to proceed")); + } else { + var me = this; + return this.frm.call({ + doc: me.frm.doc, + method: "set_missing_values", + callback: function(r) { + if(!r.exc) { + if(r.message && r.message.print_format) { + frm.pos_print_format = r.message.print_format; + } + me.frm.script_manager.trigger("update_stock"); + frappe.model.set_default_values(me.frm.doc); + me.set_dynamic_labels(); + me.calculate_taxes_and_totals(); + } + } + }); + } + } } }); @@ -430,7 +456,14 @@ frappe.ui.form.on('Sales Invoice', { ] } } - } + + if(frm.doc.is_pos){ + frm.get_field('payments').grid.editable_fields = [ + {fieldname: 'mode_of_payment', columns: 2}, + {fieldname: 'amount', columns: 2} + ]; + } + }, }) frappe.ui.form.on('Sales Invoice Timesheet', { diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index 746209f20f..af5790f9ba 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -2071,7 +2071,7 @@ { "allow_on_submit": 0, "bold": 0, - "collapsible": 1, + "collapsible": 0, "collapsible_depends_on": "", "depends_on": "eval:doc.is_pos===1||(doc.advances && doc.advances.length>0)", "fieldname": "payments_section", @@ -3676,7 +3676,7 @@ "istable": 0, "max_attachments": 0, "menu_index": 0, - "modified": "2016-07-02 20:10:14.146963", + "modified": "2016-07-07 13:40:27.977803", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice", diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index bacee7f5b6..1b68a838dc 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -9,6 +9,7 @@ from frappe import _, msgprint, throw from erpnext.accounts.party import get_party_account, get_due_date from erpnext.controllers.stock_controller import update_gl_entries_after from frappe.model.mapper import get_mapped_doc +from erpnext.accounts.doctype.sales_invoice.pos import update_multi_mode_option from erpnext.controllers.selling_controller import SellingController from erpnext.accounts.utils import get_account_currency @@ -291,6 +292,10 @@ class SalesInvoice(SellingController): if self.taxes_and_charges and not len(self.get("taxes")): self.set_taxes() + if not self.get('payments'): + pos_profile = frappe.get_doc('POS Profile', pos.name) + update_multi_mode_option(self, pos_profile) + return pos def get_company_abbr(self): diff --git a/erpnext/accounts/page/pos/pos.js b/erpnext/accounts/page/pos/pos.js index a1a502aea4..fcccfb4625 100644 --- a/erpnext/accounts/page/pos/pos.js +++ b/erpnext/accounts/page/pos/pos.js @@ -202,6 +202,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ window.pricing_rules = r.message.pricing_rules; window.meta = r.message.meta; window.print_template = r.message.print_template; + me.default_customer = r.message.default_customer || null; me.write_off_account = r.message.write_off_account; localStorage.setItem('doc', JSON.stringify(r.message.doc)); if(callback){ @@ -301,9 +302,9 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ make_customer: function() { var me = this; - if(this.customers.length == 1){ - this.party_field.$input.val(this.customers[0].name); - this.frm.doc.customer = this.customers[0].name; + if(this.default_customer){ + this.party_field.$input.val(this.default_customer); + this.frm.doc.customer = this.default_customer; } this.party_field.$input.autocomplete({