From c48071b54dfab725c2495d14f83a0eec0d7ff037 Mon Sep 17 00:00:00 2001 From: RemiFr82 Date: Sat, 13 Jan 2024 14:10:48 +0100 Subject: [PATCH] [IMP] event_sale_balance + [I18N] --- event_sale_balance/__manifest__.py | 1 + event_sale_balance/i18n/fr.po | 49 +++++++++++ event_sale_balance/models/product_template.py | 85 ++++++++++++++++++- event_sale_balance/views/product_product.xml | 7 +- event_sale_balance/views/product_template.xml | 20 +++++ 5 files changed, 156 insertions(+), 6 deletions(-) create mode 100644 event_sale_balance/i18n/fr.po create mode 100644 event_sale_balance/views/product_template.xml diff --git a/event_sale_balance/__manifest__.py b/event_sale_balance/__manifest__.py index 006d92d..a696e66 100644 --- a/event_sale_balance/__manifest__.py +++ b/event_sale_balance/__manifest__.py @@ -28,6 +28,7 @@ ], "data": [ "views/product_product.xml", + "views/product_template.xml", ], "css": [], "images": [], diff --git a/event_sale_balance/i18n/fr.po b/event_sale_balance/i18n/fr.po new file mode 100644 index 0000000..99cdb6f --- /dev/null +++ b/event_sale_balance/i18n/fr.po @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * event_sale_balance +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e-20230613\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-01-13 13:10+0000\n" +"PO-Revision-Date: 2024-01-13 13:10+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: event_sale_balance +#: model:ir.model.fields,field_description:event_sale_balance.field_product_product__balance_variant_id +#: model:ir.model.fields,field_description:event_sale_balance.field_product_template__balance_variant_id +msgid "Balance variant" +msgstr "Article de solde" + +#. module: event_sale_balance +#: model:ir.model,name:event_sale_balance.model_event_registration +msgid "Event Registration" +msgstr "Inscription à l'événement" + +#. module: event_sale_balance +#: model:ir.model.fields,field_description:event_sale_balance.field_product_product__is_event_deposit +#: model:ir.model.fields,field_description:event_sale_balance.field_product_template__is_event_deposit +msgid "Event deposit" +msgstr "Arrhe d'évènement" + +#. module: event_sale_balance +#: model_terms:ir.ui.view,arch_db:event_sale_balance.product_template_form_view_inherit +#: model_terms:ir.ui.view,arch_db:event_sale_balance.product_variant_easy_edit_view_inherit +msgid "Event sale" +msgstr "Ventes sur évènements" + +#. module: event_sale_balance +#: model:ir.model,name:event_sale_balance.model_product_template +msgid "Product" +msgstr "Produit" + +#. module: event_sale_balance +#: model:ir.model,name:event_sale_balance.model_product_product +msgid "Product Variant" +msgstr "Variante de produit" diff --git a/event_sale_balance/models/product_template.py b/event_sale_balance/models/product_template.py index 3bfbf6b..c20b0ce 100644 --- a/event_sale_balance/models/product_template.py +++ b/event_sale_balance/models/product_template.py @@ -1,8 +1,87 @@ -from odoo import models, fields +from odoo import models, fields, api class ProductTemplate(models.Model): _inherit = "product.template" - is_event_deposit = fields.Boolean("Event deposit") - balance_variant_id = fields.Many2one("product.product", string="Balance variant") + is_event_deposit = fields.Boolean( + string="Event deposit", + compute="_compute_is_event_deposit", + inverse="_set_is_event_deposit", + search="_search_is_event_deposit", + ) + balance_variant_id = fields.Many2one( + comodel_name="product.product", + string="Balance variant", + compute="_compute_balance_variant_id", + inverse="_set_balance_variant_id", + search="_search_balance_variant_id", + ) + + @api.depends("product_variant_ids.is_event_deposit") + def _compute_is_event_deposit(self): + self.is_event_deposit = False + for template in self: + variant_count = len(template.product_variant_ids) + if variant_count == 1: + template.is_event_deposit = ( + template.product_variant_ids.is_event_deposit + ) + elif variant_count == 0: + archived_variants = template.with_context( + active_test=False + ).product_variant_ids + if len(archived_variants) == 1: + template.is_event_deposit = archived_variants.is_event_deposit + + def _search_is_event_deposit(self, operator, value): + query = self.with_context(active_test=False)._search( + [("product_variant_ids.is_event_deposit", operator, value)] + ) + return [("id", "in", query)] + + def _set_is_event_deposit(self): + variant_count = len(self.product_variant_ids) + if variant_count == 1: + self.product_variant_ids.is_event_deposit = self.is_event_deposit + elif variant_count == 0: + archived_variants = self.with_context(active_test=False).product_variant_ids + if len(archived_variants) == 1: + archived_variants.is_event_deposit = self.is_event_deposit + + @api.depends("product_variant_ids.balance_variant_id") + def _compute_balance_variant_id(self): + self.balance_variant_id = False + for template in self: + variant_count = len(template.product_variant_ids) + if variant_count == 1: + template.balance_variant_id = ( + template.product_variant_ids.balance_variant_id + ) + elif variant_count == 0: + archived_variants = template.with_context( + active_test=False + ).product_variant_ids + if len(archived_variants) == 1: + template.balance_variant_id = archived_variants.balance_variant_id + + def _search_balance_variant_id(self, operator, value): + query = self.with_context(active_test=False)._search( + [("product_variant_ids.balance_variant_id", operator, value)] + ) + return [("id", "in", query)] + + def _set_balance_variant_id(self): + variant_count = len(self.product_variant_ids) + if variant_count == 1: + self.product_variant_ids.balance_variant_id = self.balance_variant_id + elif variant_count == 0: + archived_variants = self.with_context(active_test=False).product_variant_ids + if len(archived_variants) == 1: + archived_variants.balance_variant_id = self.balance_variant_id + + def _get_related_fields_variant_template(self): + return super()._get_related_fields_variant_template() + [ + "is_event_deposit", + "balance_variant_id", + ] diff --git a/event_sale_balance/views/product_product.xml b/event_sale_balance/views/product_product.xml index bfc5c27..9d63b22 100644 --- a/event_sale_balance/views/product_product.xml +++ b/event_sale_balance/views/product_product.xml @@ -12,13 +12,14 @@ - + - + \ No newline at end of file diff --git a/event_sale_balance/views/product_template.xml b/event_sale_balance/views/product_template.xml new file mode 100644 index 0000000..ecf17d1 --- /dev/null +++ b/event_sale_balance/views/product_template.xml @@ -0,0 +1,20 @@ + + + + + product.template.common.form.inherit + product.template + + + + + + + + + + + + \ No newline at end of file