feat: Let serialised Items be consumed during Asset Repairs (#28349)
This commit is contained in:
commit
fb14b0901c
@ -60,6 +60,10 @@ frappe.ui.form.on('Asset Repair', {
|
|||||||
if (frm.doc.repair_status == "Completed") {
|
if (frm.doc.repair_status == "Completed") {
|
||||||
frm.set_value('completion_date', frappe.datetime.now_datetime());
|
frm.set_value('completion_date', frappe.datetime.now_datetime());
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
stock_items_on_form_rendered() {
|
||||||
|
erpnext.setup_serial_or_batch_no();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -118,9 +118,10 @@ class AssetRepair(AccountsController):
|
|||||||
for stock_item in self.get('stock_items'):
|
for stock_item in self.get('stock_items'):
|
||||||
stock_entry.append('items', {
|
stock_entry.append('items', {
|
||||||
"s_warehouse": self.warehouse,
|
"s_warehouse": self.warehouse,
|
||||||
"item_code": stock_item.item,
|
"item_code": stock_item.item_code,
|
||||||
"qty": stock_item.consumed_quantity,
|
"qty": stock_item.consumed_quantity,
|
||||||
"basic_rate": stock_item.valuation_rate
|
"basic_rate": stock_item.valuation_rate,
|
||||||
|
"serial_no": stock_item.serial_no
|
||||||
})
|
})
|
||||||
|
|
||||||
stock_entry.insert()
|
stock_entry.insert()
|
||||||
|
|||||||
@ -11,12 +11,15 @@ from erpnext.assets.doctype.asset.test_asset import (
|
|||||||
create_asset_data,
|
create_asset_data,
|
||||||
set_depreciation_settings_in_company,
|
set_depreciation_settings_in_company,
|
||||||
)
|
)
|
||||||
|
from erpnext.stock.doctype.item.test_item import create_item
|
||||||
|
|
||||||
|
|
||||||
class TestAssetRepair(unittest.TestCase):
|
class TestAssetRepair(unittest.TestCase):
|
||||||
def setUp(self):
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
set_depreciation_settings_in_company()
|
set_depreciation_settings_in_company()
|
||||||
create_asset_data()
|
create_asset_data()
|
||||||
|
create_item("_Test Stock Item")
|
||||||
frappe.db.sql("delete from `tabTax Rule`")
|
frappe.db.sql("delete from `tabTax Rule`")
|
||||||
|
|
||||||
def test_update_status(self):
|
def test_update_status(self):
|
||||||
@ -70,9 +73,28 @@ class TestAssetRepair(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(stock_entry.stock_entry_type, "Material Issue")
|
self.assertEqual(stock_entry.stock_entry_type, "Material Issue")
|
||||||
self.assertEqual(stock_entry.items[0].s_warehouse, asset_repair.warehouse)
|
self.assertEqual(stock_entry.items[0].s_warehouse, asset_repair.warehouse)
|
||||||
self.assertEqual(stock_entry.items[0].item_code, asset_repair.stock_items[0].item)
|
self.assertEqual(stock_entry.items[0].item_code, asset_repair.stock_items[0].item_code)
|
||||||
self.assertEqual(stock_entry.items[0].qty, asset_repair.stock_items[0].consumed_quantity)
|
self.assertEqual(stock_entry.items[0].qty, asset_repair.stock_items[0].consumed_quantity)
|
||||||
|
|
||||||
|
def test_serialized_item_consumption(self):
|
||||||
|
from erpnext.stock.doctype.serial_no.serial_no import SerialNoRequiredError
|
||||||
|
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_serialized_item
|
||||||
|
|
||||||
|
stock_entry = make_serialized_item()
|
||||||
|
serial_nos = stock_entry.get("items")[0].serial_no
|
||||||
|
serial_no = serial_nos.split("\n")[0]
|
||||||
|
|
||||||
|
# should not raise any error
|
||||||
|
create_asset_repair(stock_consumption = 1, item_code = stock_entry.get("items")[0].item_code,
|
||||||
|
warehouse = "_Test Warehouse - _TC", serial_no = serial_no, submit = 1)
|
||||||
|
|
||||||
|
# should raise error
|
||||||
|
asset_repair = create_asset_repair(stock_consumption = 1, warehouse = "_Test Warehouse - _TC",
|
||||||
|
item_code = stock_entry.get("items")[0].item_code)
|
||||||
|
|
||||||
|
asset_repair.repair_status = "Completed"
|
||||||
|
self.assertRaises(SerialNoRequiredError, asset_repair.submit)
|
||||||
|
|
||||||
def test_increase_in_asset_value_due_to_stock_consumption(self):
|
def test_increase_in_asset_value_due_to_stock_consumption(self):
|
||||||
asset = create_asset(calculate_depreciation = 1, submit=1)
|
asset = create_asset(calculate_depreciation = 1, submit=1)
|
||||||
initial_asset_value = get_asset_value(asset)
|
initial_asset_value = get_asset_value(asset)
|
||||||
@ -137,11 +159,12 @@ def create_asset_repair(**args):
|
|||||||
|
|
||||||
if args.stock_consumption:
|
if args.stock_consumption:
|
||||||
asset_repair.stock_consumption = 1
|
asset_repair.stock_consumption = 1
|
||||||
asset_repair.warehouse = create_warehouse("Test Warehouse", company = asset.company)
|
asset_repair.warehouse = args.warehouse or create_warehouse("Test Warehouse", company = asset.company)
|
||||||
asset_repair.append("stock_items", {
|
asset_repair.append("stock_items", {
|
||||||
"item": args.item or args.item_code or "_Test Item",
|
"item_code": args.item_code or "_Test Stock Item",
|
||||||
"valuation_rate": args.rate if args.get("rate") is not None else 100,
|
"valuation_rate": args.rate if args.get("rate") is not None else 100,
|
||||||
"consumed_quantity": args.qty or 1
|
"consumed_quantity": args.qty or 1,
|
||||||
|
"serial_no": args.serial_no
|
||||||
})
|
})
|
||||||
|
|
||||||
asset_repair.insert(ignore_if_duplicate=True)
|
asset_repair.insert(ignore_if_duplicate=True)
|
||||||
@ -158,7 +181,7 @@ def create_asset_repair(**args):
|
|||||||
})
|
})
|
||||||
stock_entry.append('items', {
|
stock_entry.append('items', {
|
||||||
"t_warehouse": asset_repair.warehouse,
|
"t_warehouse": asset_repair.warehouse,
|
||||||
"item_code": asset_repair.stock_items[0].item,
|
"item_code": asset_repair.stock_items[0].item_code,
|
||||||
"qty": asset_repair.stock_items[0].consumed_quantity
|
"qty": asset_repair.stock_items[0].consumed_quantity
|
||||||
})
|
})
|
||||||
stock_entry.submit()
|
stock_entry.submit()
|
||||||
|
|||||||
@ -5,19 +5,13 @@
|
|||||||
"editable_grid": 1,
|
"editable_grid": 1,
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"item",
|
"item_code",
|
||||||
"valuation_rate",
|
"valuation_rate",
|
||||||
"consumed_quantity",
|
"consumed_quantity",
|
||||||
"total_value"
|
"total_value",
|
||||||
|
"serial_no"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
|
||||||
"fieldname": "item",
|
|
||||||
"fieldtype": "Link",
|
|
||||||
"in_list_view": 1,
|
|
||||||
"label": "Item",
|
|
||||||
"options": "Item"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fetch_from": "item.valuation_rate",
|
"fetch_from": "item.valuation_rate",
|
||||||
"fieldname": "valuation_rate",
|
"fieldname": "valuation_rate",
|
||||||
@ -38,12 +32,24 @@
|
|||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Total Value",
|
"label": "Total Value",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "serial_no",
|
||||||
|
"fieldtype": "Small Text",
|
||||||
|
"label": "Serial No"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "item_code",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Item",
|
||||||
|
"options": "Item"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-05-12 03:19:55.006300",
|
"modified": "2021-11-11 18:23:00.492483",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Assets",
|
"module": "Assets",
|
||||||
"name": "Asset Repair Consumed Item",
|
"name": "Asset Repair Consumed Item",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user