How to use _test method in wpt

Best JavaScript code snippet using wpt

test_sales_order.py

Source:test_sales_order.py Github

copy

Full Screen

1# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors2# License: GNU General Public License v3. See license.txt3from __future__ import unicode_literals4import frappe5from frappe.utils import flt, add_days6import frappe.permissions7import unittest8from erpnext.selling.doctype.sales_order.sales_order \9 import make_material_request, make_delivery_note, make_sales_invoice, WarehouseRequired10from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry11from frappe.tests.test_permissions import set_user_permission_doctypes12from erpnext.selling.doctype.sales_order.sales_order import make_production_orders13import json14class TestSalesOrder(unittest.TestCase):15 def tearDown(self):16 frappe.set_user("Administrator")17 for role in ("Stock User", "Sales User"):18 set_user_permission_doctypes(doctypes="Sales Order", role=role,19 apply_user_permissions=0, user_permission_doctypes=None)20 def test_make_material_request(self):21 so = make_sales_order(do_not_submit=True)22 self.assertRaises(frappe.ValidationError, make_material_request, so.name)23 so.submit()24 mr = make_material_request(so.name)25 self.assertEquals(mr.material_request_type, "Purchase")26 self.assertEquals(len(mr.get("items")), len(so.get("items")))27 def test_make_delivery_note(self):28 so = make_sales_order(do_not_submit=True)29 self.assertRaises(frappe.ValidationError, make_delivery_note, so.name)30 so.submit()31 dn = make_delivery_note(so.name)32 self.assertEquals(dn.doctype, "Delivery Note")33 self.assertEquals(len(dn.get("items")), len(so.get("items")))34 def test_make_sales_invoice(self):35 so = make_sales_order(do_not_submit=True)36 self.assertRaises(frappe.ValidationError, make_sales_invoice, so.name)37 so.submit()38 si = make_sales_invoice(so.name)39 self.assertEquals(len(si.get("items")), len(so.get("items")))40 self.assertEquals(len(si.get("items")), 1)41 si.insert()42 si.submit()43 si1 = make_sales_invoice(so.name)44 self.assertEquals(len(si1.get("items")), 0)45 def test_make_sales_invoice_with_terms(self):46 so = make_sales_order(do_not_submit=True)47 self.assertRaises(frappe.ValidationError, make_sales_invoice, so.name)48 so.update({"payment_terms_template": "_Test Payment Term Template"})49 so.save()50 so.submit()51 si = make_sales_invoice(so.name)52 self.assertEquals(len(si.get("items")), len(so.get("items")))53 self.assertEquals(len(si.get("items")), 1)54 si.insert()55 self.assertEqual(si.payment_schedule[0].payment_amount, 500.0)56 self.assertEqual(si.payment_schedule[0].due_date, so.transaction_date)57 self.assertEqual(si.payment_schedule[1].payment_amount, 500.0)58 self.assertEqual(si.payment_schedule[1].due_date, add_days(so.transaction_date, 30))59 si.submit()60 si1 = make_sales_invoice(so.name)61 self.assertEquals(len(si1.get("items")), 0)62 def test_update_qty(self):63 so = make_sales_order()64 create_dn_against_so(so.name, 6)65 so.load_from_db()66 self.assertEquals(so.get("items")[0].delivered_qty, 6)67 # Check delivered_qty after make_sales_invoice without update_stock checked68 si1 = make_sales_invoice(so.name)69 si1.get("items")[0].qty = 670 si1.insert()71 si1.submit()72 so.load_from_db()73 self.assertEquals(so.get("items")[0].delivered_qty, 6)74 # Check delivered_qty after make_sales_invoice with update_stock checked75 si2 = make_sales_invoice(so.name)76 si2.set("update_stock", 1)77 si2.get("items")[0].qty = 378 si2.insert()79 si2.submit()80 so.load_from_db()81 self.assertEquals(so.get("items")[0].delivered_qty, 9)82 def test_reserved_qty_for_partial_delivery(self):83 make_stock_entry(target="_Test Warehouse - _TC", qty=10, rate=100)84 existing_reserved_qty = get_reserved_qty()85 so = make_sales_order()86 self.assertEqual(get_reserved_qty(), existing_reserved_qty + 10)87 dn = create_dn_against_so(so.name)88 self.assertEqual(get_reserved_qty(), existing_reserved_qty + 5)89 # close so90 so.load_from_db()91 so.update_status("Closed")92 self.assertEqual(get_reserved_qty(), existing_reserved_qty)93 # unclose so94 so.load_from_db()95 so.update_status('Draft')96 self.assertEqual(get_reserved_qty(), existing_reserved_qty + 5)97 dn.cancel()98 self.assertEqual(get_reserved_qty(), existing_reserved_qty + 10)99 # cancel100 so.load_from_db()101 so.cancel()102 self.assertEqual(get_reserved_qty(), existing_reserved_qty)103 def test_reserved_qty_for_over_delivery(self):104 make_stock_entry(target="_Test Warehouse - _TC", qty=10, rate=100)105 # set over-delivery tolerance106 frappe.db.set_value('Item', "_Test Item", 'tolerance', 50)107 existing_reserved_qty = get_reserved_qty()108 so = make_sales_order()109 self.assertEqual(get_reserved_qty(), existing_reserved_qty + 10)110 dn = create_dn_against_so(so.name, 15)111 self.assertEqual(get_reserved_qty(), existing_reserved_qty)112 dn.cancel()113 self.assertEqual(get_reserved_qty(), existing_reserved_qty + 10)114 def test_reserved_qty_for_over_delivery_via_sales_invoice(self):115 make_stock_entry(target="_Test Warehouse - _TC", qty=10, rate=100)116 # set over-delivery tolerance117 frappe.db.set_value('Item', "_Test Item", 'tolerance', 50)118 existing_reserved_qty = get_reserved_qty()119 so = make_sales_order()120 self.assertEqual(get_reserved_qty(), existing_reserved_qty + 10)121 si = make_sales_invoice(so.name)122 si.update_stock = 1123 si.get("items")[0].qty = 12124 si.insert()125 si.submit()126 self.assertEqual(get_reserved_qty(), existing_reserved_qty)127 so.load_from_db()128 self.assertEqual(so.get("items")[0].delivered_qty, 12)129 self.assertEqual(so.per_delivered, 100)130 si.cancel()131 self.assertEqual(get_reserved_qty(), existing_reserved_qty + 10)132 so.load_from_db()133 self.assertEqual(so.get("items")[0].delivered_qty, 0)134 self.assertEqual(so.per_delivered, 0)135 def test_reserved_qty_for_partial_delivery_with_packing_list(self):136 make_stock_entry(target="_Test Warehouse - _TC", qty=10, rate=100)137 make_stock_entry(item="_Test Item Home Desktop 100", target="_Test Warehouse - _TC", qty=10, rate=100)138 existing_reserved_qty_item1 = get_reserved_qty("_Test Item")139 existing_reserved_qty_item2 = get_reserved_qty("_Test Item Home Desktop 100")140 so = make_sales_order(item_code="_Test Product Bundle Item")141 self.assertEqual(get_reserved_qty("_Test Item"), existing_reserved_qty_item1 + 50)142 self.assertEqual(get_reserved_qty("_Test Item Home Desktop 100"),143 existing_reserved_qty_item2 + 20)144 dn = create_dn_against_so(so.name)145 self.assertEqual(get_reserved_qty("_Test Item"), existing_reserved_qty_item1 + 25)146 self.assertEqual(get_reserved_qty("_Test Item Home Desktop 100"),147 existing_reserved_qty_item2 + 10)148 # close so149 so.load_from_db()150 so.update_status("Closed")151 self.assertEqual(get_reserved_qty("_Test Item"), existing_reserved_qty_item1)152 self.assertEqual(get_reserved_qty("_Test Item Home Desktop 100"), existing_reserved_qty_item2)153 # unclose so154 so.load_from_db()155 so.update_status('Draft')156 self.assertEqual(get_reserved_qty("_Test Item"), existing_reserved_qty_item1 + 25)157 self.assertEqual(get_reserved_qty("_Test Item Home Desktop 100"),158 existing_reserved_qty_item2 + 10)159 dn.cancel()160 self.assertEqual(get_reserved_qty("_Test Item"), existing_reserved_qty_item1 + 50)161 self.assertEqual(get_reserved_qty("_Test Item Home Desktop 100"),162 existing_reserved_qty_item2 + 20)163 so.load_from_db()164 so.cancel()165 self.assertEqual(get_reserved_qty("_Test Item"), existing_reserved_qty_item1)166 self.assertEqual(get_reserved_qty("_Test Item Home Desktop 100"), existing_reserved_qty_item2)167 def test_reserved_qty_for_over_delivery_with_packing_list(self):168 make_stock_entry(target="_Test Warehouse - _TC", qty=10, rate=100)169 make_stock_entry(item="_Test Item Home Desktop 100", target="_Test Warehouse - _TC", qty=10, rate=100)170 # set over-delivery tolerance171 frappe.db.set_value('Item', "_Test Product Bundle Item", 'tolerance', 50)172 existing_reserved_qty_item1 = get_reserved_qty("_Test Item")173 existing_reserved_qty_item2 = get_reserved_qty("_Test Item Home Desktop 100")174 so = make_sales_order(item_code="_Test Product Bundle Item")175 self.assertEqual(get_reserved_qty("_Test Item"), existing_reserved_qty_item1 + 50)176 self.assertEqual(get_reserved_qty("_Test Item Home Desktop 100"),177 existing_reserved_qty_item2 + 20)178 dn = create_dn_against_so(so.name, 15)179 self.assertEqual(get_reserved_qty("_Test Item"), existing_reserved_qty_item1)180 self.assertEqual(get_reserved_qty("_Test Item Home Desktop 100"),181 existing_reserved_qty_item2)182 dn.cancel()183 self.assertEqual(get_reserved_qty("_Test Item"), existing_reserved_qty_item1 + 50)184 self.assertEqual(get_reserved_qty("_Test Item Home Desktop 100"),185 existing_reserved_qty_item2 + 20)186 def test_warehouse_user(self):187 for role in ("Stock User", "Sales User"):188 set_user_permission_doctypes(doctypes="Sales Order", role=role,189 apply_user_permissions=1, user_permission_doctypes=["Warehouse"])190 frappe.permissions.add_user_permission("Warehouse", "_Test Warehouse 1 - _TC", "test@example.com")191 frappe.permissions.add_user_permission("Warehouse", "_Test Warehouse 2 - _TC1", "test2@example.com")192 frappe.permissions.add_user_permission("Company", "_Test Company 1", "test2@example.com")193 test_user = frappe.get_doc("User", "test@example.com")194 test_user.add_roles("Sales User", "Stock User")195 test_user.remove_roles("Sales Manager")196 test_user_2 = frappe.get_doc("User", "test2@example.com")197 test_user_2.add_roles("Sales User", "Stock User")198 test_user_2.remove_roles("Sales Manager")199 frappe.set_user("test@example.com")200 so = make_sales_order(company="_Test Company 1",201 warehouse="_Test Warehouse 2 - _TC1", do_not_save=True)202 so.conversion_rate = 0.02203 so.plc_conversion_rate = 0.02204 self.assertRaises(frappe.PermissionError, so.insert)205 frappe.set_user("test2@example.com")206 so.insert()207 frappe.set_user("Administrator")208 frappe.permissions.remove_user_permission("Warehouse", "_Test Warehouse 1 - _TC", "test@example.com")209 frappe.permissions.remove_user_permission("Warehouse", "_Test Warehouse 2 - _TC1", "test2@example.com")210 frappe.permissions.remove_user_permission("Company", "_Test Company 1", "test2@example.com")211 def test_block_delivery_note_against_cancelled_sales_order(self):212 so = make_sales_order()213 dn = make_delivery_note(so.name)214 dn.insert()215 so.cancel()216 self.assertRaises(frappe.CancelledLinkError, dn.submit)217 def test_service_type_product_bundle(self):218 from erpnext.stock.doctype.item.test_item import make_item219 from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle220 make_item("_Test Service Product Bundle", {"is_stock_item": 0})221 make_item("_Test Service Product Bundle Item 1", {"is_stock_item": 0})222 make_item("_Test Service Product Bundle Item 2", {"is_stock_item": 0})223 make_product_bundle("_Test Service Product Bundle",224 ["_Test Service Product Bundle Item 1", "_Test Service Product Bundle Item 2"])225 so = make_sales_order(item_code = "_Test Service Product Bundle", warehouse=None)226 self.assertTrue("_Test Service Product Bundle Item 1" in [d.item_code for d in so.packed_items])227 self.assertTrue("_Test Service Product Bundle Item 2" in [d.item_code for d in so.packed_items])228 def test_mix_type_product_bundle(self):229 from erpnext.stock.doctype.item.test_item import make_item230 from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle231 make_item("_Test Mix Product Bundle", {"is_stock_item": 0})232 make_item("_Test Mix Product Bundle Item 1", {"is_stock_item": 1})233 make_item("_Test Mix Product Bundle Item 2", {"is_stock_item": 0})234 make_product_bundle("_Test Mix Product Bundle",235 ["_Test Mix Product Bundle Item 1", "_Test Mix Product Bundle Item 2"])236 self.assertRaises(WarehouseRequired, make_sales_order, item_code = "_Test Mix Product Bundle", warehouse="")237 def test_auto_insert_price(self):238 from erpnext.stock.doctype.item.test_item import make_item239 make_item("_Test Item for Auto Price List", {"is_stock_item": 0})240 frappe.db.set_value("Stock Settings", None, "auto_insert_price_list_rate_if_missing", 1)241 item_price = frappe.db.get_value("Item Price", {"price_list": "_Test Price List",242 "item_code": "_Test Item for Auto Price List"})243 if item_price:244 frappe.delete_doc("Item Price", item_price)245 make_sales_order(item_code = "_Test Item for Auto Price List", selling_price_list="_Test Price List", rate=100)246 self.assertEquals(frappe.db.get_value("Item Price",247 {"price_list": "_Test Price List", "item_code": "_Test Item for Auto Price List"}, "price_list_rate"), 100)248 # do not update price list249 frappe.db.set_value("Stock Settings", None, "auto_insert_price_list_rate_if_missing", 0)250 item_price = frappe.db.get_value("Item Price", {"price_list": "_Test Price List",251 "item_code": "_Test Item for Auto Price List"})252 if item_price:253 frappe.delete_doc("Item Price", item_price)254 make_sales_order(item_code = "_Test Item for Auto Price List", selling_price_list="_Test Price List", rate=100)255 self.assertEquals(frappe.db.get_value("Item Price",256 {"price_list": "_Test Price List", "item_code": "_Test Item for Auto Price List"}, "price_list_rate"), None)257 frappe.db.set_value("Stock Settings", None, "auto_insert_price_list_rate_if_missing", 1)258 def test_drop_shipping(self):259 from erpnext.selling.doctype.sales_order.sales_order import make_purchase_order_for_drop_shipment260 from erpnext.stock.doctype.item.test_item import make_item261 from erpnext.buying.doctype.purchase_order.purchase_order import update_status262 make_stock_entry(target="_Test Warehouse - _TC", qty=10, rate=100)263 po_item = make_item("_Test Item for Drop Shipping", {"is_stock_item": 1, "delivered_by_supplier": 1,264 'default_supplier': '_Test Supplier',265 "expense_account": "_Test Account Cost for Goods Sold - _TC",266 "cost_center": "_Test Cost Center - _TC"267 })268 dn_item = make_item("_Test Regular Item", {"is_stock_item": 1, "expense_account": "_Test Account Cost for Goods Sold - _TC",269 "cost_center": "_Test Cost Center - _TC"})270 so_items = [271 {272 "item_code": po_item.item_code,273 "warehouse": "",274 "qty": 2,275 "rate": 400,276 "delivered_by_supplier": 1,277 "supplier": '_Test Supplier'278 },279 {280 "item_code": dn_item.item_code,281 "warehouse": "_Test Warehouse - _TC",282 "qty": 2,283 "rate": 300,284 "conversion_factor": 1.0285 }286 ]287 if frappe.db.get_value("Item", "_Test Regular Item", "is_stock_item")==1:288 make_stock_entry(item="_Test Regular Item", target="_Test Warehouse - _TC", qty=10, rate=100)289 #setuo existing qty from bin290 bin = frappe.get_all("Bin", filters={"item_code": po_item.item_code, "warehouse": "_Test Warehouse - _TC"},291 fields=["ordered_qty", "reserved_qty"])292 existing_ordered_qty = bin[0].ordered_qty if bin else 0.0293 existing_reserved_qty = bin[0].reserved_qty if bin else 0.0294 bin = frappe.get_all("Bin", filters={"item_code": dn_item.item_code,295 "warehouse": "_Test Warehouse - _TC"}, fields=["reserved_qty"])296 existing_reserved_qty_for_dn_item = bin[0].reserved_qty if bin else 0.0297 #create so, po and partial dn298 so = make_sales_order(item_list=so_items, do_not_submit=True)299 so.submit()300 po = make_purchase_order_for_drop_shipment(so.name, '_Test Supplier')301 po.submit()302 dn = create_dn_against_so(so.name, delivered_qty=1)303 self.assertEquals(so.customer, po.customer)304 self.assertEquals(po.items[0].sales_order, so.name)305 self.assertEquals(po.items[0].item_code, po_item.item_code)306 self.assertEquals(dn.items[0].item_code, dn_item.item_code)307 #test ordered_qty and reserved_qty308 bin = frappe.get_all("Bin", filters={"item_code": po_item.item_code, "warehouse": "_Test Warehouse - _TC"},309 fields=["ordered_qty", "reserved_qty"])310 ordered_qty = bin[0].ordered_qty if bin else 0.0311 reserved_qty = bin[0].reserved_qty if bin else 0.0312 self.assertEquals(abs(flt(ordered_qty)), existing_ordered_qty)313 self.assertEquals(abs(flt(reserved_qty)), existing_reserved_qty)314 reserved_qty = frappe.db.get_value("Bin",315 {"item_code": dn_item.item_code, "warehouse": "_Test Warehouse - _TC"}, "reserved_qty")316 self.assertEquals(abs(flt(reserved_qty)), existing_reserved_qty_for_dn_item + 1)317 #test po_item length318 self.assertEquals(len(po.items), 1)319 #test per_delivered status320 update_status("Delivered", po.name)321 self.assertEquals(flt(frappe.db.get_value("Sales Order", so.name, "per_delivered"), 2), 75.00)322 #test reserved qty after complete delivery323 dn = create_dn_against_so(so.name, delivered_qty=1)324 reserved_qty = frappe.db.get_value("Bin",325 {"item_code": dn_item.item_code, "warehouse": "_Test Warehouse - _TC"}, "reserved_qty")326 self.assertEquals(abs(flt(reserved_qty)), existing_reserved_qty_for_dn_item)327 #test after closing so328 so.db_set('status', "Closed")329 so.update_reserved_qty()330 bin = frappe.get_all("Bin", filters={"item_code": po_item.item_code, "warehouse": "_Test Warehouse - _TC"},331 fields=["ordered_qty", "reserved_qty"])332 ordered_qty = bin[0].ordered_qty if bin else 0.0333 reserved_qty = bin[0].reserved_qty if bin else 0.0334 self.assertEquals(abs(flt(ordered_qty)), existing_ordered_qty)335 self.assertEquals(abs(flt(reserved_qty)), existing_reserved_qty)336 reserved_qty = frappe.db.get_value("Bin",337 {"item_code": dn_item.item_code, "warehouse": "_Test Warehouse - _TC"}, "reserved_qty")338 self.assertEquals(abs(flt(reserved_qty)), existing_reserved_qty_for_dn_item)339 def test_reserved_qty_for_closing_so(self):340 bin = frappe.get_all("Bin", filters={"item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC"},341 fields=["reserved_qty"])342 existing_reserved_qty = bin[0].reserved_qty if bin else 0.0343 so = make_sales_order(item_code="_Test Item", qty=1)344 self.assertEquals(get_reserved_qty(item_code="_Test Item", warehouse="_Test Warehouse - _TC"), existing_reserved_qty+1)345 so.update_status("Closed")346 self.assertEquals(get_reserved_qty(item_code="_Test Item", warehouse="_Test Warehouse - _TC"), existing_reserved_qty)347 def test_create_so_with_margin(self):348 so = make_sales_order(item_code="_Test Item", qty=1, do_not_submit=True)349 so.items[0].price_list_rate = price_list_rate = 100350 so.items[0].margin_type = 'Percentage'351 so.items[0].margin_rate_or_amount = 25352 so.save()353 new_so = frappe.copy_doc(so)354 new_so.save(ignore_permissions=True)355 self.assertEquals(new_so.get("items")[0].rate, flt((price_list_rate*25)/100 + price_list_rate))356 new_so.items[0].margin_rate_or_amount = 25357 new_so.payment_schedule = []358 new_so.save()359 new_so.submit()360 self.assertEquals(new_so.get("items")[0].rate, flt((price_list_rate*25)/100 + price_list_rate))361 def test_terms_auto_added(self):362 so = make_sales_order(do_not_save=1)363 self.assertFalse(so.get('payment_schedule'))364 so.insert()365 self.assertTrue(so.get('payment_schedule'))366 def test_terms_not_copied(self):367 so = make_sales_order()368 self.assertTrue(so.get('payment_schedule'))369 si = make_sales_invoice(so.name)370 self.assertFalse(si.get('payment_schedule'))371 def test_terms_copied(self):372 so = make_sales_order(do_not_copy=1, do_not_save=1)373 so.payment_terms_template = '_Test Payment Term Template'374 so.insert()375 so.submit()376 self.assertTrue(so.get('payment_schedule'))377 si = make_sales_invoice(so.name)378 si.insert()379 self.assertTrue(si.get('payment_schedule'))380 def test_make_production_order(self):381 # Make a new Sales Order382 so = make_sales_order(**{383 "item_list": [{384 "item_code": "_Test FG Item",385 "qty": 10,386 "rate":100387 },388 {389 "item_code": "_Test FG Item",390 "qty": 20,391 "rate":200392 }]393 })394 # Raise Production Orders395 po_items= []396 so_item_name= {}397 for item in so.get_production_order_items():398 po_items.append({399 "warehouse": item.get("warehouse"),400 "item_code": item.get("item_code"),401 "pending_qty": item.get("pending_qty"),402 "sales_order_item": item.get("sales_order_item"),403 "bom": item.get("bom")404 })405 so_item_name[item.get("sales_order_item")]= item.get("pending_qty")406 make_production_orders(json.dumps({"items":po_items}), so.name, so.company)407 # Check if Production Orders were raised408 for item in so_item_name:409 po_qty = frappe.db.sql("select sum(qty) from `tabProduction Order` where sales_order=%s and sales_order_item=%s", (so.name, item))410 self.assertEquals(po_qty[0][0], so_item_name.get(item))411def make_sales_order(**args):412 so = frappe.new_doc("Sales Order")413 args = frappe._dict(args)414 if args.transaction_date:415 so.transaction_date = args.transaction_date416 so.company = args.company or "_Test Company"417 so.customer = args.customer or "_Test Customer"418 so.currency = args.currency or "INR"419 if args.selling_price_list:420 so.selling_price_list = args.selling_price_list421 if "warehouse" not in args:422 args.warehouse = "_Test Warehouse - _TC"423 if args.item_list:424 for item in args.item_list:425 so.append("items", item)426 else:427 so.append("items", {428 "item_code": args.item or args.item_code or "_Test Item",429 "warehouse": args.warehouse,430 "qty": args.qty or 10,431 "uom": args.uom or None,432 "rate": args.rate or 100433 })434 so.delivery_date = add_days(so.transaction_date, 10)435 if not args.do_not_save:436 so.insert()437 if not args.do_not_submit:438 so.submit()439 else:440 so.payment_schedule = []441 else:442 so.payment_schedule = []443 return so444def create_dn_against_so(so, delivered_qty=0):445 frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)446 dn = make_delivery_note(so)447 dn.get("items")[0].qty = delivered_qty or 5448 dn.insert()449 dn.submit()450 return dn451def get_reserved_qty(item_code="_Test Item", warehouse="_Test Warehouse - _TC"):452 return flt(frappe.db.get_value("Bin", {"item_code": item_code, "warehouse": warehouse},453 "reserved_qty"))...

Full Screen

Full Screen

test_production_planning_tool.py

Source:test_production_planning_tool.py Github

copy

Full Screen

1# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors2# MIT License. See license.txt3import frappe4import frappe.defaults5import unittest6from frappe.test_runner import make_test_records7from erpnext.manufacturing.doctype.production_planning_tool.production_planning_tool import ProductionPlanningTool8# load test records and dependencies9test_records = frappe.get_test_records('Production Planning Tool')10test_dependencies = ["Item","BOM"]11class TestEvent(unittest.TestCase):12 def test_materials_requests_all_raw_multi_level(self):13 items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D",14 "_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A",15 "_Test PPT Item SC B","_Test PPT Item Master"]16 quantities = [14,9,36,1,0,0,0,0,0,0]17 types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase",18 "Purchase","Manufacture"]19 self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=1, only_raw_materials=1, \20 include_subcontracted=1)21 def test_materials_requests_multi_no_subcontracted(self):22 items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D",23 "_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A",24 "_Test PPT Item SC B","_Test PPT Item Master"]25 quantities = [14,5,20,0,0,0,0,0,0,0]26 types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase",27 "Purchase","Manufacture"]28 # This one should fail for now29 self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=1, only_raw_materials=1, \30 include_subcontracted=0)31 def test_materials_requests_manufacture_and_sub_multi_level(self):32 items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D",33 "_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A",34 "_Test PPT Item SC B","_Test PPT Item Master"]35 quantities = [14,9,36,1,2,5,2,1,4,0]36 types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase",37 "Purchase","Manufacture"]38 self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=1, only_raw_materials=0, \39 include_subcontracted=1)40 def test_materials_requests_manufacture_multi_level(self):41 items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D",42 "_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A",43 "_Test PPT Item SC B","_Test PPT Item Master"]44 quantities = [14,5,20,0,2,5,2,1,4,0]45 types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase",46 "Purchase","Manufacture"]47 self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=1, only_raw_materials=0, \48 include_subcontracted=0)49 def test_materials_requests_single_level_purch_only(self):50 items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D",51 "_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A",52 "_Test PPT Item SC B","_Test PPT Item Master"]53 quantities = [2,0,0,0,0,0,0,1,0,0]54 types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase",55 "Purchase","Manufacture"]56 self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=0, only_raw_materials=1, \57 include_subcontracted=0)58 def test_materials_requests_single_level(self):59 items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D",60 "_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A",61 "_Test PPT Item SC B","_Test PPT Item Master"]62 quantities = [2,0,0,0,2,1,0,1,0,0]63 types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase",64 "Purchase","Manufacture"]65 self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=0, only_raw_materials=0, \66 include_subcontracted=0)67 def runtest_materials_requests(self, items, quantities, types,use_multi_level_bom, only_raw_materials, \68 include_subcontracted):69 clear_material_requests()70 create_test_records()71 ppt = run_production_planning_tool(use_multi_level_bom=use_multi_level_bom,72 only_raw_materials=only_raw_materials, include_subcontracted=include_subcontracted,73 item_code = "_Test PPT Item Master", bom_no = "BOM-_Test PPT Item Master-001",74 planned_qty = 1, planned_start_date = "5/5/2029",75 warehouse = "_Test Warehouse - _TC", company = "_Test Company")76 create_material_requests(ppt)77 for item, qty, type in zip(items, quantities, types):78 self.assertEqual(qty, get_requested_qty(item))79 for mat_req_type in get_requested_types(item):80 self.assertEqual(type, mat_req_type)81def create_test_records():82 from erpnext.stock.doctype.item.test_item import make_item83 subA = make_item("_Test PPT Item Sub A",{84 "item_code": "_Test PPT Item Sub A",85 "item_name": "_Test PPT Item Sub A",86 "description": "A manufactured _Test PPT Item Sub Assembly",87 "default_material_request_type": "Manufacture",88 "is_sub_contracted_item": 0,89 "is_stock_item": 1,90 "stock_uom": "_Test UOM",91 "item_group": "_Test Item Group",92 "default_warehouse": "_Test Warehouse - _TC"})93 subB = make_item("_Test PPT Item Sub B",{94 "item_code": "_Test PPT Item Sub B",95 "item_name": "_Test PPT Item Sub B",96 "description": "A manufactured _Test PPT Item Sub Assembly",97 "default_material_request_type": "Manufacture",98 "is_sub_contracted_item": 0,99 "is_stock_item": 1,100 "stock_uom": "_Test UOM",101 "item_group": "_Test Item Group",102 "default_warehouse": "_Test Warehouse - _TC"})103 subC = make_item("_Test PPT Item Sub C",{104 "item_code": "_Test PPT Item Sub C",105 "item_name": "_Test PPT Item Sub C",106 "description": "A manufactured _Test PPT Item Sub Assembly",107 "default_material_request_type": "Manufacture",108 "is_sub_contracted_item": 0,109 "is_stock_item": 1,110 "stock_uom": "_Test UOM",111 "item_group": "_Test Item Group",112 "default_warehouse": "_Test Warehouse - _TC"})113 sCA = make_item("_Test PPT Item SC A",{114 "item_code": "_Test PPT Item SC A",115 "item_name": "_Test PPT Item SC A",116 "description": "A subcontracted part with raw materials",117 "default_material_request_type": "Purchase",118 "is_sub_contracted_item": 1,119 "is_stock_item": 1,120 "stock_uom": "_Test UOM",121 "item_group": "_Test Item Group",122 "default_warehouse": "_Test Warehouse - _TC"})123 subA = make_item("_Test PPT Item Sub A",{124 "item_code": "_Test PPT Item Sub A",125 "item_name": "_Test PPT Item Sub A",126 "description": "A manufactured _Test PPT Item Sub Assembly",127 "default_material_request_type": "Manufacture",128 "is_sub_contracted_item": 0,129 "is_stock_item": 1,130 "stock_uom": "_Test UOM",131 "item_group": "_Test Item Group",132 "default_warehouse": "_Test Warehouse - _TC"})133 sCB = make_item("_Test PPT Item SC B",{134 "item_code": "_Test PPT Item SC B",135 "item_name": "_Test PPT Item SC B",136 "description": "A subcontracted part with raw materials",137 "default_material_request_type": "Purchase",138 "is_sub_contracted_item": 1,139 "is_stock_item": 1,140 "stock_uom": "_Test UOM",141 "item_group": "_Test Item Group",142 "default_warehouse": "_Test Warehouse - _TC"})143 rawA = make_item("_Test PPT Item Raw A",{144 "item_code": "_Test PPT Item Raw A",145 "item_name": "_Test PPT Item Raw A",146 "description": "A raw material",147 "default_material_request_type": "Purchase",148 "is_sub_contracted_item": 0,149 "is_stock_item": 1,150 "stock_uom": "_Test UOM",151 "item_group": "_Test Item Group",152 "default_warehouse": "_Test Warehouse - _TC"})153 rawB = make_item("_Test PPT Item Raw B",{154 "item_code": "_Test PPT Item Raw B",155 "item_name": "_Test PPT Item Raw B",156 "description": "A raw material",157 "default_material_request_type": "Purchase",158 "is_sub_contracted_item": 0,159 "is_stock_item": 1,160 "stock_uom": "_Test UOM",161 "item_group": "_Test Item Group",162 "default_warehouse": "_Test Warehouse - _TC"})163 rawC = make_item("_Test PPT Item Raw C",{164 "item_code": "_Test PPT Item Raw C",165 "item_name": "_Test PPT Item Raw C",166 "description": "A raw material",167 "default_material_request_type": "Purchase",168 "is_sub_contracted_item": 0,169 "is_stock_item": 1,170 "stock_uom": "_Test UOM",171 "item_group": "_Test Item Group",172 "default_warehouse": "_Test Warehouse - _TC"})173 rawD = make_item("_Test PPT Item Raw D",{174 "item_code": "_Test PPT Item Raw D",175 "item_name": "_Test PPT Item Raw D",176 "description": "A raw material",177 "default_material_request_type": "Purchase",178 "is_sub_contracted_item": 0,179 "is_stock_item": 1,180 "stock_uom": "_Test UOM",181 "item_group": "_Test Item Group",182 "default_warehouse": "_Test Warehouse - _TC"})183 master = make_item("_Test PPT Item Master",{184 "item_code": "_Test PPT Item Master",185 "item_name": "_Test PPT Item Master",186 "description": "The final assembly",187 "default_material_request_type": "Manufacture",188 "is_sub_contracted_item": 0,189 "is_stock_item": 1,190 "stock_uom": "_Test UOM",191 "item_group": "_Test Item Group",192 "default_warehouse": "_Test Warehouse - _TC"})193 bom_subB = make_bom("BOM-_Test PPT Item Sub B-001",{"quantity":1.0,194 "item": "_Test PPT Item Sub B",195 "is_active": 1,196 "is_default": 1,197 "docstatus": 1,198 "with_operations": 0}, [{"item_code": "_Test PPT Item Raw B", "doctype":"BOM Item", "stock_qty":1,199 "rate":100, "amount": 100, "stock_uom": "_Test UOM"},200 {"item_code": "_Test PPT Item Raw C", "doctype":"BOM Item", "stock_qty":4, "rate":100,201 "amount": 400,"stock_uom": "_Test UOM"}])202 bom_subC = make_bom("BOM-_Test PPT Item Sub C-001",{"quantity":1,203 "item": "_Test PPT Item Sub C",204 "is_active": 1,205 "is_default": 1,206 "docstatus": 1,207 "with_operations": 0}, [208 {"item_code": "_Test PPT Item Raw A","item_name": "_Test PPT Item Raw A",209 "doctype":"BOM Item", "stock_qty":6, "rate":100, "amount": 600},210 {"item_code": "_Test PPT Item Sub B","item_name": "_Test PPT Item Sub B",211 "bom_no":"BOM-_Test PPT Item Sub B-001", "doctype":"BOM Item", "stock_qty":2,212 "rate":100, "amount": 200}])213 bom_sCA = make_bom("BOM-_Test PPT Item SC A-001",{"quantity":1,214 "item": "_Test PPT Item SC A",215 "is_active": 1,216 "is_default": 1,217 "docstatus": 1,218 "with_operations": 0}, [219 {"item_code": "_Test PPT Item Raw D","item_name": "_Test PPT Item Raw D",220 "doctype":"BOM Item", "stock_qty":1, "rate":100, "amount": 100}])221 bom_sCB = make_bom("BOM-_Test PPT Item SC B-001",{"quantity":1,222 "item": "_Test PPT Item SC B",223 "is_active": 1,224 "is_default": 1,225 "docstatus": 1,226 "with_operations": 0}, [227 {"item_code": "_Test PPT Item Raw B","item_name": "_Test PPT Item Raw B",228 "doctype":"BOM Item", "stock_qty":1, "rate":100, "amount": 100},229 {"item_code": "_Test PPT Item Raw C","item_name": "_Test PPT Item Raw C",230 "doctype":"BOM Item", "stock_qty":4, "rate":100, "amount": 400}])231 bom_subA = make_bom("BOM-_Test PPT Item Sub A-001",{"quantity":1,232 "item": "_Test PPT Item Sub A",233 "is_active": 1,234 "is_default": 1,235 "docstatus": 1,236 "with_operations": 0}, [237 {"item_code": "_Test PPT Item Sub C","item_name": "_Test PPT Item Sub C",238 "bom_no":"BOM-_Test PPT Item Sub C-001", "doctype":"BOM Item",239 "stock_qty":1, "rate":100, "amount": 100},240 {"item_code": "_Test PPT Item SC B","item_name": "_Test PPT Item SC B",241 "bom_no":"BOM-_Test PPT Item SC B-001", "doctype":"BOM Item", "stock_qty":2,242 "rate":100, "amount": 200}])243 bom_master = make_bom("BOM-_Test PPT Item Master-001",{"quantity":1,244 "item": "_Test PPT Item Master",245 "is_active": 1,246 "is_default": 1,247 "docstatus": 1,248 "with_operations": 0}, [249 {"item_code": "_Test PPT Item Sub A","item_name": "_Test PPT Item Sub A",250 "bom_no":"BOM-_Test PPT Item Sub A-001",251 "doctype":"BOM Item", "stock_qty":2, "rate":100, "amount": 200},252 {"item_code": "_Test PPT Item Sub B","item_name": "_Test PPT Item Sub B",253 "bom_no":"BOM-_Test PPT Item Sub B-001",254 "doctype":"BOM Item", "stock_qty":1, "rate":100, "amount": 100},255 {"item_code": "_Test PPT Item Raw A","item_name": "_Test PPT Item Raw A",256 "doctype":"BOM Item", "stock_qty":2, "rate":100,257 "amount": 200},258 {"item_code": "_Test PPT Item SC A","item_name": "_Test PPT Item SC A",259 "bom_no":"BOM-_Test PPT Item SC A-001",260 "doctype":"BOM Item", "stock_qty":1, "rate":100, "amount": 100}261 ])262def make_bom(name, properties=None, items=None):263 if frappe.db.exists("BOM", name):264 return frappe.get_doc("BOM", name)265 bom = frappe.new_doc("BOM")266 item = frappe.get_doc({267 "doctype": "BOM",268 "name": name,269 "quantity": "1",270 "with_operations": 0271 })272 if properties:273 bom.update(properties)274 if items:275 for item in items:276 bom.append("items", item)277 bom.insert()278 bom.submit()279 return bom280def clear_material_requests():281 frappe.db.sql("delete from `tabMaterial Request Item`")282 frappe.db.sql("delete from `tabMaterial Request`")283def run_production_planning_tool(**args):284 ppt = frappe.new_doc("Production Planning Tool")285 args = frappe._dict(args)286 if args.use_multi_level_bom:287 ppt.use_multi_level_bom = args.use_multi_level_bom288 else:289 ppt.use_multi_level_bom = 0290 if args.only_raw_materials:291 ppt.only_raw_materials = args.only_raw_materials292 else:293 ppt.only_raw_materials = 0294 if args.include_subcontracted:295 ppt.include_subcontracted = args.include_subcontracted296 else:297 ppt.include_subcontracted = 0298 if args.warehouse:299 ppt.purchase_request_for_warehouse = args.warehouse300 if args.company:301 ppt.company = args.company302 ppt.create_material_requests_for_all_required_qty = 1303 ppt.append("items",{"item_code": args.item_code, "bom_no": args.bom_no, "planned_qty": args.planned_qty,304 "planned_start_date": args.planned_start_date, "warehouse": args.warehouse})305 return ppt306def create_material_requests(ppt):307 ppt.raise_material_requests()308def get_requested_qty(item_code):309 total_qty = 0310 for d in frappe.db.sql("""select item.qty as qty311 from `tabMaterial Request` mat_req, `tabMaterial Request Item` item312 where item.item_code = %(item_code)s and item.parent = mat_req.name""", {"item_code":item_code}, as_dict=1):313 total_qty += d.qty314 return total_qty315def get_requested_types(item_code):316 types = []317 for d in frappe.db.sql("""select mat_req.material_request_type as type318 from `tabMaterial Request` mat_req, `tabMaterial Request Item` item319 where item.item_code = %(item_code)s and item.parent = mat_req.name""", {"item_code":item_code}, as_dict=1):320 types.append(d.type)...

Full Screen

Full Screen

test_pricing_rule.py

Source:test_pricing_rule.py Github

copy

Full Screen

1# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors2# License: GNU General Public License v3. See license.txt3from __future__ import unicode_literals4import unittest5import frappe6from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order7from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice8from erpnext.stock.get_item_details import get_item_details9from frappe import MandatoryError10class TestPricingRule(unittest.TestCase):11 def test_pricing_rule_for_discount(self):12 from erpnext.stock.get_item_details import get_item_details13 from frappe import MandatoryError14 frappe.db.sql("delete from `tabPricing Rule`")15 test_record = {16 "doctype": "Pricing Rule",17 "title": "_Test Pricing Rule",18 "apply_on": "Item Code",19 "item_code": "_Test Item",20 "selling": 1,21 "price_or_discount": "Discount Percentage",22 "price": 0,23 "discount_percentage": 10,24 "company": "_Test Company"25 }26 frappe.get_doc(test_record.copy()).insert()27 args = frappe._dict({28 "item_code": "_Test Item",29 "company": "_Test Company",30 "price_list": "_Test Price List",31 "currency": "_Test Currency",32 "doctype": "Sales Order",33 "conversion_rate": 1,34 "price_list_currency": "_Test Currency",35 "plc_conversion_rate": 1,36 "order_type": "Sales",37 "customer": "_Test Customer",38 "name": None39 })40 details = get_item_details(args)41 self.assertEquals(details.get("discount_percentage"), 10)42 prule = frappe.get_doc(test_record.copy())43 prule.applicable_for = "Customer"44 prule.title = "_Test Pricing Rule for Customer"45 self.assertRaises(MandatoryError, prule.insert)46 prule.customer = "_Test Customer"47 prule.discount_percentage = 2048 prule.insert()49 details = get_item_details(args)50 self.assertEquals(details.get("discount_percentage"), 20)51 prule = frappe.get_doc(test_record.copy())52 prule.apply_on = "Item Group"53 prule.item_group = "All Item Groups"54 prule.title = "_Test Pricing Rule for Item Group"55 prule.discount_percentage = 1556 prule.insert()57 args.customer = "_Test Customer 1"58 details = get_item_details(args)59 self.assertEquals(details.get("discount_percentage"), 10)60 prule = frappe.get_doc(test_record.copy())61 prule.applicable_for = "Campaign"62 prule.campaign = "_Test Campaign"63 prule.title = "_Test Pricing Rule for Campaign"64 prule.discount_percentage = 565 prule.priority = 866 prule.insert()67 args.campaign = "_Test Campaign"68 details = get_item_details(args)69 self.assertEquals(details.get("discount_percentage"), 5)70 frappe.db.sql("update `tabPricing Rule` set priority=NULL where campaign='_Test Campaign'")71 from erpnext.accounts.doctype.pricing_rule.pricing_rule import MultiplePricingRuleConflict72 self.assertRaises(MultiplePricingRuleConflict, get_item_details, args)73 args.item_code = "_Test Item 2"74 details = get_item_details(args)75 self.assertEquals(details.get("discount_percentage"), 15)76 frappe.db.sql("delete from `tabPricing Rule`")77 def test_pricing_rule_for_margin(self):78 from erpnext.stock.get_item_details import get_item_details79 from frappe import MandatoryError80 frappe.db.sql("delete from `tabPricing Rule`")81 test_record = {82 "doctype": "Pricing Rule",83 "title": "_Test Pricing Rule",84 "apply_on": "Item Code",85 "item_code": "_Test FG Item 2",86 "selling": 1,87 "price_or_discount": "Discount Percentage",88 "price": 0,89 "margin_type": "Percentage",90 "margin_rate_or_amount": 10,91 "company": "_Test Company"92 }93 frappe.get_doc(test_record.copy()).insert()94 95 item_price = frappe.get_doc({96 "doctype": "Item Price",97 "price_list": "_Test Price List 2",98 "item_code": "_Test FG Item 2",99 "price_list_rate": 100100 })101 102 item_price.insert(ignore_permissions=True)103 args = frappe._dict({104 "item_code": "_Test FG Item 2",105 "company": "_Test Company",106 "price_list": "_Test Price List",107 "currency": "_Test Currency",108 "doctype": "Sales Order",109 "conversion_rate": 1,110 "price_list_currency": "_Test Currency",111 "plc_conversion_rate": 1,112 "order_type": "Sales",113 "customer": "_Test Customer",114 "name": None115 })116 details = get_item_details(args)117 self.assertEquals(details.get("margin_type"), "Percentage")118 self.assertEquals(details.get("margin_rate_or_amount"), 10)119 frappe.db.sql("delete from `tabPricing Rule`")120 def test_pricing_rule_for_variants(self):121 from erpnext.stock.get_item_details import get_item_details122 from frappe import MandatoryError123 frappe.db.sql("delete from `tabPricing Rule`")124 if not frappe.db.exists("Item", "Test Variant PRT"):125 frappe.get_doc({126 "doctype": "Item",127 "item_code": "Test Variant PRT",128 "item_name": "Test Variant PRT",129 "description": "Test Variant PRT",130 "item_group": "_Test Item Group",131 "is_stock_item": 1,132 "variant_of": "_Test Variant Item",133 "default_warehouse": "_Test Warehouse - _TC",134 "stock_uom": "_Test UOM",135 "attributes": [136 {137 "attribute": "Test Size",138 "attribute_value": "Medium"139 }140 ],141 }).insert()142 frappe.get_doc({143 "doctype": "Pricing Rule",144 "title": "_Test Pricing Rule 1",145 "apply_on": "Item Code",146 "item_code": "_Test Variant Item",147 "selling": 1,148 "price_or_discount": "Discount Percentage",149 "price": 0,150 "discount_percentage": 7.5,151 "company": "_Test Company"152 }).insert()153 args = frappe._dict({154 "item_code": "Test Variant PRT",155 "company": "_Test Company",156 "price_list": "_Test Price List",157 "currency": "_Test Currency",158 "doctype": "Sales Order",159 "conversion_rate": 1,160 "price_list_currency": "_Test Currency",161 "plc_conversion_rate": 1,162 "order_type": "Sales",163 "customer": "_Test Customer",164 "name": None165 })166 details = get_item_details(args)167 self.assertEquals(details.get("discount_percentage"), 7.5)168 # add a new pricing rule for that item code, it should take priority169 frappe.get_doc({170 "doctype": "Pricing Rule",171 "title": "_Test Pricing Rule 2",172 "apply_on": "Item Code",173 "item_code": "Test Variant PRT",174 "selling": 1,175 "price_or_discount": "Discount Percentage",176 "price": 0,177 "discount_percentage": 17.5,178 "company": "_Test Company"179 }).insert()180 details = get_item_details(args)181 self.assertEquals(details.get("discount_percentage"), 17.5)182 def test_pricing_rule_for_stock_qty(self):183 frappe.db.sql("delete from `tabPricing Rule`")184 test_record = {185 "doctype": "Pricing Rule",186 "title": "_Test Pricing Rule",187 "apply_on": "Item Code",188 "item_code": "_Test Item",189 "selling": 1,190 "price_or_discount": "Discount Percentage",191 "price": 0,192 "min_qty": 5,193 "max_qty": 7,194 "discount_percentage": 17.5,195 "company": "_Test Company"196 }197 frappe.get_doc(test_record.copy()).insert()198 if not frappe.db.get_value('UOM Conversion Detail',199 {'parent': '_Test Item', 'uom': 'box'}):200 item = frappe.get_doc('Item', '_Test Item')201 item.append('uoms', {202 'uom': 'Box',203 'conversion_factor': 5204 })205 item.save(ignore_permissions=True)206 # With pricing rule207 so = make_sales_order(item_code="_Test Item", qty=1, uom="Box", do_not_submit=True)208 so.items[0].price_list_rate = 100209 so.submit()210 so = frappe.get_doc('Sales Order', so.name)211 self.assertEquals(so.items[0].discount_percentage, 17.5)212 self.assertEquals(so.items[0].rate, 82.5)213 # Without pricing rule214 so = make_sales_order(item_code="_Test Item", qty=2, uom="Box", do_not_submit=True)215 so.items[0].price_list_rate = 100216 so.submit()217 so = frappe.get_doc('Sales Order', so.name)218 self.assertEquals(so.items[0].discount_percentage, 0)219 self.assertEquals(so.items[0].rate, 100)220 def test_pricing_rule_with_margin_and_discount(self):221 frappe.delete_doc_if_exists('Pricing Rule', '_Test Pricing Rule')222 make_pricing_rule(selling=1, margin_type="Percentage", margin_rate_or_amount=10)223 si = create_sales_invoice(do_not_save=True)224 si.items[0].price_list_rate = 1000225 si.payment_schedule = []226 si.insert(ignore_permissions=True)227 item = si.items[0]228 self.assertEquals(item.rate, 1100)229 self.assertEquals(item.margin_rate_or_amount, 10)230 # With discount231 item.discount_percentage = 10232 si.payment_schedule = []233 si.save()234 item = si.items[0]235 self.assertEquals(item.rate, 990)236 self.assertEquals(item.discount_percentage, 10)237 frappe.db.sql("delete from `tabPricing Rule`")238def make_pricing_rule(**args):239 args = frappe._dict(args)240 doc = frappe.get_doc({241 "doctype": "Pricing Rule",242 "title": args.title or "_Test Pricing Rule",243 "company": args.company or "_Test Company",244 "apply_on": args.apply_on or "Item Code",245 "item_code": args.item_code or "_Test Item",246 "applicable_for": args.applicable_for,247 "selling": args.selling or 0,248 "buying": args.buying or 0,249 "min_qty": args.min_qty or 0.0,250 "max_qty": args.max_qty or 0.0,251 "price_or_discount": args.price_or_discount or "Discount Percentage",252 "discount_percentage": args.discount_percentage or 0.0,253 "price": args.price or 0.0,254 "margin_type": args.margin_type,255 "margin_rate_or_amount": args.margin_rate_or_amount or 0.0256 }).insert(ignore_permissions=True)257 apply_on = doc.apply_on.replace(' ', '_').lower()258 if args.get(apply_on) and apply_on != "item_code":259 doc.db_set(apply_on, args.get(apply_on))260 applicable_for = doc.applicable_for.replace(' ', '_').lower()261 if args.get(applicable_for):...

Full Screen

Full Screen

test_customer.py

Source:test_customer.py Github

copy

Full Screen

1# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors2# License: GNU General Public License v3. See license.txt3from __future__ import unicode_literals4import frappe5import unittest6from erpnext.accounts.party import get_due_date7from frappe.test_runner import make_test_records8from erpnext.exceptions import PartyFrozen, PartyDisabled9from frappe.utils import flt10from erpnext.selling.doctype.customer.customer import get_credit_limit, get_customer_outstanding11from erpnext.tests.utils import create_test_contact_and_address12test_ignore = ["Price List"]13test_dependencies = ['Payment Term', 'Payment Terms Template']14test_records = frappe.get_test_records('Customer')15class TestCustomer(unittest.TestCase):16 def setUp(self):17 if not frappe.get_value('Item', '_Test Item'):18 make_test_records('Item')19 def tearDown(self):20 frappe.db.set_value("Customer", '_Test Customer', 'credit_limit', 0.0)21 def test_party_details(self):22 from erpnext.accounts.party import get_party_details23 to_check = {24 'selling_price_list': None,25 'customer_group': '_Test Customer Group',26 'contact_designation': None,27 'customer_address': '_Test Address for Customer-Office',28 'contact_department': None,29 'contact_email': 'test_contact_customer@example.com',30 'contact_mobile': None,31 'sales_team': [],32 'contact_display': '_Test Contact for _Test Customer',33 'contact_person': '_Test Contact for _Test Customer-_Test Customer',34 'territory': u'_Test Territory',35 'contact_phone': '+91 0000000000',36 'customer_name': '_Test Customer'37 }38 create_test_contact_and_address()39 frappe.db.set_value("Contact", "_Test Contact for _Test Customer-_Test Customer",40 "is_primary_contact", 1)41 details = get_party_details("_Test Customer")42 for key, value in to_check.iteritems():43 self.assertEquals(value, details.get(key))44 def test_rename(self):45 # delete communication linked to these 2 customers46 for name in ("_Test Customer 1", "_Test Customer 1 Renamed"):47 frappe.db.sql("""delete from `tabCommunication`48 where communication_type='Comment' and reference_doctype=%s and reference_name=%s""",49 ("Customer", name))50 # add comments51 comment = frappe.get_doc("Customer", "_Test Customer 1").add_comment("Comment", "Test Comment for Rename")52 # rename53 frappe.rename_doc("Customer", "_Test Customer 1", "_Test Customer 1 Renamed")54 # check if customer renamed55 self.assertTrue(frappe.db.exists("Customer", "_Test Customer 1 Renamed"))56 self.assertFalse(frappe.db.exists("Customer", "_Test Customer 1"))57 # test that comment gets linked to renamed doc58 self.assertEquals(frappe.db.get_value("Communication", {59 "communication_type": "Comment",60 "reference_doctype": "Customer",61 "reference_name": "_Test Customer 1 Renamed"62 }), comment.name)63 # rename back to original64 frappe.rename_doc("Customer", "_Test Customer 1 Renamed", "_Test Customer 1")65 def test_freezed_customer(self):66 make_test_records("Item")67 frappe.db.set_value("Customer", "_Test Customer", "is_frozen", 1)68 from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order69 so = make_sales_order(do_not_save= True)70 self.assertRaises(PartyFrozen, so.save)71 frappe.db.set_value("Customer", "_Test Customer", "is_frozen", 0)72 so.save()73 def test_disabled_customer(self):74 make_test_records("Item")75 frappe.db.set_value("Customer", "_Test Customer", "disabled", 1)76 from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order77 so = make_sales_order(do_not_save=True)78 self.assertRaises(PartyDisabled, so.save)79 frappe.db.set_value("Customer", "_Test Customer", "disabled", 0)80 so.save()81 def test_duplicate_customer(self):82 frappe.db.sql("delete from `tabCustomer` where customer_name='_Test Customer 1'")83 if not frappe.db.get_value("Customer", "_Test Customer 1"):84 test_customer_1 = frappe.get_doc(85 get_customer_dict('_Test Customer 1')).insert(ignore_permissions=True)86 else:87 test_customer_1 = frappe.get_doc("Customer", "_Test Customer 1")88 duplicate_customer = frappe.get_doc(89 get_customer_dict('_Test Customer 1')).insert(ignore_permissions=True)90 self.assertEquals("_Test Customer 1", test_customer_1.name)91 self.assertEquals("_Test Customer 1 - 1", duplicate_customer.name)92 self.assertEquals(test_customer_1.customer_name, duplicate_customer.customer_name)93 def get_customer_outstanding_amount(self):94 from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order95 outstanding_amt = get_customer_outstanding('_Test Customer', '_Test Company')96 # If outstanding is negative make a transaction to get positive outstanding amount97 if outstanding_amt > 0.0:98 return outstanding_amt99 item_qty = int((abs(outstanding_amt) + 200)/100)100 make_sales_order(qty=item_qty)101 return get_customer_outstanding('_Test Customer', '_Test Company')102 def test_customer_credit_limit(self):103 from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note104 from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice105 from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order106 from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice107 outstanding_amt = self.get_customer_outstanding_amount()108 credit_limit = get_credit_limit('_Test Customer', '_Test Company')109 if outstanding_amt <= 0.0:110 item_qty = int((abs(outstanding_amt) + 200)/100)111 make_sales_order(qty=item_qty)112 if credit_limit == 0.0:113 frappe.db.set_value("Customer", '_Test Customer', 'credit_limit', outstanding_amt - 50.0)114 # Sales Order115 so = make_sales_order(do_not_submit=True)116 self.assertRaises(frappe.ValidationError, so.submit)117 # Delivery Note118 dn = create_delivery_note(do_not_submit=True)119 self.assertRaises(frappe.ValidationError, dn.submit)120 # Sales Invoice121 si = create_sales_invoice(do_not_submit=True)122 self.assertRaises(frappe.ValidationError, si.submit)123 if credit_limit > outstanding_amt:124 frappe.db.set_value("Customer", '_Test Customer', 'credit_limit', credit_limit)125 # Makes Sales invoice from Sales Order126 so.save(ignore_permissions=True)127 si = make_sales_invoice(so.name)128 si.save(ignore_permissions=True)129 self.assertRaises(frappe.ValidationError, make_sales_order)130 def test_customer_credit_limit_on_change(self):131 outstanding_amt = self.get_customer_outstanding_amount()132 customer = frappe.get_doc("Customer", '_Test Customer')133 customer.credit_limit = flt(outstanding_amt - 100)134 self.assertRaises(frappe.ValidationError, customer.save)135 def test_customer_payment_terms(self):136 frappe.db.set_value(137 "Customer", "_Test Customer With Template", "payment_terms", "_Test Payment Term Template 3")138 due_date = get_due_date("2016-01-22", "Customer", "_Test Customer With Template")139 self.assertEqual(due_date, "2016-02-21")140 due_date = get_due_date("2017-01-22", "Customer", "_Test Customer With Template")141 self.assertEqual(due_date, "2017-02-21")142 frappe.db.set_value(143 "Customer", "_Test Customer With Template", "payment_terms", "_Test Payment Term Template 1")144 due_date = get_due_date("2016-01-22", "Customer", "_Test Customer With Template")145 self.assertEqual(due_date, "2016-02-29")146 due_date = get_due_date("2017-01-22", "Customer", "_Test Customer With Template")147 self.assertEqual(due_date, "2017-02-28")148 frappe.db.set_value("Customer", "_Test Customer With Template", "payment_terms", "")149 # No default payment term template attached150 due_date = get_due_date("2016-01-22", "Customer", "_Test Customer")151 self.assertEqual(due_date, "2016-01-22")152 due_date = get_due_date("2017-01-22", "Customer", "_Test Customer")153 self.assertEqual(due_date, "2017-01-22")154def get_customer_dict(customer_name):155 return {156 "customer_group": "_Test Customer Group",157 "customer_name": customer_name,158 "customer_type": "Individual",159 "doctype": "Customer",160 "territory": "_Test Territory"...

Full Screen

Full Screen

test_budget.py

Source:test_budget.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors3# See license.txt4from __future__ import unicode_literals5import frappe6import unittest7from erpnext.accounts.doctype.budget.budget import get_actual_expense, BudgetError8from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry9class TestBudget(unittest.TestCase): 10 def test_monthly_budget_crossed_ignore(self):11 set_total_expense_zero("2013-02-28", "Cost Center")12 budget = make_budget("Cost Center")13 14 jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",15 "_Test Bank - _TC", 40000, "_Test Cost Center - _TC", submit=True)16 self.assertTrue(frappe.db.get_value("GL Entry",17 {"voucher_type": "Journal Entry", "voucher_no": jv.name}))18 19 budget.cancel()20 def test_monthly_budget_crossed_stop1(self):21 set_total_expense_zero("2013-02-28", "Cost Center")22 budget = make_budget("Cost Center")23 24 frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")25 jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",26 "_Test Bank - _TC", 40000, "_Test Cost Center - _TC")27 self.assertRaises(BudgetError, jv.submit)28 29 budget.load_from_db()30 budget.cancel()31 def test_monthly_budget_crossed_stop2(self):32 set_total_expense_zero("2013-02-28", "Project")33 budget = make_budget("Project")34 35 frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")36 jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",37 "_Test Bank - _TC", 40000, "_Test Cost Center - _TC", project="_Test Project")38 self.assertRaises(BudgetError, jv.submit)39 40 budget.load_from_db()41 budget.cancel()42 def test_yearly_budget_crossed_stop1(self):43 set_total_expense_zero("2013-02-28", "Cost Center")44 budget = make_budget("Cost Center")45 46 jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",47 "_Test Bank - _TC", 150000, "_Test Cost Center - _TC")48 self.assertRaises(BudgetError, jv.submit)49 50 budget.cancel()51 def test_yearly_budget_crossed_stop2(self):52 set_total_expense_zero("2013-02-28", "Project")53 budget = make_budget("Project")54 55 jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",56 "_Test Bank - _TC", 150000, "_Test Cost Center - _TC", project="_Test Project")57 self.assertRaises(BudgetError, jv.submit)58 59 budget.cancel()60 def test_monthly_budget_on_cancellation1(self):61 set_total_expense_zero("2013-02-28", "Cost Center")62 budget = make_budget("Cost Center")63 64 jv1 = make_journal_entry("_Test Account Cost for Goods Sold - _TC",65 "_Test Bank - _TC", 20000, "_Test Cost Center - _TC", submit=True)66 self.assertTrue(frappe.db.get_value("GL Entry",67 {"voucher_type": "Journal Entry", "voucher_no": jv1.name}))68 jv2 = make_journal_entry("_Test Account Cost for Goods Sold - _TC",69 "_Test Bank - _TC", 20000, "_Test Cost Center - _TC", submit=True)70 self.assertTrue(frappe.db.get_value("GL Entry",71 {"voucher_type": "Journal Entry", "voucher_no": jv2.name}))72 frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")73 74 self.assertRaises(BudgetError, jv1.cancel)75 76 budget.load_from_db()77 budget.cancel()78 def test_monthly_budget_on_cancellation2(self):79 set_total_expense_zero("2013-02-28", "Project")80 budget = make_budget("Project")81 82 jv1 = make_journal_entry("_Test Account Cost for Goods Sold - _TC",83 "_Test Bank - _TC", 20000, "_Test Cost Center - _TC", submit=True, project="_Test Project")84 self.assertTrue(frappe.db.get_value("GL Entry",85 {"voucher_type": "Journal Entry", "voucher_no": jv1.name}))86 jv2 = make_journal_entry("_Test Account Cost for Goods Sold - _TC",87 "_Test Bank - _TC", 20000, "_Test Cost Center - _TC", submit=True, project="_Test Project")88 self.assertTrue(frappe.db.get_value("GL Entry",89 {"voucher_type": "Journal Entry", "voucher_no": jv2.name}))90 frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")91 92 self.assertRaises(BudgetError, jv1.cancel)93 94 budget.load_from_db()95 budget.cancel()96 97 def test_monthly_budget_against_group_cost_center(self):98 set_total_expense_zero("2013-02-28", "Cost Center")99 set_total_expense_zero("2013-02-28", "Cost Center", "_Test Cost Center 2 - _TC")100 101 budget = make_budget("Cost Center", "_Test Company - _TC")102 frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")103 jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",104 "_Test Bank - _TC", 40000, "_Test Cost Center 2 - _TC")105 self.assertRaises(BudgetError, jv.submit)106 107 budget.load_from_db()108 budget.cancel()109 def test_monthly_budget_against_parent_group_cost_center(self):110 cost_center = "_Test Cost Center 3 - _TC"111 if not frappe.db.exists("Cost Center", cost_center):112 frappe.get_doc({113 'doctype': 'Cost Center',114 'cost_center_name': '_Test Cost Center 3',115 'parent_cost_center': "_Test Company - _TC",116 'company': '_Test Company',117 'is_group': 0118 }).insert(ignore_permissions=True)119 budget = make_budget("Cost Center", cost_center)120 frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")121 jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",122 "_Test Bank - _TC", 40000, cost_center)123 self.assertRaises(BudgetError, jv.submit)124 budget.load_from_db()125 budget.cancel()126 jv.cancel()127 frappe.delete_doc('Journal Entry', jv.name)128 frappe.delete_doc('Cost Center', cost_center)129def set_total_expense_zero(posting_date, budget_against_field=None, budget_against_CC=None):130 if budget_against_field == "Project":131 budget_against = "_Test Project"132 else:133 budget_against = budget_against_CC or "_Test Cost Center - _TC"134 existing_expense = get_actual_expense(frappe._dict({135 "account": "_Test Account Cost for Goods Sold - _TC",136 "cost_center": "_Test Cost Center - _TC",137 "monthly_end_date": posting_date,138 "company": "_Test Company",139 "fiscal_year": "_Test Fiscal Year 2013",140 "budget_against_field": budget_against_field,141 "budget_against": budget_against142 }))143 144 if existing_expense:145 if budget_against_field == "Cost Center":146 make_journal_entry("_Test Account Cost for Goods Sold - _TC",147 "_Test Bank - _TC", -existing_expense, "_Test Cost Center - _TC", submit=True)148 elif budget_against_field == "Project":149 make_journal_entry("_Test Account Cost for Goods Sold - _TC",150 "_Test Bank - _TC", -existing_expense, "_Test Cost Center - _TC", submit=True, project="_Test Project")151 152def make_budget(budget_against=None, cost_center=None):153 if budget_against == "Project":154 budget_list = frappe.get_all("Budget", fields=["name"], filters = {"name": ("like", "_Test Project/_Test Fiscal Year 2013%")})155 else:156 cost_center_name = "{0}%".format(cost_center or "_Test Cost Center - _TC/_Test Fiscal Year 2013")157 budget_list = frappe.get_all("Budget", fields=["name"], filters = {"name": ("like", cost_center_name)})158 for d in budget_list:159 frappe.db.sql("delete from `tabBudget` where name = %(name)s", d)160 frappe.db.sql("delete from `tabBudget Account` where parent = %(name)s", d)161 budget = frappe.new_doc("Budget")162 163 if budget_against == "Project":164 budget.project = "_Test Project"165 else:166 budget.cost_center =cost_center or "_Test Cost Center - _TC"167 168 169 budget.fiscal_year = "_Test Fiscal Year 2013"170 budget.monthly_distribution = "_Test Distribution"171 budget.company = "_Test Company"172 budget.action_if_annual_budget_exceeded = "Stop"173 budget.action_if_accumulated_monthly_budget_exceeded = "Ignore"174 budget.budget_against = budget_against175 budget.append("accounts", {176 "account": "_Test Account Cost for Goods Sold - _TC",177 "budget_amount": 100000178 })179 180 budget.insert()181 budget.submit()...

Full Screen

Full Screen

test_item.py

Source:test_item.py Github

copy

Full Screen

1# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors2# License: GNU General Public License v3. See license.txt3from __future__ import unicode_literals4import unittest5import webnotes6test_ignore = ["BOM"]7test_dependencies = ["Warehouse"]8class TestItem(unittest.TestCase):9 def test_default_warehouse(self):10 from stock.doctype.item.item import WarehouseNotSet11 item = webnotes.bean(copy=test_records[0])12 item.doc.is_stock_item = "Yes"13 item.doc.default_warehouse = None14 self.assertRaises(WarehouseNotSet, item.insert)15test_records = [16 [{17 "doctype": "Item",18 "item_code": "_Test Item",19 "item_name": "_Test Item",20 "description": "_Test Item",21 "item_group": "_Test Item Group",22 "is_stock_item": "Yes",23 "is_asset_item": "No",24 "has_batch_no": "No",25 "has_serial_no": "No",26 "is_purchase_item": "Yes",27 "is_sales_item": "Yes",28 "is_service_item": "No",29 "inspection_required": "No",30 "is_pro_applicable": "Yes",31 "is_sub_contracted_item": "No",32 "stock_uom": "_Test UOM",33 "default_income_account": "Sales - _TC",34 "default_warehouse": "_Test Warehouse - _TC",35 "purchase_account": "_Test Account Cost for Goods Sold - _TC"36 }, {37 "doctype": "Item Reorder",38 "parentfield": "item_reorder",39 "warehouse": "_Test Warehouse - _TC",40 "warehouse_reorder_level": 20,41 "warehouse_reorder_qty": 20,42 "material_request_type": "Purchase"43 },44 ],45 [{46 "doctype": "Item",47 "item_code": "_Test Item 2",48 "item_name": "_Test Item 2",49 "description": "_Test Item 2",50 "item_group": "_Test Item Group",51 "is_stock_item": "Yes",52 "is_asset_item": "No",53 "has_batch_no": "No",54 "has_serial_no": "No",55 "is_purchase_item": "Yes",56 "is_sales_item": "Yes",57 "is_service_item": "No",58 "inspection_required": "No",59 "is_pro_applicable": "Yes",60 "is_sub_contracted_item": "No",61 "stock_uom": "_Test UOM",62 "default_income_account": "Sales - _TC",63 "default_warehouse": "_Test Warehouse - _TC",64 "purchase_account": "_Test Account Cost for Goods Sold - _TC"65 }], 66 [{67 "doctype": "Item",68 "item_code": "_Test Item Home Desktop 100",69 "item_name": "_Test Item Home Desktop 100",70 "description": "_Test Item Home Desktop 100",71 "item_group": "_Test Item Group Desktops",72 "default_warehouse": "_Test Warehouse - _TC",73 "default_income_account": "Sales - _TC",74 "purchase_account": "_Test Account Cost for Goods Sold - _TC",75 "is_stock_item": "Yes",76 "is_asset_item": "No",77 "has_batch_no": "No",78 "has_serial_no": "No",79 "is_purchase_item": "Yes",80 "is_sales_item": "Yes",81 "is_service_item": "No",82 "inspection_required": "No",83 "is_pro_applicable": "No",84 "is_sub_contracted_item": "No",85 "is_manufactured_item": "No",86 "stock_uom": "_Test UOM"87 },88 {89 "doctype": "Item Tax",90 "tax_type": "_Test Account Excise Duty - _TC",91 "tax_rate": 1092 }],93 [{94 "doctype": "Item",95 "item_code": "_Test Item Home Desktop 200",96 "item_name": "_Test Item Home Desktop 200",97 "description": "_Test Item Home Desktop 200",98 "item_group": "_Test Item Group Desktops",99 "default_warehouse": "_Test Warehouse - _TC",100 "default_income_account": "Sales - _TC",101 "purchase_account": "_Test Account Cost for Goods Sold - _TC",102 "is_stock_item": "Yes",103 "is_asset_item": "No",104 "has_batch_no": "No",105 "has_serial_no": "No",106 "is_purchase_item": "Yes",107 "is_sales_item": "Yes",108 "is_service_item": "No",109 "inspection_required": "No",110 "is_pro_applicable": "No",111 "is_sub_contracted_item": "No",112 "is_manufactured_item": "No",113 "stock_uom": "_Test UOM"114 }],115 [{116 "doctype": "Item",117 "item_code": "_Test Sales BOM Item",118 "item_name": "_Test Sales BOM Item",119 "description": "_Test Sales BOM Item",120 "item_group": "_Test Item Group Desktops",121 "default_income_account": "Sales - _TC",122 "purchase_account": "_Test Account Cost for Goods Sold - _TC",123 "is_stock_item": "No",124 "is_asset_item": "No",125 "has_batch_no": "No",126 "has_serial_no": "No",127 "is_purchase_item": "Yes",128 "is_sales_item": "Yes",129 "is_service_item": "No",130 "inspection_required": "No",131 "is_pro_applicable": "No",132 "is_sub_contracted_item": "No",133 "stock_uom": "_Test UOM"134 }],135 [{136 "doctype": "Item",137 "item_code": "_Test FG Item",138 "item_name": "_Test FG Item",139 "description": "_Test FG Item",140 "item_group": "_Test Item Group Desktops",141 "is_stock_item": "Yes",142 "default_warehouse": "_Test Warehouse - _TC",143 "default_income_account": "Sales - _TC",144 "purchase_account": "_Test Account Cost for Goods Sold - _TC",145 "is_asset_item": "No",146 "has_batch_no": "No",147 "has_serial_no": "No",148 "is_purchase_item": "Yes",149 "is_sales_item": "Yes",150 "is_service_item": "No",151 "inspection_required": "No",152 "is_pro_applicable": "Yes",153 "is_sub_contracted_item": "Yes",154 "stock_uom": "_Test UOM"155 }],156 [{157 "doctype": "Item",158 "item_code": "_Test Non Stock Item",159 "item_name": "_Test Non Stock Item",160 "description": "_Test Non Stock Item",161 "item_group": "_Test Item Group Desktops",162 "is_stock_item": "No",163 "is_asset_item": "No",164 "has_batch_no": "No",165 "has_serial_no": "No",166 "is_purchase_item": "Yes",167 "is_sales_item": "Yes",168 "is_service_item": "No",169 "inspection_required": "No",170 "is_pro_applicable": "No",171 "is_sub_contracted_item": "No",172 "stock_uom": "_Test UOM"173 }],174 [{175 "doctype": "Item",176 "item_code": "_Test Serialized Item",177 "item_name": "_Test Serialized Item",178 "description": "_Test Serialized Item",179 "item_group": "_Test Item Group Desktops",180 "is_stock_item": "Yes",181 "default_warehouse": "_Test Warehouse - _TC",182 "is_asset_item": "No",183 "has_batch_no": "No",184 "has_serial_no": "Yes",185 "is_purchase_item": "Yes",186 "is_sales_item": "Yes",187 "is_service_item": "No",188 "inspection_required": "No",189 "is_pro_applicable": "No",190 "is_sub_contracted_item": "No",191 "stock_uom": "_Test UOM"192 }],193 [{194 "doctype": "Item",195 "item_code": "_Test Serialized Item With Series",196 "item_name": "_Test Serialized Item With Series",197 "description": "_Test Serialized Item",198 "item_group": "_Test Item Group Desktops",199 "is_stock_item": "Yes",200 "default_warehouse": "_Test Warehouse - _TC",201 "is_asset_item": "No",202 "has_batch_no": "No",203 "has_serial_no": "Yes",204 "serial_no_series": "ABCD.#####",205 "is_purchase_item": "Yes",206 "is_sales_item": "Yes",207 "is_service_item": "No",208 "inspection_required": "No",209 "is_pro_applicable": "Yes",210 "is_sub_contracted_item": "No",211 "stock_uom": "_Test UOM"212 }],213 [{214 "doctype": "Item",215 "item_code": "_Test Item Home Desktop Manufactured",216 "item_name": "_Test Item Home Desktop Manufactured",217 "description": "_Test Item Home Desktop Manufactured",218 "item_group": "_Test Item Group Desktops",219 "default_warehouse": "_Test Warehouse - _TC",220 "default_income_account": "Sales - _TC",221 "purchase_account": "_Test Account Cost for Goods Sold - _TC",222 "is_stock_item": "Yes",223 "is_asset_item": "No",224 "has_batch_no": "No",225 "has_serial_no": "No",226 "is_purchase_item": "Yes",227 "is_sales_item": "Yes",228 "is_service_item": "No",229 "inspection_required": "No",230 "is_pro_applicable": "Yes",231 "is_sub_contracted_item": "No",232 "is_manufactured_item": "Yes",233 "stock_uom": "_Test UOM"234 }],235 [{236 "doctype": "Item",237 "item_code": "_Test FG Item 2",238 "item_name": "_Test FG Item 2",239 "description": "_Test FG Item 2",240 "item_group": "_Test Item Group Desktops",241 "is_stock_item": "Yes",242 "default_warehouse": "_Test Warehouse - _TC",243 "default_income_account": "Sales - _TC",244 "purchase_account": "_Test Account Cost for Goods Sold - _TC",245 "is_asset_item": "No",246 "has_batch_no": "No",247 "has_serial_no": "No",248 "is_purchase_item": "Yes",249 "is_sales_item": "Yes",250 "is_service_item": "No",251 "inspection_required": "No",252 "is_pro_applicable": "Yes",253 "is_sub_contracted_item": "Yes",254 "stock_uom": "_Test UOM"255 }],...

Full Screen

Full Screen

test_tax_rule.py

Source:test_tax_rule.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors3# See license.txt4from __future__ import unicode_literals5import frappe6import unittest7from erpnext.accounts.doctype.tax_rule.tax_rule import IncorrectCustomerGroup, IncorrectSupplierType, ConflictingTaxRule, get_tax_template8test_records = frappe.get_test_records('Tax Rule')9class TestTaxRule(unittest.TestCase):10 def setUp(self):11 frappe.db.sql("delete from `tabTax Rule`")12 def tearDown(self):13 frappe.db.sql("delete from `tabTax Rule`")14 def test_conflict(self):15 tax_rule1 = make_tax_rule(customer= "_Test Customer",16 sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority = 1)17 tax_rule1.save()18 tax_rule2 = make_tax_rule(customer= "_Test Customer",19 sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority = 1)20 self.assertRaises(ConflictingTaxRule, tax_rule2.save)21 def test_conflict_with_non_overlapping_dates(self):22 tax_rule1 = make_tax_rule(customer= "_Test Customer",23 sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority = 1, from_date = "2015-01-01")24 tax_rule1.save()25 tax_rule2 = make_tax_rule(customer= "_Test Customer",26 sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority = 1, to_date = "2013-01-01")27 tax_rule2.save()28 self.assertTrue(tax_rule2.name)29 def test_for_parent_customer_group(self):30 tax_rule1 = make_tax_rule(customer_group= "All Customer Groups",31 sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority = 1, from_date = "2015-01-01")32 tax_rule1.save()33 self.assertEquals(get_tax_template("2015-01-01", {"customer_group" : "Commercial", "use_for_shopping_cart":0}),34 "_Test Sales Taxes and Charges Template - _TC")35 def test_conflict_with_overlapping_dates(self):36 tax_rule1 = make_tax_rule(customer= "_Test Customer",37 sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority = 1, from_date = "2015-01-01", to_date = "2015-01-05")38 tax_rule1.save()39 tax_rule2 = make_tax_rule(customer= "_Test Customer",40 sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority = 1, from_date = "2015-01-03", to_date = "2015-01-09")41 self.assertRaises(ConflictingTaxRule, tax_rule2.save)42 def test_tax_template(self):43 tax_rule = make_tax_rule()44 self.assertEquals(tax_rule.purchase_tax_template, None)45 def test_select_tax_rule_based_on_customer(self):46 make_tax_rule(customer= "_Test Customer",47 sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", save=1)48 make_tax_rule(customer= "_Test Customer 1",49 sales_tax_template = "_Test Sales Taxes and Charges Template 1 - _TC", save=1)50 make_tax_rule(customer= "_Test Customer 2",51 sales_tax_template = "_Test Sales Taxes and Charges Template 2 - _TC", save=1)52 self.assertEquals(get_tax_template("2015-01-01", {"customer":"_Test Customer 2"}),53 "_Test Sales Taxes and Charges Template 2 - _TC")54 def test_select_tax_rule_based_on_better_match(self):55 make_tax_rule(customer= "_Test Customer", billing_city = "Test City", billing_state = "Test State",56 sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", save=1)57 make_tax_rule(customer= "_Test Customer", billing_city = "Test City1", billing_state = "Test State",58 sales_tax_template = "_Test Sales Taxes and Charges Template 1 - _TC", save=1)59 self.assertEquals(get_tax_template("2015-01-01", {"customer":"_Test Customer", "billing_city": "Test City", "billing_state": "Test State"}),60 "_Test Sales Taxes and Charges Template - _TC")61 def test_select_tax_rule_based_on_state_match(self):62 make_tax_rule(customer= "_Test Customer", shipping_state = "Test State",63 sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", save=1)64 make_tax_rule(customer= "_Test Customer", shipping_state = "Test State12",65 sales_tax_template = "_Test Sales Taxes and Charges Template 1 - _TC", priority=2, save=1)66 self.assertEquals(get_tax_template("2015-01-01", {"customer":"_Test Customer", "shipping_state": "Test State"}),67 "_Test Sales Taxes and Charges Template - _TC")68 def test_select_tax_rule_based_on_better_priority(self):69 make_tax_rule(customer= "_Test Customer", billing_city = "Test City",70 sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority=1, save=1)71 make_tax_rule(customer= "_Test Customer", billing_city = "Test City",72 sales_tax_template = "_Test Sales Taxes and Charges Template 1 - _TC", priority=2, save=1)73 self.assertEquals(get_tax_template("2015-01-01", {"customer":"_Test Customer", "billing_city": "Test City"}),74 "_Test Sales Taxes and Charges Template 1 - _TC")75 def test_select_tax_rule_based_cross_matching_keys(self):76 make_tax_rule(customer= "_Test Customer", billing_city = "Test City",77 sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", save=1)78 make_tax_rule(customer= "_Test Customer 1", billing_city = "Test City 1",79 sales_tax_template = "_Test Sales Taxes and Charges Template 1 - _TC", save=1)80 self.assertEquals(get_tax_template("2015-01-01", {"customer":"_Test Customer", "billing_city": "Test City 1"}),81 None)82 def test_select_tax_rule_based_cross_partially_keys(self):83 make_tax_rule(customer= "_Test Customer", billing_city = "Test City",84 sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", save=1)85 make_tax_rule(billing_city = "Test City 1",86 sales_tax_template = "_Test Sales Taxes and Charges Template 1 - _TC", save=1)87 self.assertEquals(get_tax_template("2015-01-01", {"customer":"_Test Customer", "billing_city": "Test City 1"}),88 "_Test Sales Taxes and Charges Template 1 - _TC")89def make_tax_rule(**args):90 args = frappe._dict(args)91 tax_rule = frappe.new_doc("Tax Rule")92 for key, val in args.iteritems():93 if key != "save":94 tax_rule.set(key, val)95 tax_rule.company = args.company or "_Test Company"96 if args.save:97 tax_rule.insert()...

Full Screen

Full Screen

test_account.py

Source:test_account.py Github

copy

Full Screen

1# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors2# License: GNU General Public License v3. See license.txt3from __future__ import unicode_literals4import unittest5import frappe6from erpnext.stock import get_warehouse_account, get_company_default_inventory_account7class TestAccount(unittest.TestCase):8 def test_rename_account(self):9 if not frappe.db.exists("Account", "1210 - Debtors - _TC"):10 acc = frappe.new_doc("Account")11 acc.account_name = "Debtors"12 acc.parent_account = "Accounts Receivable - _TC"13 acc.account_number = "1210"14 acc.company = "_Test Company"15 acc.insert()16 account_number, account_name = frappe.db.get_value("Account", "1210 - Debtors - _TC",17 ["account_number", "account_name"])18 self.assertEqual(account_number, "1210")19 self.assertEqual(account_name, "Debtors")20 frappe.rename_doc("Account", "1210 - Debtors - _TC", "1211 - Debtors 1 - _TC")21 new_acc = frappe.db.get_value("Account", "1211 - Debtors 1 - _TC",22 ["account_name", "account_number"], as_dict=1)23 self.assertEqual(new_acc.account_name, "Debtors 1")24 self.assertEqual(new_acc.account_number, "1211")25 frappe.rename_doc("Account", "1211 - Debtors 1 - _TC", "Debtors 2")26 new_acc = frappe.db.get_value("Account", "1211 - Debtors 2 - _TC",27 ["account_name", "account_number"], as_dict=1)28 self.assertEqual(new_acc.account_name, "Debtors 2")29 self.assertEqual(new_acc.account_number, "1211")30 frappe.delete_doc("Account", "1211 - Debtors 2 - _TC")31def _make_test_records(verbose):32 from frappe.test_runner import make_test_objects33 accounts = [34 # [account_name, parent_account, is_group]35 ["_Test Bank", "Bank Accounts", 0, "Bank", None],36 ["_Test Bank USD", "Bank Accounts", 0, "Bank", "USD"],37 ["_Test Bank EUR", "Bank Accounts", 0, "Bank", "EUR"],38 ["_Test Cash", "Cash In Hand", 0, "Cash", None],39 ["_Test Account Stock Expenses", "Direct Expenses", 1, None, None],40 ["_Test Account Shipping Charges", "_Test Account Stock Expenses", 0, "Chargeable", None],41 ["_Test Account Customs Duty", "_Test Account Stock Expenses", 0, "Tax", None],42 ["_Test Account Insurance Charges", "_Test Account Stock Expenses", 0, "Chargeable", None],43 ["_Test Account Stock Adjustment", "_Test Account Stock Expenses", 0, "Stock Adjustment", None],44 ["_Test Employee Advance", "Current Liabilities", 0, None, None],45 ["_Test Account Tax Assets", "Current Assets", 1, None, None],46 ["_Test Account VAT", "_Test Account Tax Assets", 0, "Tax", None],47 ["_Test Account Service Tax", "_Test Account Tax Assets", 0, "Tax", None],48 ["_Test Account Reserves and Surplus", "Current Liabilities", 0, None, None],49 ["_Test Account Cost for Goods Sold", "Expenses", 0, None, None],50 ["_Test Account Excise Duty", "_Test Account Tax Assets", 0, "Tax", None],51 ["_Test Account Education Cess", "_Test Account Tax Assets", 0, "Tax", None],52 ["_Test Account S&H Education Cess", "_Test Account Tax Assets", 0, "Tax", None],53 ["_Test Account CST", "Direct Expenses", 0, "Tax", None],54 ["_Test Account Discount", "Direct Expenses", 0, None, None],55 ["_Test Write Off", "Indirect Expenses", 0, None, None],56 ["_Test Exchange Gain/Loss", "Indirect Expenses", 0, None, None],57 # related to Account Inventory Integration58 ["_Test Account Stock In Hand", "Current Assets", 0, None, None],59 60 # fixed asset depreciation61 ["_Test Fixed Asset", "Current Assets", 0, "Fixed Asset", None],62 ["_Test Accumulated Depreciations", "Current Assets", 0, None, None],63 ["_Test Depreciations", "Expenses", 0, None, None],64 ["_Test Gain/Loss on Asset Disposal", "Expenses", 0, None, None],65 # Receivable / Payable Account66 ["_Test Receivable", "Current Assets", 0, "Receivable", None],67 ["_Test Payable", "Current Liabilities", 0, "Payable", None],68 ["_Test Receivable USD", "Current Assets", 0, "Receivable", "USD"],69 ["_Test Payable USD", "Current Liabilities", 0, "Payable", "USD"]70 ]71 for company, abbr in [["_Test Company", "_TC"], ["_Test Company 1", "_TC1"]]:72 test_objects = make_test_objects("Account", [{73 "doctype": "Account",74 "account_name": account_name,75 "parent_account": parent_account + " - " + abbr,76 "company": company,77 "is_group": is_group,78 "account_type": account_type,79 "account_currency": currency80 } for account_name, parent_account, is_group, account_type, currency in accounts])81 return test_objects82def get_inventory_account(company, warehouse=None):83 account = None84 if warehouse:85 account = get_warehouse_account(warehouse, company)86 else:87 account = get_company_default_inventory_account(company)88 return account89def create_account(**kwargs):90 account = frappe.get_doc(dict(91 doctype = "Account",92 account_name = kwargs.get('account_name'),93 account_type = kwargs.get('account_type'),94 parent_account = kwargs.get('parent_account'),95 company = kwargs.get('company')96 ))97 98 account.save()...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var util = require('util');3var wpt = new WebPageTest('www.webpagetest.org');4 if (err) return console.error(err);5 console.log(util.inspect(data));6});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var wpt_test = new wpt('_test');3 console.log(data);4});5var wpt = require('./wpt.js');6var wpt_test = new wpt('_test');7 console.log(data);8}, 'Dulles:Chrome');9var wpt = require('./wpt.js');10var wpt_test = new wpt('_test');11var options = {12};13 console.log(data);14}, 'Dulles:Chrome', options);15var wpt = require('./wpt.js');16var wpt_test = new wpt('_test');17wpt_test.getTestResults('140417_9X_6c4d6b4b6c8b6f4b6d4b6e4b6f4b6d4b', function(data){18 console.log(data);19});20var wpt = require('./wpt.js');21var wpt_test = new wpt('_test');22wpt_test.getTestResults('140417_9X_6c4d6b4b6c8b6f4b6d4b6e4b6f4b6d4b', function(data){23 console.log(data);24}, 'Dulles:Chrome');25var wpt = require('./wpt.js');26var wpt_test = new wpt('_test');27var options = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt._test(url, function(err, data) {4 if (err) return console.error(err);5 console.log('Test id: %s', data.data.testId);6 console.log('Owner Key: %s', data.data.ownerKey);7});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful