Merge branch 'develop' into asset-delete-fix
diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py
index 9ae5a87..0bd03a8 100644
--- a/erpnext/assets/doctype/asset/asset.py
+++ b/erpnext/assets/doctype/asset/asset.py
@@ -35,11 +35,9 @@
if not self.booked_fixed_asset and self.validate_make_gl_entry():
self.make_gl_entries()
- def before_cancel(self):
- self.cancel_auto_gen_movement()
-
def on_cancel(self):
self.validate_cancellation()
+ self.cancel_movement_entries()
self.delete_depreciation_entries()
self.set_status()
self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry')
@@ -134,19 +132,6 @@
Please do not book expense of multiple assets against one single Asset.")
.format(frappe.bold("equal"), "<br>"), title=_("Invalid Gross Purchase Amount"))
- def cancel_auto_gen_movement(self):
- movements = frappe.db.sql(
- """SELECT asm.name, asm.docstatus
- FROM `tabAsset Movement` asm, `tabAsset Movement Item` asm_item
- WHERE asm_item.parent=asm.name and asm_item.asset=%s and asm.docstatus=1""", self.name, as_dict=1)
- if len(movements) > 1:
- frappe.throw(_('Asset has multiple Asset Movement Entries which has to be \
- cancelled manually to cancel this asset.'))
- if movements:
- movement = frappe.get_doc('Asset Movement', movements[0].get('name'))
- movement.flags.ignore_validate = True
- movement.cancel()
-
def make_asset_movement(self):
reference_doctype = 'Purchase Receipt' if self.purchase_receipt else 'Purchase Invoice'
reference_docname = self.purchase_receipt or self.purchase_invoice
@@ -413,6 +398,16 @@
if self.status not in ("Submitted", "Partially Depreciated", "Fully Depreciated"):
frappe.throw(_("Asset cannot be cancelled, as it is already {0}").format(self.status))
+ def cancel_movement_entries(self):
+ movements = frappe.db.sql(
+ """SELECT asm.name, asm.docstatus
+ FROM `tabAsset Movement` asm, `tabAsset Movement Item` asm_item
+ WHERE asm_item.parent=asm.name and asm_item.asset=%s and asm.docstatus=1""", self.name, as_dict=1)
+
+ for movement in movements:
+ movement = frappe.get_doc('Asset Movement', movement.get('name'))
+ movement.cancel()
+
def delete_depreciation_entries(self):
for d in self.get("schedules"):
if d.journal_entry:
diff --git a/erpnext/assets/doctype/asset_movement/asset_movement.py b/erpnext/assets/doctype/asset_movement/asset_movement.py
index 3da355e..b2de250 100644
--- a/erpnext/assets/doctype/asset_movement/asset_movement.py
+++ b/erpnext/assets/doctype/asset_movement/asset_movement.py
@@ -87,33 +87,9 @@
def on_submit(self):
self.set_latest_location_in_asset()
-
- def before_cancel(self):
- self.validate_last_movement()
def on_cancel(self):
self.set_latest_location_in_asset()
-
- def validate_last_movement(self):
- for d in self.assets:
- auto_gen_movement_entry = frappe.db.sql(
- """
- SELECT asm.name
- FROM `tabAsset Movement Item` asm_item, `tabAsset Movement` asm
- WHERE
- asm.docstatus=1 and
- asm_item.parent=asm.name and
- asm_item.asset=%s and
- asm.company=%s and
- asm_item.source_location is NULL and
- asm.purpose=%s
- ORDER BY
- asm.transaction_date asc
- """, (d.asset, self.company, 'Receipt'), as_dict=1)
-
- if auto_gen_movement_entry and auto_gen_movement_entry[0].get('name') == self.name:
- frappe.throw(_('{0} will be cancelled automatically on asset cancellation as it was \
- auto generated for Asset {1}').format(self.name, d.asset))
def set_latest_location_in_asset(self):
current_location, current_employee = '', ''