Browse Source

[IMP] event_sale_balance

16.0
RemiFr82 1 year ago
parent
commit
8b5a98e92e
  1. 1
      event_sale_balance/models/__init__.py
  2. 16
      event_sale_balance/models/event_registration.py
  3. 8
      event_sale_balance/models/product_template.py
  4. 7
      event_sale_balance/views/product_product.xml

1
event_sale_balance/models/__init__.py

@ -1,2 +1,3 @@
from . import event_registration from . import event_registration
from . import product_product from . import product_product
from . import product_template

16
event_sale_balance/models/event_registration.py

@ -11,8 +11,10 @@ class EventRegistration(models.Model):
bal_prod = tic_prod.balance_variant_id bal_prod = tic_prod.balance_variant_id
if tic_prod.is_event_deposit and bal_prod: if tic_prod.is_event_deposit and bal_prod:
order = regis.sale_order_id 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: if line:
# Update existing line # Update existing line
update_values = order._prepare_order_line_update_values( update_values = order._prepare_order_line_update_values(
@ -22,5 +24,13 @@ class EventRegistration(models.Model):
order._update_cart_line_values(line, update_values) order._update_cart_line_values(line, update_values)
else: else:
# Create new line # 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) 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",
}

8
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")

7
event_sale_balance/views/product_product.xml

@ -6,9 +6,12 @@
<field name="model">product.product</field> <field name="model">product.product</field>
<field name="inherit_id" ref="product.product_variant_easy_edit_view" /> <field name="inherit_id" ref="product.product_variant_easy_edit_view" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="id" position="after">
<field name="detailed_type" invisible="1" />
</field>
<group name="product_variant_images" position="after"> <group name="product_variant_images" position="after">
<group name="event" string="Event sale" attrs="{'invisible': [('detailed_type','!=','event')]}"> <group name="event" string="Event sale" attrs="{'invisible': [('detailed_type','!=','event')]}">
<field name="is_deposit" />
<field name="is_event_deposit" />
<field name="balance_variant_id" options="{'no_create': 1}" /> <field name="balance_variant_id" options="{'no_create': 1}" />
</group> </group>
</group> </group>
@ -22,7 +25,7 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<group name="description" position="after"> <group name="description" position="after">
<group name="event" string="Event sale" attrs="{'invisible': [('detailed_type','!=','event')]}"> <group name="event" string="Event sale" attrs="{'invisible': [('detailed_type','!=','event')]}">
<field name="is_deposit" />
<field name="is_event_deposit" />
<field name="balance_variant_id" options="{'no_create': 1}" /> <field name="balance_variant_id" options="{'no_create': 1}" />
</group> </group>
</group> </group>

Loading…
Cancel
Save