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.

26 lines
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. from openerp 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. @api.multi
  7. @api.depends('share_ids', 'share_ids.share_product_id', 'share_ids.share_product_id.default_code')
  8. def _compute_share_type(self):
  9. for rec in self:
  10. codes = rec.share_ids.mapped('share_product_id.default_code')
  11. rec.cooperator_type = codes[0] if codes else ''
  12. @api.multi
  13. def _get_share_type(self):
  14. share_type_list = [('','')]
  15. for share_type in self.env['product.product'].search([('is_share','=',True)]):
  16. share_type_list.append((share_type.default_code, share_type.short_name))
  17. return share_type_list
  18. @api.noguess
  19. def _auto_init(self, cr, context=None):
  20. cr.execute("ALTER TABLE res_partner DROP COLUMN IF EXISTS cooperator_type")
  21. res = super(Partner, self)._auto_init(cr, context=context)
  22. return res