fix act_draft and minor ui fix

This commit is contained in:
Giorgio Borelli 2014-11-12 10:06:22 +01:00 committed by Loïc Faure-Lacroix
parent 858afe6390
commit 663ab547e3
5 changed files with 62 additions and 73 deletions

View File

@ -49,6 +49,7 @@ Scenario
'data': [
'document_page_wkfl.xml',
'document_page_view.xml',
'data/email_template.xml',
'security/document_page_security.xml',
'security/ir.model.access.csv',
],

View File

@ -0,0 +1,31 @@
<?xml version="1.0"?>
<openerp>
<!-- Allow user to make upgrade-proof customizations to email template -->
<data noupdate="1">
<record id="email_template_new_draft_need_approval"
model="email.template">
<field name="name">Automated new draft need approval Notification Mail</field>
<field name="email_from">${object.create_uid.company_id.email or 'noreply@localhost.com'}</field>
<field name="subject">New version of "${object.page_id.name}" to approve</field>
<field name="email_to">${object.get_approvers_email}</field>
<field name="model_id" ref="model_document_page_history"/>
<field name="auto_delete" eval="True"/>
<field name="lang">${object.create_uid.partner_id.lang}</field>
<field name="body_html"><![CDATA[
<p>Hello,</p>
<p>The page "${object.page_id.name}" has been modified and need your approval.</p>
<p>You can review the new version here : <a href="${object.get_page_url}">${object.get_page_url}</a></p>
<p>Have a great day.<br/>
--<br/>
OpenERP</p>]]>
</field>
</record>
</data>
</openerp>

View File

@ -29,19 +29,19 @@ class document_page_history_wkfl(models.Model):
def page_approval_draft(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state': 'draft'})
import pdb; pdb.set_trace( )
template_id = self.pool.get('ir.model.data').get_object_reference(
cr, uid,
'document_page_approval',
'email_template_new_draft_need_approval')[1]
for page in self:
for page in self.browse(cr, uid, ids, context=context):
if page.is_parent_approval_required:
self.pool.get('email.template').send_mail(
cr,
uid,
template_id,
page.id,
force_send=True
)
return True
def page_approval_approved(self, cr, uid, ids, context=None):
@ -92,41 +92,39 @@ class document_page_history_wkfl(models.Model):
for page in self:
emails = ''
guids = self.get_approvers_guids()
import pdb; pdb.set_trace( )
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)
uids = [i.id for i in self.env['res.users'].search([
('groups_id', 'in', guids[page.id])
])]
users = self.env['res.users'].browse(uids)
for user in users:
if user.email:
emails += user.email
emails += ','
else:
empl_id = self.pool.get('hr.employee').search(
cr, uid, [('login', '=', user.login)])[0]
empl = self.pool.get('hr.employee').browse(
cr, uid, empl_id, context=context)
empl = self.env['hr.employee'].search([
('login', '=', user.login)
])
if empl.work_email:
emails += empl.work_email
emails += ','
emails = emails[:-1]
page.get_approvers_email = emails
page.get_approvers_email = emails[:-1]
def _get_page_url(self):
res = {}
for page in self:
import pdb; pdb.set_trace( )
base_url = self.env['ir.config_parameter'].get_param(
cr, uid, 'web.base.url', default='http://localhost:8069',
context=context)
'web.base.url',
default='http://localhost:8069'
)
res[id] = base_url + (
'/#db=%s&id=%s&view_type=form&model=document.page.history' %
(cr.dbname, id))
return res
page.get_page_url = (
'{}/#db={}&id={}&view_type=form&'
'model=document.page.history').format(
base_url,
self.env.cr.dbname,
page.id
)
state = fields.Selection(
[('draft', 'Draft'), ('approved', 'Approved')],

View File

@ -36,22 +36,18 @@
<field name="arch" type="xml">
<field name="display_content"
position="before">
<group>
<!-- TODO display only to content" -->
<field name="approved_date"
class="oe_view_only" />
<field name="approved_uid"
class="oe_view_only" />
<group class="oe_read_only"
attrs="{'invisible':[('type','!=','content')]}">
<field name="approved_date" />
<field name="approved_uid" />
</group>
</field>
<field name="parent_id" position="after">
<group>
<field name="approval_required"
attrs="{'invisible':[('type','=','content')]}"/>
<field name="approver_gid"
attrs="{'invisible':['|',('type','=','content'),
('approval_required','!=', True)], 'required':[('approval_required','=', True)]}"/>
</group>
<field name="approval_required"
attrs="{'invisible':[('type','=','content')]}"/>
<field name="approver_gid"
attrs="{'invisible':['|',('type','=','content'),
('approval_required','!=', True)], 'required':[('approval_required','=', True)]}"/>
</field>
</field>
</record>

View File

@ -40,41 +40,4 @@
</data>
<!-- Allow user to make upgrade-proof customizations to email template -->
<data noupdate="1">
<record id="email_template_new_draft_need_approval"
model="email.template">
<field name="name">Automated new draft need approval Notification Mail</field>
<field name="email_from">${object.create_uid.company_id.email or 'noreply@localhost.com'}</field>
<field name="subject">New version of "${object.page_id.name}" to approve</field>
<field name="email_to">${object.get_approvers_email}</field>
<field name="model_id" ref="model_document_page_history"/>
<field name="auto_delete" eval="True"/>
<field name="lang">${object.create_uid.partner_id.lang}</field>
<field name="body_html"><![CDATA[
<p>Hello,</p>
<p>The page "${object.page_id.name}" has been modified and need your approval.</p>
<p>You can review the new version here : <a href="${object.get_page_url}">${object.get_page_url}</a></p>
<p>Have a great day.<br/>
--<br/>
OpenERP</p>]]>
</field>
<field name="body_text"><![CDATA[
Hello,
The page "${object.page_id.name}" has been modified and need your approval.
You can review the new version here: ${object.get_page_url}
Have a great day.
--
OpenERP]]></field>
</record>
</data>
</openerp>