Skip to content

Commit

Permalink
Merge pull request #29334 from nextchamp-saqib/grouped-asset-purchase
Browse files Browse the repository at this point in the history
  • Loading branch information
nextchamp-saqib authored Jan 21, 2022
2 parents 4fa93e2 + eff1d6b commit 58cc3b3
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 13 deletions.
11 changes: 10 additions & 1 deletion erpnext/assets/doctype/asset/asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"available_for_use_date",
"column_break_23",
"gross_purchase_amount",
"asset_quantity",
"purchase_date",
"section_break_23",
"calculate_depreciation",
Expand Down Expand Up @@ -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,
Expand All @@ -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": [
{
Expand Down Expand Up @@ -542,6 +550,7 @@
"show_name_in_global_search": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"title_field": "asset_name",
"track_changes": 1
}
36 changes: 31 additions & 5 deletions erpnext/assets/doctype/asset/test_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,29 @@ def test_purchase_asset(self):
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')
Expand Down Expand Up @@ -1212,25 +1235,28 @@ def create_asset_category():
})
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",
"item_group": "All Item Groups",
"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")
Expand Down
20 changes: 14 additions & 6 deletions erpnext/controllers/buying_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,13 @@ def auto_make_assets(self, asset_items):
# 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
Expand All @@ -580,14 +583,18 @@ def auto_make_assets(self, asset_items):
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,
Expand All @@ -601,6 +608,7 @@ def make_asset(self, row):
'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
})
Expand Down Expand Up @@ -687,7 +695,7 @@ def validate_items(self):

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)

Expand Down
1 change: 1 addition & 0 deletions erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,5 @@ erpnext.patches.v14_0.delete_hospitality_doctypes # 20-01-2022
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
erpnext.patches.v13_0.delete_bank_reconciliation_detail
8 changes: 8 additions & 0 deletions erpnext/patches/v13_0/update_asset_quantity_field.py
Original file line number Diff line number Diff line change
@@ -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()
11 changes: 10 additions & 1 deletion erpnext/stock/doctype/item/item.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"standard_rate",
"is_fixed_asset",
"auto_create_assets",
"is_grouped_asset",
"asset_category",
"asset_naming_series",
"over_delivery_receipt_allowance",
Expand Down Expand Up @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -1104,6 +1112,7 @@
"show_preview_popup": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"title_field": "item_name",
"track_changes": 1
}

0 comments on commit 58cc3b3

Please sign in to comment.