From 1b25a3404613e914db4ad1caf5fc8cc1b822a74c Mon Sep 17 00:00:00 2001 From: dszklarz Date: Fri, 16 Sep 2022 08:31:06 +0200 Subject: [PATCH 1/3] [IMP] add license key to estate and estate_account modules to suppres warning --- estate/__manifest__.py | 1 + estate_account/__manifest__.py | 1 + 2 files changed, 2 insertions(+) diff --git a/estate/__manifest__.py b/estate/__manifest__.py index 34e8d90..afed825 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -3,6 +3,7 @@ { "name": "Real Estate", + "license": "LGPL-3", "depends": [ "base", "web", diff --git a/estate_account/__manifest__.py b/estate_account/__manifest__.py index 51af02a..e32bb21 100644 --- a/estate_account/__manifest__.py +++ b/estate_account/__manifest__.py @@ -2,6 +2,7 @@ { "name": "Real Estate Accounting", + "license": "LGPL-3", "depends": [ "estate", "account", From 066af2a735adc4574e16e854a3cd1797edcb8a82 Mon Sep 17 00:00:00 2001 From: dszklarz Date: Fri, 16 Sep 2022 16:39:03 +0200 Subject: [PATCH 2/3] save, ch B not done yet --- estate/__manifest__.py | 2 ++ estate/models/estate_property.py | 8 ++++- estate/security/ir.model.access.csv | 16 +++++++--- estate/security/security.xml | 40 ++++++++++++++++++++++++ estate/views/estate_property_views.xml | 5 ++- estate_account/models/estate_property.py | 3 ++ 6 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 estate/security/security.xml diff --git a/estate/__manifest__.py b/estate/__manifest__.py index afed825..928e637 100644 --- a/estate/__manifest__.py +++ b/estate/__manifest__.py @@ -4,12 +4,14 @@ { "name": "Real Estate", "license": "LGPL-3", + "category": "Real Estate", "depends": [ "base", "web", ], "data": [ "security/ir.model.access.csv", + "security/security.xml", "views/estate_property_offer_views.xml", "views/estate_property_tag_views.xml", "views/estate_property_type_views.xml", diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index 21f0df1..c91eecc 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -14,6 +14,7 @@ class EstateProperty(models.Model): _name = "estate.property" _description = "Real Estate Property" _order = "id desc" + _check_company_auto = True _sql_constraints = [ ("check_expected_price", "CHECK(expected_price > 0)", "The expected price must be strictly positive"), ("check_selling_price", "CHECK(selling_price >= 0)", "The offer price must be positive"), @@ -67,7 +68,7 @@ def _default_date_availability(self): # Relational property_type_id = fields.Many2one("estate.property.type", string="Property Type") - user_id = fields.Many2one("res.users", string="Salesman", default=lambda self: self.env.user) + user_id = fields.Many2one("res.users", string="Salesman") buyer_id = fields.Many2one("res.partner", string="Buyer", readonly=True, copy=False) tag_ids = fields.Many2many("estate.property.tag", string="Tags") offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers") @@ -80,6 +81,11 @@ def _default_date_availability(self): ) best_price = fields.Float("Best Offer", compute="_compute_best_price", help="Best offer received") + # Multi-Company + company_id = fields.Many2one( + 'res.company', required=True, default = lambda self: self.env.company + ) + # ---------------------------------------- Compute methods ------------------------------------ @api.depends("living_area", "garden_area") diff --git a/estate/security/ir.model.access.csv b/estate/security/ir.model.access.csv index a73754c..e0dec1d 100644 --- a/estate/security/ir.model.access.csv +++ b/estate/security/ir.model.access.csv @@ -1,5 +1,13 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_estate_property,access.estate.property,estate.model_estate_property,base.group_user,1,1,1,1 -access_estate_property_offer,access.estate.property.offer,estate.model_estate_property_offer,base.group_user,1,1,1,1 -access_estate_property_tag,access.estate.property.tag,estate.model_estate_property_tag,base.group_user,1,1,1,1 -access_estate_property_type,access.estate.property.type,estate.model_estate_property_type,base.group_user,1,1,1,1 +access_estate_property,access_estate_property,model_estate_property,base.group_user,0,0,0,0 +access_estate_property_type,access_estate_property_type,model_estate_property_type,base.group_user,0,0,0,0 +access_estate_property_tag,access_estate_property_tag,model_estate_property_tag,base.group_user,0,0,0,0 +access_estate_property_offer,access_estate_property_offer,model_estate_property_offer,base.group_user,0,0,0,0 +access_estate_property_manager,access.estate.property,estate.model_estate_property,estate.estate_group_manager,1,1,1,1 +access_estate_property_offer_manager,access.estate.property.offer,estate.model_estate_property_offer,estate.estate_group_manager,1,1,1,1 +access_estate_property_tag_manager,access.estate.property.tag,estate.model_estate_property_tag,estate.estate_group_manager,1,1,1,1 +access_estate_property_type_manager,access.estate.property.type,estate.model_estate_property_type,estate.estate_group_manager,1,1,1,1 +access_estate_property_agent,access.estate.property,estate.model_estate_property,estate.estate_group_user,1,1,1,0 +access_estate_property_offer_agent,access.estate.property.offer,estate.model_estate_property_offer,estate.estate_group_user,1,0,0,0 +access_estate_property_tag_agent,access.estate.property.tag,estate.model_estate_property_tag,estate.estate_group_user,1,0,0,0 +access_estate_property_type_agent,access.estate.property.type,estate.model_estate_property_type,estate.estate_group_user,1,0,0,0 diff --git a/estate/security/security.xml b/estate/security/security.xml new file mode 100644 index 0000000..1af7f09 --- /dev/null +++ b/estate/security/security.xml @@ -0,0 +1,40 @@ + + + + + Agent + + + + + Manager + + + + + + limit estate agent access to own properties or unclaimed properties + + + + [ + '|', ('user_id', '=', user.id), + ('user_id', '=', False) + ] + + + + Estate manager rule + + + [(1, '=', 1)] + + + + multi company rule + + + [('company_id','in', company_ids)] + + + diff --git a/estate/views/estate_property_views.xml b/estate/views/estate_property_views.xml index 40b213c..b69f400 100644 --- a/estate/views/estate_property_views.xml +++ b/estate/views/estate_property_views.xml @@ -21,6 +21,7 @@ + @@ -48,7 +49,8 @@ - + + @@ -79,6 +81,7 @@ + diff --git a/estate_account/models/estate_property.py b/estate_account/models/estate_property.py index bce5ecc..e921db6 100644 --- a/estate_account/models/estate_property.py +++ b/estate_account/models/estate_property.py @@ -17,6 +17,9 @@ def action_sold(self): # Another way to get the journal: # journal = self.env["account.move"].with_context(default_move_type="out_invoice")._get_default_journal() for prop in self: + if not self.env['estate.property'].check_access_rights('write') or not prop.check_access_rule('write'): + return res + print(" reached ".center(100, '=')) self.env["account.move"].create( { "partner_id": prop.buyer_id.id, From 7d40ba51e57f308fc8cf21d242e9bac4333c96b9 Mon Sep 17 00:00:00 2001 From: dszklarz Date: Mon, 19 Sep 2022 09:26:58 +0200 Subject: [PATCH 3/3] [IMP] Real Estate: add security and visibility changes restrict estate_agent access and give access to all to managers don't show settings menu to agents, only to managers setup multi-company --- estate/models/estate_property.py | 2 +- estate/security/security.xml | 17 +++-------------- estate/views/estate_menus.xml | 2 +- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/estate/models/estate_property.py b/estate/models/estate_property.py index c91eecc..12e15d2 100644 --- a/estate/models/estate_property.py +++ b/estate/models/estate_property.py @@ -83,7 +83,7 @@ def _default_date_availability(self): # Multi-Company company_id = fields.Many2one( - 'res.company', required=True, default = lambda self: self.env.company + 'res.company', required=True, default=lambda self: self.env.company ) # ---------------------------------------- Compute methods ------------------------------------ diff --git a/estate/security/security.xml b/estate/security/security.xml index 1af7f09..9155047 100644 --- a/estate/security/security.xml +++ b/estate/security/security.xml @@ -15,26 +15,15 @@ limit estate agent access to own properties or unclaimed properties - - - [ - '|', ('user_id', '=', user.id), - ('user_id', '=', False) - ] + + [('company_id', 'in', company_ids), '|', ('user_id', '=', False), ('user_id', '=', user.id)] Estate manager rule - + [(1, '=', 1)] - - multi company rule - - - [('company_id','in', company_ids)] - - diff --git a/estate/views/estate_menus.xml b/estate/views/estate_menus.xml index 4c931bf..1f46615 100644 --- a/estate/views/estate_menus.xml +++ b/estate/views/estate_menus.xml @@ -5,7 +5,7 @@ - +