Using the module Event (website_event_sale), there is an error occuring for some (few) of the customers in front office, when they click on the REGISTER-button that bring to the cart:
ERROR xxxxx-oerp-master-1178741 odoo.sql_db: bad query:
INSERT INTO "utm_medium" (
"active", "create_date", "create_uid", "name",
"write_date", "write_uid"
)
VALUES (
true, '2024-10-30 14:48:16.373602', 1, 'email',
'2024-10-30 14:48:16.373602', 1
) RETURNING "id"
ERROR: duplicate key value violates unique constraint "utm_medium_unique_name"
DETAIL: Key (name)=(email) already exists.
WARNING xxxxxx-1178741 odoo.http: L'opération ne peut pas être terminée : Le nom doit être unique
POST /event/initiation-au-3eme-degre-reiki-shinpiden-2024-11-02-2024-11-03-2997/registration/newdirecttocart HTTP/1.0" 400 - 77 0.088 0.093
It seems that, during the creation of a new registration via front-office, odoo wants to create a new value in the utm.medium model... but while creating this new value 'email', odoo triggers the UNIQUE constrainst (probably because the value 'Email' already exist in this model). My question: why does odoo does not check wether this value already exist before trying to create it...and how to fix it ?
addons/event_sale > model: event.registration:
class EventRegistration(models.Model):
_inherit = 'event.registration'
# ...
# ...
utm_medium_id = fields.Many2one(compute='_compute_utm_medium_id', readonly=False,
store=True, ondelete="set null")
@api.depends('sale_order_id')
def _compute_utm_medium_id(self):
for registration in self:
if registration.sale_order_id.medium_id:
registration.utm_medium_id = registration.sale_order_id.medium_id
elif not registration.utm_medium_id:
registration.utm_medium_id = False
addons/utm > model: utm.medium:
class UtmMedium(models.Model):
_name = 'utm.medium'
_description = 'UTM Medium'
_order = 'name'
name = fields.Char(string='Medium Name', required=True, translate=False)
active = fields.Boolean(default=True)
_sql_constraints = [
('unique_name', 'UNIQUE(name)', 'The name must be unique'),
]
@api.model_create_multi
def create(self, vals_list):
new_names = self.env['utm.mixin']._get_unique_names(self._name, [vals.get('name') for vals in vals_list])
for vals, new_name in zip(vals_list, new_names):
vals['name'] = new_name
return super().create(vals_list)
