From eaf02c709fd59d1b69ee9782e7bbaa7973040d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20V=C3=A9zina?= Date: Mon, 30 Oct 2023 17:39:45 -0400 Subject: [PATCH] lot of refactor --- bemade_sethy_configuration/__manifest__.py | 15 ++++--- .../data/company_data.xml | 8 ++-- .../data/membership_category_data.xml | 11 +++++ ...ags_data.xml => partner_category_data.xml} | 0 ...ata.xml => partner_relation_type_data.xml} | 0 .../data/product_template_data.xml | 35 ++++++++++++++++ .../models/res_partner.py | 42 +++++++++++++++---- 7 files changed, 96 insertions(+), 15 deletions(-) create mode 100644 bemade_sethy_configuration/data/membership_category_data.xml rename bemade_sethy_configuration/data/{partner_tags_data.xml => partner_category_data.xml} (100%) rename bemade_sethy_configuration/data/{partner_relations_data.xml => partner_relation_type_data.xml} (100%) create mode 100644 bemade_sethy_configuration/data/product_template_data.xml diff --git a/bemade_sethy_configuration/__manifest__.py b/bemade_sethy_configuration/__manifest__.py index 7ff25fa..e8d4cb6 100644 --- a/bemade_sethy_configuration/__manifest__.py +++ b/bemade_sethy_configuration/__manifest__.py @@ -4,7 +4,7 @@ 'name': 'Bemade Sethy', 'version': '1.0', 'category': 'Specific Module Category', # Specify your module's category here - 'summary': 'This module is developed by Bemade to instantiate the Sethy Odoo', # Provide a brief summary of the module + 'summary': "This module is developed by Bemade to instantiate the Sethy's Odoo", 'author': 'Bemade', 'website': 'https://bemade.org', 'email': 'it@bemade.org', @@ -14,15 +14,20 @@ 'base', 'contacts', 'crm', + 'l10n_ca', 'membership', - 'partner_multi_relation' + 'membership_extension', + 'membership_variable_period', + 'partner_multi_relation', + 'sale_management' ], 'data': [ # Reference to XML, CSV, and other data files + 'data/membership_category_data.xml', + 'data/product_template_data.xml', + 'data/partner_category_data.xml', + 'data/partner_relation_type_data.xml', 'data/company_data.xml', - 'data/partner_tags_data.xml', - 'data/partner_relations_data.xml', - 'views/res_partner_views.xml', 'views/res_partner_relation_views.xml', 'views/membership_membership_line.xml' diff --git a/bemade_sethy_configuration/data/company_data.xml b/bemade_sethy_configuration/data/company_data.xml index da86baf..3ab45b6 100644 --- a/bemade_sethy_configuration/data/company_data.xml +++ b/bemade_sethy_configuration/data/company_data.xml @@ -1,6 +1,6 @@ - + Fondation Séthy @@ -9,10 +9,12 @@ 164, rue Cowie local 335 Granby - + J2G 3V3 - + 450 994-3173 + + diff --git a/bemade_sethy_configuration/data/membership_category_data.xml b/bemade_sethy_configuration/data/membership_category_data.xml new file mode 100644 index 0000000..0070139 --- /dev/null +++ b/bemade_sethy_configuration/data/membership_category_data.xml @@ -0,0 +1,11 @@ + + + + + Perpetual Membership + + + Annual Membership + + + diff --git a/bemade_sethy_configuration/data/partner_tags_data.xml b/bemade_sethy_configuration/data/partner_category_data.xml similarity index 100% rename from bemade_sethy_configuration/data/partner_tags_data.xml rename to bemade_sethy_configuration/data/partner_category_data.xml diff --git a/bemade_sethy_configuration/data/partner_relations_data.xml b/bemade_sethy_configuration/data/partner_relation_type_data.xml similarity index 100% rename from bemade_sethy_configuration/data/partner_relations_data.xml rename to bemade_sethy_configuration/data/partner_relation_type_data.xml diff --git a/bemade_sethy_configuration/data/product_template_data.xml b/bemade_sethy_configuration/data/product_template_data.xml new file mode 100644 index 0000000..a1a2b36 --- /dev/null +++ b/bemade_sethy_configuration/data/product_template_data.xml @@ -0,0 +1,35 @@ + + + + + + + + Perpetual Membership + + service + 2000-01-01 + 2100-01-01 + 225.0 + + + MBRAV + + + + + Annual Membership + + service + 20.0 + + + MBRAN + variable + + + + + + + diff --git a/bemade_sethy_configuration/models/res_partner.py b/bemade_sethy_configuration/models/res_partner.py index 5aa8a65..c6074ef 100644 --- a/bemade_sethy_configuration/models/res_partner.py +++ b/bemade_sethy_configuration/models/res_partner.py @@ -69,12 +69,6 @@ class ResPartner(models.Model): line.type_id.name == 'Owner' and line.is_inverse) ) - # @api.depends('is_property') - # def _forcing_company(self): - # for record in self: - # if record.is_property: - # record.is_company = True - @api.onchange('is_property') def _onchange_is_property(self): """ Set is_company to True when is_property is set to True. """ @@ -97,4 +91,38 @@ class ResPartner(models.Model): def _compute_property_count(self): for record in self: record.property_count = len(record.relation_property_ids) - record.is_owner = record.property_count > 0 \ No newline at end of file + record.is_owner = record.property_count > 0 + + def write(self, vals): + property_tag = self.env.ref('bemade_sethy_configuration.partner_tag_property', raise_if_not_found=False) + owner_tag = self.env.ref('bemade_sethy_configuration.partner_tag_owner', raise_if_not_found=False) + if 'is_property' in vals: + if vals['is_property'] and property_tag: + vals['category_id'] = [(4, property_tag.id)] + elif not vals['is_property'] and property_tag: + vals['category_id'] = [(3, property_tag.id)] + if len(self.relation_owner_ids) > 0: + vals['category_id'] = [(4, owner_tag.id)] + else: + vals['category_id'] = [(3, owner_tag.id)] + return super(ResPartner, self).write(vals) + + @api.model + def create(self, vals): + property_tag = self.env.ref('bemade_sethy_configuration.partner_tag_property', raise_if_not_found=False) + if 'is_property' in vals: + if vals['is_property'] and property_tag: + vals['category_id'] = [(4, property_tag.id)] + elif not vals['is_property'] and property_tag: + vals['category_id'] = [(3, property_tag.id)] + return super(ResPartner, self).create(vals) + + @api.onchange('is_property') + def _inverse_is_property(self): + property_tag = self.env.ref('bemade_sethy_configuration.partner_tag_property', raise_if_not_found=False) + for partner in self: + if partner.is_property: + partner.category_id |= property_tag + else: + partner.category_id -= property_tag +