diff --git a/event_sale_balance/__init__.py b/event_sale_balance/__init__.py
new file mode 100644
index 0000000..0650744
--- /dev/null
+++ b/event_sale_balance/__init__.py
@@ -0,0 +1 @@
+from . import models
diff --git a/event_sale_balance/__manifest__.py b/event_sale_balance/__manifest__.py
new file mode 100644
index 0000000..006d92d
--- /dev/null
+++ b/event_sale_balance/__manifest__.py
@@ -0,0 +1,38 @@
+# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
+{
+ "name": "Event sale balance",
+ "version": "1.0.0",
+ "summary": """
+ "Event ticket" product variants can be marked as "Event deposit", linked to a "Balance" variant, and added to sales order on presence confirmation.
+ """,
+ "description": """
+ TO WRITE
+ """,
+ "author": "RemiFr82",
+ "contributors": "",
+ "website": "https://remifr82.me",
+ "license": "LGPL-3",
+ "category": "Events",
+ # "price": 0,
+ # "currency": "EUR",
+ "application": False,
+ "installable": True,
+ "auto_install": False,
+ "pre_init_hook": "",
+ "post_init_hook": "",
+ "uninstall_hook": "",
+ "excludes": [],
+ "external_dependencies": [],
+ "depends": [
+ "website_event_sale",
+ ],
+ "data": [
+ "views/product_product.xml",
+ ],
+ "css": [],
+ "images": [],
+ "js": [],
+ "test": [],
+ "demo": [],
+ "maintainer": "RemiFr82",
+}
diff --git a/event_sale_balance/models/__init__.py b/event_sale_balance/models/__init__.py
new file mode 100644
index 0000000..cdea0ac
--- /dev/null
+++ b/event_sale_balance/models/__init__.py
@@ -0,0 +1,2 @@
+from . import event_registration
+from . import product_product
diff --git a/event_sale_balance/models/event_registration.py b/event_sale_balance/models/event_registration.py
new file mode 100644
index 0000000..d55c4fc
--- /dev/null
+++ b/event_sale_balance/models/event_registration.py
@@ -0,0 +1,26 @@
+from odoo import models, api
+
+
+class EventRegistration(models.Model):
+ _inherit = "event.registration"
+
+ def action_set_done(self):
+ super().action_set_done()
+ for regis in self:
+ tic_prod = regis.event_ticket_id.product_id
+ 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)
+ if line:
+ # Update existing line
+ update_values = order._prepare_order_line_update_values(
+ line, line.product_uom_qty + 1
+ )
+ if update_values:
+ order._update_cart_line_values(line, update_values)
+ else:
+ # Create new line
+ line_values = order._prepare_order_line_values(bal_prod, 1)
+ line.sudo().create(line_values)
diff --git a/event_sale_balance/models/product_product.py b/event_sale_balance/models/product_product.py
new file mode 100644
index 0000000..2ba21ff
--- /dev/null
+++ b/event_sale_balance/models/product_product.py
@@ -0,0 +1,8 @@
+from odoo import models, fields
+
+
+class ProductProduct(models.Model):
+ _inherit = "product.product"
+
+ is_event_deposit = fields.Boolean("Event deposit")
+ balance_variant_id = fields.Many2one("product.product", string="Balance variant")
diff --git a/event_sale_balance/security/event_sale_balance.xml b/event_sale_balance/security/event_sale_balance.xml
new file mode 100644
index 0000000..edf36ce
--- /dev/null
+++ b/event_sale_balance/security/event_sale_balance.xml
@@ -0,0 +1,8 @@
+
+
+
+
+ Use event balance
+
+
+
\ No newline at end of file
diff --git a/event_sale_balance/views/product_product.xml b/event_sale_balance/views/product_product.xml
new file mode 100644
index 0000000..ca2b091
--- /dev/null
+++ b/event_sale_balance/views/product_product.xml
@@ -0,0 +1,32 @@
+
+
+
+
+ product.product.view.form.inherit
+ product.product
+
+
+
+
+
+
+
+
+
+
+
+
+ product.product.view.form.inherit
+ product.product
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file