fiix: cannot cancel asset and asset movement
This commit is contained in:
parent
53346217d2
commit
acdaf2b001
@ -35,9 +35,6 @@ class Asset(AccountsController):
|
|||||||
if not self.booked_fixed_asset and self.validate_make_gl_entry():
|
if not self.booked_fixed_asset and self.validate_make_gl_entry():
|
||||||
self.make_gl_entries()
|
self.make_gl_entries()
|
||||||
|
|
||||||
def before_cancel(self):
|
|
||||||
self.cancel_auto_gen_movement()
|
|
||||||
|
|
||||||
def on_cancel(self):
|
def on_cancel(self):
|
||||||
self.validate_cancellation()
|
self.validate_cancellation()
|
||||||
self.delete_depreciation_entries()
|
self.delete_depreciation_entries()
|
||||||
@ -134,19 +131,6 @@ class Asset(AccountsController):
|
|||||||
Please do not book expense of multiple assets against one single Asset.")
|
Please do not book expense of multiple assets against one single Asset.")
|
||||||
.format(frappe.bold("equal"), "<br>"), title=_("Invalid Gross Purchase Amount"))
|
.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):
|
def make_asset_movement(self):
|
||||||
reference_doctype = 'Purchase Receipt' if self.purchase_receipt else 'Purchase Invoice'
|
reference_doctype = 'Purchase Receipt' if self.purchase_receipt else 'Purchase Invoice'
|
||||||
reference_docname = self.purchase_receipt or self.purchase_invoice
|
reference_docname = self.purchase_receipt or self.purchase_invoice
|
||||||
|
@ -87,33 +87,9 @@ class AssetMovement(Document):
|
|||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
self.set_latest_location_in_asset()
|
self.set_latest_location_in_asset()
|
||||||
|
|
||||||
def before_cancel(self):
|
|
||||||
self.validate_last_movement()
|
|
||||||
|
|
||||||
def on_cancel(self):
|
def on_cancel(self):
|
||||||
self.set_latest_location_in_asset()
|
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):
|
def set_latest_location_in_asset(self):
|
||||||
current_location, current_employee = '', ''
|
current_location, current_employee = '', ''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user