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.

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