Skip to content

Commit

Permalink
[FIX] spreadsheet_oca: Cannot open spreadsheet when using undo / redo
Browse files Browse the repository at this point in the history
commands

Steps:
1. Open spreadsheet
2. Press command Ctrl + Z
3. F5 (refresh browse)

An error occurred:
Operation undefined not found

Because missing key `undoneRevisionId` / `redoneRevisionId` in revisions
data

Solutions:
Save all spreadsheet message in commands field
  • Loading branch information
royle-vietnam committed Feb 22, 2024
1 parent fbf111d commit e318ca5
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions spreadsheet_oca/models/spreadsheet_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import json

from odoo import fields, models
from odoo import api, fields, models
from odoo.exceptions import AccessError


Expand Down Expand Up @@ -31,13 +31,11 @@ def get_spreadsheet_data(self):
"name": self.name,
"spreadsheet_raw": self.spreadsheet_raw,
"revisions": [
{
"type": revision.type,
"clientId": revision.client_id,
"nextRevisionId": revision.next_revision_id,
"serverRevisionId": revision.server_revision_id,
"commands": json.loads(revision.commands),
}
dict(
json.loads(revision.commands),
nextRevisionId=revision.next_revision_id,
serverRevisionId=revision.server_revision_id,
)
for revision in self.spreadsheet_revision_ids
],
"mode": mode,
Expand All @@ -64,12 +62,21 @@ def send_spreadsheet_message(self, message):
"client_id": message.get("clientId"),
"next_revision_id": message["nextRevisionId"],
"server_revision_id": message["serverRevisionId"],
"commands": json.dumps(message.get("commands", [])),
"commands": json.dumps(self._build_spreadsheet_revision_commands_data(message)),
}
)
self.env["bus.bus"]._sendone(channel, "spreadsheet_oca", message)
return True

@api.model
def _build_spreadsheet_revision_commands_data(self, message):
"""Prepare spreadsheet revision commands data from the message"""
commands = dict(message)
commands.pop("serverRevisionId", None)
commands.pop("nextRevisionId", None)
commands.pop("clientId", None)
return commands

Check warning on line 78 in spreadsheet_oca/models/spreadsheet_abstract.py

View check run for this annotation

Codecov / codecov/patch

spreadsheet_oca/models/spreadsheet_abstract.py#L74-L78

Added lines #L74 - L78 were not covered by tests

def write(self, vals):
if "spreadsheet_raw" in vals:
self.spreadsheet_revision_ids.unlink()
Expand Down

0 comments on commit e318ca5

Please sign in to comment.