-
-
Notifications
You must be signed in to change notification settings - Fork 379
[IMP][9.0] Change Requests and workflow improvements on documents #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ec5ec36
6da6d85
2b43277
dbeec6e
a125c0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright 2018 Ivan Todorovich <[email protected]> | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
|
||
|
|
||
| def migrate(cr, version): # pragma: no cover | ||
| # Set all pre-existing categories template to its content | ||
| cr.execute(""" | ||
| UPDATE document_page | ||
| SET template = content | ||
| WHERE type = 'category' | ||
| """) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,11 +18,8 @@ | |
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| # | ||
| ############################################################################## | ||
| import logging | ||
| import difflib | ||
| from openerp import models, fields, _ | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
| from openerp import models, fields, api, _ | ||
|
|
||
|
|
||
| class DocumentPageHistory(models.Model): | ||
|
|
@@ -31,24 +28,40 @@ class DocumentPageHistory(models.Model): | |
| _name = "document.page.history" | ||
| _description = "Document Page History" | ||
| _order = 'id DESC' | ||
| _rec_name = "create_date" | ||
|
|
||
| page_id = fields.Many2one('document.page', 'Page') | ||
| page_id = fields.Many2one('document.page', 'Page', ondelete='cascade') | ||
| summary = fields.Char('Summary', index=True) | ||
| content = fields.Text("Content") | ||
| create_date = fields.Datetime("Date") | ||
| create_uid = fields.Many2one('res.users', "Modified By") | ||
| diff = fields.Text(compute='_compute_diff') | ||
|
|
||
| @api.multi | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ivantodorovich I think we still need an api.depends here, no?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it's not stored, it's actually not needed.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just in case, just added it. |
||
| @api.depends('content', 'page_id.history_ids') | ||
| def _compute_diff(self): | ||
| """Shows a diff between this version and the previous version""" | ||
| history = self.env['document.page.history'] | ||
| for rec in self: | ||
| prev = history.search([ | ||
| ('page_id', '=', rec.page_id.id), | ||
| ('create_date', '<', rec.create_date)], | ||
| limit=1, | ||
| order='create_date DESC') | ||
| if prev: | ||
| rec.diff = self.getDiff(prev.id, rec.id) | ||
| else: | ||
| rec.diff = self.getDiff(False, rec.id) | ||
|
|
||
| @api.model | ||
| def getDiff(self, v1, v2): | ||
| """Return the difference between two version of document version.""" | ||
| text1 = self.browse(v1).content | ||
| text2 = self.browse(v2).content | ||
| line1 = line2 = '' | ||
| if text1: | ||
| line1 = text1.splitlines(1) | ||
| if text2: | ||
| line2 = text2.splitlines(1) | ||
| if (not line1 and not line2) or (line1 == line2): | ||
| text1 = v1 and self.browse(v1).content or '' | ||
| text2 = v2 and self.browse(v2).content or '' | ||
| # Include line breaks to make it more readable | ||
| # TODO: consider using a beautify library directly on the content | ||
| text1 = text1.replace('</p><p>', '</p>\r\n<p>') | ||
| text2 = text2.replace('</p><p>', '</p>\r\n<p>') | ||
| line1 = text1.splitlines(1) | ||
| line2 = text2.splitlines(1) | ||
| if line1 == line2: | ||
| return _('There are no changes in revisions.') | ||
| else: | ||
| diff = difflib.HtmlDiff() | ||
|
|
@@ -58,3 +71,11 @@ def getDiff(self, v1, v2): | |
| "Revision-{}".format(v2), | ||
| context=True | ||
| ) | ||
|
|
||
| @api.multi | ||
| def name_get(self): | ||
| result = [] | ||
| for rec in self: | ||
| name = "%s #%i" % (rec.page_id.name, rec.id) | ||
| result.append((rec.id, name)) | ||
| return result | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,24 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo> | ||
| <data noupdate="0"> | ||
|
|
||
| <!-- Defined in Knowledge. Change it's name --> | ||
| <record id="base.group_document_user" model="res.groups"> | ||
| <field name="name">User (Read only)</field> | ||
| </record> | ||
|
|
||
| <record id="group_document_editor" model="res.groups"> | ||
| <field name="name">Editor</field> | ||
| <field name="category_id" ref="knowledge.module_category_knowledge_management"/> | ||
| <field name="implied_ids" eval="[(4, ref('base.group_document_user'))]"/> | ||
| </record> | ||
|
|
||
| <record id="group_document_manager" model="res.groups"> | ||
| <field name="name">Manager</field> | ||
| <field name="category_id" ref="knowledge.module_category_knowledge_management"/> | ||
| <field name="implied_ids" eval="[(4, ref('group_document_editor'))]"/> | ||
| <field name="users" eval="[(4, ref('base.user_root'))]"/> | ||
| </record> | ||
|
|
||
| </data> | ||
| </odoo> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use api.depends for this compute field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's not stored, I think it's not actually needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just checked and indeed I've already added depends here: dbeec6e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zaoral where you able to look at this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ivantodorovich yes thank you for apply the api.depends. LGTM