From 8b5a98e92e96d17710d0c47a6c4928cda021eaaa Mon Sep 17 00:00:00 2001 From: RemiFr82 Date: Thu, 23 Nov 2023 10:26:20 +0100 Subject: [PATCH] [IMP] event_sale_balance --- event_sale_balance/models/__init__.py | 1 + event_sale_balance/models/event_registration.py | 16 +++++++++++++--- event_sale_balance/models/product_template.py | 8 ++++++++ event_sale_balance/views/product_product.xml | 7 +++++-- 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 event_sale_balance/models/product_template.py diff --git a/event_sale_balance/models/__init__.py b/event_sale_balance/models/__init__.py index cdea0ac..aebe6ba 100644 --- a/event_sale_balance/models/__init__.py +++ b/event_sale_balance/models/__init__.py @@ -1,2 +1,3 @@ from . import event_registration from . import product_product +from . import product_template diff --git a/event_sale_balance/models/event_registration.py b/event_sale_balance/models/event_registration.py index d55c4fc..6c7ba3a 100644 --- a/event_sale_balance/models/event_registration.py +++ b/event_sale_balance/models/event_registration.py @@ -11,8 +11,10 @@ class EventRegistration(models.Model): bal_prod = tic_prod.balance_variant_id if tic_prod.is_event_deposit and bal_prod: order = regis.sale_order_id - lines = order.order_line - line = lines.filtered(lambda sol: sol.product_id == bal_prod, limit=1) + lines = order.order_line.filtered( + lambda sol: sol.product_id == bal_prod + ) + line = lines and lines[0] if line: # Update existing line update_values = order._prepare_order_line_update_values( @@ -22,5 +24,13 @@ class EventRegistration(models.Model): order._update_cart_line_values(line, update_values) else: # Create new line - line_values = order._prepare_order_line_values(bal_prod, 1) + line_values = order._prepare_order_line_values(bal_prod.id, 1) line.sudo().create(line_values) + if len(self) == 1 and self.env.context.get("open_sale_order", False): + return { + "type": "ir.actions.act_window", + "view_mode": "form", + "res_model": "sale.order", + "res_id": self.id, + "target": "current", + } diff --git a/event_sale_balance/models/product_template.py b/event_sale_balance/models/product_template.py new file mode 100644 index 0000000..3bfbf6b --- /dev/null +++ b/event_sale_balance/models/product_template.py @@ -0,0 +1,8 @@ +from odoo import models, fields + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + is_event_deposit = fields.Boolean("Event deposit") + balance_variant_id = fields.Many2one("product.product", string="Balance variant") diff --git a/event_sale_balance/views/product_product.xml b/event_sale_balance/views/product_product.xml index ca2b091..bfc5c27 100644 --- a/event_sale_balance/views/product_product.xml +++ b/event_sale_balance/views/product_product.xml @@ -6,9 +6,12 @@ product.product + + + - + @@ -22,7 +25,7 @@ - +