diff --git a/document_page/__openerp__.py b/document_page/__openerp__.py index 2b5323b7..a358f00a 100644 --- a/document_page/__openerp__.py +++ b/document_page/__openerp__.py @@ -37,6 +37,8 @@ 'wizard/document_page_create_menu.xml', 'wizard/document_page_show_diff.xml', 'views/document_page.xml', + 'views/document_page_category.xml', + 'views/document_page_history.xml', 'views/document_page_assets.xml', 'views/report_document_page.xml', 'security/document_page_security.xml', diff --git a/document_page/models/document_page.py b/document_page/models/document_page.py index 9b2a6ad5..1d8d63fe 100644 --- a/document_page/models/document_page.py +++ b/document_page/models/document_page.py @@ -55,6 +55,7 @@ class DocumentPage(models.Model): "Content", compute='_compute_content', inverse='_inverse_content', + search='_search_content', required=True, ) @@ -78,12 +79,20 @@ class DocumentPage(models.Model): compute='_compute_display_content' ) + history_head = fields.Many2one( + 'document.page.history', + 'HEAD', + compute='_compute_history_head', + store=True, + auto_join=True, + ) + history_ids = fields.One2many( 'document.page.history', 'page_id', 'History', order='create_date DESC', - readonly=True + readonly=True, ) menu_id = fields.Many2one( @@ -92,29 +101,21 @@ class DocumentPage(models.Model): readonly=True ) - create_date = fields.Datetime( - "Created on", + content_date = fields.Datetime( + 'Last Contribution Date', + related='history_head.create_date', + store=True, index=True, - readonly=True + readonly=True, ) - create_uid = fields.Many2one( + content_uid = fields.Many2one( 'res.users', - 'Author', + 'Last Contributor', + related='history_head.create_uid', + store=True, index=True, - readonly=True - ) - - write_date = fields.Datetime( - "Modification Date", - index=True, - readonly=True) - - write_uid = fields.Many2one( - 'res.users', - "Last Contributor", - index=True, - readonly=True + readonly=True, ) @api.multi @@ -133,19 +134,21 @@ class DocumentPage(models.Model): return r @api.multi + @api.depends('content') def _compute_display_content(self): # @deprecated, simply use content for rec in self: rec.display_content = rec.content @api.multi + @api.depends('history_head', 'history_ids') def _compute_content(self): for rec in self: if rec.type == 'category': rec.content = rec._get_page_index(link=False) else: - if rec.history_ids: - rec.content = rec.history_ids[0].content + if rec.history_head: + rec.content = rec.history_head.content else: # html widget's default, so it doesn't trigger ghost save rec.content = '


' @@ -159,6 +162,17 @@ class DocumentPage(models.Model): 'summary': rec.summary, }) + @api.multi + def _search_content(self, operator, value): + return [('history_head.content', operator, value)] + + @api.multi + @api.depends('history_ids') + def _compute_history_head(self): + for rec in self: + if rec.history_ids: + rec.history_head = rec.history_ids[0] + @api.multi def _create_history(self, vals): self.ensure_one() diff --git a/document_page/models/document_page_history.py b/document_page/models/document_page_history.py index 30fc861d..5ce1dd49 100644 --- a/document_page/models/document_page_history.py +++ b/document_page/models/document_page_history.py @@ -28,7 +28,6 @@ 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', ondelete='cascade') summary = fields.Char('Summary', index=True) diff --git a/document_page/views/document_page.xml b/document_page/views/document_page.xml index 22fbfe2e..deb2810e 100644 --- a/document_page/views/document_page.xml +++ b/document_page/views/document_page.xml @@ -1,10 +1,7 @@ - + @@ -15,8 +12,8 @@ - - + + @@ -30,8 +27,8 @@ - - + + @@ -50,8 +47,8 @@ - - + + @@ -59,8 +56,8 @@ @@ -89,7 +86,7 @@

- + @@ -100,72 +97,19 @@ document.page - - + + + - + - + - - - document.page.category.form - document.page - -
- - -

- - - - - - - - - - - - - - - - - - -
-
- - -
-
-
-
- - - document.page.category.tree - document.page - - - - - - - - - - @@ -183,135 +127,35 @@

+ tree + form + + + + + + + name="Pages" + parent="menu_wiki" + action="action_page" + sequence="10" /> - - Category - document.page - [('type','=','category')] - {'default_type': 'category'} - form - tree,form - - - - - - tree - - - - - - form - - - - - - - - document.page.history.tree - document.page.history - - - - - - - - - - - - - - document.page.history.search - document.page.history - - - - - - - - - - - - - - - document.page.history.form - document.page.history - -
- -

- - - - - - - - - - - - - -
-
-
-
- - - - Page history - document.page.history - form - tree,form - - - - - + + + + + + document.page.category.form + document.page + +
+ + +

+ + + + + + + + + + + + + + + + + + +
+
+ + +
+
+
+
+ + + document.page.category.tree + document.page + + + + + + + + + + + + + + + Category + document.page + [('type','=','category')] + {'default_type': 'category'} + form + tree,form + + + + + + + tree + + + + + + + form + + + + + + + +
+
diff --git a/document_page/views/document_page_history.xml b/document_page/views/document_page_history.xml new file mode 100755 index 00000000..1112e103 --- /dev/null +++ b/document_page/views/document_page_history.xml @@ -0,0 +1,90 @@ + + + + + + + document.page.history.tree + document.page.history + + + + + + + + + + + + + + document.page.history.search + document.page.history + + + + + + + + + + + + + + + document.page.history.form + document.page.history + +
+ +

+ + + + + + + + + + + + + +
+
+
+
+ + + + Page history + document.page.history + form + tree,form + + + + + + + +
+
diff --git a/document_page_approval/models/document_page_approval.py b/document_page_approval/models/document_page_approval.py index 2c9e57af..6e00fe3d 100644 --- a/document_page_approval/models/document_page_approval.py +++ b/document_page_approval/models/document_page_approval.py @@ -34,14 +34,20 @@ class DocumentPageApproval(models.Model): ) approved_date = fields.Datetime( - compute='_compute_approved_info', - string="Approved Date" + 'Approved Date', + related='history_head.approved_date', + store=True, + index=True, + readonly=True, ) approved_uid = fields.Many2one( 'res.users', - compute='_compute_approved_info', - string="Approved By", + 'Approved by', + related='history_head.approved_uid', + store=True, + index=True, + readonly=True, ) approval_required = fields.Boolean( @@ -61,6 +67,10 @@ class DocumentPageApproval(models.Model): compute='_compute_is_approval_required', ) + am_i_approver = fields.Boolean( + compute='_compute_am_i_approver' + ) + approver_group_ids = fields.Many2many( 'res.groups', string='Approver groups', @@ -73,15 +83,6 @@ class DocumentPageApproval(models.Model): string='Has changes pending approval' ) - @api.multi - @api.depends('history_ids') - def _compute_approved_info(self): - """Return the approved date of a document.""" - for page in self: - if page.history_ids: - page.approved_date = page.history_ids[0].approved_date - page.approved_uid = page.history_ids[0].approved_uid - @api.multi @api.depends('approval_required', 'parent_id.is_approval_required') def _compute_is_approval_required(self): @@ -102,6 +103,30 @@ class DocumentPageApproval(models.Model): res = res | page.parent_id.approver_group_ids page.approver_group_ids = res + @api.multi + @api.depends('is_approval_required', 'approver_group_ids') + def _compute_am_i_approver(self): + """Check if the current user can approve changes to this page.""" + for rec in self: + rec.am_i_approver = rec.can_user_approve_this_page(self.env.user) + + @api.multi + def can_user_approve_this_page(self, user): + """Check if a user can approve this page.""" + self.ensure_one() + # if it's not required, anyone can approve + if not self.is_approval_required: + return True + # to approve, you must have approver rights + approver_group_id = self.env.ref( + 'document_page_approval.group_document_approver_user') + if approver_group_id not in user.groups_id: + return False + # and belong to at least one of the approver_groups (if any is set) + if not self.approver_group_ids: + return True + return len(user.groups_id & self.approver_group_ids) > 0 + @api.multi def _compute_has_changes_pending_approval(self): history = self.env['document.page.history'] diff --git a/document_page_approval/models/document_page_history_workflow.py b/document_page_approval/models/document_page_history_workflow.py index fd03f4d2..e66e05e1 100644 --- a/document_page_approval/models/document_page_history_workflow.py +++ b/document_page_approval/models/document_page_history_workflow.py @@ -40,11 +40,13 @@ class DocumentPageHistoryWorkflow(models.Model): readonly=True, ) - approved_date = fields.Datetime("Approved Date") + approved_date = fields.Datetime( + 'Approved Date', + ) approved_uid = fields.Many2one( 'res.users', - "Approved By" + 'Approved by', ) is_approval_required = fields.Boolean( @@ -52,8 +54,13 @@ class DocumentPageHistoryWorkflow(models.Model): string="Approval required", ) - am_i_owner = fields.Boolean(compute='_compute_am_i_owner') - am_i_approver = fields.Boolean(compute='_compute_am_i_approver') + am_i_owner = fields.Boolean( + compute='_compute_am_i_owner' + ) + + am_i_approver = fields.Boolean( + related='page_id.am_i_approver' + ) page_url = fields.Text( compute='_compute_page_url', @@ -92,6 +99,8 @@ class DocumentPageHistoryWorkflow(models.Model): 'approved_uid': self.env.uid }) for rec in self: + # Trigger computed field update + rec.page_id._compute_history_head() # Notify state change rec.message_post( subtype='mt_comment', @@ -125,29 +134,6 @@ class DocumentPageHistoryWorkflow(models.Model): for rec in self: rec.am_i_owner = (rec.create_uid == self.env.user) - @api.multi - def _compute_am_i_approver(self): - """Check if the current user can approve the page.""" - for rec in self: - rec.am_i_approver = rec.can_user_approve_this_page(self.env.user) - - @api.multi - def can_user_approve_this_page(self, user): - """Check if a user can approve this page.""" - self.ensure_one() - # if it's not required, anyone can approve - if not self.is_approval_required: - return True - # to approve, you must have approver rights - approver_group_id = self.env.ref( - 'document_page_approval.group_document_approver_user') - if approver_group_id not in user.groups_id: - return False - # and belong to at least one of the approver_groups (if any is set) - if not self.page_id.approver_group_ids: - return True - return len(user.groups_id & self.page_id.approver_group_ids) > 0 - @api.multi def _compute_page_url(self): """Compute the page url.""" diff --git a/document_page_approval/views/document_page_approval.xml b/document_page_approval/views/document_page_approval.xml index a1ec792d..60a8176e 100644 --- a/document_page_approval/views/document_page_approval.xml +++ b/document_page_approval/views/document_page_approval.xml @@ -1,5 +1,7 @@ + + document.page.history.form document.page.history @@ -46,6 +48,7 @@
+ document.page.form document.page @@ -73,11 +76,11 @@
- + - + @@ -94,6 +97,7 @@ + document.page.form document.page @@ -108,6 +112,7 @@ + document.page.category.form document.page @@ -121,6 +126,7 @@ + document.page.history.tree document.page.history @@ -149,6 +155,18 @@ + + + + + + + + + + + + @@ -162,9 +180,9 @@ + name="Change Requests" + parent="document_page.menu_wiki" + action="action_change_requests" + sequence="25" + groups="document_page.group_document_editor" />