From 35a6b58c127695e016495765d94d45b41eb8550d Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Tue, 18 Jan 2022 13:10:23 +0530 Subject: [PATCH] feat: purchase grouped asset --- erpnext/assets/doctype/asset/asset.json | 11 ++++++++++- erpnext/controllers/buying_controller.py | 20 ++++++++++++++------ erpnext/stock/doctype/item/item.json | 11 ++++++++++- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.json b/erpnext/assets/doctype/asset/asset.json index de060757e2..3c3be98b07 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": 1 } ], "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/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index a3d2502268..f088b9ffc2 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -554,10 +554,13 @@ class BuyingController(StockController, Subcontracting): # 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 @@ class BuyingController(StockController, Subcontracting): 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 @@ class BuyingController(StockController, Subcontracting): '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 @@ class BuyingController(StockController, Subcontracting): 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/stock/doctype/item/item.json b/erpnext/stock/doctype/item/item.json index 29abd45fcc..2d28cc09f9 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