[IMP] event: refactor barcode

Commit is responsible for refactoring
code related to barcode.

Part-of: odoo/odoo#135153
This commit is contained in:
dane@odoo.com
2023-10-05 16:49:01 +00:00
parent a653d22aeb
commit a98717b0e5
4 changed files with 14 additions and 7 deletions
+6
View File
@@ -124,6 +124,7 @@ class EventEvent(models.Model):
user_id = fields.Many2one(
'res.users', string='Responsible', tracking=True,
default=lambda self: self.env.user)
use_barcode = fields.Boolean(compute='_compute_use_barcode')
company_id = fields.Many2one(
'res.company', string='Company', change_default=True,
default=lambda self: self.env.company,
@@ -236,6 +237,11 @@ class EventEvent(models.Model):
compute='_compute_ticket_instructions', store=True, readonly=False,
help="This information will be printed on your tickets.")
def _compute_use_barcode(self):
use_barcode = self.env['ir.config_parameter'].sudo().get_param('event.use_event_barcode') == 'True'
for record in self:
record.use_barcode = use_barcode
@api.depends('stage_id', 'kanban_state')
def _compute_kanban_state_label(self):
for event in self:
+3 -2
View File
@@ -18,7 +18,7 @@ class EventRegistration(models.Model):
_order = 'id desc'
@api.model
def _get_random_token(self):
def _get_random_barcode(self):
"""Generate a string representation of a pseudo-random 8-byte number for barcode
generation.
@@ -29,7 +29,6 @@ class EventRegistration(models.Model):
compatible with all scanners.
"""
return str(int.from_bytes(os.urandom(8), 'little'))
barcode = fields.Char(default=_get_random_token, readonly=True, copy=False, index=True)
# event
event_id = fields.Many2one(
@@ -37,6 +36,8 @@ class EventRegistration(models.Model):
event_ticket_id = fields.Many2one(
'event.event.ticket', string='Event Ticket', ondelete='restrict')
active = fields.Boolean(default=True)
barcode = fields.Char(string='Barcode', default=lambda self: self._get_random_barcode(), readonly=True, copy=False)
# utm informations
utm_campaign_id = fields.Many2one('utm.campaign', 'Campaign', index=True, ondelete='set null')
utm_source_id = fields.Many2one('utm.source', 'Source', index=True, ondelete='set null')
+1 -1
View File
@@ -25,10 +25,10 @@ class ResConfigSettings(models.TransientModel):
module_website_event_track_quiz = fields.Boolean("Quiz on Tracks")
module_website_event_exhibitor = fields.Boolean("Advanced Sponsors")
use_event_barcode = fields.Boolean(string="Use Event Barcode", help="Enable or Disable Event Barcode functionality.", config_parameter='event.use_event_barcode')
barcode_nomenclature_id = fields.Many2one('barcode.nomenclature', related='company_id.nomenclature_id', readonly=False)
module_website_event_sale = fields.Boolean("Online Ticketing")
module_event_booth = fields.Boolean("Booth Management")
use_google_maps_static_api = fields.Boolean("Google Maps static API", default=_default_use_google_maps_static_api)
barcode_nomenclature_id = fields.Many2one('barcode.nomenclature', related='company_id.nomenclature_id', readonly=False)
@api.depends('use_google_maps_static_api')
def _compute_maps_static_api_key(self):
@@ -15,7 +15,7 @@
<div class="page col-6 position-relative p-1">
<div class="oe_structure"/>
<div class="o_event_foldable_badge_back text-center">
<t t-if="env['ir.config_parameter'].sudo().get_param('event.use_event_barcode') == 'True'">
<t t-if="event.use_barcode">
<t t-if="attendee">
<span t-field="attendee.barcode" class="barcode ms-2" t-options="{'widget': 'barcode', 'width': 200, 'height': 84, 'quiet': 0, 'humanreadable': 1}"/>
</t>
@@ -37,7 +37,7 @@
<div class="o_event_foldable_badge_bottom_quarter page col-6 p-1">
<div class="oe_structure"/>
<div class="o_event_foldable_badge_back text-center">
<t t-if="env['ir.config_parameter'].sudo().get_param('event.use_event_barcode') == 'True'">
<t t-if="event.use_barcode">
<t t-if="attendee">
<span t-field="attendee.barcode" class="barcode ms-2" t-options="{'widget': 'barcode', 'width': 200, 'height': 84, 'quiet': 0, 'humanreadable': 1}"/>
</t>
@@ -164,7 +164,7 @@
<img t-attf-src="/report/barcode/QR/{{attendee.barcode if attendee and attendee.barcode else '12345678901234567890'}}?&amp;width=116&amp;height=116&amp;quiet=0" alt="QR Code"/>
</div>
<t t-if="env['ir.config_parameter'].sudo().get_param('event.use_event_barcode') == 'True'">
<t t-if="event.use_barcode">
<img class="o_event_barcode" t-attf-src="/report/barcode/?barcode_type=Code128&amp;value={{attendee.barcode if attendee and attendee.barcode else '12345678901234567890'}}&amp;width=168&amp;height=84&amp;humanreadable=1&amp;quiet=0" alt="Barcode"/>
</t>
</t>
@@ -264,7 +264,7 @@
<img t-if="event.organizer_id.image_256" class="o_event_badge_logo text-center mb-2" t-att-src="image_data_uri(event.organizer_id.image_256)"/>
<span t-if="event.badge_format != 'A4_french_fold'" class="o_event_badge_barcode_container mb-2">
<img t-att-class="'mb-2' + (' ms-5' if event.organizer_id.image_256 else '')" t-attf-src="/report/barcode/QR/{{attendee.barcode if attendee else '12345678901234567890'}}?&amp;width=116&amp;height=116&amp;quiet=0" alt="QR Code"/>
<t t-if="env['ir.config_parameter'].sudo().get_param('event.use_event_barcode') == 'True'">
<t t-if="event.use_barcode">
<t t-if="attendee">
<span t-field="attendee.barcode" class="barcode ms-2" t-options="{'widget': 'barcode', 'width': 200, 'height': 84, 'quiet': 0, 'humanreadable': 1}"/>
</t>