Created
April 29, 2024 22:45
-
-
Save name1984/39bcf6b5b502c9a772399af4a85fb0c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if len(records) > 1: | |
raise UserError("Solo corre sobre un solo registro") | |
total = len(records) | |
asset_ids = records.ids | |
am_obj = env["account.move"].with_context(force_delete=True) | |
asset_obj = env["account.asset"] | |
for count, asset_id in enumerate(asset_ids, 1): | |
try: | |
ID = asset_id | |
record = asset_obj.browse(asset_id) | |
record.write({'state': 'draft'}) | |
moves_to_delete_ids = record.mapped('depreciation_move_ids').ids | |
for move_id in moves_to_delete_ids: | |
move = am_obj.browse(move_id) | |
move.filtered(lambda x: x.state == 'posted').button_draft() | |
move.unlink() | |
# record.unlink() | |
log("SUCCESS: ID: %s, COUNT: %s, TOTAL: %s" % (ID, count, total)) | |
except Exception as e: | |
log("FAILURE: ID: %s, COUNT: %s, TOTAL: %s, ERROR: %s" % (ID, count, total, e)) | |
env.cr.rollback() | |
finally: | |
env.cr.commit() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment