forked from Lokavaluto/dev-pack
Browse Source
Cyclos docker containers added to docker-compose.yml + complete init script for odoo & cyclos
dev
Cyclos docker containers added to docker-compose.yml + complete init script for odoo & cyclos
dev
Maxime Mazouth-Laurol
5 years ago
15 changed files with 495777 additions and 0 deletions
-
24src/.env.dist
-
2src/.gitignore
-
6src/Dockerfile
-
99src/docker-compose.yml
-
121src/etc/cyclos/cyclos_constants.yml.sample
-
120src/etc/cyclos/cyclos_constants_dev.yml
-
245786src/etc/cyclos/dump/cyclos.sql
-
245786src/etc/cyclos/dump/cyclos_test.sql
-
460src/etc/cyclos/init_test_data.py
-
120src/etc/cyclos/script_clean_database.sql
-
90src/etc/cyclos/script_transaction_extensionpoint.groovy
-
80src/etc/cyclos/script_transfer_extensionpoint.groovy
-
2878src/etc/cyclos/setup.py
-
43src/etc/cyclos/setup_cyclos.sh
-
162src/init.sh
@ -0,0 +1,24 @@ |
|||
## Location of the charm-store (to build postgres) |
|||
CHARM_STORE=/home/cairn/.charm-store |
|||
|
|||
## Password for postgres's 'odoo' user |
|||
PG_DATABASE=odoo |
|||
PG_USER=odoo |
|||
PG_PASS=password |
|||
|
|||
## Password for odoo admin tasks (create/delete/archive databases) |
|||
ODOO_ADMIN_PASSWORD=password |
|||
|
|||
## Password for postgres admin user 'postgres' |
|||
POSTGRES_ROOT_PASSWORD=password |
|||
|
|||
CYCLOS_PORT=1234 |
|||
CURRENCY_SLUG=cairn |
|||
CURRENCY_SYMBOL=CRN |
|||
ENV=dev |
|||
SESSION_TIMEOUT=1500 |
|||
MIN_LENGTH_PWD=8 |
|||
MAX_LENGTH_PWD=25 |
|||
POSTGRES_DB=cyclos |
|||
POSTGRES_USER=cyclos |
|||
POSTGRES_PASSWORD=cyclos |
@ -0,0 +1,2 @@ |
|||
.env |
|||
./logs/cyclos/* |
@ -0,0 +1,6 @@ |
|||
FROM cyclos/cyclos:4.11.2 |
|||
|
|||
RUN set -x; \ |
|||
apt-get update \ |
|||
&& apt-get install -y --no-install-recommends python3 \ |
|||
python3-requests python3-slugify python3-yaml |
@ -0,0 +1,99 @@ |
|||
version: '3.5' |
|||
|
|||
networks: |
|||
mlc_net: |
|||
driver: bridge |
|||
name: mlc_net |
|||
|
|||
services: |
|||
odoo: |
|||
image: docker.0k.io/mirror/odoo:rc_12.0-MYC-INIT |
|||
container_name: odoo_server |
|||
ports: |
|||
- 8069:8069 |
|||
command: |
|||
- odoo |
|||
- --config=/opt/odoo/auto/odoo.conf |
|||
- --workers=1 |
|||
- -i base,l10n_fr |
|||
- --database=odoo |
|||
- --addons-path=/opt/odoo/auto/my_addons,/opt/odoo/auto/addons |
|||
environment: |
|||
- ADMIN_PASSWORD=${ODOO_ADMIN_PASSWORD} |
|||
- INITIAL_LANG=fr_FR |
|||
- LIST_DB='true' |
|||
- PGDATABASE=${PG_DATABASE} |
|||
- PGHOST=postgres |
|||
- PGPASSWORD=${PG_PASS} |
|||
- PGUSER=${PG_USER} |
|||
restart: unless-stopped |
|||
tty: true |
|||
volumes: |
|||
## Volume is changed from normal 'compose' build |
|||
- ./etc/cyclos:/cyclos |
|||
- odoo-data:/var/lib/odoo:rw |
|||
- ./my_addons:/opt/odoo/auto/my_addons |
|||
depends_on: |
|||
- postgres |
|||
- cyclos-app |
|||
networks: |
|||
- mlc_net |
|||
|
|||
|
|||
postgres: |
|||
build: ${CHARM_STORE}/postgres/build |
|||
container_name: postgres_odoo |
|||
restart: unless-stopped |
|||
volumes: |
|||
## Volume is changed from normal 'compose' build |
|||
- postgres-data:/var/lib/postgresql/data:rw |
|||
## Was added, differing from the normal 'compose' build |
|||
environment: |
|||
- POSTGRES_ROOT_PASSWORD |
|||
- PG_DATABASE |
|||
- PG_USER |
|||
- PG_PASS |
|||
networks: |
|||
- mlc_net |
|||
|
|||
cyclos-app: |
|||
build: . |
|||
container_name: cyclos-app |
|||
environment: |
|||
- CURRENCY_SLUG=${CURRENCY_SLUG} |
|||
- CURRENCY_SYMBOL=${CURRENCY_SYMBOL} |
|||
- ENV=${ENV} |
|||
- SESSION_TIMEOUT=${SESSION_TIMEOUT} |
|||
- MIN_LENGTH_PWD=${MIN_LENGTH_PWD} |
|||
- MAX_LENGTH_PWD=${MAX_LENGTH_PWD} |
|||
- DB_HOST=cyclos-db |
|||
- DB_NAME=${POSTGRES_DB} |
|||
- DB_USER=${POSTGRES_USER} |
|||
- DB_PASSWORD=${POSTGRES_PASSWORD} |
|||
ports: |
|||
- '${CYCLOS_PORT}:8080' |
|||
volumes: |
|||
- ./etc/cyclos:/cyclos |
|||
- ./logs/cyclos:/var/log/cyclos |
|||
depends_on: |
|||
- cyclos-db |
|||
networks: |
|||
- mlc_net |
|||
|
|||
cyclos-db: |
|||
image: cyclos/db |
|||
container_name: cyclos-db |
|||
environment: |
|||
- POSTGRES_DB=${POSTGRES_DB} |
|||
- POSTGRES_USER=${POSTGRES_USER} |
|||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD} |
|||
volumes: |
|||
- ./etc/cyclos/dump/cyclos.sql:/docker-entrypoint-initdb.d/cyclos.sql |
|||
- ./data/cyclos/postgresql:/var/lib/postgresql/data |
|||
networks: |
|||
- mlc_net |
|||
|
|||
## new section |
|||
volumes: |
|||
odoo-data: |
|||
postgres-data: |
@ -0,0 +1,121 @@ |
|||
access_clients: |
|||
point_de_vente_nfc: -7371965201600299221 |
|||
account_types: |
|||
banque_de_depot: -7371965184420430037 |
|||
caisse_euro_bdc: -7371965205895266517 |
|||
caisse_eusko_bdc: -7371965175830495445 |
|||
compte_d_adherent: -7371965162945593557 |
|||
compte_de_debit_euro: -7371965197305331925 |
|||
compte_de_debit_eusko_billet: -7371965214485201109 |
|||
compte_de_debit_eusko_numerique: -7371965158650626261 |
|||
compte_de_transit: -7371965223075135701 |
|||
compte_dedie: -7371965188715397333 |
|||
compte_des_billets_en_circulation: -7371965193010364629 |
|||
retours_d_eusko_bdc: -7371965180125462741 |
|||
stock_de_billets: -7371965218780168405 |
|||
stock_de_billets_bdc: -7371965201600299221 |
|||
currencies: |
|||
euro: -7371965218780168405 |
|||
eusko: -7371965214485201109 |
|||
groups: |
|||
adherents_prestataires: -7371965180125462741 |
|||
adherents_sans_compte: -7371965158650626261 |
|||
adherents_utilisateurs: -7371965184420430037 |
|||
anonyme: -7371965197305331925 |
|||
banques_de_depot: -7371965205895266517 |
|||
bureaux_de_change: -7371965201600299221 |
|||
comptes_dedies: -7371965175830495445 |
|||
gestion_interne: -7371965223075135701 |
|||
operateurs_bdc: -7371965193010364629 |
|||
porteurs: -7371965188715397333 |
|||
password_types: |
|||
login_password: -7371965214485201109 |
|||
one_time_password: -7371965193010364629 |
|||
pin: -7371965223075135701 |
|||
transaction_password: -7371965218780168405 |
|||
payment_modes: |
|||
cheque: -7371965214485201109 |
|||
especes: -7371965218780168405 |
|||
paiement_en_ligne: -7371965223075135701 |
|||
prelevement: -7371965193010364629 |
|||
virement: -7371965197305331925 |
|||
payment_types: |
|||
change_billets_versement_des_euro: -7371965188715397333 |
|||
change_numerique_en_bdc_versement_des_euro: -7371965235960037589 |
|||
change_numerique_en_ligne_versement_des_euro: -7371965227370102997 |
|||
change_numerique_en_ligne_versement_des_eusko: -7371965231665070293 |
|||
cotisation_en_euro: -7371965167240560853 |
|||
cotisation_en_eusko: -7371965171535528149 |
|||
credit_du_compte: -7371965351924154581 |
|||
de_retours_d_eusko_bdc_vers_stock_de_billets_bdc: -7371965343334219989 |
|||
de_stock_de_billets_bdc_vers_retours_d_eusko_bdc: -7371965339039252693 |
|||
depot_de_billets: -7371965347629187285 |
|||
depot_en_banque: -7371965287499645141 |
|||
destruction_de_billets_d_eusko: -7371965218780168405 |
|||
entree_coffre: -7371965193010364629 |
|||
entree_stock_bdc: -7371965197305331925 |
|||
gain_de_billets: -7371965184420430037 |
|||
impression_de_billets_d_eusko: -7371965214485201109 |
|||
paiement_de_banque_de_depot_vers_caisse_euro_bdc: -7371965261729841365 |
|||
paiement_de_caisse_euro_bdc_vers_banque_de_depot: -7371965266024808661 |
|||
paiement_par_carte: -7371965334744285397 |
|||
perte_de_billets: -7371965180125462741 |
|||
reconversion_billets_versement_des_eusko: -7371965162945593557 |
|||
reconversion_numerique: -7371965240255004885 |
|||
regularisation_depot_excessif: -7371965270319775957 |
|||
regularisation_depot_insuffisant: -7371965291794612437 |
|||
remise_d_euro_en_caisse: -7371965274614743253 |
|||
retrait_de_billets: -7371965356219121877 |
|||
retrait_du_compte: -7371965360514089173 |
|||
sortie_caisse_eusko_bdc: -7371965205895266517 |
|||
sortie_coffre: -7371965223075135701 |
|||
sortie_retours_eusko_bdc: -7371965175830495445 |
|||
sortie_stock_bdc: -7371965201600299221 |
|||
vente_en_euro: -7371965278909710549 |
|||
vente_en_eusko: -7371965283204677845 |
|||
virement_de_banque_de_depot_vers_compte_debit_euro: -7371965244549972181 |
|||
virement_de_banque_de_depot_vers_compte_dedie: -7371965248844939477 |
|||
virement_de_compte_dedie_vers_compte_debit_euro: -7371965253139906773 |
|||
virement_entre_comptes_dedies: -7371965257434874069 |
|||
virement_inter_adherent: -7371965330449318101 |
|||
products: |
|||
foulard: -7371965201600299221 |
|||
system_accounts: |
|||
compte_de_debit_euro: -7371965197305331925 |
|||
compte_de_debit_eusko_billet: -7371965214485201109 |
|||
compte_de_debit_eusko_numerique: -7371965201600299221 |
|||
compte_de_transit: -7371965223075135701 |
|||
compte_des_billets_en_circulation: -7371965193010364629 |
|||
stock_de_billets: -7371965218780168405 |
|||
tokens: |
|||
carte_nfc: -7371965197305331925 |
|||
transaction_custom_fields: |
|||
adherent: -7371965223075135701 |
|||
adherent_facultatif: -7371965193010364629 |
|||
bdc: -7371965214485201109 |
|||
mode_de_paiement: -7371965197305331925 |
|||
montant_changes_billet: -7371965184420430037 |
|||
montant_changes_numerique: -7371965188715397333 |
|||
montant_cotisations: -7371965175830495445 |
|||
montant_ventes: -7371965180125462741 |
|||
numero_de_bordereau: -7371965205895266517 |
|||
numero_de_facture: -7371965162945593557 |
|||
numero_de_transaction_banque: -7371965158650626261 |
|||
porteur: -7371965218780168405 |
|||
produit: -7371965201600299221 |
|||
transfer_status_flows: |
|||
rapprochement: -7371965214485201109 |
|||
remise_a_euskal_moneta: -7371965218780168405 |
|||
virements: -7371965223075135701 |
|||
transfer_statuses: |
|||
a_rapprocher: -7371965218780168405 |
|||
a_remettre_a_euskal_moneta: -7371965193010364629 |
|||
rapproche: -7371965214485201109 |
|||
remis_a_euskal_moneta: -7371965223075135701 |
|||
virements_a_faire: -7371965201600299221 |
|||
virements_faits: -7371965197305331925 |
|||
user_custom_fields: |
|||
bdc: -7371965214485201109 |
|||
users: |
|||
compte_dedie_eusko_billet: -7371965218780168405 |
|||
compte_dedie_eusko_numerique: -7371965223075135701 |
@ -0,0 +1,120 @@ |
|||
access_clients: |
|||
client_sms: -1928164551898939653 |
|||
main: -1567876581709299973 |
|||
point_de_vente_nfc: -2000222145936867589 |
|||
account_types: |
|||
banque_de_depot: -1711991769785155845 |
|||
caisse_euro_bdc: -1928164551898939653 |
|||
caisse_mlc_bdc: -1567876581709299973 |
|||
compte_d_adherent: -1423761393633444101 |
|||
compte_de_credit_coffre_numerique: -1279646205557588229 |
|||
compte_de_debit_euro: -1784049363823083781 |
|||
compte_de_debit_mlc_billet: -2072279739974795525 |
|||
compte_de_debit_mlc_numerique: -1207588611519660293 |
|||
compte_de_transit: -2216394928050651397 |
|||
compte_dedie: -1639934175747227909 |
|||
compte_des_billets_en_circulation: -1856106957861011717 |
|||
retours_d_mlc_bdc: -1495818987671372037 |
|||
stock_de_billets: -2288452522088579333 |
|||
stock_de_billets_bdc: -2000222145936867589 |
|||
currencies: |
|||
euro: -2288452522088579333 |
|||
mlc: -2072279739974795525 |
|||
groups: |
|||
adherents_prestataires: -1495818987671372037 |
|||
adherents_sans_compte: -1279646205557588229 |
|||
adherents_utilisateurs: -1711991769785155845 |
|||
anonyme: -1784049363823083781 |
|||
banques_de_depot: -1928164551898939653 |
|||
bureaux_de_change: -2000222145936867589 |
|||
comptes_dedies: -1567876581709299973 |
|||
gestion_interne: -2216394928050651397 |
|||
operateurs_bdc: -1856106957861011717 |
|||
porteurs: -1639934175747227909 |
|||
password_types: |
|||
login_password: -2072279739974795525 |
|||
one_time_password: -1856106957861011717 |
|||
pin: -2216394928050651397 |
|||
transaction_password: -2288452522088579333 |
|||
payment_modes: |
|||
cheque: -2072279739974795525 |
|||
especes: -2288452522088579333 |
|||
paiement_en_ligne: -2216394928050651397 |
|||
prelevement: -1856106957861011717 |
|||
virement: -1784049363823083781 |
|||
payment_types: |
|||
change_billets_versement_des_euro: -1207588611519660293 |
|||
change_numerique_en_bdc_versement_des_euro: -4450180343226417413 |
|||
change_numerique_en_ligne_versement_des_euro: -270839889026597125 |
|||
change_numerique_en_ligne_versement_des_mlc: -198782294988669189 |
|||
cotisation_en_euro: -991415829405876485 |
|||
cotisation_en_mlc: -919358235367948549 |
|||
creation_mlc_numeriques: -1856106957861011717 |
|||
credit_du_compte: -4522237937264345349 |
|||
de_retours_des_mlc_bdc_vers_stock_de_billets_bdc: -4017834778998849797 |
|||
de_stock_de_billets_bdc_vers_retours_de_mlc_bdc: -3801661996885065989 |
|||
depot_de_billets: -4594295531302273285 |
|||
depot_en_banque: -703185453254164741 |
|||
destruction_de_billets_mlc: -2288452522088579333 |
|||
destruction_mlc_numeriques: -1784049363823083781 |
|||
entree_coffre: -2000222145936867589 |
|||
entree_stock_bdc: -1928164551898939653 |
|||
gain_de_billets: -1279646205557588229 |
|||
impression_de_billets_mlc: -2072279739974795525 |
|||
paiement_de_banque_de_depot_vers_caisse_euro_bdc: -847300641330020613 |
|||
paiement_de_caisse_euro_bdc_vers_banque_de_depot: -775243047292092677 |
|||
paiement_par_carte: -3873719590922993925 |
|||
paiement_par_sms: -4234007561112633605 |
|||
perte_de_billets: -1639934175747227909 |
|||
reconversion_billets_versement_des_mlcs: -1351703799595516165 |
|||
reconversion_numerique: -4378122749188489477 |
|||
regularisation_depot_excessif: -414955077102452997 |
|||
regularisation_depot_insuffisant: -631127859216236805 |
|||
remise_d_euro_en_caisse: -342897483064525061 |
|||
retrait_de_billets: -4161949967074705669 |
|||
retrait_du_compte: -4089892373036777733 |
|||
sortie_caisse_mlc_bdc: -1495818987671372037 |
|||
sortie_coffre: -2216394928050651397 |
|||
sortie_retours_mlc_bdc: -1711991769785155845 |
|||
sortie_stock_bdc: -1567876581709299973 |
|||
vente_en_euro: -1135531017481732357 |
|||
vente_en_mlc: -1063473423443804421 |
|||
virement_de_banque_de_depot_vers_compte_debit_euro: -559070265178308869 |
|||
virement_de_banque_de_depot_vers_compte_dedie: -487012671140380933 |
|||
virement_de_compte_dedie_vers_compte_debit_euro: -126724700950741253 |
|||
virement_entre_comptes_dedies: -54667106912813317 |
|||
virement_inter_adherent: -4306065155150561541 |
|||
products: |
|||
foulard: -2000222145936867589 |
|||
tokens: |
|||
carte_nfc: -1784049363823083781 |
|||
transaction_custom_fields: |
|||
adherent: -2216394928050651397 |
|||
adherent_facultatif: -1856106957861011717 |
|||
bdc: -2072279739974795525 |
|||
mode_de_paiement: -1784049363823083781 |
|||
montant_changes_billet: -1711991769785155845 |
|||
montant_changes_numerique: -1639934175747227909 |
|||
montant_cotisations: -1567876581709299973 |
|||
montant_ventes: -1495818987671372037 |
|||
numero_de_bordereau: -1928164551898939653 |
|||
numero_de_facture: -1207588611519660293 |
|||
numero_de_transaction_banque: -1279646205557588229 |
|||
porteur: -2288452522088579333 |
|||
produit: -2000222145936867589 |
|||
transfer_status_flows: |
|||
rapprochement: -2072279739974795525 |
|||
remise_a_l_assocation: -2288452522088579333 |
|||
virements: -2216394928050651397 |
|||
transfer_statuses: |
|||
a_rapprocher: -2288452522088579333 |
|||
a_remettre_a_l_assocation: -1856106957861011717 |
|||
rapproche: -2072279739974795525 |
|||
remis_a_l_assocation: -2216394928050651397 |
|||
virements_a_faire: -2000222145936867589 |
|||
virements_faits: -1784049363823083781 |
|||
user_custom_fields: |
|||
bdc: -2072279739974795525 |
|||
users: |
|||
compte_dedie_mlc_billet: -2288452522088579333 |
|||
compte_dedie_mlc_numerique: -2216394928050651397 |
245786
src/etc/cyclos/dump/cyclos.sql
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
245786
src/etc/cyclos/dump/cyclos_test.sql
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,460 @@ |
|||
# coding: utf-8 |
|||
from __future__ import unicode_literals |
|||
|
|||
import os |
|||
import argparse |
|||
import base64 |
|||
import logging |
|||
|
|||
import requests |
|||
import yaml # PyYAML |
|||
from datetime import datetime |
|||
from datetime import timedelta |
|||
|
|||
logging.basicConfig() |
|||
logger = logging.getLogger(__name__) |
|||
|
|||
|
|||
def check_request_status(r): |
|||
if r.status_code == requests.codes.ok: |
|||
logger.info('OK') |
|||
else: |
|||
logger.error(r.text) |
|||
r.raise_for_status() |
|||
|
|||
# Ensemble des constantes nécessaires au fonctionnement du script. |
|||
ENV = os.environ.get('ENV') |
|||
|
|||
LOCAL_CURRENCY_INTERNAL_NAME = os.environ.get('CURRENCY_SLUG') |
|||
NETWORK_INTERNAL_NAME = LOCAL_CURRENCY_INTERNAL_NAME |
|||
|
|||
if ENV != 'prod': |
|||
NETWORK_INTERNAL_NAME = ENV + LOCAL_CURRENCY_INTERNAL_NAME |
|||
|
|||
LOCAL_CURRENCY_SYMBOL = os.environ.get('CURRENCY_SYMBOL') |
|||
|
|||
# Arguments à fournir dans la ligne de commande |
|||
parser = argparse.ArgumentParser() |
|||
parser.add_argument('url', help='URL of Cyclos') |
|||
parser.add_argument('authorization', |
|||
help='string to use for Basic Authentication') |
|||
parser.add_argument('--debug', |
|||
help='enable debug messages', |
|||
action='store_true') |
|||
args = parser.parse_args() |
|||
|
|||
if not args.url.endswith('/'): |
|||
args.url = args.url + '/' |
|||
if args.debug: |
|||
logger.setLevel(logging.DEBUG) |
|||
else: |
|||
logger.setLevel(logging.INFO) |
|||
|
|||
for k, v in vars(args).items(): |
|||
logger.debug('args.%s = %s', k, v) |
|||
|
|||
# URLs des web services |
|||
global_web_services = args.url + 'global/web-rpc/' |
|||
network_web_services = args.url + '/' + NETWORK_INTERNAL_NAME + '/web-rpc/' |
|||
|
|||
# En-têtes pour toutes les requêtes (il n'y a qu'un en-tête, pour |
|||
# l'authentification). |
|||
headers = {'Authorization': 'Basic ' + args.authorization} |
|||
|
|||
# On fait une 1ère requête en lecture seule uniquement pour vérifier |
|||
# si les paramètres fournis sont corrects. |
|||
logger.info('Vérification des paramètres fournis...') |
|||
r = requests.post(global_web_services + 'network/search', |
|||
headers=headers, json={}) |
|||
check_request_status(r) |
|||
|
|||
|
|||
######################################################################## |
|||
# Création des utilisateurs pour les banques de dépôt et les comptes |
|||
# dédiés. |
|||
# |
|||
def create_user(group, name, login, email=None, password=None,city=None, custom_values=None): |
|||
logger.info('Création de l\'utilisateur "%s" (groupe "%s")...', name, group) |
|||
# FIXME code à déplacer pour ne pas l'exécuter à chaque fois |
|||
r = requests.post(network_web_services + 'group/search', |
|||
headers=headers, json={}) |
|||
check_request_status(r) |
|||
groups = r.json()['result']['pageItems'] |
|||
for g in groups: |
|||
if g['name'] == group: |
|||
group_id = g['id'] |
|||
if not city: |
|||
city = 'Grenoble' |
|||
user_registration = { |
|||
'group': group_id, |
|||
'name': name, |
|||
'username': login, |
|||
'skipActivationEmail': True, |
|||
'addresses':[ |
|||
{ |
|||
'name': 'work', |
|||
'addressLine1': '10 rue du test', |
|||
'city': city, |
|||
'defaultAddress': True, |
|||
'hidden': False |
|||
} |
|||
] |
|||
} |
|||
if email: |
|||
user_registration['email'] = email |
|||
if password: |
|||
user_registration['passwords'] = [ |
|||
{ |
|||
'type': 'login', |
|||
'value': password, |
|||
'confirmationValue': password, |
|||
'assign': True, |
|||
'forceChange': False, |
|||
}, |
|||
] |
|||
if custom_values: |
|||
user_registration['customValues'] = [] |
|||
for field_id, value in custom_values.items(): |
|||
r = requests.get(network_web_services + 'userCustomField/load/' + field_id, headers=headers) |
|||
check_request_status(r) |
|||
custom_field_type = r.json()['result']['type'] |
|||
if custom_field_type == 'LINKED_ENTITY': |
|||
value_key = 'linkedEntityValue' |
|||
user_registration['customValues'].append({ |
|||
'field': field_id, |
|||
value_key: value, |
|||
}) |
|||
logger.debug('create_user : json = %s', user_registration) |
|||
r = requests.post(network_web_services + 'user/register', |
|||
headers=headers, |
|||
json=user_registration) |
|||
check_request_status(r) |
|||
logger.debug('result = %s', r.json()['result']) |
|||
user_id = r.json()['result']['user']['id'] |
|||
logger.debug('user_id = %s', user_id) |
|||
return user_id |
|||
|
|||
create_user( |
|||
group='Network administrators', |
|||
name= 'Administrator', |
|||
login= 'admin_network', |
|||
email= 'administrator@localhost.fr', |
|||
password= '@@bbccdd' #@WARNING : nécessité d'avoir ce mot de passe pour les tests appli CEL du Cairn |
|||
) |
|||
|
|||
create_user( |
|||
group='Banques de dépôt', |
|||
name='Banque de dépôt 1', |
|||
login='BDP1', |
|||
) |
|||
create_user( |
|||
group='Banques de dépôt', |
|||
name='Banque de dépôt 2', |
|||
login='BDP2', |
|||
) |
|||
|
|||
|
|||
######################################################################## |
|||
# Création des utilisateurs pour les tests. |
|||
if ENV != 'prod': |
|||
# On récupère l'id du champ perso 'BDC'. |
|||
r = requests.get(network_web_services + 'userCustomField/list', headers=headers) |
|||
check_request_status(r) |
|||
user_custom_fields = r.json()['result'] |
|||
for field in user_custom_fields: |
|||
if field['internalName'] == 'bdc': |
|||
id_user_custom_field_bdc = field['id'] |
|||
|
|||
gestion_interne = { |
|||
'demo': 'Demo', |
|||
'demo2': 'Demo2', |
|||
} |
|||
for login, name in gestion_interne.items(): |
|||
create_user( |
|||
group='Gestion interne', |
|||
name=name, |
|||
login=login, |
|||
password=login, |
|||
) |
|||
|
|||
bureaux_de_change = { |
|||
'B000': 'Association Monnaie Locale', |
|||
'B001': 'Bureau de change 1', |
|||
'B002': 'Bureau de change 2', |
|||
} |
|||
for login, name in bureaux_de_change.items(): |
|||
id_bdc = create_user( |
|||
group='Bureaux de change', |
|||
name=name + ' (BDC)', |
|||
login=login + '_BDC', |
|||
password=login, |
|||
) |
|||
create_user( |
|||
group='Opérateurs BDC', |
|||
name=name, |
|||
login=login, |
|||
password=login, |
|||
custom_values={ |
|||
id_user_custom_field_bdc: id_bdc, |
|||
} |
|||
) |
|||
|
|||
create_user( |
|||
group='Anonyme', |
|||
name='Anonyme', |
|||
login='anonyme', |
|||
password='anonyme', |
|||
) |
|||
|
|||
adherents_utilisateurs = [ |
|||
['gjanssens', 'Janssens Gaetan'], |
|||
['cretine_agnes', 'Créttine Agnès'], |
|||
['alberto_malik', 'Malik Alberto'], |
|||
['noire_aliss', 'La noire Aliss'], |
|||
['tous_andre', 'Tous Ensemble André'], |
|||
['speedy_andrew', 'Speedy Andrew'], |
|||
['stuart_andrew', 'Stuart Andrew'], |
|||
['crabe_arnold', 'Le Crabe Arnold'], |
|||
['barbare_cohen', 'le Barbare Cohen'], |
|||
['lacreuse_desiderata', 'Lacreuse Desiderata'], |
|||
['comblant_michel', 'Comblant Michel'], |
|||
['nico_faus_perso', 'Le Caméléon Nicolas'], |
|||
['benoit_perso', 'Le Rigolo Benoît'], |
|||
] |
|||
|
|||
adherents_prestataires = [ |
|||
['asso_mlc', 'Association Monnaie Locale','Grenoble'], |
|||
['maltobar', 'MaltOBar','Grenoble'], |
|||
['labonnepioche', 'La Bonne Pioche','Grenoble'], |
|||
['DrDBrew', 'DocteurD Brew Pub','Grenoble'], |
|||
['apogee_du_vin', 'Apogée du vin','Grenoble'], |
|||
['tout_1_fromage', 'Tout un fromage','Grenoble'], |
|||
['vie_integrative', 'vie intégrative','Voiron'], |
|||
['denis_ketels', 'Denis Ketels','Voiron'], #used only for changePassword test |
|||
['nico_faus_prod', 'Nico Faus Production','Grenoble'], |
|||
['hirundo_archi', 'Hirundo Architecture','Villard-de-Lans'], |
|||
['maison_bambous', 'Maison aux Bambous','Vinay'], |
|||
['recycleco', 'Recycleco','Saint-Marcellin'], |
|||
['elotine_photo', 'Elotine Photo','Grenoble'], |
|||
['boule_antan', 'La Boule d Antan','Villard-de-Lans'], |
|||
['la_remise', 'La Remise','Grenoble'], |
|||
['episol', 'Episol','Grenoble'], |
|||
['alter_mag', 'Alter Mag','Saint-Marcellin'], |
|||
['verre_a_soi', 'Le Verre à soi','Bilieu'], |
|||
['FluoDelik', 'Fluodélik','Méaudre'], |
|||
['1001_saveurs', '1001 Saveurs','Villard-de-Lans'], |
|||
['belle_verte', 'La Belle Verte','Susville'], |
|||
['kheops_boutique', 'Khéops boutique','Saint-Marcellin'], |
|||
['ferme_bressot', 'La ferme du Bressot','Beaulieu'], |
|||
['atelier_eltilo', 'Atelier Eltilo','Grenoble'], |
|||
['la_belle_verte', 'Belle Verte Permaculture','Sillans'], |
|||
['mon_vrac', 'Mon Vrac','Voiron'], |
|||
['le_marque_page', 'Le Marque Page','Saint-Marcellin'], |
|||
['boutik_creative', 'La Boutik Creative','Rives'], |
|||
['pain_beauvoir', 'Le Pain de Beauvoir','Beauvoir-en-Royans'], |
|||
['la_mandragore', 'La Mandragore','Grenoble'], |
|||
['jardins_epices', 'Les jardins epicés tout','Herbeys'], |
|||
['lib_colibri', 'Librairie Colibri','Voiron'], |
|||
['Claire_Dode', 'La Vie Claire Dode','Voiron'], |
|||
['fil_chantant', 'Le Fil qui Chante','Voiron'], |
|||
['epicerie_sol', 'Epicerie Solidaire Amandine','Voiron'], |
|||
['NaturaVie', 'Naturavie','Voiron'], |
|||
['montagne_arts', 'Les montagnarts','Valbonnais'], |
|||
['Biocoop', 'Biocoop','Chatte'], |
|||
['Alpes_EcoTour', 'Alpes Ecotourisme','Grenoble'], |
|||
['trankilou', 'Le Trankilou','Grenoble'] |
|||
] |
|||
|
|||
groupes_locaux = [ |
|||
['gl_grenoble', 'Groupe Local Grenoble','Grenoble'], |
|||
['gl_voiron', 'Groupe Local Voiron','Voiron'], |
|||
['gl_tullins', 'Groupe Local Tullins','Tullins'], |
|||
] |
|||
|
|||
for member in adherents_utilisateurs: |
|||
create_user( |
|||
group='Adhérents utilisateurs', |
|||
name=member[1], |
|||
login=member[0], |
|||
email = member[0] + '@test.fr', |
|||
password = '@@bbccdd', |
|||
) |
|||
|
|||
create_user( |
|||
group='Adhérents utilisateurs', |
|||
name='Max Maz', |
|||
login='mazmax', |
|||
email = 'maxime.mazouth-laurol@cairn-monnaie.com', |
|||
password = '@@bbccdd', |
|||
) |
|||
|
|||
for member in adherents_prestataires: |
|||
create_user( |
|||
group='Adhérents prestataires', |
|||
name=member[1], |
|||
login=member[0], |
|||
email = member[0] + '@test.fr', |
|||
city = member[2], |
|||
password = '@@bbccdd', |
|||
) |
|||
|
|||
for member in groupes_locaux: |
|||
create_user( |
|||
group='Network administrators', |
|||
name=member[1], |
|||
login=member[0], |
|||
email = member[0] + '@test.fr', |
|||
city = member[2], |
|||
password = '@@bbccdd', |
|||
) |
|||
|
|||
porteurs = { |
|||
'P001': 'Porteur 1', |
|||
'P002': 'Porteur 2', |
|||
'P003': 'Porteur 3', |
|||
'P004': 'Porteur 4', |
|||
} |
|||
for login, name in porteurs.items(): |
|||
create_user( |
|||
group='Porteurs', |
|||
name=name, |
|||
login=login, |
|||
) |
|||
|
|||
# Récupération des constantes |
|||
|
|||
logger.info('Récupération des constantes depuis le YAML...') |
|||
CYCLOS_CONSTANTS = None |
|||
with open("/cyclos/cyclos_constants_"+ENV+".yml", 'r') as cyclos_stream: |
|||
try: |
|||
CYCLOS_CONSTANTS = yaml.load(cyclos_stream) |
|||
except yaml.YAMLError as exc: |
|||
assert False, exc |
|||
|
|||
# Impression billets mlc |
|||
logger.info('Impression billets '+ LOCAL_CURRENCY_INTERNAL_NAME +'...') |
|||
logger.debug(str(CYCLOS_CONSTANTS['payment_types']['impression_de_billets_mlc']) + "\r\n" + |
|||
str(CYCLOS_CONSTANTS['currencies']['mlc']) + "\r\n" + |
|||
str(CYCLOS_CONSTANTS['account_types']['compte_de_debit_mlc_billet']) + "\r\n" + |
|||
str(CYCLOS_CONSTANTS['account_types']['stock_de_billets'])) |
|||
|
|||
|
|||
r = requests.post(network_web_services + 'payment/perform', |
|||
headers={'Authorization': 'Basic {}'.format(base64.standard_b64encode(b'demo:demo').decode('utf-8'))}, # noqa |
|||
json={ |
|||
'type': CYCLOS_CONSTANTS['payment_types']['impression_de_billets_mlc'], |
|||
'amount': 126500, |
|||
'currency': CYCLOS_CONSTANTS['currencies']['mlc'], |
|||
'from': 'SYSTEM', |
|||
'to': 'SYSTEM', |
|||
}) |
|||
|
|||
logger.info('Impression billets ' + LOCAL_CURRENCY_INTERNAL_NAME + '... Terminé !') |
|||
logger.debug(r.json()) |
|||
|
|||
#@WARNING : specifique au cairn, à supprimer dans le rendu au mvt Sol |
|||
today = datetime.now() |
|||
|
|||
def date_modify(nb_days): |
|||
today = datetime.now() |
|||
date = today + timedelta(days=nb_days) |
|||
return date.strftime("%Y")+ '-' + date.strftime("%m")+'-'+date.strftime("%d") |
|||
|
|||
|
|||
def credit_numeric_money_safe(amount): |
|||
logger.info('Creation de MLC numeriques ...') |
|||
r = requests.post(network_web_services + 'payment/perform', |
|||
headers={'Authorization': 'Basic {}'.format(base64.standard_b64encode(b'admin_network:@@bbccdd').decode('utf-8'))}, |
|||
json={ |
|||
'type': CYCLOS_CONSTANTS['payment_types']['creation_mlc_numeriques'], |
|||
'amount': amount, |
|||
'currency': CYCLOS_CONSTANTS['currencies']['mlc'], |
|||
'from': 'SYSTEM', |
|||
'to': 'SYSTEM', |
|||
'description': 'creation initiale de ' + LOCAL_CURRENCY_INTERNAL_NAME , |
|||
}) |
|||
logger.info('Creation de MLC numeriques... Terminé !') |
|||
logger.debug(r.json()) |
|||
|
|||
def credit_de_compte(member,amount): |
|||
logger.info('Change numérique pour ' + member[1] + ' ...') |
|||
r = requests.post(network_web_services + 'payment/perform', |
|||
headers={'Authorization': 'Basic {}'.format(base64.standard_b64encode(b'admin_network:@@bbccdd').decode('utf-8'))}, |
|||
json={ |
|||
'type': CYCLOS_CONSTANTS['payment_types']['credit_du_compte'], |
|||
'amount': amount, |
|||
'currency': CYCLOS_CONSTANTS['currencies']['mlc'], |
|||
'from': 'SYSTEM', |
|||
'to': member[0], |
|||
'description': 'dépôt ' + LOCAL_CURRENCY_INTERNAL_NAME , |
|||
'customValues': [ |
|||
{ |
|||
'field': str(CYCLOS_CONSTANTS['transaction_custom_fields']['bdc']), |
|||
'linkedEntityValue': id_bdc # ID de l'utilisateur Bureau de change |
|||
}, |
|||
] |
|||
}) |
|||
logger.info('Change numérique pour ' + member[1] + '... Terminé !') |
|||
logger.debug(r.json()) |
|||
|
|||
def payment_inter_adherent(debitor, creditor, amount, offset): |
|||
logger.info('Virement de ' + str(amount) + ' ' + LOCAL_CURRENCY_INTERNAL_NAME + ' ' + debitor + ' vers ' + creditor + ' ...') |
|||
|
|||
if offset == 0: |
|||
cyclos_method = 'payment/perform' |
|||
else: |
|||
cyclos_method = 'scheduledPayment/perform' |
|||
|
|||
r = requests.post(network_web_services + cyclos_method, |
|||
headers={'Authorization': 'Basic {}'.format(base64.standard_b64encode(b'admin_network:@@bbccdd').decode('utf-8'))}, |
|||
json={ |
|||
'type': CYCLOS_CONSTANTS['payment_types']['virement_inter_adherent'], |
|||
'amount': amount, |
|||
'currency': CYCLOS_CONSTANTS['currencies']['mlc'], |
|||
'description': 'virement ' + LOCAL_CURRENCY_INTERNAL_NAME , |
|||
'firstInstallmentDate': date_modify(offset), |
|||
'installmentsCount': 1, |
|||
'from': debitor, |
|||
'to': creditor, |
|||
}) |
|||
logger.info('Virement de ' + str(amount) + ' ' + LOCAL_CURRENCY_INTERNAL_NAME + ' ' + debitor + ' vers ' + creditor + ' ... Terminé !') |
|||
logger.debug(r.json()) |
|||
|
|||
#Creation initiale de MLC numeriques |
|||
credit_numeric_money_safe(10000000000) |
|||
|
|||
# Changes numériques afin d'avoir des comptes avec des soldes non nuls + des opérations à injecter dans l'appli CEL |
|||
logger.info('Changes numériques en '+ LOCAL_CURRENCY_INTERNAL_NAME +' pour tous les pros à Grenoble...') |
|||
logger.debug(str(CYCLOS_CONSTANTS['payment_types']['credit_du_compte']) + "\r\n" + |
|||
str(CYCLOS_CONSTANTS['account_types']['compte_de_debit_mlc_numerique']) + "\r\n" + |
|||
str(CYCLOS_CONSTANTS['account_types']['compte_d_adherent'])) |
|||
|
|||
initial_credit = 1000 |
|||
|
|||
for pro in adherents_prestataires: |
|||
if pro[2] == 'Grenoble': |
|||
credit_de_compte(pro, initial_credit) |
|||
|
|||
for person in adherents_utilisateurs: |
|||
credit_de_compte(person, initial_credit) |
|||
|
|||
logger.info('Changes numériques en ' + LOCAL_CURRENCY_INTERNAL_NAME + '... Terminé !') |
|||
|
|||
logger.info('Virements immédiats de compte à compte en '+ LOCAL_CURRENCY_INTERNAL_NAME +' ...') |
|||
|
|||
#trankilou has null account again |
|||
logger.info('"Le Trankilou" réalise un virement vers "la Remise" remettant son solde à 0') |
|||
payment_inter_adherent('trankilou','la_remise',initial_credit,0) |
|||
|
|||
# for i in range(0,10): |
|||
# payment_inter_adherent('DrDBrew','apogee_du_vin',10,0) |
|||
|
|||
logger.info('Virements immédiats de compte à compte en '+ LOCAL_CURRENCY_INTERNAL_NAME +'... Terminé !') |
|||
|
|||
logger.info('Virements programmés en '+ LOCAL_CURRENCY_INTERNAL_NAME +' de La Bonne Pioche vers AlterMag...') |
|||
for i in range(0,5): |
|||
payment_inter_adherent('labonnepioche','alter_mag',10,2) |
|||
|
|||
logger.info('Virements programmés en '+ LOCAL_CURRENCY_INTERNAL_NAME +' ... Terminé !!') |
|||
|
|||
logger.info('Fin du script !') |
@ -0,0 +1,120 @@ |
|||
begin; |
|||
create table del_users as select id from users where user_group_id in (select id from groups where name <> 'Global administrators' and network_id in (select id from networks where internal_name like :network)); |
|||
create table del_transactions as select id from transactions where (by_id in (select id from del_users) or from_user_id in (select id from del_users) or to_user_id in (select id from del_users)); |
|||
create table del_transfers as select id from transfers where (transaction_id in (select id from del_transactions)); |
|||
|
|||
create table del_accounts as select id from accounts where user_id in (select id from del_users); |
|||
update users set registered_by_id = null where registered_by_id in (select id from del_users); |
|||
update transactions set transaction_id = null, original_transfer_id = null, last_occurrence_success_id = null, last_occurrence_failure_id = null, feedback_id = null, access_client_id = null where id in (select id from del_transactions) ; |
|||
delete from amount_reservations; |
|||
delete from vouchers; |
|||
delete from voucher_packs; |
|||
delete from transfer_status_logs; |
|||
delete from transfers_transfer_status_flows; |
|||
delete from failed_payment_occurrences where transfer_id in (select id from del_transfers); |
|||
delete from account_balances where transfer_id in (select id from del_transfers); |
|||
delete from transfers where id in (select id from del_transfers); |
|||
delete from transaction_enum_values; |
|||
delete from stored_files where transaction_value_id is not null; |
|||
delete from transaction_custom_field_values; |
|||
delete from scheduled_payment_installments where id in (select scheduled_payment_installment_id from transfers where id in (select id from del_transfers)); |
|||
delete from scheduled_payment_installments where scheduled_payment_id in (select id from del_transactions); |
|||
delete from failed_payment_occurrences where recurring_payment_id in (select id from del_transactions); |
|||
delete from transaction_authorizations; |
|||
delete from refs; |
|||
delete from transactions where id in (select id from del_transactions); |
|||
delete from access_client_logs where access_client_id in (select id from access_clients where user_id in (select id from del_users)); |
|||
delete from access_clients where user_id in (select id from del_users); |
|||
delete from user_account_fee_logs; |
|||
delete from closed_account_balances where account_id in (select id from del_accounts); |
|||
delete from account_limit_logs where account_id in (select id from del_accounts); |
|||
update accounts set account_rates_id = null where id in (select id from del_accounts) ; |
|||
delete from account_rates where account_id in (select id from del_accounts); |
|||
delete from accounts where id in (select id from del_accounts); |
|||
delete from webshop_ads_delivery_methods; |
|||
delete from ad_delivery_methods; |
|||
delete from ad_history_logs; |
|||
delete from ads_categories; |
|||
delete from ad_order_products; |
|||
delete from notified_ad_interests; |
|||
delete from ads_addresses; |
|||
update ads set image_id = null; |
|||
delete from stored_files where ad_id is not null; |
|||
delete from ad_enum_values; |
|||
delete from ad_custom_field_values; |
|||
delete from ad_questions; |
|||
delete from ad_order_logs; |
|||
delete from stored_files where contact_info_id is not null; |
|||
delete from contact_infos; |
|||
update addresses set ad_order_id =null; |
|||
delete from ad_orders; |
|||
delete from ad_web_shop_settings; |
|||
delete from ad_interests; |
|||
delete from addresses; |
|||
delete from ads; |
|||
delete from phones; |
|||
delete from entity_property_logs; |
|||
delete from entity_logs; |
|||
update users set image_id = null; |
|||
delete from stored_files where user_id is not null; |
|||
delete from agreement_logs; |
|||
delete from passwords where user_id in (select id from del_users); |
|||
delete from brokering_logs; |
|||
delete from brokerings; |
|||
delete from login_history_logs where user_id in (select id from del_users); |
|||
delete from bulk_actions_users; |
|||
delete from user_enum_values; |
|||
delete from stored_files where user_value_id is not null; |
|||
delete from user_custom_field_values; |
|||
delete from notification_type_settings where subclass = 'USER'; |
|||
delete from notification_settings where subclass = 'USER'; |
|||
delete from notifications where user_id in (select id from del_users); |
|||
delete from operator_group_logs; |
|||
delete from operator_groups_restrict_payments_users; |
|||
delete from operator_groups_custom_operations; |
|||
delete from operator_groups_record_types; |
|||
delete from operator_groups_account_types; |
|||
delete from operator_groups_payment_types; |
|||
update users set operator_group_id = null; |
|||
delete from operator_groups; |
|||
delete from outbound_sms; |
|||
delete from inbound_sms; |
|||
delete from stored_files where record_value_id is not null; |
|||
delete from record_enum_values where owner_id in (select id from record_custom_field_values where owner_id in (select id from records where user_id in (select id from del_users))); |
|||
delete from record_custom_field_values where owner_id in (select id from records where user_id in (select id from del_users)); |
|||
delete from records where user_id in (select id from del_users); |
|||
delete from user_group_logs where user_id in (select id from del_users); |
|||
update user_status_logs set by_id = null where by_id in (select id from del_users); |
|||
delete from user_status_logs where user_id in (select id from del_users); |
|||
update users set operator_user_id = null; |
|||
delete from user_activities where user_id in (select id from del_users); |
|||
delete from user_regional_settings where user_id in (select id from del_users); |
|||
delete from contacts where owner_id in (select id from del_users); |
|||
delete from contacts where contact_id in (select id from del_users); |
|||
delete from alerts where user_id in (select id from del_users); |
|||
delete from failed_action_logs where user_id in (select id from del_users); |
|||
delete from tokens where user_id in (select id from del_users); |
|||
delete from user_channels where user_id in (select id from del_users); |
|||
delete from users_products_logs where user_id in (select id from del_users); |
|||
delete from users_products where user_id in (select id from del_users); |
|||
delete from messages_to_groups; |
|||
delete from messages_to_users; |
|||
delete from messages; |
|||
delete from mailing_lists_to_groups; |
|||
delete from mailing_lists_to_users; |
|||
delete from mailings; |
|||
delete from mailing_lists; |
|||
delete from notifications where related_user_id is not null; |
|||
delete from reference_history; |
|||
delete from users_dashboard_actions; |
|||
delete from documents where user_id in (select id from del_users); |
|||
delete from error_logs; |
|||
delete from users_ignore_feedbacks; |
|||
delete from sessions where user_id in (select id from del_users); |
|||
delete from user_registration_account_configuration where user_id in (select id from del_users); |
|||
delete from users where id in (select id from del_users); |
|||
drop table del_users; |
|||
drop table del_transfers; |
|||
drop table del_transactions; |
|||
drop table del_accounts; |
|||
commit; |
@ -0,0 +1,90 @@ |
|||
// TRANSACTION |
|||
import static groovyx.net.http.ContentType.* |
|||
import static groovyx.net.http.Method.* |
|||
import groovyx.net.http.HTTPBuilder |
|||
|
|||
import java.util.concurrent.CountDownLatch |
|||
|
|||
import org.cyclos.model.ValidationException |
|||
|
|||
import org.cyclos.entities.banking.ScheduledPayment |
|||
import org.cyclos.entities.banking.RecurringPayment |
|||
import org.cyclos.model.banking.transactions.RecurringPaymentStatus |
|||
import org.cyclos.model.banking.transactions.RecurringPaymentOccurrenceStatus |
|||
import org.cyclos.model.banking.transactions.ScheduledPaymentInstallmentStatus |
|||
|
|||
def url = '' |
|||
def jsonBody = [] |
|||
|
|||
def tx = scriptHelper.wrap(transaction) |
|||
|
|||
if (! ((transaction instanceof RecurringPayment) | (transaction instanceof ScheduledPayment)) ){ |
|||
return |
|||
} |
|||
|
|||
def sendWarning = false |
|||
if( transaction instanceof RecurringPayment ){ |
|||
if(tx.status != RecurringPaymentStatus.CANCELED){ |
|||
if( tx.lastOccurrence.status == RecurringPaymentOccurrenceStatus.FAILED){ |
|||
sendWarning = true |
|||
url = 'http://172.18.0.2:8000/operations/sync/recurring' |
|||
jsonBody = [ |
|||
paymentID: maskId(tx.lastOccurrence.transferId), //will be null |
|||
transactionID: maskId(tx.id), |
|||
amount: tx.amount, |
|||
description: tx.description, |
|||
status: tx.lastOccurrence.status |
|||
] |
|||
} |
|||
} |
|||
} else { // scheduled payment |
|||
if( tx.firstInstallment.status == ScheduledPaymentInstallmentStatus.FAILED){ |
|||
sendWarning = true |
|||
url = 'http://172.18.0.2:8000/operations/sync/scheduled' |
|||
jsonBody = [ |
|||
paymentID: maskId(tx.firstInstallment.transferId), //will be null |
|||
transactionID: maskId(tx.id), |
|||
amount: tx.amount, |
|||
description: tx.description, |
|||
status: tx.firstInstallment.status |
|||
] |
|||
|
|||
} |
|||
} |
|||
|
|||
|
|||
if (sendWarning == true){ |
|||
// Send the POST request |
|||
def http = new HTTPBuilder(url) |
|||
http.headers["Content-Type"] = "application/json; charset=UTF-8" |
|||
def responseJson = null |
|||
def responseError = [] |
|||
|
|||
scriptHelper.addOnCommit { |
|||
CountDownLatch latch = new CountDownLatch(1) |
|||
def error = false |
|||
http.request(POST, JSON) { |
|||
body = jsonBody |
|||
|
|||
response.success = { resp, json -> |
|||
responseJson = json |
|||
latch.countDown() |
|||
} |
|||
response.failure = { resp -> |
|||
responseError << resp.statusLine.statusCode |
|||
responseError << resp.statusLine.reasonPhrase |
|||
latch.countDown() |
|||
} |
|||
} |
|||
//Await for the response |
|||
latch.await() |
|||
if (!responseError.empty) { |
|||
throw new RuntimeException("Error making Cyclos sync to ${url}" |
|||
+ ", got error code ${responseError[0]}: ${responseError[1]}") |
|||
} |
|||
return responseJson |
|||
} |
|||
} else { |
|||
return |
|||
} |
|||
|
@ -0,0 +1,80 @@ |
|||
// TRANSFER |
|||
import static groovyx.net.http.ContentType.* |
|||
import static groovyx.net.http.Method.* |
|||
import groovyx.net.http.HTTPBuilder |
|||
|
|||
import java.util.concurrent.CountDownLatch |
|||
|
|||
import org.cyclos.model.ValidationException |
|||
|
|||
import org.cyclos.entities.banking.RecurringPaymentTransfer |
|||
import org.cyclos.entities.banking.ScheduledPaymentInstallmentTransfer |
|||
import org.cyclos.entities.banking.FailedPaymentOccurrence |
|||
|
|||
def url = '' |
|||
def jsonBody = [] |
|||
|
|||
def tf = scriptHelper.wrap(transfer) |
|||
|
|||
if (! ((transfer instanceof RecurringPaymentTransfer) | (transfer instanceof ScheduledPaymentInstallmentTransfer) | (transfer instanceof FailedPaymentOccurrence)) ){ |
|||
return |
|||
} |
|||
|
|||
|
|||
|
|||
if( (transfer instanceof RecurringPaymentTransfer) | (transfer instanceof FailedPaymentOccurrence) ){ |
|||
url = 'http://front:8000/operations/sync/recurring' |
|||
jsonBody = [ |
|||
paymentID: maskId(tf.transferId), |
|||
transactionID: maskId(tf.recurringPayment.id), |
|||
amount: tf.amount, |
|||
description: tf.recurringPayment.description, |
|||
fromAccountNumber: tf.from.number, |
|||
toAccountNumber: tf.to.number, |
|||
status: tf.status |
|||
] |
|||
|
|||
} else { |
|||
url = 'http://front:8000/operations/sync/scheduled' |
|||
jsonBody = [ |
|||
paymentID: maskId(tf.installment.transferId), |
|||
transactionID: maskId(tf.transactionId), |
|||
amount: tf.amount, |
|||
description: tf.transaction.description, |
|||
fromAccountNumber: tf.from.number, |
|||
toAccountNumber: tf.to.number, |
|||
status: tf.installment.status |
|||
] |
|||
} |
|||
|
|||
|
|||
// Send the POST request |
|||
def http = new HTTPBuilder(url) |
|||
http.headers["Content-Type"] = "application/json; charset=UTF-8" |
|||
def responseJson = null |
|||
def responseError = [] |
|||
|
|||
scriptHelper.addOnCommit { |
|||
CountDownLatch latch = new CountDownLatch(1) |
|||
def error = false |
|||
http.request(POST, JSON) { |
|||
body = jsonBody |
|||
|
|||
response.success = { resp, json -> |
|||
responseJson = json |
|||
latch.countDown() |
|||
} |
|||
response.failure = { resp -> |
|||
responseError << resp.statusLine.statusCode |
|||
responseError << resp.statusLine.reasonPhrase |
|||
latch.countDown() |
|||
} |
|||
} |
|||
//Await for the response |
|||
latch.await() |
|||
if (!responseError.empty) { |
|||
throw new RuntimeException("Error making Cyclos sync to ${url}" |
|||
+ ", got error code ${responseError[0]}: ${responseError[1]}") |
|||
} |
|||
return responseJson |
|||
} |
2878
src/etc/cyclos/setup.py
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,43 @@ |
|||
#!/bin/bash |
|||
set -e |
|||
|
|||
WORKDIR=$(pwd) |
|||
|
|||
cd /cyclos |
|||
|
|||
|
|||
until [ `curl --silent --write-out '%{response_code}' -o /dev/null http://cyclos-app:8080/global/` -eq 200 ]; |
|||
do |
|||
echo '--- waiting for Cyclos to be fully up (10 seconds)' |
|||
sleep 10 |
|||
done |
|||
|
|||
if [ ! -f ./cyclos_constants_$ENV.yml ]; then |
|||
read -p "Global Admin Login?" login |
|||
read -p "Global Admin password?" password |
|||
|
|||
PASS=`echo -n $login:$password | base64` |
|||
|
|||
python3 setup.py http://cyclos-app:8080/ $PASS |
|||
sleep 5 |
|||
python3 init_test_data.py http://cyclos-app:8080/ $PASS |
|||
fi |
|||
|
|||
cd ${WORKDIR} |
|||
|
|||
exec "$@" |
|||
|
|||
|
|||
# This is how I launch this script (in dev): |
|||
# docker-compose exec api bash /cyclos/setup_cyclos.sh |
|||
|
|||
# This cd will do this: cd /cyclos/ |
|||
#~ cd "${0%/*}" |
|||
#~ |
|||
#~ echo $PWD |
|||
#~ |
|||
#~ rm -f cyclos_constants.yml |
|||
#~ |
|||
#~ # Base64('admin:admin') = YWRtaW46YWRtaW4= |
|||
#~ python setup.py http://cyclos-app:8080/ YWRtaW46YWRtaW4= |
|||
#~ python init_static_data.py http://cyclos-app:8080/ YWRtaW46YWRtaW4= |
@ -0,0 +1,162 @@ |
|||
#!/bin/sh |
|||
|
|||
ROOT_DIR=$(pwd) |
|||
|
|||
DATA_ONLY=0 |
|||
for i in "$@" |
|||
do |
|||
case $i in |
|||
-e|--env) |
|||
ENV="$2" |
|||
shift #past argument |
|||
shift #past value |
|||
;; |
|||
-d|--data-only) |
|||
DATA_ONLY=1 |
|||
shift |
|||
;; |
|||
-h|--help) |
|||
echo "Generates scripts to initialize docker services and containers with a dev/test dataset \n" |
|||
echo "WARNING : This script should never be executed in a production context \n" |
|||
echo "Usage: --env ENV [--data-only] \n" |
|||
echo "Options: \r" |
|||
echo " -e, --env Set environment variable. It can be either dev/test. \r" |
|||
echo " -d, --data-only Delete then generate dataset only instead of all services and docker containers. \r" |
|||
echo " -h, --help Show this prompt with a list of options. \r" |
|||
exit 0 |
|||
;; |
|||
esac |
|||
done |
|||
|
|||
if [ "$ENV" = "dev" -o "$ENV" = "test" ]; then |
|||
#analyse de la commande |
|||
|
|||
#if config to generate |
|||
if [ "$DATA_ONLY" = "0" ]; then |
|||
if [ "$ENV" = "dev" ]; then |
|||
OTHER_ENV="test" |
|||
else |
|||
OTHER_ENV="dev" |
|||
fi |
|||
|
|||
if [ -f ./etc/cyclos/cyclos_constants_$ENV.yml ] || [ ! -f ./etc/cyclos/cyclos_constants_$OTHER_ENV.yml ]; then |
|||
read -p "You are about to regenerate all the docker services. Are you sure? (y/n)" response |
|||
|
|||
if [ -z $response ]; then |
|||
response="n" |
|||
echo "To regenerate dataset only, use -d option" |
|||
fi |
|||
|
|||
while [ $response != "y" ] && [ $response != "n" ]; do |
|||
read -p "You are about to regenerate all the docker services. Are you sure? (y/n)" response |
|||
done |
|||
|
|||
if [ $response = "n" ]; then |
|||
exit 0 |
|||
fi |
|||
|
|||
echo "$(tput setaf 3) Delete cyclos data... $(tput sgr 0)" |
|||
rm -rf data/cyclos |
|||
rm -f etc/cyclos/cyclos_constants_$ENV.yml |
|||
rm -f etc/cyclos/cyclos_constants_$OTHER_ENV.yml |
|||
echo "$(tput setaf 2) Delete cyclos data... OK ! " |
|||
|
|||
sleep 2 |
|||
echo "$(tput setaf 3) Stop and remove containers, networks and volumes... $(tput sgr 0)" |
|||
docker-compose down -v |
|||
echo "$(tput setaf 2) Stop and remove containers, networks and volumes... OK !" |
|||
|
|||
sleep 2 |
|||
|
|||
echo "$(tput setaf 3) (Re)create cyclos database container from cyclos-db service $(tput sgr 0)" |
|||
docker-compose up -d cyclos-db |
|||
|
|||
echo "INFO : Wait for cyclos init process to finish initial dump. It should take up to 3mins \n" |
|||
echo "HINT : In order to check progression, input sudo docker-compose logs -f cyclos-db in another terminal \n" |
|||
docker logs cyclos-db 2>&1 | grep -Pzl '(?s)init process complete.*\n.*ready to accept connections' |
|||
while [ $? -ne 0 ]; do |
|||
sleep 5; |
|||
#this must be the last line of the while loop |
|||
docker logs cyclos-db 2>&1 | grep -Pzl '(?s)init process complete.*\n.*ready to accept connections' |
|||
done |
|||
|
|||
echo "$(tput setaf 2) (Re)create cyclos database container from cyclos-db service... OK !" |
|||
sleep 2 |
|||
|
|||
docker-compose up -d cyclos-app |
|||
|
|||
sleep 2 |
|||
docker-compose up -d odoo |
|||
|
|||
echo "wait for odoo postgres database to finish process after startup" |
|||
docker logs postgres_odoo 2>&1 | grep -Pzl '(?s)init process complete' |
|||
while [ $? -ne 0 ]; do |
|||
sleep 5; |
|||
#this must be the last line of the while loop |
|||
docker logs postgres_odoo 2>&1 | grep -Pzl '(?s)init process complete' |
|||
done |
|||
|
|||
## Update postgres password |
|||
docker-compose exec -T postgres bash -c \ |
|||
'PGUSER=postgres psql <<<"ALTER USER postgres WITH ENCRYPTED password "'\\\''$POSTGRES_ROOT_PASSWORD'\\\' |
|||
|
|||
## Set pg_hba.conf |
|||
docker-compose exec -T postgres bash -c ' |
|||
PG_HBA=/var/lib/postgresql/data/pg_hba.conf |
|||
if ! grep -E "^host all all (0.0.0.0/0|all) md5\$" "$PG_HBA" >/dev/null 2>&1; then |
|||
if grep -E "^host all all (0.0.0.0/0|all) trust\$" "$PG_HBA" >/dev/null 2>&1; then |
|||
sed -ri '\''s%^host all all (0\.0\.0\.0/0|all) trust$%host all all \1 md5%g'\'' \ |
|||
"$PG_HBA" |
|||
echo "Accepting connection from outside." |
|||
else |
|||
echo "Can'\''t ensure connection from outside." >&2 |
|||
exit 1 |
|||
fi |
|||
fi |
|||
' |
|||
|
|||
if [ "$?" != 0 ]; then |
|||
echo "Error: can't update pg_hba.conf" >&2 |
|||
else |
|||
docker-compose restart postgres |
|||
fi |
|||
|
|||
sleep 5 |
|||
docker-compose exec -T postgres bash -c \ |
|||
'PGUSER=postgres createdb $PG_DATABASE' |
|||
|
|||
docker-compose exec -T postgres bash -c \ |
|||
'PGUSER=postgres psql $PG_DATABASE -c "CREATE EXTENSION IF NOT EXISTS unaccent;"' |
|||
|
|||
docker-compose exec -T postgres bash -c \ |
|||
'PGUSER=postgres psql <<<"CREATE USER \"$PG_USER\" WITH PASSWORD '\''$PG_PASS'\'' CREATEDB NOCREATEROLE;"' |
|||
|
|||
docker-compose exec -T postgres bash -c \ |
|||
'PGUSER=postgres prefix_pg_local_command=" " pgm chown $PG_USER $PG_DATABASE' |
|||
|
|||
fi |
|||
|
|||
echo "$(tput setaf 3) Generate cyclos configuration and initial data... $(tput sgr 0)" |
|||
docker-compose exec -e ENV=$ENV cyclos-app sh /cyclos/setup_cyclos.sh |
|||
echo "$(tput setaf 2) Generate cyclos configuration and initial data... OK !" |
|||
|
|||
else |
|||
if [ -f ./etc/cyclos/cyclos_constants_$ENV.yml ]; then |
|||
echo "$(tput setaf 3) Clean cyclos database from all users, payments and accounts data... $(tput sgr 0)" |
|||
sleep 2 |
|||
docker-compose exec -T cyclos-db psql -v network="'%$ENV%'" -U cyclos cyclos < etc/cyclos/script_clean_database.sql |
|||
echo "$(tput setaf 2) Clean cyclos database from all users, payments and accounts data... OK !" |
|||
sleep 2 |
|||
echo "$(tput setaf 3) Regenerate cyclos init data : users, accounts credit and payments ... $(tput sgr 0)" |
|||
sleep 2 |
|||
docker-compose exec -T -e ENV=$ENV cyclos-app python3 /cyclos/init_test_data.py http://cyclos-app:8080/ YWRtaW46YWRtaW4= |
|||
echo "$(tput setaf 2) Regenerate cyclos init data : users, accounts credit and payments... OK !" |
|||
else |
|||
echo "Cyclos constants file not found for $ENV mode. The cyclos containers and configuration have not been settled. \n Remove -d option from the command" |
|||
exit 0 |
|||
fi |
|||
fi |
|||
else |
|||
echo "choose dev / test as a script variable" |
|||
exit 1 |
|||
fi |
Write
Preview
Loading…
Cancel
Save
Reference in new issue