diff --git a/bemade_sethy_configuration/__manifest__.py b/bemade_sethy_configuration/__manifest__.py index 6dbd6c9..c133121 100644 --- a/bemade_sethy_configuration/__manifest__.py +++ b/bemade_sethy_configuration/__manifest__.py @@ -27,6 +27,7 @@ 'data': [ # Reference to XML, CSV, and other data files 'data/membership_category_data.xml', + 'data/ir_cron_data.xml', 'data/product_template_data.xml', 'data/partner_category_data.xml', 'data/partner_relation_type_data.xml', @@ -36,7 +37,7 @@ 'views/property_view.xml', 'views/res_partner_views.xml', 'security/ir.model.access.csv', - + 'wizard/transfer_property_wizard_views.xml' ], 'demo': [ # Reference to demo data files diff --git a/bemade_sethy_configuration/data/ir_cron_data.xml b/bemade_sethy_configuration/data/ir_cron_data.xml new file mode 100644 index 0000000..330150b --- /dev/null +++ b/bemade_sethy_configuration/data/ir_cron_data.xml @@ -0,0 +1,20 @@ + + + + + Sethy: Update relation + + code + partners = env['res.partner'].search([]) +for rec in partners: + rec._compute_relation_count() + + + 12 + months + -1 + + + + + \ No newline at end of file diff --git a/bemade_sethy_configuration/models/res_partner.py b/bemade_sethy_configuration/models/res_partner.py index d2a2078..cfabf3e 100644 --- a/bemade_sethy_configuration/models/res_partner.py +++ b/bemade_sethy_configuration/models/res_partner.py @@ -2,27 +2,38 @@ from odoo import api, fields, models, _ from odoo.addons.website.models import ir_http +import logging +_logger = logging.getLogger(__name__) class ResPartner(models.Model): _inherit = 'res.partner' @api.model - def _property_category_id(self): + def _tag_property(self): return self.env.ref('bemade_sethy_configuration.partner_tag_property', raise_if_not_found=False) - surface = fields.Float(string='Surface (ha)') # terrain - lot_number = fields.Text(string='Lot Number') # terrain + @api.model + def _tag_owner(self): + return self.env.ref('bemade_sethy_configuration.partner_tag_owner', raise_if_not_found=False) - ref_project = fields.Text(string='Project No') # proprio - intent_signing = fields.Boolean(string='Intent to sign') # proprio - cyberimpact = fields.Boolean(string='Cyberimpact') # proprio - specification_date = fields.Date(string='Specification date') # proprio - crm_stage_activity = fields.Text(string='Activity Stage') # proprio + @api.model + def _relation_owner_property(self): + return self.env.ref('bemade_sethy_configuration.partner_relation_property', raise_if_not_found=False) - property_count = fields.Integer(string='Property count', compute='_compute_property_count', store=True) - is_owner = fields.Boolean(string='Is Owner', compute='_compute_property_count', store=True) + # Add new fields to the res.partner model for property management + surface = fields.Float(string='Surface (ha)') + lot_number = fields.Text(string='Lot Number') + # Add new fields to the res.partner model for owner/member management + ref_project = fields.Text(string='Project No') + intent_signing = fields.Boolean(string='Intent to sign') + cyberimpact = fields.Boolean(string='Cyberimpact') + specification_date = fields.Date(string='Specification date') + crm_stage_activity = fields.Text(string='Activity Stage') + company_use = fields.Text(string='Company related') + + # Add new fields to the res.partner model for member management sethy_first_date = fields.Date(string='First membership date') # member sethy_last_date = fields.Date(string='Last membership date') # member sethy_renew_date = fields.Date(string='Next renew date date') # member @@ -32,7 +43,6 @@ class ResPartner(models.Model): is_property = fields.Boolean( string='Is Property', - default=False, compute='_compute_is_property', inverse='_inverse_is_property', store=True @@ -46,60 +56,149 @@ class ResPartner(models.Model): ('4', 'High')], string='Interest Level') # proprio - company_use = fields.Text(string='Company related') # proprio - + # Filtered fields relation_all_ids for owner relation_owner_ids = fields.One2many( "res.partner.relation.all", - compute="_compute_owner_ids", - string="Owner ids" + compute="_compute_relation_property_owner", + string="Owner ids", + compute_sudo=True, ) + # Filtered fields relation_all_ids for property relation_property_ids = fields.One2many( "res.partner.relation.all", - compute="_compute_property_ids", - string="Property ids" + compute="_compute_relation_property_owner", + string="Property ids", + compute_sudo=True, ) + # Add new fields to the res.partner model for owner management + property_count = fields.Integer( + string='Property count', + compute='_compute_property_count', + store=True, + compute_sudo=True + ) + + is_owner = fields.Boolean( + string='Is Owner', + compute='_compute_owner', + store=True, + compute_sudo=True, + ) + + @api.depends('relation_all_ids') + def _compute_owner(self): + #owner_tag = self._tag_owner() + owner_tag = self.env.ref('bemade_sethy_configuration.partner_tag_owner', raise_if_not_found=False) + for record in self: + record.is_owner = record.relation_count > 0 + if record.is_owner: + record.category_id |= owner_tag + else: + record.category_id -= owner_tag + + # this is an hugly fix because @api depends doesn't work on new function so hacking it here + @api.depends("relation_all_ids") + def _compute_relation_count(self): + super()._compute_relation_count() + #owner_tag = self._tag_owner() + owner_tag = self.env.ref('bemade_sethy_configuration.partner_tag_owner', raise_if_not_found=False) + for record in self: + for line in record.relation_all_ids: + if line.active and line.type_id == owner_tag: + record.relation_count += 1 + record.is_owner = record.relation_count > 0 and not record.is_property + if record.is_owner: + record.category_id |= owner_tag + else: + record.category_id -= owner_tag + @api.depends('category_id') def _compute_is_property(self): + default_is_property = self._context.get('default_is_property', None) + #property_tag = self._tag_property() property_tag = self.env.ref('bemade_sethy_configuration.partner_tag_property', raise_if_not_found=False) for partner in self: # Check if the property tag exists. If it doesn't, set is_property to False. # Because module installation order is not guaranteed, the tag may not exist yet when this method is called. # This is due to store=True on the is_property field. - if property_tag is None: - partner.is_property = False + if default_is_property is not None and not self.id: + partner.is_property = default_is_property else: - partner.is_property = property_tag and property_tag in partner.category_id + if property_tag is None: + partner.is_property = False + else: + partner.is_property = property_tag and property_tag in partner.category_id + def _inverse_is_property(self): + #property_tag = self._tag_property() property_tag = self.env.ref('bemade_sethy_configuration.partner_tag_property', raise_if_not_found=False) - for partner in self: - if partner.is_property and property_tag not in partner.category_id and property_tag: - partner.category_id |= property_tag - elif not partner.is_property and property_tag in partner.category_id: - partner.category_id -= property_tag + if property_tag is not None: + for partner in self: + if partner.is_property and property_tag not in partner.category_id and property_tag: + partner.category_id |= property_tag + elif not partner.is_property and property_tag in partner.category_id: + partner.category_id -= property_tag - @api.depends('relation_property_ids') + @api.depends("relation_all_ids") def _compute_property_count(self): for record in self: - record.property_count = len(record.relation_property_ids) + #owner_tag = self._tag_owner() + owner_tag = self.env.ref('bemade_sethy_configuration.partner_tag_owner', raise_if_not_found=False) + record.property_count = len(record._get_owners()) record.is_owner = record.property_count > 0 + if owner_tag is not None: + if record.is_owner: + record.category_id |= owner_tag + else: + record.category_id -= owner_tag - @api.depends('relation_all_ids') - def _compute_owner_ids(self): + @api.depends( + 'relation_all_ids', + 'relation_all_ids.type_id', + 'relation_all_ids.date_end', + 'relation_all_ids.this_partner_id', + 'relation_all_ids.other_partner_id', + 'relation_all_ids.is_inverse' + ) + def _compute_relation_property_owner(self): for record in self: - record.relation_owner_ids = record.relation_all_ids.filtered( - lambda line: ( - line.type_id.name == 'Owner' and not line.is_inverse) - ) - @api.depends('relation_all_ids') - def _compute_property_ids(self): - for record in self: - record.relation_property_ids = record.relation_all_ids.filtered( - lambda line: ( - line.type_id.name == 'Owner' and line.is_inverse) - ) + # relations = self.env['res.partner.relation.all'] + # for line in record.relation_all_ids: + # if active and is_property and is_inverse: + # relations |= line + # record.relation_property_ids = relations + record.relation_property_ids = record._get_properties() + record.relation_owner_ids = record._get_owners() + # Just for debugging below this line + type_property = self._relation_owner_property() + #type_property = self.env.ref('bemade_sethy_configuration.partner_relation_property') + for line in record.relation_all_ids: + active = line.active + is_property = line.type_id == type_property + is_inverse = line.is_inverse + _logger.info(f"This partner: {line.this_partner_id.name}") + _logger.info(f"Other partner: {line.other_partner_id.name}") + _logger.info(f"Active: {active}, Property: {is_property}, Inverse: {is_inverse}, Type: {line.type_id.name}") + + def _get_properties(self): + self.ensure_one() + #type_property = self._relation_owner_property() + type_property = self.env.ref('bemade_sethy_configuration.partner_relation_property') + return self.relation_all_ids.filtered( + lambda line: (line.type_id.id == type_property.id and line.is_inverse and line.active) + ) + + def _get_owners(self): + self.ensure_one() + #type_property = self._relation_owner_property() + type_property = self.env.ref('bemade_sethy_configuration.partner_relation_property', raise_if_not_found=False) + return self.relation_all_ids.filtered( + lambda line: (line.type_id.id == type_property.id and not line.is_inverse and line.active) + ) + @api.onchange('lot_number') def _onchange_lot_number(self): for lot in self: diff --git a/bemade_sethy_configuration/security/ir.model.access.csv b/bemade_sethy_configuration/security/ir.model.access.csv index 2c6ae27..38525a7 100644 --- a/bemade_sethy_configuration/security/ir.model.access.csv +++ b/bemade_sethy_configuration/security/ir.model.access.csv @@ -1,3 +1,2 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_create_property_wizard_salesman,"Access Create Property Wizard Salesman",model_create_property_wizard,sales_team.group_sale_salesman,1,1,1,1 -access_create_property_wizard_manager,"Access Create Property Wizard Manager",model_create_property_wizard,sales_team.group_sale_manager,1,1,1,1 \ No newline at end of file +access_transfer_property_wizard,access_transfer_property_wizard,model_transfer_property_wizard,base.group_user,1,1,1,1 diff --git a/bemade_sethy_configuration/views/property_view.xml b/bemade_sethy_configuration/views/property_view.xml index a0d34ee..e550001 100644 --- a/bemade_sethy_configuration/views/property_view.xml +++ b/bemade_sethy_configuration/views/property_view.xml @@ -18,6 +18,22 @@ + + res.partner.kanban.property + res.partner + + + + + + + + + + + + + Properties res.partner - tree,form + kanban,tree,form [('is_property','=',True)] - {'default_is_property': True} + {'default_is_property': True, 'default_is_company': True} - - Add Property - create.property.wizard + + Open Partner + ir.actions.act_window + res.partner + form + current + + + + + Transfer Property + ir.actions.act_window + transfer.property.wizard form new @@ -13,17 +23,44 @@ res.partner + +
+
+
+ - + - - - + + is_property == True + + + + + + + + not is_company or is_property + + + + is_company or is_property + + + + + + is_property == True + + @@ -65,41 +106,41 @@ - + - - - + + + - - + + + -