#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Create res.users for OCA members with a github login filled in.

This enables adding them to project teams in the OCA instance.
"""
from __future__ import absolute_import, print_function

import xmlrpclib

from . odoo_login import login, get_parser


def main():
    parser = get_parser(with_help=True)
    args = parser.parse_args()
    client = login(args.username, args.store)
    ResPartner = client.ResPartner
    ResUsers = client.ResUsers
    ResGroups = client.ResGroups
    grp_project_user = ResGroups.get('project.group_project_user')
    members_with_gh = ResPartner.search([('x_github_login', '!=', False),
                                         ('user_ids', '=', False)])
    for partner in ResPartner.browse(members_with_gh):
        try:
            user = ResUsers.create({'partner_id': partner.id,
                                    'login': partner.email,
                                    'groups_id': [(4, grp_project_user.id, 0)],
                                    })
        except xmlrpclib.Fault as exc:
            print('unable to create user for partner %r: '
                  'missing email address' % partner.x_github_login)
        else:
            print(u'created user %r for partner %r' % (user, partner.x_github_login))

if __name__ == '__main__':
    main()

#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Create res.users for OCA members with a github login filled in.

This enables adding them to project teams in the OCA instance.
"""
from __future__ import absolute_import, print_function

import xmlrpclib

from . odoo_login import login, get_parser


def main():
    parser = get_parser(with_help=True)
    args = parser.parse_args()
    client = login(args.username, args.store)
    ResPartner = client.ResPartner
    ResUsers = client.ResUsers
    ResGroups = client.ResGroups
    grp_project_user = ResGroups.get('project.group_project_user')
    members_with_gh = ResPartner.search([('x_github_login', '!=', False),
                                         ('user_ids', '=', False)])
    if not members_with_gh:
        return
    for partner in ResPartner.browse(members_with_gh):
        try:
            user = ResUsers.create({'partner_id': partner.id,
                                    'login': partner.email,
                                    'groups_id': [(4, grp_project_user.id, 0)],
                                    })
        except xmlrpclib.Fault as exc:
            print('unable to create user for partner %r: '
                  'missing email address' % partner.x_github_login)
        else:
            print(u'created user %r for partner %r' % (user, partner.x_github_login))

if __name__ == '__main__':
    main()

fix bug: side effect of erppeek smart browse