sale_order.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  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. class SaleOrder(models.Model):
  5. _inherit = 'sale.order'
  6. event_booth_ids = fields.One2many('event.booth', 'sale_order_id', string='Booths')
  7. event_booth_count = fields.Integer(string='Booth Count', compute='_compute_event_booth_count')
  8. @api.depends('event_booth_ids')
  9. def _compute_event_booth_count(self):
  10. if self.ids:
  11. slot_data = self.env['event.booth']._read_group(
  12. [('sale_order_id', 'in', self.ids)],
  13. ['sale_order_id'], ['sale_order_id']
  14. )
  15. slot_mapped = dict((data['sale_order_id'][0], data['sale_order_id_count']) for data in slot_data)
  16. else:
  17. slot_mapped = dict()
  18. for so in self:
  19. so.event_booth_count = slot_mapped.get(so.id, 0)
  20. def action_confirm(self):
  21. res = super(SaleOrder, self).action_confirm()
  22. for so in self:
  23. so.order_line._update_event_booths()
  24. return res
  25. def action_view_booth_list(self):
  26. action = self.env['ir.actions.act_window']._for_xml_id('event_booth.event_booth_action')
  27. action['domain'] = [('sale_order_id', 'in', self.ids)]
  28. return action