2
0

[FIX] account_asset_management: Proper asset unlink + move unlink

2 related fixes:

- When removing an asset line depreciation move, we have to pass it
  first to draft, or we won't be able to remove it even with the
  context.
- When removing a move, the check for removing the linked asset should
  be only for purchase documents, not for "not sale" documents.
This commit is contained in:
Pedro M. Baeza 2020-12-22 09:06:05 +01:00 committed by Rodrigo
parent 3945771c61
commit 2aa11d4e40
3 changed files with 3 additions and 2 deletions

View File

@ -4,7 +4,7 @@
{ {
"name": "Assets Management", "name": "Assets Management",
"version": "13.0.1.3.1", "version": "13.0.1.3.2",
"license": "AGPL-3", "license": "AGPL-3",
"depends": ["account"], "depends": ["account"],
"excludes": ["account_asset"], "excludes": ["account_asset"],

View File

@ -280,6 +280,7 @@ class AccountAssetLine(models.Model):
def unlink_move(self): def unlink_move(self):
for line in self: for line in self:
move = line.move_id move = line.move_id
move.button_draft()
move.with_context(force_delete=True, unlink_from_asset=True).unlink() move.with_context(force_delete=True, unlink_from_asset=True).unlink()
# trigger store function # trigger store function
line.with_context(unlink_from_asset=True).write({"move_id": False}) line.with_context(unlink_from_asset=True).write({"move_id": False})

View File

@ -92,7 +92,7 @@ class AccountMove(models.Model):
move.message_post(body=message) move.message_post(body=message)
def button_draft(self): def button_draft(self):
invoices = self.filtered(lambda r: not r.is_sale_document()) invoices = self.filtered(lambda r: r.is_purchase_document())
if invoices: if invoices:
invoices.line_ids.asset_id.unlink() invoices.line_ids.asset_id.unlink()
super().button_draft() super().button_draft()