diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.json b/erpnext/accounts/doctype/pos_profile/pos_profile.json index b1420fc2a19..a7e49dd48f4 100644 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.json +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.json @@ -307,10 +307,10 @@ "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, - "label": "Payments", + "label": "Sales Invoice Payment", "length": 0, "no_copy": 0, - "options": "Payments", + "options": "Sales Invoice Payment", "permlevel": 0, "precision": "", "print_hide": 0, @@ -350,6 +350,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "default": "Point of Sale", "fieldname": "print_format", "fieldtype": "Link", "hidden": 0, @@ -824,13 +825,14 @@ "hide_toolbar": 0, "icon": "icon-cog", "idx": 1, + "image_view": 0, "in_create": 0, "in_dialog": 0, "is_submittable": 0, "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2016-05-25 15:00:09.335025", + "modified": "2016-06-13 21:20:13.805101", "modified_by": "Administrator", "module": "Accounts", "name": "POS Profile", diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py index 9689328898c..54d47b5e3e1 100644 --- a/erpnext/accounts/doctype/sales_invoice/pos.py +++ b/erpnext/accounts/doctype/sales_invoice/pos.py @@ -25,15 +25,16 @@ def get_pos_data(): update_pos_profile_data(doc, pos_profile) update_multi_mode_option(doc, pos_profile) - print_template = frappe.db.get_value('Print Format', pos_profile.get('print_format'), 'html') or '' + default_print_format = pos_profile.get('print_format') or "Point of Sale" + print_template = frappe.db.get_value('Print Format', default_print_format, 'html') return { 'doc': doc, 'items': get_items(doc, pos_profile), 'customers': get_customers(pos_profile, doc), 'pricing_rules': get_pricing_rules(doc), - 'mode_of_payment': get_mode_of_payment(doc), 'print_template': print_template, + 'write_off_account': pos_profile.get('write_off_account'), 'meta': { 'invoice': frappe.get_meta('Sales Invoice'), 'items': frappe.get_meta('Sales Invoice Item'), @@ -70,11 +71,11 @@ def update_multi_mode_option(doc, pos_profile): from frappe.model import default_fields if not pos_profile: - for payment in frappe.get_all('Mode of Payment Account', fields=["default_account", "parent"], - filters = {'company': doc.company}): + for payment in get_mode_of_payment(doc): payments = doc.append('payments', {}) payments.mode_of_payment = payment.parent payments.account = payment.default_account + payments.type = payment.type return @@ -87,6 +88,10 @@ def update_multi_mode_option(doc, pos_profile): doc.append('payments', payment_mode) +def get_mode_of_payment(doc): + return frappe.db.sql(""" select mpa.default_account, mpa.parent, mp.type as type from `tabMode of Payment Account` mpa, + `tabMode of Payment` mp where mpa.parent = mp.name and company = %(company)s""", {'company': doc.company}, as_dict=1) + def update_tax_table(doc): taxes = get_taxes_and_charges('Sales Taxes and Charges Template', doc.taxes_and_charges) for tax in taxes: @@ -136,9 +141,6 @@ def get_pricing_rules(doc): ifnull(valid_from, '2000-01-01') and ifnull(valid_upto, '2500-12-31') order by priority desc, name desc""", {'company': doc.company, 'price_list': doc.selling_price_list, 'date': nowdate()}, as_dict=1) -def get_mode_of_payment(doc): - return frappe.get_all('Mode of Payment Account', fields = ['distinct parent'], filters={'company': doc.company}) - @frappe.whitelist() def make_invoice(doc_list): if isinstance(doc_list, basestring): diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index 9da4aaef0dc..357dec2b935 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -2055,10 +2055,10 @@ "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, - "label": "Payments", + "label": "Sales Invoice Payment", "length": 0, "no_copy": 0, - "options": "Payments", + "options": "Sales Invoice Payment", "permlevel": 0, "precision": "", "print_hide": 1, @@ -3589,6 +3589,7 @@ "hide_toolbar": 0, "icon": "icon-file-text", "idx": 181, + "image_view": 0, "in_create": 0, "in_dialog": 0, "is_submittable": 1, @@ -3596,7 +3597,7 @@ "istable": 0, "max_attachments": 0, "menu_index": 0, - "modified": "2016-05-09 15:03:33.236351", + "modified": "2016-06-10 12:57:08.818701", "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 109a9ebcbfe..2584d407d56 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -650,6 +650,7 @@ class SalesInvoice(SellingController): # write off entries, applicable if only pos if self.write_off_account and self.write_off_amount: write_off_account_currency = get_account_currency(self.write_off_account) + default_cost_center = frappe.db.get_value('Company', self.company, 'cost_center') gl_entries.append( self.get_gl_dict({ @@ -671,7 +672,7 @@ class SalesInvoice(SellingController): "debit": self.base_write_off_amount, "debit_in_account_currency": self.base_write_off_amount \ if write_off_account_currency==self.company_currency else self.write_off_amount, - "cost_center": self.write_off_cost_center + "cost_center": self.write_off_cost_center or default_cost_center }, write_off_account_currency) ) diff --git a/erpnext/accounts/doctype/payments/__init__.py b/erpnext/accounts/doctype/sales_invoice_payment/__init__.py similarity index 100% rename from erpnext/accounts/doctype/payments/__init__.py rename to erpnext/accounts/doctype/sales_invoice_payment/__init__.py diff --git a/erpnext/accounts/doctype/payments/payments.json b/erpnext/accounts/doctype/sales_invoice_payment/sales_invoice_payment.json similarity index 97% rename from erpnext/accounts/doctype/payments/payments.json rename to erpnext/accounts/doctype/sales_invoice_payment/sales_invoice_payment.json index d52fb1519c6..6a17483cc7a 100644 --- a/erpnext/accounts/doctype/payments/payments.json +++ b/erpnext/accounts/doctype/sales_invoice_payment/sales_invoice_payment.json @@ -169,16 +169,17 @@ "hide_heading": 0, "hide_toolbar": 0, "idx": 0, + "image_view": 0, "in_create": 0, "in_dialog": 0, "is_submittable": 0, "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2016-05-09 00:14:18.975568", + "modified": "2016-06-10 12:54:18.343417", "modified_by": "Administrator", "module": "Accounts", - "name": "Payments", + "name": "Sales Invoice Payment", "name_case": "", "owner": "Administrator", "permissions": [], diff --git a/erpnext/accounts/doctype/payments/payments.py b/erpnext/accounts/doctype/sales_invoice_payment/sales_invoice_payment.py similarity index 87% rename from erpnext/accounts/doctype/payments/payments.py rename to erpnext/accounts/doctype/sales_invoice_payment/sales_invoice_payment.py index 15cf0b26a77..cc0b7a620db 100644 --- a/erpnext/accounts/doctype/payments/payments.py +++ b/erpnext/accounts/doctype/sales_invoice_payment/sales_invoice_payment.py @@ -6,5 +6,5 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document -class Payments(Document): +class SalesInvoicePayment(Document): pass diff --git a/erpnext/accounts/page/pos/pos.js b/erpnext/accounts/page/pos/pos.js index 2bff8414bf7..f3c8c33ca69 100644 --- a/erpnext/accounts/page/pos/pos.js +++ b/erpnext/accounts/page/pos/pos.js @@ -12,6 +12,9 @@ frappe.pages['pos'].on_page_load = function(wrapper) { } frappe.pages['pos'].refresh = function(wrapper) { + window.onbeforeunload = function () { + return wrapper.pos.beforeunload() + } wrapper.pos.on_refresh_page() } @@ -39,6 +42,21 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ } }, + beforeunload: function(e){ + if(this.connection_status == false && frappe.get_route()[0] == "pos"){ + e = e || window.event; + + // For IE and Firefox prior to version 4 + if (e) { + e.returnValue = __("You are in offline mode. You will not be able to reload until you have network."); + return + } + + // For Safari + return __("You are in offline mode. You will not be able to reload until you have network."); + } + }, + check_internet_connection: function(){ var me = this; //Check Internet connection after every 30 seconds @@ -76,19 +94,19 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ var me = this; this.page.add_menu_item(__("New Sales Invoice"), function() { - me.save_previous_entry() - me.create_new() + me.save_previous_entry(); + me.create_new(); }) this.page.add_menu_item(__("View Offline Records"), function(){ - me.show_unsync_invoice_list() + me.show_unsync_invoice_list(); }); this.page.add_menu_item(__("Sync Master Data"), function(){ me.get_data_from_server(function(){ - me.load_data() - me.make_customer() - me.make_item_list() + me.load_data(); + me.make_customer(); + me.make_item_list(); }) }); @@ -107,36 +125,40 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ this.list_dialog.show(); this.list_body = this.list_dialog.body; - $(this.list_body).append('
No payment mode selected in pos profile
").appendTo(multimode_payments) } }, + + set_outstanding_amount: function(){ + this.selected_mode = $(this.$body).find(repl("input[idx='%(idx)s']",{'idx': this.idx})); + this.highlight_selected_row() + this.payment_val = 0.0 + if(this.frm.doc.outstanding_amount > 0 && flt(this.selected_mode.val()) == 0.0){ + //When user first tithis click on row + this.payment_val = flt(this.frm.doc.outstanding_amount) + this.selected_mode.val(format_number(this.payment_val, 2)); + this.update_paid_amount() + }else if(flt(this.selected_mode.val()) > 0){ + //If user click on existing row which has value + this.payment_val = flt(this.selected_mode.val()); + } + this.selected_mode.select() + this.bind_amount_change_event(); + }, bind_keyboard_event: function(){ var me = this; @@ -69,28 +92,15 @@ erpnext.payments = erpnext.stock.StockController.extend({ this.bind_payment_mode_keys_event(); this.bind_keyboard_keys_event(); }, - + bind_payment_mode_keys_event: function(){ var me = this; $(this.$body).find('.pos-payment-row').click(function(){ me.idx = $(this).attr("idx"); - me.selected_mode = $(me.$body).find(repl("input[idx='%(idx)s']",{'idx': me.idx})); - me.highlight_selected_row() - me.payment_val = 0.0 - if(me.frm.doc.outstanding_amount > 0 && flt(me.selected_mode.val()) == 0.0){ - //When user first time click on row - me.payment_val = flt(me.frm.doc.outstanding_amount) - me.selected_mode.val(format_number(me.payment_val, 2)); - me.update_paid_amount() - }else if(flt(me.selected_mode.val()) > 0){ - //If user click on existing row which has value - me.payment_val = flt(me.selected_mode.val()); - } - me.selected_mode.select() - me.bind_amount_change_event(); + me.set_outstanding_amount() }) }, - + highlight_selected_row: function(){ var me = this; selected_row = $(this.$body).find(repl(".pos-payment-row[idx='%(idx)s']",{'idx': this.idx})); @@ -127,7 +137,19 @@ erpnext.payments = erpnext.stock.StockController.extend({ me.update_paid_amount() }) }, - + + clear_amount: function(){ + var me = this; + $(this.$body).find('.clr').click(function(e){ + e.stopPropagation(); + me.idx = $(this).attr("idx"); + me.selected_mode = $(me.$body).find(repl("input[idx='%(idx)s']",{'idx': me.idx})); + me.payment_val = 0.0; + me.selected_mode.val(0.0); + me.update_paid_amount(); + }) + }, + update_paid_amount: function(){ var me = this; $.each(this.frm.doc.payments, function(index, data){ diff --git a/erpnext/public/js/pos/pos_invoice_list.html b/erpnext/public/js/pos/pos_invoice_list.html index cb25072756c..c0b47641296 100644 --- a/erpnext/public/js/pos/pos_invoice_list.html +++ b/erpnext/public/js/pos/pos_invoice_list.html @@ -1,6 +1,6 @@