[MERGE] 'Invite & Quick Create User' update. The server branch holds in res_users.create() the support of key in context, allowing to put xml_ids of user groups in the context of relational fields linking to res.users. The purpose of this modification is to quick-create users that will have the access rights related to the functional meaning of the field. For example creating an user in the 'Responsible' field of a task should add him in the group related to project management.

Example of use : <field name="user_id" string="Project Manager" context="{'default_groups_ref': ['base.group_user', 'project.group_project_manager']}"/> will add Employee (base.group_user) and Project Manager (project.group_project_manager) groups, as well as implied groups.

res_users:
- [add] added support of  key in context of default_get. It contains a list of xml_ids of user groups; those groups, if found, are added to the newly created user,
- [ref] refactored simplified (quick create) view that is now more like a contact card, with login and email required because of the login email that will be send to the user

bzr revid: tde@openerp.com-20130318120905-1w9xpoyppnj62wlj
This commit is contained in:
Thibault Delavallée 2013-03-18 13:09:05 +01:00
commit 027c419181
3 changed files with 61 additions and 49 deletions

View File

@ -269,7 +269,8 @@
<page string="Sales &amp; Purchases">
<group>
<group>
<field name="user_id"/>
<field name="user_id"
context="{'default_groups_ref': ['base.group_partner_manager']}"/>
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
</group>
<group>

View File

@ -744,6 +744,7 @@ class users_view(osv.osv):
def create(self, cr, uid, values, context=None):
self._set_reified_groups(values)
return super(users_view, self).create(cr, uid, values, context)
def write(self, cr, uid, ids, values, context=None):
@ -782,6 +783,21 @@ class users_view(osv.osv):
fields1 = (fields + ['groups_id']) if group_fields else fields
values = super(users_view, self).default_get(cr, uid, fields1, context)
self._get_reified_groups(group_fields, values)
# add "default_groups_ref" inside the context to set default value for group_id with xml values
if 'groups_id' in fields and isinstance(context.get("default_groups_ref"), list):
groups = []
ir_model_data = self.pool.get('ir.model.data')
for group_xml_id in context["default_groups_ref"]:
group_split = group_xml_id.split('.')
if len(group_split) != 2:
raise osv.except_osv(_('Invalid context value'), _('Invalid context default_groups_ref value (model.name_id) : "%s"') % group_xml_id)
try:
temp, group_id = ir_model_data.get_object_reference(cr, uid, group_split[0], group_split[1])
except ValueError:
group_id = False
groups += [group_id]
values['groups_id'] = groups
return values
def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):

View File

@ -84,48 +84,39 @@
</record>
<menuitem action="action_res_groups" id="menu_action_res_groups" parent="base.menu_users" groups="base.group_no_one"/>
<!-- res.users -->
<record id="view_users_simple_form" model="ir.ui.view">
<field name="name">res.users.simplified.form</field>
<field name="model">res.users</field>
<field name="priority">1</field>
<field name="arch" type="xml">
<form string="Contact" version="7.0">
<form string="Users" version="7.0">
<sheet>
<field name="image" widget='image' class="oe_left oe_avatar" options='{"preview_image": "image_medium", "size": [90, 90]}'/>
<div class="oe_title">
<div class="oe_edit_only">
<label for="name"/>
<field name="id" invisible="1"/>
<div class="oe_form_box_info oe_text_center" style="margin-bottom: 10px" attrs="{'invisible': [('id', '>', 0)]}">
You are creating a new user. After saving, the user will receive an invite email containing a link to set its password.
</div>
<field name="image" widget='image' class="oe_avatar oe_left" options='{"preview_image": "image_medium"}'/>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<h1><field name="name"/></h1>
<label for="login" class="oe_edit_only"/>
<h2><field name="login"/></h2>
<label for="company_id" class="oe_edit_only" groups="base.group_multi_company"/>
<field name="company_id" context="{'user_preference': 0}" groups="base.group_multi_company"/>
</div>
<h1>
<field name="name" default_focus="1" placeholder="Name" />
</h1>
<field name="category_id" widget="many2many_tags" placeholder="Tags..."/>
</div>
<group>
<group>
<label for="street" string="Address"/>
<div>
<field name="street" placeholder="Street..."/>
<field name="street2"/>
<div class="address_format">
<field name="city" placeholder="City" style="width: 40%%"/>
<field name="state_id" class="oe_no_button" placeholder="State" style="width: 37%%" options='{"no_open": True}' on_change="onchange_state(state_id)"/>
<field name="zip" placeholder="ZIP" style="width: 20%%"/>
</div>
<field name="country_id" placeholder="Country" class="oe_no_button" options='{"no_open": True}'/>
<label for="groups_id" string="Access Rights"
attrs="{'invisible': [('id', '>', 0)]}"/>
<div attrs="{'invisible': [('id', '>', 0)]}">
<field name="groups_id" readonly="1" widget="many2many_tags" style="display: inline;"/> You will be able to define additional access rights by editing the newly created user under the Settings / Users menu.
</div>
<field name="website" widget="url" placeholder="e.g. www.openerp.com"/>
</group>
<group>
<field name="phone" placeholder="e.g. +32.81.81.37.00"/>
<field name="mobile"/>
<field name="fax"/>
<field name="email" widget="email"/>
<field name="email" widget="email" required="True"/>
</group>
</group>
</sheet>
</sheet>
</form>
</field>
</record>
@ -134,8 +125,8 @@
<field name="model">res.users</field>
<field name="arch" type="xml">
<form string="Users" version="7.0">
<field name="id" invisible="1"/>
<sheet>
<field name="id" invisible="1"/>
<div class="oe_right oe_button_box">
<button string="Change Password" type="action" name="%(change_password_wizard_action)d"
help="Change the user password."/>
@ -146,17 +137,29 @@
<h1><field name="name"/></h1>
<label for="login" class="oe_edit_only"/>
<h2><field name="login"/></h2>
<label for="company_id" class="oe_edit_only" groups="base.group_multi_company"/>
<field name="company_id" context="{'user_preference': 0}" groups="base.group_multi_company"/>
</div>
<group>
<group>
<field name="company_id" context="{'user_preference': 0}"/>
</group>
<group>
<field name="active"/>
</group>
</group>
<notebook colspan="4">
<page string="Access Rights">
<group>
<field name="active"/>
</group>
<group string="Allowed Companies" groups="base.group_multi_company">
<field name="company_ids" nolabel="1" widget="many2many_tags"/>
</group>
<group col="4">
<field name="groups_id"/>
</group>
</page>
<page string="Contact">
<group>
<field name="phone" placeholder="e.g. +32.81.81.37.00"/>
<field name="mobile"/>
<field name="fax"/>
<field name="email" widget="email"/>
</group>
</page>
<page string="Preferences">
<group>
<group name="preferences">
@ -168,24 +171,16 @@
<field domain="[('usage','=','menu')]" name="menu_id" required="True"/>
</group>
</group>
<group>
<field name="email" widget="email"/>
<group string="Email preferences">
<field name="signature"/>
</group>
</page>
<page string="Access Rights">
<group string="Allowed Companies" groups="base.group_multi_company">
<field name="company_ids" nolabel="1" widget="many2many_tags"/>
</group>
<group col="4">
<field name="groups_id"/>
</group>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<record id="view_users_tree" model="ir.ui.view">
<field name="name">res.users.tree</field>
<field name="model">res.users</field>