[REF] event_sale: create registrations in batch in SO confirm or registration editor
PURPOSE Create event registrations in batch. It will allow to customize group-creation of registrations, notably with automated rules for crm / event synchronization. SPECIFICATIONS Improve registration editor to create registrations in batch. Also be less dependent from context in its code, currently a bit weird. Move creation of registrations based on line from _action_confirm to action_confirm. Indeed it adds complexity and we are unsure it really helps having two methods. Update based on lines now create registrations in batch instead of one by one. LINKS Task ID 2258685 Prepare Task ID 2166679 (create leads from registrations) PR odoo/odoo#51341 Co-Authored-By: Jeremy Hennecart <jeh@odoo.com> Co-Authored-By: Thibault Delavallée <tde@odoo.com>
This commit is contained in:
committed by
Thibault Delavallée
co-authored by
Thibault Delavallée
parent
d01144e17d
commit
5ccfdfd96d
@@ -18,16 +18,11 @@ class SaleOrder(models.Model):
|
||||
registrations_toupdate.write({'partner_id': vals['partner_id']})
|
||||
return result
|
||||
|
||||
def _action_confirm(self):
|
||||
res = super(SaleOrder, self)._action_confirm()
|
||||
for so in self:
|
||||
# confirm registration if it was free (otherwise it will be confirmed once invoice fully paid)
|
||||
so.order_line._update_registrations(confirm=so.amount_total == 0, cancel_to_draft=False)
|
||||
return res
|
||||
|
||||
def action_confirm(self):
|
||||
res = super(SaleOrder, self).action_confirm()
|
||||
for so in self:
|
||||
# confirm registration if it was free (otherwise it will be confirmed once invoice fully paid)
|
||||
so.order_line._update_registrations(confirm=so.amount_total == 0, cancel_to_draft=False)
|
||||
if any(so.order_line.filtered(lambda line: line.event_id)):
|
||||
return self.env['ir.actions.act_window'] \
|
||||
.with_context(default_sale_order_id=so.id) \
|
||||
@@ -87,13 +82,17 @@ class SaleOrderLine(models.Model):
|
||||
if cancel_to_draft:
|
||||
existing_registrations.filtered(lambda self: self.state == 'cancel').action_set_draft()
|
||||
|
||||
registrations_vals = []
|
||||
for count in range(int(so_line.product_uom_qty) - len(existing_registrations)):
|
||||
registration_vals = {}
|
||||
if registration_data:
|
||||
registration_vals = registration_data.pop()
|
||||
values = {
|
||||
'sale_order_line_id': so_line.id,
|
||||
'sale_order_id': so_line.order_id.id
|
||||
}
|
||||
# TDE CHECK: auto confirmation
|
||||
registration_vals['sale_order_line_id'] = so_line.id
|
||||
Registration.create(registration_vals)
|
||||
if registration_data:
|
||||
values.update(registration_data.pop())
|
||||
registrations_vals.append(values)
|
||||
Registration.create(registrations_vals)
|
||||
return True
|
||||
|
||||
@api.onchange('product_id')
|
||||
|
||||
@@ -41,6 +41,10 @@ class RegistrationEditor(models.TransientModel):
|
||||
'event_id': so_line.event_id.id,
|
||||
'event_ticket_id': so_line.event_ticket_id.id,
|
||||
'sale_order_line_id': so_line.id,
|
||||
'name': so_line.order_partner_id.name,
|
||||
'email': so_line.order_partner_id.email,
|
||||
'phone': so_line.order_partner_id.phone,
|
||||
'mobile': so_line.order_partner_id.mobile,
|
||||
}])
|
||||
res['event_registration_ids'] = attendee_list
|
||||
res = self._convert_to_write(res)
|
||||
@@ -48,15 +52,17 @@ class RegistrationEditor(models.TransientModel):
|
||||
|
||||
def action_make_registration(self):
|
||||
self.ensure_one()
|
||||
registrations_to_create = []
|
||||
for registration_line in self.event_registration_ids:
|
||||
values = registration_line.get_registration_data()
|
||||
if registration_line.registration_id:
|
||||
registration_line.registration_id.write(values)
|
||||
else:
|
||||
self.env['event.registration'].create(values)
|
||||
if self.env.context.get('active_model') == 'sale.order':
|
||||
for order in self.env['sale.order'].browse(self.env.context.get('active_ids', [])):
|
||||
order.order_line._update_registrations(confirm=False)
|
||||
registrations_to_create.append(values)
|
||||
|
||||
self.env['event.registration'].create(registrations_to_create)
|
||||
self.sale_order_id.order_line._update_registrations(confirm=self.sale_order_id.amount_total == 0)
|
||||
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user