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.

40 lines
1.6 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. can_shop = fields.Boolean(compute='_can_shop', store=True)
  7. @api.depends('cooperator_type', 'cooperative_status_ids', 'cooperative_status_ids.can_shop')
  8. def _can_shop(self):
  9. for rec in self:
  10. if rec.cooperator_type == 'share_b':
  11. rec.can_shop = True
  12. elif rec.cooperative_status_ids and rec.cooperative_status_ids[0].can_shop:
  13. rec.can_shop = True
  14. else:
  15. rec.can_shop = False
  16. @api.multi
  17. @api.depends('share_ids', 'share_ids.share_product_id', 'share_ids.share_product_id.default_code', 'share_ids.share_number')
  18. def _compute_share_type(self):
  19. for rec in self:
  20. if rec.share_ids and rec.share_ids[0].share_number > 0:
  21. rec.cooperator_type = rec.share_ids[0].share_product_id.default_code
  22. else:
  23. rec.cooperator_type = ''
  24. @api.multi
  25. def _get_share_type(self):
  26. share_type_list = [('','')]
  27. for share_type in self.env['product.product'].search([('is_share','=',True)]):
  28. share_type_list.append((share_type.default_code, share_type.short_name))
  29. return share_type_list
  30. @api.noguess
  31. def _auto_init(self, cr, context=None):
  32. cr.execute("ALTER TABLE res_partner DROP COLUMN IF EXISTS cooperator_type")
  33. res = super(Partner, self)._auto_init(cr, context=context)
  34. return res