Server IP : 127.0.0.2 / Your IP : 3.15.145.122 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /opt/odoo/addons/event_sale/wizard/ |
Upload File : |
# -*- coding: utf-8 -*- from odoo import models, fields, api class RegistrationEditor(models.TransientModel): _name = "registration.editor" sale_order_id = fields.Many2one('sale.order', 'Sale Order', required=True) event_registration_ids = fields.One2many('registration.editor.line', 'editor_id', string='Registrations to Edit') @api.model def default_get(self, fields): res = super(RegistrationEditor, self).default_get(fields) if not res.get('sale_order_id'): sale_order_id = res.get('sale_order_id', self._context.get('active_id')) res['sale_order_id'] = sale_order_id sale_order = self.env['sale.order'].browse(res.get('sale_order_id')) registrations = self.env['event.registration'].search([ ('sale_order_id', '=', sale_order.id), ('event_ticket_id', 'in', sale_order.mapped('order_line.event_ticket_id').ids), ('state', '!=', 'cancel')]) attendee_list = [] for so_line in [l for l in sale_order.order_line if l.event_ticket_id]: existing_registrations = [r for r in registrations if r.event_ticket_id == so_line.event_ticket_id] for reg in existing_registrations: attendee_list.append({ 'event_id': reg.event_id.id, 'event_ticket_id': reg.event_ticket_id.id, 'registration_id': reg.id, 'name': reg.name, 'email': reg.email, 'phone': reg.phone, 'sale_order_line_id': so_line.id, }) for count in range(int(so_line.product_uom_qty) - len(existing_registrations)): attendee_list.append([0, 0, { 'event_id': so_line.event_id.id, 'event_ticket_id': so_line.event_ticket_id.id, 'sale_order_line_id': so_line.id, }]) res['event_registration_ids'] = attendee_list res = self._convert_to_write(res) return res @api.multi def action_make_registration(self): self.ensure_one() 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=True) return {'type': 'ir.actions.act_window_close'} class RegistrationEditorLine(models.TransientModel): """Event Registration""" _name = "registration.editor.line" editor_id = fields.Many2one('registration.editor') sale_order_line_id = fields.Many2one('sale.order.line', string='Sale Order Line') event_id = fields.Many2one('event.event', string='Event', required=True) registration_id = fields.Many2one('event.registration', 'Original Registration') event_ticket_id = fields.Many2one('event.event.ticket', string='Event Ticket') email = fields.Char(string='Email') phone = fields.Char(string='Phone') name = fields.Char(string='Name', index=True) @api.multi def get_registration_data(self): self.ensure_one() return { 'event_id': self.event_id.id, 'event_ticket_id': self.event_ticket_id.id, 'partner_id': self.editor_id.sale_order_id.partner_id.id, 'name': self.name or self.editor_id.sale_order_id.partner_id.name, 'phone': self.phone or self.editor_id.sale_order_id.partner_id.phone, 'email': self.email or self.editor_id.sale_order_id.partner_id.email, 'origin': self.editor_id.sale_order_id.name, 'sale_order_id': self.editor_id.sale_order_id.id, 'sale_order_line_id': self.sale_order_line_id.id, }