feat: purchase grouped asset

This commit is contained in:
Saqib Ansari
2022-01-18 13:10:23 +05:30
parent fabe0bce15
commit 35a6b58c12
3 changed files with 34 additions and 8 deletions

View File

@@ -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)