From cb1cc96210c08e0e278a00781ad1afd2bc561d17 Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Wed, 13 May 2020 16:30:10 +0530 Subject: [PATCH 1/2] fix: item tax template fetching in offline pos --- erpnext/accounts/doctype/sales_invoice/pos.py | 3 +- erpnext/accounts/page/pos/pos.js | 31 ++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py index 16e918cc728..c2f79841725 100755 --- a/erpnext/accounts/doctype/sales_invoice/pos.py +++ b/erpnext/accounts/doctype/sales_invoice/pos.py @@ -180,10 +180,11 @@ def get_items_list(pos_profile, company): i.name, i.item_code, i.item_name, i.description, i.item_group, i.has_batch_no, i.has_serial_no, i.is_stock_item, i.brand, i.stock_uom, i.image, id.expense_account, id.selling_cost_center, id.default_warehouse, - i.sales_uom, c.conversion_factor + i.sales_uom, c.conversion_factor, it.item_tax_template, it.valid_from from `tabItem` i left join `tabItem Default` id on id.parent = i.name and id.company = %s + left join `tabItem Tax` it on it.parent = i.name left join `tabUOM Conversion Detail` c on i.name = c.parent and i.sales_uom = c.uom where i.disabled = 0 and i.has_variants = 0 and i.is_sales_item = 1 diff --git a/erpnext/accounts/page/pos/pos.js b/erpnext/accounts/page/pos/pos.js index 24fcb41a5db..06575ac3a69 100755 --- a/erpnext/accounts/page/pos/pos.js +++ b/erpnext/accounts/page/pos/pos.js @@ -1458,7 +1458,36 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ this.child.batch_no = this.item_batch_no[this.child.item_code]; this.child.serial_no = (this.item_serial_no[this.child.item_code] ? this.item_serial_no[this.child.item_code][0] : ''); - this.child.item_tax_rate = JSON.stringify(this.tax_data[this.child.item_code]); + + const tax_template_is_valid = frappe.datetime.get_diff(frappe.datetime.now_date(), this.items[0].valid_from) > 0; + + this.child.item_tax_template = tax_template_is_valid ? this.items[0].item_tax_template : ''; + this.child.item_tax_rate = JSON.stringify(this.tax_data[this.child.item_tax_template]); + + if (this.child.item_tax_rate) { + this.add_taxes_from_item_tax_template(this.child.item_tax_rate); + } + }, + + add_taxes_from_item_tax_template: function(item_tax_map) { + let me = this; + + if(item_tax_map && cint(frappe.defaults.get_default("add_taxes_from_item_tax_template"))) { + if(typeof (item_tax_map) == "string") { + item_tax_map = JSON.parse(item_tax_map); + } + + $.each(item_tax_map, function(tax, rate) { + let found = (me.frm.doc.taxes || []).find(d => d.account_head === tax); + if(!found) { + let child = frappe.model.add_child(me.frm.doc, "taxes"); + child.charge_type = "On Net Total"; + child.account_head = tax; + child.description = String(tax); + child.rate = rate; + } + }); + } }, update_paid_amount_status: function (update_paid_amount) { From 0af125f6fe721716773f8b6484f60f8f949d86ce Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Fri, 15 May 2020 05:26:41 +0530 Subject: [PATCH 2/2] fix: test --- erpnext/accounts/doctype/pos_profile/test_pos_profile.py | 6 +++--- erpnext/accounts/doctype/sales_invoice/pos.py | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/pos_profile/test_pos_profile.py b/erpnext/accounts/doctype/pos_profile/test_pos_profile.py index 58f12162d14..f8d52a78336 100644 --- a/erpnext/accounts/doctype/pos_profile/test_pos_profile.py +++ b/erpnext/accounts/doctype/pos_profile/test_pos_profile.py @@ -15,12 +15,12 @@ class TestPOSProfile(unittest.TestCase): pos_profile = get_pos_profile("_Test Company") or {} if pos_profile: doc = frappe.get_doc("POS Profile", pos_profile.get("name")) - doc.append('item_groups', {'item_group': '_Test Item Group'}) - doc.append('customer_groups', {'customer_group': '_Test Customer Group'}) + doc.set('item_groups', [{'item_group': '_Test Item Group'}]) + doc.set('customer_groups', [{'customer_group': '_Test Customer Group'}]) doc.save() items = get_items_list(doc, doc.company) customers = get_customers_list(doc) - + products_count = frappe.db.sql(""" select count(name) from tabItem where item_group = '_Test Item Group'""", as_list=1) customers_count = frappe.db.sql(""" select count(name) from tabCustomer where customer_group = '_Test Customer Group'""") diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py index c2f79841725..f371bd425c5 100755 --- a/erpnext/accounts/doctype/sales_invoice/pos.py +++ b/erpnext/accounts/doctype/sales_invoice/pos.py @@ -189,6 +189,7 @@ def get_items_list(pos_profile, company): where i.disabled = 0 and i.has_variants = 0 and i.is_sales_item = 1 {cond} + group by i.item_code """.format(cond=cond), tuple([company] + args_list), as_dict=1)