From 7127a8f522b998cb461eec78a47cf9d73365917b Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 4 Aug 2016 14:56:15 +0530 Subject: [PATCH] Allow user to edit change amount from sales invoice form for is pos --- .../doctype/pos_profile/pos_profile.json | 26 ++++ .../doctype/sales_invoice/sales_invoice.js | 9 ++ .../doctype/sales_invoice/sales_invoice.json | 130 ++++++++++++++---- .../doctype/sales_invoice/sales_invoice.py | 8 +- erpnext/controllers/taxes_and_totals.py | 4 + .../public/js/controllers/taxes_and_totals.js | 6 + 6 files changed, 151 insertions(+), 32 deletions(-) diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.json b/erpnext/accounts/doctype/pos_profile/pos_profile.json index cb637d254a..8882491866 100644 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.json +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.json @@ -690,6 +690,32 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "change_amount_account", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Change Amount Account", + "length": 0, + "no_copy": 0, + "options": "Account", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_on_submit": 0, "bold": 0, diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index b73673fe94..417d3468f2 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -267,6 +267,15 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte amount: function(){ this.write_off_outstanding_amount_automatically() + }, + + change_amount: function(){ + if((this.frm.doc.paid_amount - this.frm.doc.grand_total) < this.frm.doc.change_amount){ + this.frm.set_value("change_amount", 0.0) + frappe.msgprint(__("You can not return change amount, limit has been exceeded")) + }else{ + this.calculate_write_off_amount() + } } }); diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index 06bc6359b9..df7f89ed69 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -2200,32 +2200,6 @@ "set_only_once": 0, "unique": 0 }, - { - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "fieldname": "base_change_amount", - "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_list_view": 0, - "label": "Base Change Amount (Company Currency)", - "length": 0, - "no_copy": 1, - "options": "Company:company:default_currency", - "permlevel": 0, - "precision": "", - "print_hide": 1, - "print_hide_if_no_value": 0, - "read_only": 1, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, { "allow_on_submit": 0, "bold": 0, @@ -2278,6 +2252,80 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "section_break_88", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "base_change_amount", + "fieldtype": "Currency", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Base Change Amount (Company Currency)", + "length": 0, + "no_copy": 1, + "options": "Company:company:default_currency", + "permlevel": 0, + "precision": "", + "print_hide": 1, + "print_hide_if_no_value": 0, + "read_only": 1, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "column_break_90", + "fieldtype": "Column Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_on_submit": 0, "bold": 0, @@ -2297,7 +2345,33 @@ "precision": "", "print_hide": 1, "print_hide_if_no_value": 0, - "read_only": 1, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "change_amount_account", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Change Amount Account", + "length": 0, + "no_copy": 0, + "options": "Account", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -3677,7 +3751,7 @@ "istable": 0, "max_attachments": 0, "menu_index": 0, - "modified": "2016-08-03 11:50:49.680278", + "modified": "2016-08-04 05:08:15.008493", "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 f055140348..bc2c3b8cfa 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -233,6 +233,10 @@ class SalesInvoice(SellingController): from erpnext.stock.get_item_details import get_pos_profile_item_details, get_pos_profile pos = get_pos_profile(self.company) + if not self.get('payments'): + pos_profile = frappe.get_doc('POS Profile', pos.name) if pos else None + update_multi_mode_option(self, pos_profile) + if pos: if not for_validate and not self.customer: self.customer = pos.customer @@ -265,10 +269,6 @@ 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/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 28b2f7c756..afb3befcfc 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -440,6 +440,7 @@ class calculate_taxes_and_totals(object): paid_amount = self.doc.paid_amount \ if self.doc.party_account_currency == self.doc.currency else self.doc.base_paid_amount + self.calculate_write_off_amount() self.calculate_change_amount() self.doc.outstanding_amount = flt(total_amount_to_pay - flt(paid_amount) + @@ -468,6 +469,9 @@ class calculate_taxes_and_totals(object): self.doc.base_change_amount = flt(self.doc.change_amount * self.doc.conversion_rate, self.doc.precision("base_change_amount")) + def calculate_write_off_amount(self): + self.doc.write_off_amount = self.doc.grand_total - self.doc.paid_amount + self.doc.change_amount + def calculate_margin(self, item): total_margin = 0.0 if item.price_list_rate: diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 576bc7137b..ad6f0ed4f9 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -615,4 +615,10 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ this.frm.doc.base_change_amount = flt(this.frm.doc.change_amount * this.frm.doc.conversion_rate, precision("base_change_amount")); }, + + calculate_write_off_amount: function(){ + this.frm.set_value("write_off_amount", + flt(this.frm.doc.grand_total - this.frm.doc.paid_amount + this.frm.doc.change_amount, + precision("write_off_amount"))); + } })