You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.8 KiB

  1. # -*- coding: utf-8 -*-
  2. from odoo import models, fields, api, _
  3. class Partner(models.Model):
  4. _inherit = 'res.partner'
  5. cooperator_type = fields.Selection(selection='_get_share_type', compute='_compute_share_type', string='Cooperator Type', store=True)
  6. can_shop = fields.Boolean(compute='_can_shop', store=True)
  7. info_session_confirmed = fields.Boolean(
  8. string="Confirmed presence to info session",
  9. default=False,
  10. )
  11. @api.depends('cooperator_type', 'cooperative_status_ids', 'cooperative_status_ids.can_shop')
  12. def _can_shop(self):
  13. for rec in self:
  14. if rec.cooperator_type == 'share_b':
  15. rec.can_shop = True
  16. elif rec.cooperative_status_ids and rec.cooperative_status_ids[0].can_shop:
  17. rec.can_shop = True
  18. else:
  19. rec.can_shop = False
  20. @api.multi
  21. @api.depends('share_ids', 'share_ids.share_product_id', 'share_ids.share_product_id.default_code', 'share_ids.share_number')
  22. def _compute_share_type(self):
  23. for rec in self:
  24. if rec.share_ids and rec.share_ids[0].share_number > 0:
  25. rec.cooperator_type = rec.share_ids[0].share_product_id.default_code
  26. else:
  27. rec.cooperator_type = ''
  28. @api.multi
  29. def _get_share_type(self):
  30. share_type_list = [('','')]
  31. for share_type in self.env['product.product'].search([('is_share','=',True)]):
  32. share_type_list.append((share_type.default_code, share_type.short_name))
  33. return share_type_list
  34. @api.noguess
  35. def _auto_init(self, cr, context=None):
  36. cr.execute("ALTER TABLE res_partner DROP COLUMN IF EXISTS cooperator_type")
  37. res = super(Partner, self)._auto_init(cr, context=context)
  38. return res