Merge branch 'develop' into grouped-asset-purchase
diff --git a/erpnext/assets/doctype/asset/asset.json b/erpnext/assets/doctype/asset/asset.json
index de06075..0a7c041 100644
--- a/erpnext/assets/doctype/asset/asset.json
+++ b/erpnext/assets/doctype/asset/asset.json
@@ -35,6 +35,7 @@
"available_for_use_date",
"column_break_23",
"gross_purchase_amount",
+ "asset_quantity",
"purchase_date",
"section_break_23",
"calculate_depreciation",
@@ -480,6 +481,12 @@
"fieldname": "section_break_36",
"fieldtype": "Section Break",
"label": "Finance Books"
+ },
+ {
+ "fieldname": "asset_quantity",
+ "fieldtype": "Int",
+ "label": "Asset Quantity",
+ "read_only_depends_on": "eval:!doc.is_existing_asset"
}
],
"idx": 72,
@@ -502,10 +509,11 @@
"link_fieldname": "asset"
}
],
- "modified": "2021-06-24 14:58:51.097908",
+ "modified": "2022-01-18 12:57:36.741192",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset",
+ "naming_rule": "By \"Naming Series\" field",
"owner": "Administrator",
"permissions": [
{
@@ -542,6 +550,7 @@
"show_name_in_global_search": 1,
"sort_field": "modified",
"sort_order": "DESC",
+ "states": [],
"title_field": "asset_name",
"track_changes": 1
}
\ No newline at end of file
diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py
index 05ab1d8..dca67b3 100644
--- a/erpnext/assets/doctype/asset/test_asset.py
+++ b/erpnext/assets/doctype/asset/test_asset.py
@@ -134,6 +134,29 @@
pr.cancel()
self.assertEqual(asset.docstatus, 2)
+ def test_purchase_of_grouped_asset(self):
+ create_fixed_asset_item("Rack", is_grouped_asset=1)
+ pr = make_purchase_receipt(item_code="Rack", qty=3, rate=100000.0, location="Test Location")
+
+ asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name')
+ asset = frappe.get_doc('Asset', asset_name)
+ self.assertEqual(asset.asset_quantity, 3)
+ asset.calculate_depreciation = 1
+
+ month_end_date = get_last_day(nowdate())
+ purchase_date = nowdate() if nowdate() != month_end_date else add_days(nowdate(), -15)
+
+ asset.available_for_use_date = purchase_date
+ asset.purchase_date = purchase_date
+ asset.append("finance_books", {
+ "expected_value_after_useful_life": 10000,
+ "depreciation_method": "Straight Line",
+ "total_number_of_depreciations": 3,
+ "frequency_of_depreciation": 10,
+ "depreciation_start_date": month_end_date
+ })
+ asset.submit()
+
def test_is_fixed_asset_set(self):
asset = create_asset(is_existing_asset = 1)
doc = frappe.new_doc('Purchase Invoice')
@@ -1212,13 +1235,13 @@
})
asset_category.insert()
-def create_fixed_asset_item():
+def create_fixed_asset_item(item_code=None, auto_create_assets=1, is_grouped_asset=0):
meta = frappe.get_meta('Asset')
naming_series = meta.get_field("naming_series").options.splitlines()[0] or 'ACC-ASS-.YYYY.-'
try:
- frappe.get_doc({
+ item = frappe.get_doc({
"doctype": "Item",
- "item_code": "Macbook Pro",
+ "item_code": item_code or "Macbook Pro",
"item_name": "Macbook Pro",
"description": "Macbook Pro Retina Display",
"asset_category": "Computers",
@@ -1226,11 +1249,14 @@
"stock_uom": "Nos",
"is_stock_item": 0,
"is_fixed_asset": 1,
- "auto_create_assets": 1,
+ "auto_create_assets": auto_create_assets,
+ "is_grouped_asset": is_grouped_asset,
"asset_naming_series": naming_series
- }).insert()
+ })
+ item.insert()
except frappe.DuplicateEntryError:
pass
+ return item
def set_depreciation_settings_in_company():
company = frappe.get_doc("Company", "_Test Company")
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index a3d2502..f088b9f 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -554,10 +554,13 @@
# Check for asset naming series
if item_data.get('asset_naming_series'):
created_assets = []
-
- for qty in range(cint(d.qty)):
- asset = self.make_asset(d)
+ if item_data.get('is_grouped_asset'):
+ asset = self.make_asset(d, is_grouped_asset=True)
created_assets.append(asset)
+ else:
+ for qty in range(cint(d.qty)):
+ asset = self.make_asset(d)
+ created_assets.append(asset)
if len(created_assets) > 5:
# dont show asset form links if more than 5 assets are created
@@ -580,14 +583,18 @@
for message in messages:
frappe.msgprint(message, title="Success", indicator="green")
- def make_asset(self, row):
+ def make_asset(self, row, is_grouped_asset=False):
if not row.asset_location:
frappe.throw(_("Row {0}: Enter location for the asset item {1}").format(row.idx, row.item_code))
item_data = frappe.db.get_value('Item',
row.item_code, ['asset_naming_series', 'asset_category'], as_dict=1)
- purchase_amount = flt(row.base_rate + row.item_tax_amount)
+ if is_grouped_asset:
+ purchase_amount = flt(row.base_amount + row.item_tax_amount)
+ else:
+ purchase_amount = flt(row.base_rate + row.item_tax_amount)
+
asset = frappe.get_doc({
'doctype': 'Asset',
'item_code': row.item_code,
@@ -601,6 +608,7 @@
'calculate_depreciation': 1,
'purchase_receipt_amount': purchase_amount,
'gross_purchase_amount': purchase_amount,
+ 'asset_quantity': row.qty if is_grouped_asset else 0,
'purchase_receipt': self.name if self.doctype == 'Purchase Receipt' else None,
'purchase_invoice': self.name if self.doctype == 'Purchase Invoice' else None
})
@@ -687,7 +695,7 @@
def get_asset_item_details(asset_items):
asset_items_data = {}
- for d in frappe.get_all('Item', fields = ["name", "auto_create_assets", "asset_naming_series"],
+ for d in frappe.get_all('Item', fields = ["name", "auto_create_assets", "asset_naming_series", "is_grouped_asset"],
filters = {'name': ('in', asset_items)}):
asset_items_data.setdefault(d.name, d)
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index e21671c..f2268fe 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -330,3 +330,4 @@
erpnext.patches.v13_0.update_exchange_rate_settings
erpnext.patches.v14_0.rearrange_company_fields
erpnext.patches.v14_0.update_leave_notification_template
+erpnext.patches.v13_0.update_asset_quantity_field
diff --git a/erpnext/patches/v13_0/update_asset_quantity_field.py b/erpnext/patches/v13_0/update_asset_quantity_field.py
new file mode 100644
index 0000000..47884d1
--- /dev/null
+++ b/erpnext/patches/v13_0/update_asset_quantity_field.py
@@ -0,0 +1,8 @@
+import frappe
+
+
+def execute():
+ if frappe.db.count('Asset'):
+ frappe.reload_doc("assets", "doctype", "Asset")
+ asset = frappe.qb.DocType('Asset')
+ frappe.qb.update(asset).set(asset.asset_quantity, 1).run()
\ No newline at end of file
diff --git a/erpnext/stock/doctype/item/item.json b/erpnext/stock/doctype/item/item.json
index 29abd45..2d28cc0 100644
--- a/erpnext/stock/doctype/item/item.json
+++ b/erpnext/stock/doctype/item/item.json
@@ -28,6 +28,7 @@
"standard_rate",
"is_fixed_asset",
"auto_create_assets",
+ "is_grouped_asset",
"asset_category",
"asset_naming_series",
"over_delivery_receipt_allowance",
@@ -1026,6 +1027,13 @@
"fieldname": "grant_commission",
"fieldtype": "Check",
"label": "Grant Commission"
+ },
+ {
+ "default": "0",
+ "depends_on": "auto_create_assets",
+ "fieldname": "is_grouped_asset",
+ "fieldtype": "Check",
+ "label": "Create Grouped Asset"
}
],
"has_web_view": 1,
@@ -1034,7 +1042,7 @@
"image_field": "image",
"index_web_pages_for_search": 1,
"links": [],
- "modified": "2021-12-14 04:13:16.857534",
+ "modified": "2022-01-18 12:57:54.273202",
"modified_by": "Administrator",
"module": "Stock",
"name": "Item",
@@ -1104,6 +1112,7 @@
"show_preview_popup": 1,
"sort_field": "modified",
"sort_order": "DESC",
+ "states": [],
"title_field": "item_name",
"track_changes": 1
}
\ No newline at end of file