-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix_member_birthdate.py
executable file
·68 lines (55 loc) · 2.21 KB
/
fix_member_birthdate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /usr/bin/env python3
# -*- encoding: utf-8 -*-
import sys
import argparse
import erppeek
import csv
import unidecode
from datetime import datetime
from cfg_secret_configuration \
import odoo_configuration_user_test as odoo_configuration_user
###############################################################################
# Odoo Connection
###############################################################################
def init_openerp(url, login, password, database):
openerp = erppeek.Client(url)
uid = openerp.login(login, password=password, database=database)
user = openerp.ResUsers.browse(uid)
tz = user.tz
return openerp, uid, tz
openerp, uid, tz = init_openerp(
odoo_configuration_user['url'],
odoo_configuration_user['login'],
odoo_configuration_user['password'],
odoo_configuration_user['database'])
###############################################################################
# Configuration
###############################################################################
###############################################################################
# Script
###############################################################################
def main():
# Configure arguments parser
parser = argparse.ArgumentParser(
description='Force la date de naissance du membre au bon format')
parser.add_argument('nom', help='Nom du membre (NOM, prenom)')
parser.add_argument('date_naissance',
help='Date de naissance (YYYY-MM-DD)')
args = parser.parse_args()
# Check arg format
try:
datetime.strptime(args.date_naissance, '%Y-%m-%d')
except Exception as e:
raise Exception('%s : Mauvais format de date (AAAA-MM-JJ)' %\
(args.date_naissance))
# Get member from Odoo
members = openerp.ResPartner.browse([("name", "=", args.nom)])
if len(members) < 1:
raise Exception('%s : Membre introuvable dans Odoo' % (args.nom))
for member in members:
print('Date de naissance avant : %s' % (member.birthdate))
print('Modification...')
member.birthdate = args.date_naissance
print('Date de naissance après : %s' % (member.birthdate))
if __name__ == "__main__":
main()