[IMP] event(_sale): add a description on event tickets

PURPOSE

This commit is part of ticket model support directly in event application.

SPECIFICATIONS

In this commit we add a description on event.type.ticket and event.event.type
models. Its purpose is to have a description to use notably in frontend
(website_event and website_event_sale).

Currently a ticket description is available only in website_event_sale and is
the description_sale field of the ticket product. As we now have tickets
independent from products, we introduce a real description field on ticket
that is either put by hand (event), either coming from the product with
event_sale.

Field is therefore also copied from event type tickets configuration to its
event tickets.

Naming on sale order does not take into account ticket description as we
consider this fields as being used for front-end mainly. SO line descripiton
is now updated as the following

  * either we have a description_sale on the product, and SO line description
    is 'product.description_sale \n event.display_name';
  * either not and SO line description is 'ticket.name \n event.display_name';

LINKS

Task ID 2177281
Community PR #43488
This commit is contained in:
Thibault Delavallée
2020-01-30 15:18:08 +00:00
parent 6b09c1b8c6
commit 1a2fcf0add
8 changed files with 32 additions and 9 deletions
+5 -6
View File
@@ -13,6 +13,9 @@ class EventTemplateTicket(models.Model):
name = fields.Char(
string='Name', default=lambda self: _('Registration'),
required=True, translate=True)
description = fields.Text(
'Description', translate=True,
help="A description of the ticket that you want to communicate to your customers.")
event_type_id = fields.Many2one(
'event.type', string='Event Category', ondelete='cascade', required=True)
# sale
@@ -66,7 +69,7 @@ class EventTemplateTicket(models.Model):
def _get_event_ticket_fields_whitelist(self):
""" Whitelist of fields that are copied from event_type_ticket_ids to event_ticket_ids when
changing the event_type_id field of event.event """
return ['name']
return ['name', 'description']
class EventTicket(models.Model):
@@ -129,11 +132,7 @@ class EventTicket(models.Model):
""" Compute a multiline description of this ticket. It is used when ticket
description are necessary without having to encode it manually, like sales
information. """
self.ensure_one()
lines = [self.display_name]
if self.event_id:
lines.append(self.event_id.display_name)
return '\n'.join(lines)
return '%s\n%s' % (self.display_name, self.event_id.display_name)
def _get_ticket_tz(self):
return self.event_id.date_tz or self.env.user.tz
@@ -9,6 +9,7 @@
<field name="arch" type="xml">
<tree string="Event Template Tickets" editable="bottom">
<field name="name"/>
<field name="description"/>
<field name="seats_max"/>
<field name="seats_availability"/>
</tree>
@@ -24,6 +25,7 @@
<sheet>
<group>
<field name="name"/>
<field name="description"/>
<field name="seats_availability"/>
<field name="seats_max"/>
</group>
@@ -69,6 +71,7 @@
<field name="arch" type="xml">
<tree string="Tickets" editable="bottom">
<field name="name"/>
<field name="description"/>
<field name="start_sale_date"/>
<field name="end_sale_date"/>
<field name="seats_max"/>
@@ -88,6 +91,7 @@
<group>
<group>
<field name="name"/>
<field name="description"/>
<field name="start_sale_date"/>
<field name="end_sale_date"/>
</group><group>
@@ -34,7 +34,7 @@
<div class="o_setting_right_pane">
<label for="module_event_sale"/>
<div class="text-muted">
Configure tickets and sell them online
Sell tickets with sales orders
</div>
</div>
</div>
@@ -13,6 +13,7 @@
<field name="uom_id" ref="uom.product_uom_unit"/>
<field name="uom_po_id" ref="uom.product_uom_unit"/>
<field name="name">Event Registration</field>
<field name="description_sale" eval="False"/>
<field name="default_code">EVENT_REG</field>
<field name="categ_id" ref="event_sale.product_category_events"/>
<field name="type">service</field>
+10
View File
@@ -38,6 +38,8 @@ class EventTemplateTicket(models.Model):
@api.onchange('product_id')
def _onchange_product_id(self):
self.price = self.product_id.list_price or 0
if not self.description and self.product_id.description_sale:
self.description = self.product_id.description_sale
def _init_column(self, column_name):
if column_name != "product_id":
@@ -93,3 +95,11 @@ class EventTicket(models.Model):
tax_ids = record.sudo().product_id.taxes_id.filtered(lambda r: r.company_id == record.event_id.company_id)
taxes = tax_ids.compute_all(record.price_reduce, record.event_id.company_id.currency_id, 1.0, product=record.product_id)
record.price_reduce_taxinc = taxes['total_included']
def _get_ticket_multiline_description(self):
""" If people set a description on their product it has more priority
than the ticket name itself for the SO description. """
self.ensure_one()
if self.product_id.description_sale:
return '%s\n%s' % (self.product_id.description_sale, self.event_id.display_name)
return super(EventTicket, self)._get_ticket_multiline_description()
+1
View File
@@ -12,6 +12,7 @@ class TestEventSaleCommon(TestEventCommon):
cls.event_product = cls.env['product.product'].create({
'name': 'Test Registration Product',
'description_sale': 'Mighty Description',
'list_price': 10,
'event_ok': True,
'standard_price': 30.0,
@@ -39,10 +39,14 @@ class TestEventData(TestEventSaleCommon):
})]
})
event_type.event_type_ticket_ids._onchange_product_id()
self.assertEqual(event_type.event_type_ticket_ids.description, self.event_product.description_sale)
# synchronize event
event._onchange_type()
self.assertEqual(event.event_ticket_ids.name, 'Registration for %s' % event.name)
self.assertEqual(event.event_ticket_ids.product_id, self.event_product)
self.assertEqual(event.event_ticket_ids.price, self.event_product.list_price)
self.assertEqual(event.event_ticket_ids.description, self.event_product.description_sale)
def test_event_registrable(self):
"""Test if `_compute_event_registrations_open` works properly with additional
@@ -9,6 +9,8 @@
<field name="arch" type="xml">
<field name="name" position="after">
<field name="product_id"/>
</field>
<field name="description" position="after">
<field name="price"/>
</field>
</field>
@@ -21,6 +23,8 @@
<field name="arch" type="xml">
<field name="name" position="after">
<field name="product_id"/>
</field>
<field name="description" position="after">
<field name="price"/>
</field>
</field>
@@ -35,7 +39,7 @@
<field name="name" position="after">
<field name="product_id" context="{'default_event_ok': 1}"/>
</field>
<field name="end_sale_date" position="after">
<field name="description" position="after">
<field name="price"/>
</field>
</field>
@@ -49,7 +53,7 @@
<field name="name" position="after">
<field name="product_id" context="{'default_event_ok':1}"/>
</field>
<field name="end_sale_date" position="after">
<field name="description" position="after">
<field name="price"/>
</field>
</field>