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.

43 lines
1.7 KiB

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