Test case fixes for item defaults

This commit is contained in:
Nabin Hait 2018-05-24 18:19:21 +05:30
parent b903fc4e71
commit f87ec61043
4 changed files with 113 additions and 55 deletions

View File

@ -268,8 +268,11 @@ def get_item_details(args):
return cost_center, expense_account return cost_center, expense_account
if args.item_code: if args.item_code:
cost_center, expense_account = frappe.db.get_value('Item Default', item_defaults = frappe.db.get_value('Item Default',
{'parent': args.item_code, 'company': args.get('company')}, ['buying_cost_center', 'expense_account']) {'parent': args.item_code, 'company': args.get('company')},
['buying_cost_center', 'expense_account'])
if item_defaults:
cost_center, expense_account = item_defaults
if not (cost_center and expense_account): if not (cost_center and expense_account):
for doctype in ['Item Group', 'Company']: for doctype in ['Item Group', 'Company']:

View File

@ -479,7 +479,6 @@ def get_party_shipping_address(doctype, name):
def get_patry_tax_withholding_details(ref_doc): def get_patry_tax_withholding_details(ref_doc):
supplier = frappe.get_doc("Supplier", ref_doc.supplier) supplier = frappe.get_doc("Supplier", ref_doc.supplier)
tax_withholding_details = [] tax_withholding_details = []
print(supplier)
for tax in supplier.tax_withholding_config: for tax in supplier.tax_withholding_config:
tax_mapper = get_tax_mapper() tax_mapper = get_tax_mapper()

View File

@ -36,9 +36,8 @@ def make_item(item_code, properties=None):
if item.is_stock_item: if item.is_stock_item:
for item_default in [doc for doc in item.item_defaults if not doc.default_warehouse]: for item_default in [doc for doc in item.get("item_defaults") if not doc.default_warehouse]:
item_default.default_warehouse = "_Test Warehouse - _TC" item_default.default_warehouse = "_Test Warehouse - _TC"
item.insert() item.insert()
return item return item

View File

@ -1,13 +1,10 @@
[ [
{ {
"default_warehouse": "_Test Warehouse - _TC",
"description": "_Test Item 1", "description": "_Test Item 1",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"cost_center": "_Test Cost Center - _TC",
"has_batch_no": 0, "has_batch_no": 0,
"has_serial_no": 0, "has_serial_no": 0,
"income_account": "Sales - _TC",
"inspection_required": 0, "inspection_required": 0,
"is_stock_item": 1, "is_stock_item": 1,
"is_sub_contracted_item": 0, "is_sub_contracted_item": 0,
@ -17,6 +14,14 @@
"apply_warehouse_wise_reorder_level": 1, "apply_warehouse_wise_reorder_level": 1,
"gst_hsn_code": "999800", "gst_hsn_code": "999800",
"valuation_rate": 100, "valuation_rate": 100,
"item_defaults": [{
"company": "_Test Company",
"default_warehouse": "_Test Warehouse - _TC",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"buying_cost_center": "_Test Cost Center - _TC",
"selling_cost_center": "_Test Cost Center - _TC",
"income_account": "Sales - _TC",
}],
"reorder_levels": [ "reorder_levels": [
{ {
"material_request_type": "Purchase", "material_request_type": "Purchase",
@ -40,14 +45,10 @@
"website_warehouse": "_Test Warehouse - _TC" "website_warehouse": "_Test Warehouse - _TC"
}, },
{ {
"default_warehouse": "_Test Warehouse - _TC",
"description": "_Test Item 2", "description": "_Test Item 2",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"cost_center": "_Test Cost Center - _TC",
"has_batch_no": 0, "has_batch_no": 0,
"has_serial_no": 0, "has_serial_no": 0,
"income_account": "Sales - _TC",
"inspection_required": 0, "inspection_required": 0,
"is_stock_item": 1, "is_stock_item": 1,
"is_sub_contracted_item": 0, "is_sub_contracted_item": 0,
@ -56,17 +57,22 @@
"item_name": "_Test Item 2", "item_name": "_Test Item 2",
"stock_uom": "_Test UOM", "stock_uom": "_Test UOM",
"show_in_website": 1, "show_in_website": 1,
"website_warehouse": "_Test Warehouse - _TC" "website_warehouse": "_Test Warehouse - _TC",
"item_defaults": [{
"company": "_Test Company",
"default_warehouse": "_Test Warehouse - _TC",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"buying_cost_center": "_Test Cost Center - _TC",
"selling_cost_center": "_Test Cost Center - _TC",
"income_account": "Sales - _TC",
}],
}, },
{ {
"default_warehouse": "_Test Warehouse - _TC",
"description": "_Test Item Home Desktop 100 3", "description": "_Test Item Home Desktop 100 3",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"cost_center": "_Test Cost Center - _TC",
"has_batch_no": 0, "has_batch_no": 0,
"has_serial_no": 0, "has_serial_no": 0,
"income_account": "Sales - _TC",
"inspection_required": 0, "inspection_required": 0,
"is_stock_item": 1, "is_stock_item": 1,
"is_sub_contracted_item": 0, "is_sub_contracted_item": 0,
@ -74,6 +80,15 @@
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"item_name": "_Test Item Home Desktop 100", "item_name": "_Test Item Home Desktop 100",
"valuation_rate": 100, "valuation_rate": 100,
"item_defaults": [{
"company": "_Test Company",
"default_warehouse": "_Test Warehouse - _TC",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"buying_cost_center": "_Test Cost Center - _TC",
"selling_cost_center": "_Test Cost Center - _TC",
"income_account": "Sales - _TC",
}],
"taxes": [ "taxes": [
{ {
"doctype": "Item Tax", "doctype": "Item Tax",
@ -85,53 +100,66 @@
"stock_uom": "_Test UOM 1" "stock_uom": "_Test UOM 1"
}, },
{ {
"default_warehouse": "_Test Warehouse - _TC",
"description": "_Test Item Home Desktop 200 4", "description": "_Test Item Home Desktop 200 4",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"cost_center": "_Test Cost Center - _TC",
"has_batch_no": 0, "has_batch_no": 0,
"has_serial_no": 0, "has_serial_no": 0,
"income_account": "Sales - _TC",
"inspection_required": 0, "inspection_required": 0,
"is_sub_contracted_item": 0, "is_sub_contracted_item": 0,
"item_code": "_Test Item Home Desktop 200", "item_code": "_Test Item Home Desktop 200",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"item_name": "_Test Item Home Desktop 200", "item_name": "_Test Item Home Desktop 200",
"stock_uom": "_Test UOM 1" "stock_uom": "_Test UOM 1",
"item_defaults": [{
"company": "_Test Company",
"default_warehouse": "_Test Warehouse - _TC",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"buying_cost_center": "_Test Cost Center - _TC",
"selling_cost_center": "_Test Cost Center - _TC",
"income_account": "Sales - _TC",
}]
}, },
{ {
"description": "_Test Product Bundle Item 5", "description": "_Test Product Bundle Item 5",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"cost_center": "_Test Cost Center - _TC",
"has_batch_no": 0, "has_batch_no": 0,
"has_serial_no": 0, "has_serial_no": 0,
"income_account": "Sales - _TC",
"inspection_required": 0, "inspection_required": 0,
"is_stock_item": 0, "is_stock_item": 0,
"is_sub_contracted_item": 0, "is_sub_contracted_item": 0,
"item_code": "_Test Product Bundle Item", "item_code": "_Test Product Bundle Item",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"item_name": "_Test Product Bundle Item", "item_name": "_Test Product Bundle Item",
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM",
"item_defaults": [{
"company": "_Test Company",
"default_warehouse": "_Test Warehouse - _TC",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"buying_cost_center": "_Test Cost Center - _TC",
"selling_cost_center": "_Test Cost Center - _TC",
"income_account": "Sales - _TC",
}]
}, },
{ {
"default_warehouse": "_Test Warehouse - _TC",
"description": "_Test FG Item 6", "description": "_Test FG Item 6",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"cost_center": "_Test Cost Center - _TC",
"has_batch_no": 0, "has_batch_no": 0,
"has_serial_no": 0, "has_serial_no": 0,
"income_account": "Sales - _TC",
"inspection_required": 0, "inspection_required": 0,
"is_stock_item": 1, "is_stock_item": 1,
"is_sub_contracted_item": 1, "is_sub_contracted_item": 1,
"item_code": "_Test FG Item", "item_code": "_Test FG Item",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"item_name": "_Test FG Item", "item_name": "_Test FG Item",
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM",
"item_defaults": [{
"company": "_Test Company",
"default_warehouse": "_Test Warehouse - _TC",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"buying_cost_center": "_Test Cost Center - _TC",
"selling_cost_center": "_Test Cost Center - _TC",
"income_account": "Sales - _TC",
}]
}, },
{ {
"description": "_Test Non Stock Item 7", "description": "_Test Non Stock Item 7",
@ -147,7 +175,6 @@
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM"
}, },
{ {
"default_warehouse": "_Test Warehouse - _TC",
"description": "_Test Serialized Item 8", "description": "_Test Serialized Item 8",
"doctype": "Item", "doctype": "Item",
"has_batch_no": 0, "has_batch_no": 0,
@ -158,10 +185,17 @@
"item_code": "_Test Serialized Item", "item_code": "_Test Serialized Item",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"item_name": "_Test Serialized Item", "item_name": "_Test Serialized Item",
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM",
"item_defaults": [{
"company": "_Test Company",
"default_warehouse": "_Test Warehouse - _TC",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"buying_cost_center": "_Test Cost Center - _TC",
"selling_cost_center": "_Test Cost Center - _TC",
"income_account": "Sales - _TC",
}]
}, },
{ {
"default_warehouse": "_Test Warehouse - _TC",
"description": "_Test Serialized Item 9", "description": "_Test Serialized Item 9",
"doctype": "Item", "doctype": "Item",
"has_batch_no": 0, "has_batch_no": 0,
@ -173,51 +207,63 @@
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"item_name": "_Test Serialized Item With Series", "item_name": "_Test Serialized Item With Series",
"serial_no_series": "ABCD.#####", "serial_no_series": "ABCD.#####",
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM",
"item_defaults": [{
"company": "_Test Company",
"default_warehouse": "_Test Warehouse - _TC",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"buying_cost_center": "_Test Cost Center - _TC",
"selling_cost_center": "_Test Cost Center - _TC",
"income_account": "Sales - _TC",
}]
}, },
{ {
"default_warehouse": "_Test Warehouse - _TC",
"description": "_Test Item Home Desktop Manufactured 10", "description": "_Test Item Home Desktop Manufactured 10",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"cost_center": "_Test Cost Center - _TC",
"has_batch_no": 0, "has_batch_no": 0,
"has_serial_no": 0, "has_serial_no": 0,
"income_account": "Sales - _TC",
"inspection_required": 0, "inspection_required": 0,
"is_stock_item": 1, "is_stock_item": 1,
"is_sub_contracted_item": 0, "is_sub_contracted_item": 0,
"item_code": "_Test Item Home Desktop Manufactured", "item_code": "_Test Item Home Desktop Manufactured",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"item_name": "_Test Item Home Desktop Manufactured", "item_name": "_Test Item Home Desktop Manufactured",
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM",
"item_defaults": [{
"company": "_Test Company",
"default_warehouse": "_Test Warehouse - _TC",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"buying_cost_center": "_Test Cost Center - _TC",
"selling_cost_center": "_Test Cost Center - _TC",
"income_account": "Sales - _TC",
}]
}, },
{ {
"default_warehouse": "_Test Warehouse - _TC",
"description": "_Test FG Item 2 11", "description": "_Test FG Item 2 11",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"cost_center": "_Test Cost Center - _TC",
"has_batch_no": 0, "has_batch_no": 0,
"has_serial_no": 0, "has_serial_no": 0,
"income_account": "Sales - _TC",
"inspection_required": 0, "inspection_required": 0,
"is_stock_item": 1, "is_stock_item": 1,
"is_sub_contracted_item": 1, "is_sub_contracted_item": 1,
"item_code": "_Test FG Item 2", "item_code": "_Test FG Item 2",
"item_group": "_Test Item Group Desktops", "item_group": "_Test Item Group Desktops",
"item_name": "_Test FG Item 2", "item_name": "_Test FG Item 2",
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM",
"item_defaults": [{
"company": "_Test Company",
"default_warehouse": "_Test Warehouse - _TC",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"buying_cost_center": "_Test Cost Center - _TC",
"selling_cost_center": "_Test Cost Center - _TC",
"income_account": "Sales - _TC",
}]
}, },
{ {
"default_warehouse": "_Test Warehouse - _TC",
"description": "_Test Variant Item 12", "description": "_Test Variant Item 12",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"cost_center": "_Test Cost Center - _TC",
"has_batch_no": 0, "has_batch_no": 0,
"has_serial_no": 0, "has_serial_no": 0,
"income_account": "Sales - _TC",
"inspection_required": 0, "inspection_required": 0,
"is_stock_item": 1, "is_stock_item": 1,
"is_sub_contracted_item": 1, "is_sub_contracted_item": 1,
@ -226,6 +272,14 @@
"item_name": "_Test Variant Item", "item_name": "_Test Variant Item",
"stock_uom": "_Test UOM", "stock_uom": "_Test UOM",
"has_variants": 1, "has_variants": 1,
"item_defaults": [{
"company": "_Test Company",
"default_warehouse": "_Test Warehouse - _TC",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"buying_cost_center": "_Test Cost Center - _TC",
"selling_cost_center": "_Test Cost Center - _TC",
"income_account": "Sales - _TC",
}],
"attributes": [ "attributes": [
{ {
"attribute": "Test Size" "attribute": "Test Size"
@ -242,14 +296,10 @@
] ]
}, },
{ {
"default_warehouse": "_Test Warehouse Group-C1 - _TC",
"description": "_Test Item 1", "description": "_Test Item 1",
"doctype": "Item", "doctype": "Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"cost_center": "_Test Cost Center - _TC",
"has_batch_no": 0, "has_batch_no": 0,
"has_serial_no": 0, "has_serial_no": 0,
"income_account": "Sales - _TC",
"inspection_required": 0, "inspection_required": 0,
"is_stock_item": 1, "is_stock_item": 1,
"is_sub_contracted_item": 0, "is_sub_contracted_item": 0,
@ -257,6 +307,14 @@
"item_group": "_Test Item Group", "item_group": "_Test Item Group",
"item_name": "_Test Item Warehouse Group Wise Reorder", "item_name": "_Test Item Warehouse Group Wise Reorder",
"apply_warehouse_wise_reorder_level": 1, "apply_warehouse_wise_reorder_level": 1,
"item_defaults": [{
"company": "_Test Company",
"default_warehouse": "_Test Warehouse Group-C1 - _TC",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"buying_cost_center": "_Test Cost Center - _TC",
"selling_cost_center": "_Test Cost Center - _TC",
"income_account": "Sales - _TC",
}],
"reorder_levels": [ "reorder_levels": [
{ {
"warehouse_group": "_Test Warehouse Group - _TC", "warehouse_group": "_Test Warehouse Group - _TC",
@ -270,5 +328,4 @@
"show_in_website": 1, "show_in_website": 1,
"website_warehouse": "_Test Warehouse Group-C1 - _TC" "website_warehouse": "_Test Warehouse Group-C1 - _TC"
} }
] ]