Permalink
Browse files

[IMP] base: Add support for private addresses

Purpose
=======

Add the possibility to create private addresses, only accessible for a subset
of users.

Specification
=============

- Add a new 'Private' partner type
- Add a res.groups in base 'Access to Private Addresses'
- Add ir.rules for the following behavior:
    - Every employees/internal users can read non-private addresses
    - Only users in group_private_addresses can access private addresses
- Add in base a simplified form view for private addresses
- A HR Officer is automatically granted in group_private_addresses
- Use the simplified form view to open the address_home_id form on employees
  • Loading branch information...
tivisse committed May 4, 2018
1 parent ec92934 commit 2f15a5fa647d55df36c9019df467802a3aa9b4e3
@@ -4,6 +4,7 @@
<record id="group_hr_user" model="res.groups">
<field name="name">Officer</field>
<field name="category_id" ref="base.module_category_human_resources"/>
<field name="implied_ids" eval="[(4, ref('base.group_private_addresses'))]"/>
<field name="comment">The user will be able to approve document created by employees.</field>
</record>
@@ -86,7 +86,10 @@
</group>
<group string="Contact Information">
<field name="address_home_id"
context="{'show_address': 1}"
context="{
'show_address': 1,
'default_type': 'private',
'form_view_ref': 'base.res_partner_view_form_private'}"
options='{"always_reload": True, "highlight_first_line": True}'/>
<field name="is_address_home_a_company" invisible="1"/>
<div class="text-warning" groups="hr.group_hr_user"
@@ -177,7 +177,8 @@ def _default_company(self):
[('contact', 'Contact'),
('invoice', 'Invoice address'),
('delivery', 'Shipping address'),
('other', 'Other address')], string='Address Type',
('other', 'Other address'),
("private", "Private Address")], string='Address Type',
default='contact',
help="Used to select automatically the right address according to the context in sales and purchases documents.")
street = fields.Char()
@@ -231,6 +231,10 @@ def _get_company(self):
'Contact Creation', compute='_compute_groups_id', inverse='_inverse_groups_id',
group_xml_id='base.group_partner_manager')
has_group_private_addresses = fields.Boolean(
'Access to Private Addresses', compute='_compute_groups_id', inverse='_inverse_groups_id',
group_xml_id='base.group_private_addresses')
_sql_constraints = [
('login_key', 'UNIQUE (login)', 'You can not have two users with the same login !')
]
@@ -49,6 +49,9 @@
<field name="groups_id" eval="[(4,ref('base.group_partner_manager'))]"/>
</record>
<record id="group_private_addresses" model="res.groups">
<field name="name">Access to Private Addresses</field>
</record>
<!--
A group dedicated to the portal users, making groups
restrictions more convenient.
@@ -30,6 +30,37 @@
<field name="perm_write" eval="False"/>
</record>
<!-- Security restriction for private addresses -->
<record id="res_partner_rule_private_employee" model="ir.rule">
<field name="name">res.partner.rule.private.employee</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="domain_force">
[('type', '!=', 'private')]
</field>
<field name="groups" eval="[
(4, ref('base.group_user')),
]"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
<field name="perm_unlink" eval="False"/>
</record>
<!-- Relex previous rule for group_private_addresses -->
<record id="res_partner_rule_private_group" model="ir.rule">
<field name="name">res.partner.rule.private.group</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="domain_force">
[('type', '=', 'private')]
</field>
<field name="groups" eval="[
(4, ref('base.group_private_addresses'))
]"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
<field name="perm_unlink" eval="False"/>
</record>
<record model="ir.rule" id="ir_default_user_rule">
<field name="name">Defaults: alter personal defaults</field>
<field name="model_id" ref="model_ir_default"/>
@@ -391,6 +391,50 @@
</field>
</record>
<!-- Special restricted view for private address, with limited "named" info that
can be traced back to the employee -->
<record id="res_partner_view_form_private" model="ir.ui.view">
<field name="name">res.partner.view.form.private</field>
<field name="model">res.partner</field>
<field name="priority" eval="300"/>
<field name="arch" type="xml">
<form string="Private Address Form">
<sheet>
<field name="type" invisible="1"/>
<label for="name" class="oe_editonly"/>
<field name="name" required="0"/>
<group>
<group>
<label for="street" string="Address"/>
<div>
<div class="o_address_format" name="div_address">
<field name="street" placeholder="Street..." class="o_address_street"/>
<field name="street2" placeholder="Street 2..." class="o_address_street"/>
<field name="city" placeholder="City" class="o_address_city"/>
<field name="state_id" class="o_address_state" placeholder="State" options='{"no_open": True}' context="{'country_id': country_id, 'zip': zip}"/>
<field name="zip" placeholder="ZIP" class="o_address_zip"/>
<field name="country_id" placeholder="Country" class="o_address_country" options='{"no_open": True, "no_create": True}'/>
</div>
</div>
</group>
<group>
<field name="phone" widget="phone"/>
<field name="mobile" widget="phone"/>
<field name="email"/>
</group>
</group>
<group string="Bank Accounts">
<field name="bank_ids">
<tree editable="bottom">
<field name="acc_number"/>
</tree>
</field>
</group>
</sheet>
</form>
</field>
</record>
<record id="view_res_partner_filter" model="ir.ui.view">
<field name="name">res.partner.select</field>
<field name="model">res.partner</field>
@@ -205,6 +205,10 @@
<div>
<field name='has_group_partner_manager' colspan="1" class="oe_inline"/>
</div>
<label for="has_group_private_addresses" colspan="3"/>
<div>
<field name="has_group_private_addresses" colspan="1" class="oe_inline"/>
</div>
</group>
</page>
<page string="Preferences">

0 comments on commit 2f15a5f

Please sign in to comment.