[MIG] document_page: Migration to 12.0

This commit is contained in:
mreficent 2019-03-12 13:23:37 +01:00 committed by Justine Doutreloux
parent fc22ca50fb
commit 792991fba3
25 changed files with 51 additions and 60 deletions

View File

@ -1,5 +1,5 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg .. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3 :alt: License: AGPL-3
============= =============
@ -30,17 +30,15 @@ To use this module, you need to:
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/118/11.0 :target: https://runbot.odoo-community.org/runbot/118/12.0
Known issues / Roadmap
======================
Bug Tracker Bug Tracker
=========== ===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/Knowledge/issues>`_. Bugs are tracked on `GitHub Issues
In case of trouble, please check there if your issue has already been reported. <https://github.com/OCA/knowledge/issues>`_. In case of trouble, please
If you spotted it first, help us smash it by providing detailed and welcomed feedback. check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.
Credits Credits
======= =======
@ -48,7 +46,7 @@ Credits
Images Images
------ ------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. * Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.
Contributors Contributors
------------ ------------

View File

@ -1,4 +1,3 @@
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models from . import models

View File

@ -4,7 +4,7 @@
{ {
'name': 'Document Page', 'name': 'Document Page',
'version': '11.0.2.3.0', 'version': '12.0.1.0.0',
'category': 'Knowledge Management', 'category': 'Knowledge Management',
'author': 'OpenERP SA, Odoo Community Association (OCA)', 'author': 'OpenERP SA, Odoo Community Association (OCA)',
'images': [ 'images': [
@ -22,6 +22,8 @@
'knowledge', 'knowledge',
], ],
'data': [ 'data': [
'security/document_page_security.xml',
'security/ir.model.access.csv',
'wizard/document_page_create_menu.xml', 'wizard/document_page_create_menu.xml',
'wizard/document_page_show_diff.xml', 'wizard/document_page_show_diff.xml',
'views/document_page.xml', 'views/document_page.xml',
@ -29,8 +31,6 @@
'views/document_page_history.xml', 'views/document_page_history.xml',
'views/document_page_assets.xml', 'views/document_page_assets.xml',
'views/report_document_page.xml', 'views/report_document_page.xml',
'security/document_page_security.xml',
'security/ir.model.access.csv',
], ],
'demo': [ 'demo': [
'demo/document_page.xml' 'demo/document_page.xml'

View File

@ -1,12 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Ivan Todorovich <ivan.todorovich@gmail.com>
# 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'
""")

View File

@ -1,4 +1,3 @@
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import document_page from . import document_page

View File

@ -14,28 +14,23 @@ class DocumentPage(models.Model):
_order = 'name' _order = 'name'
name = fields.Char('Title', required=True) name = fields.Char('Title', required=True)
type = fields.Selection( type = fields.Selection(
[('content', 'Content'), ('category', 'Category')], [('content', 'Content'), ('category', 'Category')],
'Type', 'Type',
help="Page type", help="Page type",
default="content" default="content"
) )
active = fields.Boolean(default=True) active = fields.Boolean(default=True)
parent_id = fields.Many2one( parent_id = fields.Many2one(
'document.page', 'document.page',
'Category', 'Category',
domain=[('type', '=', 'category')] domain=[('type', '=', 'category')]
) )
child_ids = fields.One2many( child_ids = fields.One2many(
'document.page', 'document.page',
'parent_id', 'parent_id',
'Children' 'Children'
) )
content = fields.Text( content = fields.Text(
"Content", "Content",
compute='_compute_content', compute='_compute_content',
@ -65,7 +60,6 @@ class DocumentPage(models.Model):
help="Template that will be used as a content template " help="Template that will be used as a content template "
"for all new page of this category.", "for all new page of this category.",
) )
history_head = fields.Many2one( history_head = fields.Many2one(
'document.page.history', 'document.page.history',
'HEAD', 'HEAD',
@ -73,7 +67,6 @@ class DocumentPage(models.Model):
store=True, store=True,
auto_join=True, auto_join=True,
) )
history_ids = fields.One2many( history_ids = fields.One2many(
'document.page.history', 'document.page.history',
'page_id', 'page_id',
@ -81,13 +74,11 @@ class DocumentPage(models.Model):
order='create_date DESC', order='create_date DESC',
readonly=True, readonly=True,
) )
menu_id = fields.Many2one( menu_id = fields.Many2one(
'ir.ui.menu', 'ir.ui.menu',
"Menu", "Menu",
readonly=True, readonly=True,
) )
content_date = fields.Datetime( content_date = fields.Datetime(
'Last Contribution Date', 'Last Contribution Date',
related='history_head.create_date', related='history_head.create_date',
@ -95,7 +86,6 @@ class DocumentPage(models.Model):
index=True, index=True,
readonly=True, readonly=True,
) )
content_uid = fields.Many2one( content_uid = fields.Many2one(
'res.users', 'res.users',
'Last Contributor', 'Last Contributor',
@ -104,7 +94,6 @@ class DocumentPage(models.Model):
index=True, index=True,
readonly=True, readonly=True,
) )
company_id = fields.Many2one( company_id = fields.Many2one(
'res.company', 'res.company',
'Company', 'Company',

View File

@ -40,12 +40,12 @@ class DocumentPageHistory(models.Model):
limit=1, limit=1,
order='create_date DESC') order='create_date DESC')
if prev: if prev:
rec.diff = self.getDiff(prev.id, rec.id) rec.diff = self._get_diff(prev.id, rec.id)
else: else:
rec.diff = self.getDiff(False, rec.id) rec.diff = self._get_diff(False, rec.id)
@api.model @api.model
def getDiff(self, v1, v2): def _get_diff(self, v1, v2):
"""Return the difference between two version of document version.""" """Return the difference between two version of document version."""
text1 = v1 and self.browse(v1).content or '' text1 = v1 and self.browse(v1).content or ''
text2 = v2 and self.browse(v2).content or '' text2 = v2 and self.browse(v2).content or ''
@ -53,8 +53,8 @@ class DocumentPageHistory(models.Model):
# TODO: consider using a beautify library directly on the content # TODO: consider using a beautify library directly on the content
text1 = text1.replace('</p><p>', '</p>\r\n<p>') text1 = text1.replace('</p><p>', '</p>\r\n<p>')
text2 = text2.replace('</p><p>', '</p>\r\n<p>') text2 = text2.replace('</p><p>', '</p>\r\n<p>')
line1 = text1.splitlines(1) line1 = text1.splitlines(True)
line2 = text2.splitlines(1) line2 = text2.splitlines(True)
if line1 == line2: if line1 == line2:
return _('There are no changes in revisions.') return _('There are no changes in revisions.')
else: else:

View File

@ -0,0 +1 @@
No configuration required.

View File

@ -0,0 +1,5 @@
* Gervais Naoussi <gervaisnaoussi@gmail.com>
* Maxime Chambreuil <mchambreuil@ursainfosystems.com>
* Iván Todorovich <ivan.todorovich@gmail.com>
* Jose Maria Alzaga <jose.alzaga@aselcis.com>
* Lois Rilo <lois.rilo@eficent.com>

View File

@ -0,0 +1,4 @@
The development of this module has been financially supported by:
* Odoo SA <http://www.odoo.com>
* Savoir-faire Linux <http://www.savoirfairelinux.com>

View File

@ -0,0 +1 @@
This module allows you to write web pages for internal documentation.

View File

@ -0,0 +1 @@
This module depends on module knowledge. So make sure to have it in your addons list.

View File

@ -0,0 +1,5 @@
To use this module, you need to:
* Go to Knowledge menu
* Click on Categories to create the document's category you need with the template
* Click on Pages to create pages and select the previous category to use the template

View File

@ -11,7 +11,7 @@
<field name="name">Manager</field> <field name="name">Manager</field>
<field name="category_id" ref="knowledge.module_category_knowledge"/> <field name="category_id" ref="knowledge.module_category_knowledge"/>
<field name="implied_ids" eval="[(4, ref('group_document_editor'))]"/> <field name="implied_ids" eval="[(4, ref('group_document_editor'))]"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/> <field name="users" eval="[(4, ref('base.user_admin'))]"/>
</record> </record>
<record model="ir.rule" id="document_page_rule"> <record model="ir.rule" id="document_page_rule">

View File

@ -1,3 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_document_page from . import test_document_page
from . import test_document_page_create_menu from . import test_document_page_create_menu

View File

@ -1,4 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests import common from odoo.tests import common

View File

@ -1,4 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests import common from odoo.tests import common

View File

@ -13,8 +13,8 @@ class TestDocumentPageHistory(common.TransactionCase):
history_pages = history_document.search([('page_id', '=', page.id)]) history_pages = history_document.search([('page_id', '=', page.id)])
active_ids = [i.id for i in history_pages] active_ids = [i.id for i in history_pages]
result = history_document.getDiff(active_ids[0], active_ids[0]) result = history_document._get_diff(active_ids[0], active_ids[0])
self.assertEqual(result, 'There are no changes in revisions.') self.assertEqual(result, 'There are no changes in revisions.')
result = history_document.getDiff(active_ids[0], active_ids[1]) result = history_document._get_diff(active_ids[0], active_ids[1])
self.assertNotEqual(result, 'There are no changes in revisions.') self.assertNotEqual(result, 'There are no changes in revisions.')

View File

@ -1,3 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.exceptions import UserError from odoo.exceptions import UserError
from odoo.tests import common from odoo.tests import common

View File

@ -117,9 +117,9 @@
<field name="create_uid"/> <field name="create_uid"/>
<field name="content_uid"/> <field name="content_uid"/>
<group expand="0" string="Group By..."> <group expand="0" string="Group By...">
<filter string="Category" context="{'group_by':'parent_id'}"/> <filter name="group_by_category" string="Category" context="{'group_by':'parent_id'}"/>
<filter string="Author" context="{'group_by':'create_uid'}"/> <filter name="group_by_author" string="Author" context="{'group_by':'create_uid'}"/>
<filter string="Last Contributor" context="{'group_by':'content_uid'}"/> <filter name="group_by_last_contributor" string="Last Contributor" context="{'group_by':'content_uid'}"/>
</group> </group>
</search> </search>
</field> </field>

View File

@ -62,9 +62,9 @@
<field name="create_uid"/> <field name="create_uid"/>
<field name="content_uid"/> <field name="content_uid"/>
<group expand="0" string="Group By..."> <group expand="0" string="Group By...">
<filter string="Category" context="{'group_by':'parent_id'}"/> <filter name="group_by_category" string="Category" context="{'group_by':'parent_id'}"/>
<filter string="Author" context="{'group_by':'create_uid'}"/> <filter name="group_by_author" string="Author" context="{'group_by':'create_uid'}"/>
<filter string="Last Contributor" context="{'group_by':'content_uid'}"/> <filter name="group_by_last_contributor" string="Last Contributor" context="{'group_by':'content_uid'}"/>
</group> </group>
</search> </search>
</field> </field>

View File

@ -27,7 +27,7 @@
<field name="content"/> <field name="content"/>
<field name="create_uid"/> <field name="create_uid"/>
<group expand="0" string="Group By..."> <group expand="0" string="Group By...">
<filter name="group_author" string="Author" context="{'group_by':'create_uid'}" /> <filter name="group_by_author" string="Author" context="{'group_by':'create_uid'}" />
</group> </group>
</search> </search>
</field> </field>

View File

@ -1,4 +1,3 @@
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import document_page_create_menu from . import document_page_create_menu

View File

@ -14,7 +14,6 @@ class DocumentPageCreateMenu(models.TransientModel):
'Menu Name', 'Menu Name',
required=True required=True
) )
menu_parent_id = fields.Many2one( menu_parent_id = fields.Many2one(
'ir.ui.menu', 'ir.ui.menu',
'Parent Menu', 'Parent Menu',
@ -53,7 +52,7 @@ class DocumentPageCreateMenu(models.TransientModel):
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',
'target': 'current', 'target': 'current',
} }
value['domain'] = "[('parent_id','=',%d)]" % (page.id) value['domain'] = "[('parent_id','=',%d)]" % page.id
value['res_id'] = page.id value['res_id'] = page.id
# only the super user is allowed to create menu due to security rules # only the super user is allowed to create menu due to security rules

View File

@ -10,6 +10,7 @@ class DocumentPageShowDiff(models.TransientModel):
"""Display Difference for History.""" """Display Difference for History."""
_name = 'wizard.document.page.history.show_diff' _name = 'wizard.document.page.history.show_diff'
_description = 'Document Page Show Diff'
def _get_diff(self): def _get_diff(self):
"""Return the Difference between two document.""" """Return the Difference between two document."""
@ -18,9 +19,9 @@ class DocumentPageShowDiff(models.TransientModel):
diff = False diff = False
if len(ids) == 2: if len(ids) == 2:
if ids[0] > ids[1]: if ids[0] > ids[1]:
diff = history.getDiff(ids[1], ids[0]) diff = history._get_diff(ids[1], ids[0])
else: else:
diff = history.getDiff(ids[0], ids[1]) diff = history._get_diff(ids[0], ids[1])
elif len(ids) == 1: elif len(ids) == 1:
diff = history.browse(ids[0]).diff diff = history.browse(ids[0]).diff
else: else: