diff options
| author | RomainLibert <rli@odoo.com> | 2019-09-02 12:19:18 +0000 |
|---|---|---|
| committer | RomainLibert <rli@odoo.com> | 2019-09-04 07:26:43 +0000 |
| commit | 9ef2157d17badd50bbdf43334f3031f139e4c33d (patch) | |
| tree | b2b5fca0e91c0f509a85cafc0818887880f6c0e4 /addons | |
| parent | ba8bdcfaf270339c506faf7ed687bd126e530dbd (diff) | |
[IMP] lunch: location multi company
closes odoo/odoo#36331
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/lunch/controllers/main.py | 13 | ||||
| -rw-r--r-- | addons/lunch/models/lunch_location.py | 1 | ||||
| -rw-r--r-- | addons/lunch/security/lunch_security.xml | 7 | ||||
| -rw-r--r-- | addons/lunch/views/lunch_location_views.xml | 2 |
4 files changed, 20 insertions, 3 deletions
diff --git a/addons/lunch/controllers/main.py b/addons/lunch/controllers/main.py index 690c37ce14d..9be1d8aa6b3 100644 --- a/addons/lunch/controllers/main.py +++ b/addons/lunch/controllers/main.py @@ -75,7 +75,12 @@ class LunchController(http.Controller): self._check_user_impersonification(user_id) user = request.env['res.users'].browse(user_id) if user_id else request.env.user - return user.last_lunch_location_id.id + user_location = user.last_lunch_location_id + has_multi_company_access = not user_location.company_id or user_location.company_id.id in request._context.get('allowed_company_ids', request.env.company.ids) + + if not user_location or not has_multi_company_access: + return request.env['lunch.location'].search([], limit=1).id + return user_location.id def _make_infos(self, user, **kwargs): res = dict(kwargs) @@ -93,9 +98,11 @@ class LunchController(http.Controller): 'currency': {'symbol': currency.symbol, 'position': currency.position}, }) - if not user.last_lunch_location_id: - user.last_lunch_location_id = request.env['lunch.location'].search([], limit=1) user_location = user.last_lunch_location_id + has_multi_company_access = not user_location.company_id or user_location.company_id.id in request._context.get('allowed_company_ids', request.env.company.ids) + + if not user_location or not has_multi_company_access: + user.last_lunch_location_id = user_location = request.env['lunch.location'].search([], limit=1) alert_domain = expression.AND([ [('available_today', '=', True)], diff --git a/addons/lunch/models/lunch_location.py b/addons/lunch/models/lunch_location.py index af2a8509de6..5bb47de3a10 100644 --- a/addons/lunch/models/lunch_location.py +++ b/addons/lunch/models/lunch_location.py @@ -10,3 +10,4 @@ class LunchLocation(models.Model): name = fields.Char('Location Name', required=True) address = fields.Text('Address') + company_id = fields.Many2one('res.company', default=lambda self: self.env.company) diff --git a/addons/lunch/security/lunch_security.xml b/addons/lunch/security/lunch_security.xml index 6c4e0891c98..ac8d3eee796 100644 --- a/addons/lunch/security/lunch_security.xml +++ b/addons/lunch/security/lunch_security.xml @@ -78,5 +78,12 @@ <field name="global" eval="True"/> <field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field> </record> + + <record id="ir_rule_lunch_location_multi_company" model="ir.rule"> + <field name="name">Lunch location: Multi Company</field> + <field name="model_id" ref="model_lunch_location"/> + <field name="global" eval="True"/> + <field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field> + </record> </data> </odoo> diff --git a/addons/lunch/views/lunch_location_views.xml b/addons/lunch/views/lunch_location_views.xml index db9cd3af5a5..7eb13fb98cf 100644 --- a/addons/lunch/views/lunch_location_views.xml +++ b/addons/lunch/views/lunch_location_views.xml @@ -21,6 +21,7 @@ <group> <field name="name"/> <field name="address"/> + <field name="company_id" groups="base.group_multi_company"/> </group> </group> </sheet> @@ -35,6 +36,7 @@ <tree editable="bottom"> <field name="name"/> <field name="address"/> + <field name="company_id" groups="base.group_multi_company"/> </tree> </field> </record> |
