From 2a81960e0bc3d562e8163cc159babf7fb73d7253 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 17 Nov 2016 13:01:52 +0530 Subject: [PATCH] test cases --- .../doctype/pos_profile/test_pos_profile.py | 45 +++++++++++++++++-- erpnext/accounts/doctype/sales_invoice/pos.py | 4 ++ .../sales_invoice/test_sales_invoice.py | 27 ++--------- 3 files changed, 50 insertions(+), 26 deletions(-) diff --git a/erpnext/accounts/doctype/pos_profile/test_pos_profile.py b/erpnext/accounts/doctype/pos_profile/test_pos_profile.py index 62274a332f..9c6a11487c 100644 --- a/erpnext/accounts/doctype/pos_profile/test_pos_profile.py +++ b/erpnext/accounts/doctype/pos_profile/test_pos_profile.py @@ -5,8 +5,47 @@ from __future__ import unicode_literals import frappe import unittest - -# test_records = frappe.get_test_records('POS Profile') +from erpnext.stock.get_item_details import get_pos_profile +from erpnext.accounts.doctype.sales_invoice.pos import get_items_list, get_customers_list class TestPOSProfile(unittest.TestCase): - pass + def test_pos_profile(self): + make_pos_profile() + + 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.save() + + items = get_items_list(doc) + 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'""") + + self.assertEquals(len(items), products_count[0][0]) + self.assertEquals(len(customers), customers_count[0][0]) + + frappe.db.sql("delete from `tabPOS Profile`") + +def make_pos_profile(): + pos_profile = frappe.get_doc({ + "company": "_Test Company", + "cost_center": "_Test Cost Center - _TC", + "currency": "INR", + "doctype": "POS Profile", + "expense_account": "_Test Account Cost for Goods Sold - _TC", + "income_account": "Sales - _TC", + "name": "_Test POS Profile", + "naming_series": "_T-POS Profile-", + "selling_price_list": "_Test Price List", + "territory": "_Test Territory", + "warehouse": "_Test Warehouse - _TC", + "write_off_account": "_Test Write Off - _TC", + "write_off_cost_center": "_Test Write Off Cost Center - _TC" + }) + + if not frappe.db.exists("POS Profile", "_Test POS Profile"): + pos_profile.insert() \ No newline at end of file diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py index ec30cb00a7..11c68a3e63 100644 --- a/erpnext/accounts/doctype/sales_invoice/pos.py +++ b/erpnext/accounts/doctype/sales_invoice/pos.py @@ -133,6 +133,8 @@ def get_items_list(pos_profile): cond = "1=1" item_groups = [] if pos_profile.get('item_groups'): + # Get items based on the item groups defined in the POS profile + cond = "item_group in (%s)"%(', '.join(['%s']*len(pos_profile.get('item_groups')))) item_groups = [d.item_group for d in pos_profile.get('item_groups')] @@ -143,6 +145,8 @@ def get_customers_list(pos_profile): cond = "1=1" customer_groups = [] if pos_profile.get('customer_groups'): + # Get customers based on the customer groups defined in the POS profile + cond = "customer_group in (%s)"%(', '.join(['%s']*len(pos_profile.get('customer_groups')))) customer_groups = [d.customer_group for d in pos_profile.get('customer_groups')] diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 511eeaab9f..c4f275aba9 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -7,6 +7,7 @@ import unittest, copy from frappe.utils import nowdate, add_days, flt, nowdate from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry, get_qty_after_transaction from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import unlink_payment_on_cancel_of_invoice +from erpnext.accounts.doctype.pos_profile.test_pos_profile import make_pos_profile from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory from erpnext.exceptions import InvalidAccountCurrency, InvalidCurrency from erpnext.stock.doctype.serial_no.serial_no import SerialNoWarehouseError @@ -467,7 +468,7 @@ class TestSalesInvoice(unittest.TestCase): def test_pos_gl_entry_with_perpetual_inventory(self): set_perpetual_inventory() - self.make_pos_profile() + make_pos_profile() self._insert_purchase_receipt() pos = copy.deepcopy(test_records[1]) @@ -486,7 +487,7 @@ class TestSalesInvoice(unittest.TestCase): def test_pos_change_amount(self): set_perpetual_inventory() - self.make_pos_profile() + make_pos_profile() self._insert_purchase_receipt() pos = copy.deepcopy(test_records[1]) @@ -508,7 +509,7 @@ class TestSalesInvoice(unittest.TestCase): set_perpetual_inventory() - self.make_pos_profile() + make_pos_profile() self._insert_purchase_receipt() pos = copy.deepcopy(test_records[1]) @@ -572,26 +573,6 @@ class TestSalesInvoice(unittest.TestCase): frappe.db.sql("delete from `tabPOS Profile`") - def make_pos_profile(self): - pos_profile = frappe.get_doc({ - "company": "_Test Company", - "cost_center": "_Test Cost Center - _TC", - "currency": "INR", - "doctype": "POS Profile", - "expense_account": "_Test Account Cost for Goods Sold - _TC", - "income_account": "Sales - _TC", - "name": "_Test POS Profile", - "naming_series": "_T-POS Profile-", - "selling_price_list": "_Test Price List", - "territory": "_Test Territory", - "warehouse": "_Test Warehouse - _TC", - "write_off_account": "_Test Write Off - _TC", - "write_off_cost_center": "_Test Write Off Cost Center - _TC" - }) - - if not frappe.db.exists("POS Profile", "_Test POS Profile"): - pos_profile.insert() - def test_sales_invoice_gl_entry_with_perpetual_inventory_no_item_code(self): set_perpetual_inventory()