Skip to content

Commit

Permalink
[IMP] dms_version: simplify code by creating the file with the correc…
Browse files Browse the repository at this point in the history
…t name

This also simplifies the work for interaction with the storage module
  • Loading branch information
len-foss committed Dec 16, 2023
1 parent 77c4efa commit c899326
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions dms_version/models/dms_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ def write(self, vals):
if vals.get("content"):
versions = self.filtered(lambda x: x.has_versioning)
super(DmsFile, versions).write({"active": False})
action = versions.with_context(new_vals=vals).create_revision()
versions = versions.with_context(new_vals=vals, force_dms_file_name=True)
action = versions.create_revision()
res = self.search(action["domain"])
if versions.ids == self.ids:
return res
Expand All @@ -206,6 +207,7 @@ def _get_new_rev_data(self, new_rev_number):
max(self.origin_id.all_revision_ids.mapped("revision_number")) + 1
)
res["revision_number"] = max_new_rev_number
res["name"] = "%s-%02d" % (self.unrevisioned_name, max_new_rev_number)
return res

def action_restore_old_revision(self):
Expand All @@ -230,16 +232,6 @@ def action_restore_old_revision(self):
self.origin_id.all_revision_ids.write({"current_revision_id": self.id})
self.current_revision_id.write({"current_revision_id": False})

def copy_revision_with_context(self):
new_revision = super().copy_revision_with_context()
new_rev_number = new_revision.revision_number
new_revision.write(
{
"name": "%s-%02d" % (self.unrevisioned_name, new_rev_number),
}
)
return new_revision

def get_html_link(self):
self.ensure_one()
res = '<a href="#" data-oe-model="dms.file" data-oe-id="%s">%s</a>' % (
Expand Down

0 comments on commit c899326

Please sign in to comment.