3
votes

I have a module which will not inherit from another one it will be for sports club

players and trainers will have access rights to use the system and my question as follows:

1- which is better, create new model from scratch or inherit from partners, employee, contact or users

2- if I create new model or inherit from another model which is not users how to make any player a user by default

1

1 Answers

4
votes

You will probably have to create a partner for your user anyways. My thought is that you may want to make your players partners. You can override the view and remove the elements that are not player oriented or hide them if the is_player flag is true. (You may want to add a new is_player boolean). You can use the is_player boolean to define when to display the player view or a generic contact view.

Personally I would use partner and users as so much of Odoo's security and structures are already built around these models.

If your player inherits partner you can override the create() method and within it simply create a user after you have created your contact.

@api.model
@api.returns('self', lambda rec: rec.id)
def create(self, vals):
    vals['notify_email'] = 'always'
    rec = super(Partner, self).create(vals)
    v = {
         'active': True,
         'login': rec.email,
         'company_id': 1,
         'partner_id': rec.id,
         'create_uid': 1,
         'write_uid': 1,
         'display_groups_suggestions': False,
         'share': False
    }
    user_id = self.env['res.users'].sudo().create(v)

    return rec

The above example creates a user with a bunch of values you will probably want to change to be more appropriate for your needs. After you create the user you will want to send a password reset.