mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-22 03:56:56 -06:00
commit
388fc96c4b
@ -67,7 +67,8 @@ class document_file(orm.Model):
|
|||||||
cr, uid, ids_to_unlink, context=context)
|
cr, uid, ids_to_unlink, context=context)
|
||||||
else:
|
else:
|
||||||
# Normal delete
|
# Normal delete
|
||||||
result = super(document_file, self).unlink(cr, uid, ids, context=context)
|
result = super(document_file, self).unlink(
|
||||||
|
cr, uid, ids, context=context)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@ -78,8 +79,8 @@ class ir_attachment_document(orm.Model):
|
|||||||
_columns = {
|
_columns = {
|
||||||
'res_id': fields.integer('Resource ID', readonly=True,
|
'res_id': fields.integer('Resource ID', readonly=True,
|
||||||
help="The record id this is attached to."),
|
help="The record id this is attached to."),
|
||||||
'res_model': fields.char('Resource Model', size=64,
|
'res_model': fields.char(
|
||||||
readonly=True,
|
'Resource Model', size=64, readonly=True,
|
||||||
help="The database object this attachment will be attached to"),
|
help="The database object this attachment will be attached to"),
|
||||||
'res_name': fields.char('Resource Name', type='char',
|
'res_name': fields.char('Resource Name', type='char',
|
||||||
size=128,
|
size=128,
|
||||||
|
@ -40,17 +40,24 @@ class document_wizard(orm.Model):
|
|||||||
context = {}
|
context = {}
|
||||||
ir_attach_obj = self.pool.get('ir.attachment')
|
ir_attach_obj = self.pool.get('ir.attachment')
|
||||||
ir_attach_doc_obj = self.pool.get('ir.attachment.document')
|
ir_attach_doc_obj = self.pool.get('ir.attachment.document')
|
||||||
ir_model_obj = self.pool.get(context.get('model') or context.get('active_model'))
|
ir_model_obj = self.pool.get(
|
||||||
|
context.get('model') or context.get('active_model'))
|
||||||
|
|
||||||
name = ir_model_obj.browse(cr, uid, context.get('ids') or context.get('active_ids'), context=context)[0]['name']
|
name = ir_model_obj.browse(
|
||||||
|
cr, uid, context.get('ids') or context.get('active_ids'),
|
||||||
|
context=context)[0]['name']
|
||||||
data = self.read(cr, uid, ids, [], context=context)[0]
|
data = self.read(cr, uid, ids, [], context=context)[0]
|
||||||
if not data['attachment_ids']:
|
if not data['attachment_ids']:
|
||||||
raise orm.except_orm(_('Error'),
|
raise orm.except_orm(
|
||||||
|
_('Error'),
|
||||||
_('You have to select at least 1 Document. And try again'))
|
_('You have to select at least 1 Document. And try again'))
|
||||||
for attach in ir_attach_obj.browse(cr, uid, data['attachment_ids'], context=context):
|
for attach in ir_attach_obj.browse(cr, uid, data['attachment_ids'],
|
||||||
|
context=context):
|
||||||
data_attach = {
|
data_attach = {
|
||||||
'res_model': context.get('model') or context.get('active_model'),
|
'res_model': context.get('model') or
|
||||||
'res_id': context.get('ids') and context.get('ids')[0] or context.get('active_id'),
|
context.get('active_model'),
|
||||||
|
'res_id': context.get('ids') and context.get('ids')[0] or
|
||||||
|
context.get('active_id'),
|
||||||
'res_name': name,
|
'res_name': name,
|
||||||
'attachment_id': attach.id,
|
'attachment_id': attach.id,
|
||||||
}
|
}
|
||||||
|
@ -27,16 +27,18 @@
|
|||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
'category': 'Knowledge Management',
|
'category': 'Knowledge Management',
|
||||||
'description': """
|
'description': """
|
||||||
This module adds a workflow to approve page modification and show the approved version by default.
|
This module adds a workflow to approve page modification and show the approved
|
||||||
|
version by default.
|
||||||
|
|
||||||
Scenario
|
Scenario
|
||||||
========
|
========
|
||||||
|
|
||||||
* Set a valid email address on the company settings.
|
* Set a valid email address on the company settings.
|
||||||
* Create a new page category and set an approver group. Make sure users belonging to that group
|
* Create a new page category and set an approver group. Make sure users
|
||||||
have valid email addresses.
|
belonging to that group have valid email addresses.
|
||||||
* Create a new page and choose the previously created category.
|
* Create a new page and choose the previously created category.
|
||||||
* A notification is sent to the group with a link to the page history to review.
|
* A notification is sent to the group with a link to the page history to
|
||||||
|
review.
|
||||||
* Depending on the review, the page history is approved or not.
|
* Depending on the review, the page history is approved or not.
|
||||||
* Users reading the page see the last approved version.
|
* Users reading the page see the last approved version.
|
||||||
""",
|
""",
|
||||||
@ -52,5 +54,9 @@ Scenario
|
|||||||
],
|
],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
'auto_install': False,
|
'auto_install': False,
|
||||||
'images': ['images/category.png', 'images/page_history_list.png', 'images/page_history.png'],
|
'images': [
|
||||||
|
'images/category.png',
|
||||||
|
'images/page_history_list.png',
|
||||||
|
'images/page_history.png',
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,8 @@ class document_page_history_wkfl(orm.Model):
|
|||||||
|
|
||||||
template_id = self.pool.get('ir.model.data').get_object_reference(
|
template_id = self.pool.get('ir.model.data').get_object_reference(
|
||||||
cr, uid,
|
cr, uid,
|
||||||
'document_page_approval', 'email_template_new_draft_need_approval')[1]
|
'document_page_approval',
|
||||||
|
'email_template_new_draft_need_approval')[1]
|
||||||
for page in self.browse(cr, uid, ids, context=context):
|
for page in self.browse(cr, uid, ids, context=context):
|
||||||
if page.is_parent_approval_required:
|
if page.is_parent_approval_required:
|
||||||
self.pool.get('email.template').send_mail(
|
self.pool.get('email.template').send_mail(
|
||||||
@ -44,7 +45,8 @@ class document_page_history_wkfl(orm.Model):
|
|||||||
def page_approval_approved(self, cr, uid, ids, context=None):
|
def page_approval_approved(self, cr, uid, ids, context=None):
|
||||||
self.write(cr, uid, ids, {
|
self.write(cr, uid, ids, {
|
||||||
'state': 'approved',
|
'state': 'approved',
|
||||||
'approved_date': datetime.now().strftime(DEFAULT_SERVER_DATETIME_FORMAT),
|
'approved_date': datetime.now().strftime(
|
||||||
|
DEFAULT_SERVER_DATETIME_FORMAT),
|
||||||
'approved_uid': uid
|
'approved_uid': uid
|
||||||
}, context=context)
|
}, context=context)
|
||||||
return True
|
return True
|
||||||
@ -89,9 +91,12 @@ class document_page_history_wkfl(orm.Model):
|
|||||||
res = {}
|
res = {}
|
||||||
for id in ids:
|
for id in ids:
|
||||||
emails = ''
|
emails = ''
|
||||||
guids = self.get_approvers_guids(cr, uid, ids, name, args, context=context)
|
guids = self.get_approvers_guids(
|
||||||
uids = self.pool.get('res.users').search(cr, uid, [('groups_id', 'in', guids[id])])
|
cr, uid, ids, name, args, context=context)
|
||||||
users = self.pool.get('res.users').browse(cr, uid, uids, context=context)
|
uids = self.pool.get('res.users').search(
|
||||||
|
cr, uid, [('groups_id', 'in', guids[id])])
|
||||||
|
users = self.pool.get('res.users').browse(
|
||||||
|
cr, uid, uids, context=context)
|
||||||
|
|
||||||
for user in users:
|
for user in users:
|
||||||
if user.email:
|
if user.email:
|
||||||
@ -100,7 +105,8 @@ class document_page_history_wkfl(orm.Model):
|
|||||||
else:
|
else:
|
||||||
empl_id = self.pool.get('hr.employee').search(
|
empl_id = self.pool.get('hr.employee').search(
|
||||||
cr, uid, [('login', '=', user.login)])[0]
|
cr, uid, [('login', '=', user.login)])[0]
|
||||||
empl = self.pool.get('hr.employee').browse(cr, uid, empl_id, context=context)
|
empl = self.pool.get('hr.employee').browse(
|
||||||
|
cr, uid, empl_id, context=context)
|
||||||
if empl.work_email:
|
if empl.work_email:
|
||||||
emails += empl.work_email
|
emails += empl.work_email
|
||||||
emails += ','
|
emails += ','
|
||||||
@ -113,9 +119,12 @@ class document_page_history_wkfl(orm.Model):
|
|||||||
res = {}
|
res = {}
|
||||||
for id in ids:
|
for id in ids:
|
||||||
base_url = self.pool.get('ir.config_parameter').get_param(
|
base_url = self.pool.get('ir.config_parameter').get_param(
|
||||||
cr, uid, 'web.base.url', default='http://localhost:8069', context=context)
|
cr, uid, 'web.base.url', default='http://localhost:8069',
|
||||||
|
context=context)
|
||||||
|
|
||||||
res[id] = base_url + '/#db=%s&id=%s&view_type=form&model=document.page.history' % (cr.dbname, id)
|
res[id] = base_url + (
|
||||||
|
'/#db=%s&id=%s&view_type=form&model=document.page.history' %
|
||||||
|
(cr.dbname, id))
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@ -129,10 +138,13 @@ class document_page_history_wkfl(orm.Model):
|
|||||||
'page_id', 'is_parent_approval_required',
|
'page_id', 'is_parent_approval_required',
|
||||||
string="parent approval", type='boolean', store=False),
|
string="parent approval", type='boolean', store=False),
|
||||||
'can_user_approve_page': fields.function(
|
'can_user_approve_page': fields.function(
|
||||||
can_user_approve_page, string="can user approve this page", type='boolean', store=False),
|
can_user_approve_page, string="can user approve this page",
|
||||||
|
type='boolean', store=False),
|
||||||
'get_approvers_email': fields.function(
|
'get_approvers_email': fields.function(
|
||||||
get_approvers_email, string="get all approvers email", type='text', store=False),
|
get_approvers_email, string="get all approvers email",
|
||||||
'get_page_url': fields.function(get_page_url, string="URL", type='text', store=False),
|
type='text', store=False),
|
||||||
|
'get_page_url': fields.function(get_page_url, string="URL",
|
||||||
|
type='text', store=False),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -153,7 +165,8 @@ class document_page_approval(orm.Model):
|
|||||||
('page_id', '=', page.id),
|
('page_id', '=', page.id),
|
||||||
('state', '=', 'approved')
|
('state', '=', 'approved')
|
||||||
], limit=1, order='create_date DESC')
|
], limit=1, order='create_date DESC')
|
||||||
for h in history.browse(cr, uid, history_ids, context=context):
|
for h in history.browse(cr, uid, history_ids,
|
||||||
|
context=context):
|
||||||
content = h.content
|
content = h.content
|
||||||
else:
|
else:
|
||||||
content = page.content
|
content = page.content
|
||||||
@ -186,7 +199,8 @@ class document_page_approval(orm.Model):
|
|||||||
history = self.pool.get('document.page.history')
|
history = self.pool.get('document.page.history')
|
||||||
history_ids = history.search(cr, uid, [
|
history_ids = history.search(cr, uid, [
|
||||||
('page_id', '=', page.id),
|
('page_id', '=', page.id),
|
||||||
('state', '=', 'approved')], limit=1, order='create_date DESC')
|
('state', '=', 'approved')], limit=1,
|
||||||
|
order='create_date DESC')
|
||||||
approved_uid = False
|
approved_uid = False
|
||||||
for h in history.browse(cr, uid, history_ids):
|
for h in history.browse(cr, uid, history_ids):
|
||||||
approved_uid = h.approved_uid.id
|
approved_uid = h.approved_uid.id
|
||||||
@ -196,7 +210,8 @@ class document_page_approval(orm.Model):
|
|||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _is_parent_approval_required(self, cr, uid, ids, name, args, context=None):
|
def _is_parent_approval_required(self, cr, uid, ids, name, args,
|
||||||
|
context=None):
|
||||||
res = {}
|
res = {}
|
||||||
for page in self.browse(cr, uid, ids, context=context):
|
for page in self.browse(cr, uid, ids, context=context):
|
||||||
res[page.id] = self.is_approval_required(page)
|
res[page.id] = self.is_approval_required(page)
|
||||||
@ -213,11 +228,16 @@ class document_page_approval(orm.Model):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'display_content': fields.function(_get_display_content, string='Displayed Content', type='text'),
|
'display_content': fields.function(
|
||||||
'approved_date': fields.function(_get_approved_date, string="Approved Date", type='datetime'),
|
_get_display_content, string='Displayed Content', type='text'),
|
||||||
'approved_uid': fields.function(_get_approved_uid, string="Approved By", type='many2one', obj='res.users'),
|
'approved_date': fields.function(
|
||||||
|
_get_approved_date, string="Approved Date", type='datetime'),
|
||||||
|
'approved_uid': fields.function(
|
||||||
|
_get_approved_uid, string="Approved By", type='many2one',
|
||||||
|
obj='res.users'),
|
||||||
'approval_required': fields.boolean("Require approval"),
|
'approval_required': fields.boolean("Require approval"),
|
||||||
'is_parent_approval_required': fields.function(
|
'is_parent_approval_required': fields.function(
|
||||||
_is_parent_approval_required, string="parent approval", type='boolean'),
|
_is_parent_approval_required, string="parent approval",
|
||||||
|
type='boolean'),
|
||||||
'approver_gid': fields.many2one("res.groups", "Approver group"),
|
'approver_gid': fields.many2one("res.groups", "Approver group"),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user