code totally migrate to odoo 9.0 api

This commit is contained in:
Gervais Naoussi 2016-01-20 12:07:18 +01:00
parent 8626a02aef
commit 84d81949d7
4 changed files with 14 additions and 19 deletions

View File

@ -1,3 +1,2 @@
"""Data models initialisation."""
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from . import document_page_approval, document_page_history_workflow from . import document_page_approval, document_page_history_workflow

View File

@ -86,6 +86,7 @@ class DocumentPageApproval(models.Model):
approved_uid = history_ids.approved_uid.id approved_uid = history_ids.approved_uid.id
page.approved_uid = approved_uid page.approved_uid = approved_uid
@api.multi
def _is_parent_approval_required(self): def _is_parent_approval_required(self):
"""Check if the document required approval base on his parrent.""" """Check if the document required approval base on his parrent."""
for page in self: for page in self:

View File

@ -22,7 +22,7 @@
from datetime import datetime from datetime import datetime
from openerp.tools.translate import _ from openerp.tools.translate import _
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
from openerp import models, fields, SUPERUSER_ID from openerp import models, fields, api
class DocumentPageHistoryWorkflow(models.Model): class DocumentPageHistoryWorkflow(models.Model):
@ -30,27 +30,21 @@ class DocumentPageHistoryWorkflow(models.Model):
_inherit = 'document.page.history' _inherit = 'document.page.history'
@api.multi
def page_approval_draft(self): def page_approval_draft(self):
"""Set a document state as draft and notified the reviewers.""" """Set a document state as draft and notified the reviewers."""
self.write({'state': 'draft'}) self.write({'state': 'draft'})
template_id = self.pool.get('ir.model.data').get_object_reference( template = self.env.ref(
self.env.cr, self.env.uid, 'document_page_approval.email_template_new_draft_need_approval')
'document_page_approval',
'email_template_new_draft_need_approval')[1]
for page in self: for page in self:
if page.is_parent_approval_required: if page.is_parent_approval_required:
self.pool.get('mail.template').send_mail( template.send_mail(page.id, force_send=True)
self.env.cr, self.env.uid,
template_id,
page.id,
force_send=True
)
return True return True
@api.multi
def page_approval_approved(self): def page_approval_approved(self):
"""Set a document state as approve.""" """Set a document state as approve."""
model_data_obj = self.pool.get('ir.model.data') message_obj = self.env['mail.message']
message_obj = self.pool.get('mail.message')
self.write({ self.write({
'state': 'approved', 'state': 'approved',
'approved_date': datetime.now().strftime( 'approved_date': datetime.now().strftime(
@ -59,19 +53,18 @@ class DocumentPageHistoryWorkflow(models.Model):
}) })
# Notify followers a new version is available # Notify followers a new version is available
for page_history in self: for page_history in self:
subtype_id = model_data_obj.get_object_reference( subtype = self.env.ref('mail.mt_comment')
self.env.cr, SUPERUSER_ID, 'mail', 'mt_comment')[1]
message_obj.create( message_obj.create(
self.env.cr, self.env.uid,
{'res_id': page_history.page_id.id, {'res_id': page_history.page_id.id,
'model': 'document.page', 'model': 'document.page',
'subtype_id': subtype_id, 'subtype_id': subtype.id,
'body': _('New version of the document %s' 'body': _('New version of the document %s'
' approved.') % page_history.page_id.name ' approved.') % page_history.page_id.name
} }
) )
return True return True
@api.multi
def _can_user_approve_page(self): def _can_user_approve_page(self):
"""Check if a user cas approve the page.""" """Check if a user cas approve the page."""
user = self.env.user user = self.env.user
@ -90,6 +83,7 @@ class DocumentPageHistoryWorkflow(models.Model):
res = False res = False
return res return res
@api.multi
def get_approvers_guids(self): def get_approvers_guids(self):
"""Return the approvers group.""" """Return the approvers group."""
res = {} res = {}
@ -110,6 +104,7 @@ class DocumentPageHistoryWorkflow(models.Model):
return res return res
@api.multi
def _get_approvers_email(self): def _get_approvers_email(self):
"""Get the approvers email.""" """Get the approvers email."""
for page in self: for page in self:
@ -134,6 +129,7 @@ class DocumentPageHistoryWorkflow(models.Model):
page.get_approvers_email = emails[:-1] page.get_approvers_email = emails[:-1]
@api.multi
def _get_page_url(self): def _get_page_url(self):
"""Get the page url.""" """Get the page url."""
for page in self: for page in self:

View File

@ -1,3 +1,2 @@
"""Module test initialisation."""
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from . import test_document_page_approval, test_document_page_history_workflow from . import test_document_page_approval, test_document_page_history_workflow