Skip to content

Commit b4e6536

Browse files
ivantodorovichhspl-parbo
authored andcommitted
[document_page] FIX creating history when there are no changes made. Add history name field, to name revisions. Modified views to allow setting this field.
[document_page] FIX BUG: UI hanging when editing content. This was due to the api.depends on _compute_diff. Removing it because it's not really necessary since the field is not stored. [document_page] page_id should be readonly. Improve active field [document_page] Update version number [UPD] Update document_page.pot [MIG] document_page_multi_company (OCA#188) * [MIG] document_page_multi_company Added this feature from the old module directly in document_page
1 parent 88069c9 commit b4e6536

7 files changed

Lines changed: 99 additions & 18 deletions

File tree

document_page/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
{
66
'name': 'Document Page',
7-
'version': '11.0.1.0.0',
7+
'version': '11.0.2.1.0',
88
'category': 'Knowledge Management',
99
'author': 'OpenERP SA, Odoo Community Association (OCA)',
1010
'images': [

document_page/i18n/document_page.pot

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ msgstr ""
1313
"Content-Transfer-Encoding: \n"
1414
"Plural-Forms: \n"
1515

16+
#. module: document_page
17+
#: model:ir.model.fields,field_description:document_page.field_document_page_active
18+
msgid "Active"
19+
msgstr ""
20+
1621
#. module: document_page
1722
#: model:ir.ui.view,arch_db:document_page.view_wiki_filter
1823
#: model:ir.ui.view,arch_db:document_page.view_wiki_history_filter
@@ -94,7 +99,7 @@ msgid "Created on"
9499
msgstr ""
95100

96101
#. module: document_page
97-
#: model:ir.model.fields,help:document_page.field_document_page_summary
102+
#: model:ir.model.fields,help:document_page.field_document_page_draft_summary
98103
msgid "Describe the changes made"
99104
msgstr ""
100105

@@ -233,12 +238,19 @@ msgid "Menu Name"
233238
msgstr ""
234239

235240
#. module: document_page
241+
#: model:ir.model.fields,field_description:document_page.field_document_page_draft_name
242+
#: model:ir.model.fields,field_description:document_page.field_document_page_history_name
236243
#: model:ir.ui.view,arch_db:document_page.view_category_form
237244
#: model:ir.ui.view,arch_db:document_page.view_wiki_form
238245
#: model:ir.ui.view,arch_db:document_page.view_wiki_menu_form
239246
msgid "Name"
240247
msgstr ""
241248

249+
#. module: document_page
250+
#: model:ir.model.fields,help:document_page.field_document_page_draft_name
251+
msgid "Name for the changes made"
252+
msgstr ""
253+
242254
#. module: document_page
243255
#: model:ir.model.fields,field_description:document_page.field_document_page_history_page_id
244256
msgid "Page"
@@ -276,15 +288,26 @@ msgstr ""
276288
msgid "Parent Menu"
277289
msgstr ""
278290

291+
#. module: document_page
292+
#: model:ir.ui.view,arch_db:document_page.view_wiki_form
293+
#: model:ir.ui.view,arch_db:document_page.wiki_history_form
294+
msgid "Rev 01"
295+
msgstr ""
296+
297+
#. module: document_page
298+
#: model:ir.ui.view,arch_db:document_page.view_wiki_form
299+
msgid "Revision"
300+
msgstr ""
301+
279302
#. module: document_page
280303
#: code:addons/document_page/wizard/document_page_show_diff.py:28
281304
#, python-format
282305
msgid "Select one or maximum two history revisions!"
283306
msgstr ""
284307

285308
#. module: document_page
309+
#: model:ir.model.fields,field_description:document_page.field_document_page_draft_summary
286310
#: model:ir.model.fields,field_description:document_page.field_document_page_history_summary
287-
#: model:ir.model.fields,field_description:document_page.field_document_page_summary
288311
msgid "Summary"
289312
msgstr ""
290313

document_page/models/document_page.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class DocumentPage(models.Model):
2121
default="content"
2222
)
2323

24+
active = fields.Boolean(default=True)
25+
2426
parent_id = fields.Many2one(
2527
'document.page',
2628
'Category',
@@ -42,7 +44,16 @@ class DocumentPage(models.Model):
4244
)
4345

4446
# no-op computed field
45-
summary = fields.Char(
47+
draft_name = fields.Char(
48+
string='Name',
49+
help='Name for the changes made',
50+
compute=lambda x: x,
51+
inverse=lambda x: x,
52+
)
53+
54+
# no-op computed field
55+
draft_summary = fields.Char(
56+
string='Summary',
4657
help='Describe the changes made',
4758
compute=lambda x: x,
4859
inverse=lambda x: x,
@@ -93,6 +104,14 @@ class DocumentPage(models.Model):
93104
readonly=True,
94105
)
95106

107+
company_id = fields.Many2one(
108+
'res.company',
109+
'Company',
110+
help='If set, page is accessible only from this company',
111+
index=True,
112+
ondelete='cascade',
113+
)
114+
96115
@api.multi
97116
def _get_page_index(self, link=True):
98117
"""Return the index of a document."""
@@ -124,10 +143,12 @@ def _compute_content(self):
124143
@api.multi
125144
def _inverse_content(self):
126145
for rec in self:
127-
if rec.type == 'content':
146+
if rec.type == 'content' and \
147+
rec.content != rec.history_head.content:
128148
rec._create_history({
149+
'name': rec.draft_name,
150+
'summary': rec.draft_summary,
129151
'content': rec.content,
130-
'summary': rec.summary,
131152
})
132153

133154
@api.multi

document_page/models/document_page_history.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,22 @@ class DocumentPageHistory(models.Model):
1414
_order = 'id DESC'
1515

1616
page_id = fields.Many2one('document.page', 'Page', ondelete='cascade')
17-
summary = fields.Char('Summary', index=True)
18-
content = fields.Text("Content")
17+
name = fields.Char(index=True)
18+
summary = fields.Char(index=True)
19+
content = fields.Text()
1920
diff = fields.Text(compute='_compute_diff')
2021

22+
company_id = fields.Many2one(
23+
'res.company',
24+
'Company',
25+
help='If set, page is accessible only from this company',
26+
related='page_id.company_id',
27+
store=True,
28+
index=True,
29+
readonly=True,
30+
)
31+
2132
@api.multi
22-
@api.depends('content', 'page_id.history_ids')
2333
def _compute_diff(self):
2434
"""Shows a diff between this version and the previous version"""
2535
history = self.env['document.page.history']

document_page/security/document_page_security.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,18 @@
1414
<field name="users" eval="[(4, ref('base.user_root'))]"/>
1515
</record>
1616

17+
<record model="ir.rule" id="document_page_rule">
18+
<field name="name">document_page multi-company</field>
19+
<field name="model_id" ref="model_document_page"/>
20+
<field name="global" eval="True"/>
21+
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
22+
</record>
23+
24+
<record model="ir.rule" id="document_page_history_rule">
25+
<field name="name">document_page_history multi-company</field>
26+
<field name="model_id" ref="model_document_page_history"/>
27+
<field name="global" eval="True"/>
28+
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
29+
</record>
30+
1731
</odoo>

document_page/views/document_page.xml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<tree string="Document Page">
2525
<field name="name"/>
2626
<field name="parent_id"/>
27+
<field name="company_id" groups="base.group_multi_company"/>
2728
<field name="create_uid" invisible="1"/>
2829
<field name="content_uid"/>
2930
<field name="content_date"/>
@@ -38,13 +39,19 @@
3839
<field name="arch" type="xml">
3940
<form string="Document Page">
4041
<sheet>
42+
<div class="oe_button_box" name="button_box">
43+
<button name="toggle_active" type="object" groups="document_page.group_document_manager" class="oe_stat_button" icon="fa-archive">
44+
<field name="active" widget="boolean_button" options="{'terminology': 'archive'}"/>
45+
</button>
46+
</div>
4147
<field name="type" invisible="1"/>
4248
<h1>
4349
<field name="name" placeholder="Name"/>
4450
</h1>
4551
<group>
4652
<group>
4753
<field name="parent_id" string="Category" context="{'default_type':'category'}"/>
54+
<field name="company_id" groups="base.group_multi_company"/>
4855
</group>
4956
<group>
5057
<field name="content_uid"/>
@@ -54,17 +61,21 @@
5461
</group>
5562
<notebook>
5663
<page name="content" string="Content">
57-
<label for="summary" class="oe_edit_only"/>
58-
<field name="summary" placeholder="eg: Changed ... for ..." class="oe_edit_only"/>
59-
<label for="content" class="oe_edit_only"/>
60-
<field name="content" widget="html" placeholder="e.g. Once upon a time..." required="1"
61-
options="{'safe': True}"/>
64+
<group string="Revision" class="oe_edit_only">
65+
<field name="draft_name" placeholder="Rev 01" class="oe_edit_only" />
66+
<field name="draft_summary" placeholder="eg: Changed ... for ..." class="oe_edit_only" />
67+
</group>
68+
<div>
69+
<label for="content" class="oe_edit_only"/>
70+
<field name="content" widget="html" placeholder="e.g. Once upon a time..." required="1" options="{'safe': True}"/>
71+
</div>
6272
</page>
6373
<page name="history" string="History">
6474
<field name="history_ids">
6575
<tree>
6676
<field name="id"/>
6777
<field name="create_date"/>
78+
<field name="name"/>
6879
<field name="summary"/>
6980
<field name="create_uid"/>
7081
</tree>

document_page/views/document_page_history.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<tree string="Document History">
1010
<field name="id"/>
1111
<field name="page_id"/>
12+
<field name="name"/>
1213
<field name="summary"/>
1314
<field name="create_uid"/>
1415
<field name="create_date"/>
@@ -39,18 +40,19 @@
3940
<field name="arch" type="xml">
4041
<form string="Document Page History">
4142
<sheet>
42-
<h1><field name="page_id"/></h1>
43+
<h1><field name="page_id" readonly="1"/></h1>
4344
<group>
4445
<group>
4546
<field name="create_uid" readonly="1"/>
4647
<field name="create_date" readonly="1"/>
4748
</group>
4849
</group>
50+
<group>
51+
<field name="name" placeholder="Rev 01"/>
52+
<field name="summary" placeholder="eg: Changed ... for ..."/>
53+
</group>
4954
<notebook>
5055
<page name="content" string="Content">
51-
<label for="summary"/>
52-
<field name="summary" placeholder="eg: Changed ... for ..."/>
53-
<label for="content"/>
5456
<field name="content" widget="html" placeholder="e.g. Once upon a time..." options="{'safe': True}"/>
5557
</page>
5658
<page name="diff" string="Changes">

0 commit comments

Comments
 (0)