From 57914f140e9ff27187c4bcdd84fdcc72c4da69ba Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Tue, 24 Apr 2018 19:19:47 +0530 Subject: [PATCH] [HotFix] Taxes not adding in POS sales invoice (#13776) --- .../doctype/sales_invoice/sales_invoice.js | 1 + .../doctype/sales_invoice/sales_invoice.py | 4 +-- erpnext/controllers/accounts_controller.py | 7 ++++- erpnext/patches.txt | 3 ++- erpnext/patches/v10_0/taxes_issue_with_pos.py | 26 +++++++++++++++++++ 5 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 erpnext/patches/v10_0/taxes_issue_with_pos.py diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index bb2d071dc2..2fcca755d8 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -319,6 +319,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte }, pos_profile: function() { + this.frm.doc.taxes = [] this.set_pos_data(); }, diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index d8220528d4..b174d9b224 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -344,8 +344,8 @@ class SalesInvoice(SellingController): self.terms = frappe.db.get_value("Terms and Conditions", self.tc_name, "terms") # fetch charges - if self.taxes_and_charges: - self.set_other_charges() + if self.taxes_and_charges and not len(self.get("taxes")): + self.set_taxes() return pos diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index d690241736..4cca72007f 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -232,7 +232,7 @@ class AccountsController(TransactionBase): tax_master_doctype = self.meta.get_field("taxes_and_charges").options - if self.is_new() and not self.get("taxes"): + if (self.is_new() or self.is_pos_profile_changed()) and not self.get("taxes"): if self.company and not self.get("taxes_and_charges"): # get the default tax master self.taxes_and_charges = frappe.db.get_value(tax_master_doctype, @@ -240,6 +240,11 @@ class AccountsController(TransactionBase): self.append_taxes_from_master(tax_master_doctype) + def is_pos_profile_changed(self): + if (self.doctype == 'Sales Invoice' and self.is_pos and + self.pos_profile != frappe.db.get_value('Sales Invoice', self.name, 'pos_profile')): + return True + def append_taxes_from_master(self, tax_master_doctype=None): if self.get("taxes_and_charges"): if not tax_master_doctype: diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 410636fbd4..3e035b1de1 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -498,4 +498,5 @@ erpnext.patches.v10_0.update_reserved_qty_for_purchase_order erpnext.patches.v10_0.update_hub_connector_domain erpnext.patches.v10_0.set_student_party_type erpnext.patches.v10_0.update_project_in_sle -erpnext.patches.v10_0.fix_reserved_qty_for_sub_contract \ No newline at end of file +erpnext.patches.v10_0.fix_reserved_qty_for_sub_contract +erpnext.patches.v10_0.taxes_issue_with_pos \ No newline at end of file diff --git a/erpnext/patches/v10_0/taxes_issue_with_pos.py b/erpnext/patches/v10_0/taxes_issue_with_pos.py new file mode 100644 index 0000000000..5d6b78663b --- /dev/null +++ b/erpnext/patches/v10_0/taxes_issue_with_pos.py @@ -0,0 +1,26 @@ +# Copyright (c) 2017, Frappe and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + for d in frappe.get_all('Sales Invoice', fields=["name"], + filters = {'is_pos':1, 'docstatus': 1, 'creation': ('>', '2018-04-23')}): + doc = frappe.get_doc('Sales Invoice', d.name) + if (not doc.taxes and doc.taxes_and_charges and doc.pos_profile and + frappe.db.get_value('POS Profile', doc.pos_profile, 'taxes_and_charges', cache=True) == doc.taxes_and_charges): + + doc.append_taxes_from_master() + doc.calculate_taxes_and_totals() + for d in doc.taxes: + d.db_update() + + doc.db_update() + + delete_gle_for_voucher(doc.name) + doc.make_gl_entries() + +def delete_gle_for_voucher(voucher_no): + frappe.db.sql("""delete from `tabGL Entry` where voucher_no = %(voucher_no)s""", + {'voucher_no': voucher_no}) \ No newline at end of file