mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 16:34:46 +00:00
refactor(test): make item deterministic
This commit is contained in:
@@ -5,8 +5,8 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
from frappe import qb
|
||||||
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
|
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
|
||||||
from frappe.test_runner import make_test_objects
|
|
||||||
from frappe.utils import add_days, today
|
from frappe.utils import add_days, today
|
||||||
|
|
||||||
from erpnext.controllers.item_variant import (
|
from erpnext.controllers.item_variant import (
|
||||||
@@ -85,11 +85,25 @@ class TestItem(ERPNextTestSuite):
|
|||||||
item = frappe.get_doc("Item", item_code)
|
item = frappe.get_doc("Item", item_code)
|
||||||
return item
|
return item
|
||||||
|
|
||||||
def test_get_item_details(self):
|
def make_bin(self, records):
|
||||||
# delete modified item price record and make as per self.globalTestRecords["Item"]
|
for x in records:
|
||||||
frappe.db.sql("""delete from `tabItem Price`""")
|
x = frappe._dict(x)
|
||||||
frappe.db.sql("""delete from `tabBin`""")
|
bin = qb.DocType("Bin")
|
||||||
|
filters = {
|
||||||
|
"item_code": x.get("item_code"),
|
||||||
|
"warehouse": x.get("warehouse"),
|
||||||
|
"reserved_qty": x.get("reserved_qty"),
|
||||||
|
"actual_qty": x.get("actual_qty"),
|
||||||
|
"ordered_qty": x.get("ordered_qty"),
|
||||||
|
"projected_qty": x.get("projected_qty"),
|
||||||
|
}
|
||||||
|
if not frappe.db.exists("Bin", filters):
|
||||||
|
qb.from_(bin).delete().where(
|
||||||
|
bin.item_code.eq(x.item_code) & bin.warehouse.eq(x.warehouse)
|
||||||
|
).run()
|
||||||
|
frappe.get_doc(x).insert()
|
||||||
|
|
||||||
|
def test_get_item_details(self):
|
||||||
to_check = {
|
to_check = {
|
||||||
"item_code": "_Test Item",
|
"item_code": "_Test Item",
|
||||||
"item_name": "_Test Item",
|
"item_name": "_Test Item",
|
||||||
@@ -114,11 +128,10 @@ class TestItem(ERPNextTestSuite):
|
|||||||
"projected_qty": 14,
|
"projected_qty": 14,
|
||||||
}
|
}
|
||||||
|
|
||||||
make_test_objects("Item Price")
|
self.make_bin(
|
||||||
make_test_objects(
|
|
||||||
"Bin",
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
"doctype": "Bin",
|
||||||
"item_code": "_Test Item",
|
"item_code": "_Test Item",
|
||||||
"warehouse": "_Test Warehouse - _TC",
|
"warehouse": "_Test Warehouse - _TC",
|
||||||
"reserved_qty": 1,
|
"reserved_qty": 1,
|
||||||
@@ -954,6 +967,7 @@ class TestItem(ERPNextTestSuite):
|
|||||||
msg="Different Variant UOM should not be allowed when `allow_different_uom` is disabled.",
|
msg="Different Variant UOM should not be allowed when `allow_different_uom` is disabled.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ERPNextTestSuite.change_settings("Global Defaults", {"default_company": "_Test Company"})
|
||||||
def test_opening_stock_for_serial_batch(self):
|
def test_opening_stock_for_serial_batch(self):
|
||||||
items = {
|
items = {
|
||||||
"Test Opening Stock for Serial No": {
|
"Test Opening Stock for Serial No": {
|
||||||
|
|||||||
@@ -246,6 +246,7 @@ class ERPNextTestSuite(unittest.TestCase):
|
|||||||
cls.make_quality_inspection_param()
|
cls.make_quality_inspection_param()
|
||||||
cls.make_quality_inspection_template()
|
cls.make_quality_inspection_template()
|
||||||
cls.make_employees()
|
cls.make_employees()
|
||||||
|
cls.make_brand()
|
||||||
cls.update_selling_settings()
|
cls.update_selling_settings()
|
||||||
cls.update_stock_settings()
|
cls.update_stock_settings()
|
||||||
cls.update_system_settings()
|
cls.update_system_settings()
|
||||||
@@ -2919,6 +2920,31 @@ class ERPNextTestSuite(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def make_brand(cls):
|
||||||
|
records = [
|
||||||
|
{"brand": "_Test Brand", "doctype": "Brand"},
|
||||||
|
{
|
||||||
|
"brand": "_Test Brand With Item Defaults",
|
||||||
|
"doctype": "Brand",
|
||||||
|
"brand_defaults": [
|
||||||
|
{
|
||||||
|
"company": "_Test Company",
|
||||||
|
"expense_account": "_Test Account Cost for Goods Sold - _TC",
|
||||||
|
"income_account": "_Test Account Sales - _TC",
|
||||||
|
"buying_cost_center": "_Test Cost Center - _TC",
|
||||||
|
"selling_cost_center": "_Test Cost Center - _TC",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
cls.brand = []
|
||||||
|
for x in records:
|
||||||
|
if not frappe.db.exists("Brand", {"brand": x.get("brand")}):
|
||||||
|
cls.brand.append(frappe.get_doc(x).insert())
|
||||||
|
else:
|
||||||
|
cls.brand.append(frappe.get_doc("Brand", {"Brand": x.get("brand")}))
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def set_user(self, user: str):
|
def set_user(self, user: str):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user