Asset cancellation fix (#19671)
* fix: remove asset movement mandatory fields * fix: label for reference doctype
This commit is contained in:
@@ -641,7 +641,10 @@ class BuyingController(StockController):
|
||||
asset = frappe.get_doc('Asset', asset.name)
|
||||
if delete_asset and is_auto_create_enabled:
|
||||
# need to delete movements to delete assets otherwise throws link exists error
|
||||
movements = frappe.db.get_all('Asset Movement', filters={ 'reference_name': self.name })
|
||||
movements = frappe.db.sql(
|
||||
"""SELECT asm.name
|
||||
FROM `tabAsset Movement` asm, `tabAsset Movement Item` asm_item
|
||||
WHERE asm_item.parent=asm.name and asm_item.asset=%s""", asset.name, as_dict=1)
|
||||
for movement in movements:
|
||||
frappe.delete_doc('Asset Movement', movement.name, force=1)
|
||||
frappe.delete_doc("Asset", asset.name, force=1)
|
||||
@@ -652,8 +655,12 @@ class BuyingController(StockController):
|
||||
asset.purchase_date = self.posting_date
|
||||
asset.supplier = self.supplier
|
||||
elif self.docstatus == 2:
|
||||
asset.set(field, None)
|
||||
asset.supplier = None
|
||||
if asset.docstatus == 0:
|
||||
asset.set(field, None)
|
||||
asset.supplier = None
|
||||
if asset.docstatus == 1 and delete_asset:
|
||||
frappe.throw(_('Cannot cancel this document as it is linked with submitted asset {0}.\
|
||||
Please cancel the it to continue.').format(asset.name))
|
||||
|
||||
asset.flags.ignore_validate_update_after_submit = True
|
||||
asset.flags.ignore_mandatory = True
|
||||
|
||||
Reference in New Issue
Block a user