ajay javiya (OpenERP) has proposed merging
lp:~openerp-dev/openobject-addons/trunk-user-profile-tpa-add-coworker-aja into
lp:~openerp-dev/openobject-addons/trunk-user-profile-tpa.
Requested reviews:
Turkesh Patel (openERP) (turkesh-tinyerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-user-profile-tpa-add-coworker-aja/+merge/146560
Hello,
Add code for invite coworker from user profile.
Thank You.
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-user-profile-tpa-add-coworker-aja/+merge/146560
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-addons/trunk-user-profile-tpa.
=== modified file 'user_profile/__init__.py'
--- user_profile/__init__.py 2013-01-30 10:18:53 +0000
+++ user_profile/__init__.py 2013-02-05 06:10:28 +0000
@@ -19,5 +19,5 @@
#
##############################################################################
-
+import wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== modified file 'user_profile/__openerp__.py'
--- user_profile/__openerp__.py 2013-01-30 10:18:53 +0000
+++ user_profile/__openerp__.py 2013-02-05 06:10:28 +0000
@@ -29,7 +29,8 @@
""",
'version': '1.0',
- 'depends': ['mail'],
+ 'depends': ['mail','portal'],
+ 'data': ['wizard/add_coworker_view.xml'],
'css': ['static/src/css/*.css'],
'js': ['static/src/js/*.js'],
'qweb': ['static/src/xml/*.xml'],
=== modified file 'user_profile/static/src/js/user_profile.js'
--- user_profile/static/src/js/user_profile.js 2013-01-31 11:31:53 +0000
+++ user_profile/static/src/js/user_profile.js 2013-02-05 06:10:28 +0000
@@ -19,6 +19,7 @@
bind_events: function() {
var self = this;
this.$('.oe_add_link').on('click', 'a', { uid: this.session.uid}, self.open_user_profile_view);
+ this.$el.on('click', '.oe_coworker', { uid: this.session.uid}, self.open_co_workers_view);
this.$('.oe_suggest_groups').on('click','button',{ uid: this.session.uid,data:this}, self.join_group);
this.$('.oe_suggest_peoples').on('click','button',{ uid: this.session.uid,data:this}, self.follow_peoples);
},
@@ -89,6 +90,20 @@
});
return false;
},
+ open_co_workers_view: function(event){
+ var self = this;
+ var action = {
+ name : 'Invite Coworkers',
+ type: 'ir.actions.act_window',
+ res_model: 'invite.coworkers.wizard',
+ view_mode: 'form',
+ view_type: 'form',
+ views: [[false, 'form']],
+ target: 'new',
+ };
+ var action_manager = new session.web.ActionManager(this);
+ action_manager.do_action(action);
+ },
get_suggested_people: function() {
var self = this;
var show = 0;
=== modified file 'user_profile/static/src/xml/user_profile.xml'
--- user_profile/static/src/xml/user_profile.xml 2013-01-31 08:52:48 +0000
+++ user_profile/static/src/xml/user_profile.xml 2013-02-05 06:10:28 +0000
@@ -7,6 +7,9 @@
<p class="oe_user_display">Complete Your Profile</p>
<div class="oe_profile_complete"/>
<ul class="oe_add_link"/>
+ <div class="oe_add_coworkers">
+ <a class="oe_coworker">Add CoWorkers</a>
+ </div>
</div>
<div class="oe_user_profile_group">
<p class="oe_user_display">Suggested Groups</p>
=== added directory 'user_profile/wizard'
=== added file 'user_profile/wizard/__init__.py'
--- user_profile/wizard/__init__.py 1970-01-01 00:00:00 +0000
+++ user_profile/wizard/__init__.py 2013-02-05 06:10:28 +0000
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2010-2013 OpenERP s.a. (<http://openerp.com>).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+import add_coworker
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== added file 'user_profile/wizard/add_coworker.py'
--- user_profile/wizard/add_coworker.py 1970-01-01 00:00:00 +0000
+++ user_profile/wizard/add_coworker.py 2013-02-05 06:10:28 +0000
@@ -0,0 +1,139 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2010-2013 OpenERP s.a. (<http://openerp.com>).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from osv import osv
+from osv import fields
+from openerp.tools.translate import _
+from lxml import etree
+from openerp import SUPERUSER_ID
+WELCOME_EMAIL_SUBJECT = _("Your OpenERP account at %(company)s")
+WELCOME_EMAIL_BODY = _("""Dear %(name)s,
+
+Your login account data is:
+Database: %(db)s
+Username: %(login)s
+
+In order to complete the signin process, click on the following url:
+%(url)s
+
+--
+OpenERP - Open Source Business Applications
+http://www.openerp.com
+""")
+
+class invite_coworkers_wizard(osv.TransientModel):
+ _name = 'invite.coworkers.wizard'
+ _description = 'Invite Coworker Wizard'
+
+ def _get_alias_domain(self, cr, uid, ids, context=None):
+ ir_config_parameter = self.pool.get("ir.config_parameter")
+ domain = ir_config_parameter.get_param(cr, uid, "mail.catchall.domain", context=context)
+ return domain or ""
+
+ def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False):
+ res = super(invite_coworkers_wizard, self).fields_view_get(cr, user, view_id, view_type, context, toolbar)
+ doc = etree.XML(res['arch'])
+ doc = etree.XML(res['arch'])
+ for fields in res['fields']:
+ nodes = doc.xpath("//label[@for='"+fields+"']")
+ for node in nodes:
+ node.set('string', self._get_alias_domain(cr, user, context))
+ res['arch'] = etree.tostring(doc)
+ return res
+
+ def default_get(self, cr, uid, fields, context=None):
+ result = super(invite_coworkers_wizard, self).default_get(cr, uid, fields, context=context)
+ if 'name' in fields:
+ message = _('<div>You have been invited to follow OpenERP.</div>')
+ result['name'] = message
+ return result
+
+ def invite_coworker(self, cr, uid, ids, context=None):
+ coworkers=['coworker1','coworker2','coworker3','coworker4','coworker5','coworker6']
+ invite_wizard=self.browse(cr, SUPERUSER_ID, ids, context)[0]
+ res_users = self.pool.get('res.users')
+ for coworker in coworkers:
+ if invite_wizard[coworker]:
+ user = self._retrieve_user(cr, SUPERUSER_ID, invite_wizard[coworker], context)
+ if not user:
+ user = self._create_user(cr, SUPERUSER_ID, invite_wizard[coworker], context)
+ user.partner_id.signup_prepare()
+ self._send_email(cr, uid, user, context)
+
+ def _retrieve_user(self, cr, uid, invite_wizard, context=None):
+ res_users = self.pool.get('res.users')
+ domain = [('name', '=', invite_wizard)]
+ user_ids = res_users.search(cr, uid, domain)
+ return user_ids and res_users.browse(cr, uid, user_ids[0], context) or False
+
+ def _create_user(self, cr, uid, invite_wizard, context=None):
+ res_users = self.pool.get('res.users')
+ create_context = dict(context or {}, noshortcut=True)
+ if invite_wizard:
+ values = {
+ 'name': invite_wizard,
+ 'email':invite_wizard+'@'+self._get_alias_domain(cr, uid, context),
+ 'login': invite_wizard,
+ 'groups_id': [(6, 0, [])],
+ 'share': True,
+ }
+ user_id = res_users.create(cr, uid, values, context=create_context)
+ return res_users.browse(cr, uid, user_id, context)
+ return False
+
+ def _send_email(self, cr, uid, user, context=None):
+ this_context = context
+ this_user = self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid, context)
+ if not this_user.email:
+ raise osv.except_osv(_('Email required'),
+ _('You must have an email address in your User Preferences to send emails.'))
+
+ context = dict(this_context or {}, lang=user.lang)
+ data = {
+ 'company': this_user.company_id.name,
+ 'db': cr.dbname,
+ 'name': user.name,
+ 'login': user.login,
+ 'url': user.signup_url,
+ }
+ mail_mail = self.pool.get('mail.mail')
+ mail_values = {
+ 'email_from': this_user.email,
+ 'email_to': user.email,
+ 'subject': _(WELCOME_EMAIL_SUBJECT) % data,
+ 'body_html': '<pre>%s</pre>' % (_(WELCOME_EMAIL_BODY) % data),
+ 'state': 'outgoing',
+ 'type': 'email',
+ }
+ mail_id = mail_mail.create(cr, uid, mail_values, context=this_context)
+ return mail_mail.send(cr, uid, [mail_id], context=this_context)
+
+ _columns = {
+ 'name':fields.html('Message Body'),
+ 'coworker1':fields.char('Coworker', size=64),
+ 'coworker2':fields.char('Coworker', size=64),
+ 'coworker3':fields.char('Coworker', size=64),
+ 'coworker4':fields.char('Coworker', size=64),
+ 'coworker5':fields.char('Coworker', size=64),
+ 'coworker6':fields.char('Coworker', size=64),
+ }
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== added file 'user_profile/wizard/add_coworker_view.xml'
--- user_profile/wizard/add_coworker_view.xml 1970-01-01 00:00:00 +0000
+++ user_profile/wizard/add_coworker_view.xml 2013-02-05 06:10:28 +0000
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+ <data>
+ <record model="ir.ui.view" id="wizard_invite_coworker_form">
+ <field name="name">Invite Coworkers</field>
+ <field name="model">invite.coworkers.wizard</field>
+ <field name="arch" type="xml">
+ <form string="Invite Coworkers" version="7.0">
+ <group string="coworker" col="4" colspan="4">
+ <field name="coworker1" nolabel="1"/>
+ <label for="coworker1"/>
+ <field name="coworker2" nolabel="1"/>
+ <label for="coworker2"/>
+ <field name="coworker3" nolabel="1"/>
+ <label for="coworker3"/>
+ <field name="coworker4" nolabel="1"/>
+ <label for="coworker4"/>
+ <field name="coworker5" nolabel="1"/>
+ <label for="coworker5"/>
+ <field name="coworker6" nolabel="1"/>
+ <label for="coworker6"/>
+ </group>
+ <group>
+ <field name="name"/>
+ </group>
+ <footer>
+ <button string="Invite" name="invite_coworker" type="object" class="oe_highlight" />
+ or
+ <button string="Cancel" class="oe_link" special="cancel" />
+ </footer>
+ </form>
+ </field>
+ </record>
+ </data>
+</openerp>
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp