event_booth.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import api, fields, models, _
  4. from odoo.exceptions import UserError
  5. class EventBooth(models.Model):
  6. _inherit = 'event.booth'
  7. # registrations
  8. event_booth_registration_ids = fields.One2many('event.booth.registration', 'event_booth_id')
  9. # sale information
  10. sale_order_line_registration_ids = fields.Many2many(
  11. 'sale.order.line', 'event_booth_registration',
  12. 'event_booth_id', 'sale_order_line_id', string='SO Lines with reservations',
  13. groups='sales_team.group_sale_salesman', copy=False)
  14. sale_order_line_id = fields.Many2one(
  15. 'sale.order.line', string='Final Sale Order Line', ondelete='set null',
  16. readonly=True, states={'available': [('readonly', False)]},
  17. groups='sales_team.group_sale_salesman', copy=False)
  18. sale_order_id = fields.Many2one(
  19. related='sale_order_line_id.order_id', store='True', readonly=True,
  20. groups='sales_team.group_sale_salesman')
  21. is_paid = fields.Boolean('Is Paid', copy=False)
  22. @api.ondelete(at_uninstall=False)
  23. def _unlink_except_linked_sale_order(self):
  24. booth_with_so = self.sudo().filtered('sale_order_id')
  25. if booth_with_so:
  26. raise UserError(_(
  27. 'You can\'t delete the following booths as they are linked to sales orders: '
  28. '%(booths)s', booths=', '.join(booth_with_so.mapped('name'))))
  29. def action_set_paid(self):
  30. self.write({'is_paid': True})
  31. def action_view_sale_order(self):
  32. self.sale_order_id.ensure_one()
  33. action = self.env['ir.actions.actions']._for_xml_id('sale.action_orders')
  34. action['views'] = [(False, 'form')]
  35. action['res_id'] = self.sale_order_id.id
  36. return action
  37. def _get_booth_multiline_description(self):
  38. return '%s : \n%s' % (
  39. self.event_id.display_name,
  40. '\n'.join(['- %s' % booth.name for booth in self])
  41. )