Server IP : 127.0.0.2 / Your IP : 3.138.36.87 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/models/ |
Upload File : |
# -*- coding: utf-8 -*- from odoo import api, fields, models class SaleOrder(models.Model): _inherit = "sale.order" @api.multi def action_confirm(self): self.ensure_one() res = super(SaleOrder, self).action_confirm() self.order_line._update_registrations(confirm=True) if any(self.order_line.filtered(lambda line: line.event_id)): return self.env['ir.actions.act_window'].with_context(default_sale_order_id=self.id).for_xml_id('event_sale', 'action_sale_order_event_registration') return res class SaleOrderLine(models.Model): _inherit = 'sale.order.line' event_id = fields.Many2one('event.event', string='Event', help="Choose an event and it will automatically create a registration for this event.") event_ticket_id = fields.Many2one('event.event.ticket', string='Event Ticket', help="Choose " "an event ticket and it will automatically create a registration for this event ticket.") event_ok = fields.Boolean(related='product_id.event_ok', readonly=True) @api.multi def _prepare_invoice_line(self, qty): self.ensure_one() res = super(SaleOrderLine, self)._prepare_invoice_line(qty) if self.event_id: res['name'] = '%s: %s' % (res.get('name', ''), self.event_id.name) return res @api.multi def _update_registrations(self, confirm=True, registration_data=None): """ Create or update registrations linked to a sale order line. A sale order line has a product_uom_qty attribute that will be the number of registrations linked to this line. This method update existing registrations and create new one for missing one. """ Registration = self.env['event.registration'] registrations = Registration.search([('sale_order_line_id', 'in', self.ids), ('state', '!=', 'cancel')]) for so_line in self.filtered('event_id'): existing_registrations = registrations.filtered(lambda self: self.sale_order_line_id.id == so_line.id) if confirm: existing_registrations.filtered(lambda self: self.state != 'open').confirm_registration() else: existing_registrations.filtered(lambda self: self.state == 'cancel').do_draft() for count in range(int(so_line.product_uom_qty) - len(existing_registrations)): registration = {} if registration_data: registration = registration_data.pop() # TDE CHECK: auto confirmation registration['sale_order_line_id'] = so_line Registration.with_context(registration_force_draft=True).create( Registration._prepare_attendee_values(registration)) return True @api.onchange('event_ticket_id') def _onchange_event_ticket_id(self): self.price_unit = (self.event_id.company_id or self.env.user.company_id).currency_id.compute(self.event_ticket_id.price, self.order_id.currency_id)