Commit 38dee935 by Thibault Grandjean

update pair create

parent 5cd5e736
Pipeline #1896 failed with stage
in 1 minute 26 seconds
...@@ -415,7 +415,7 @@ def delete_shift_registration(request): ...@@ -415,7 +415,7 @@ def delete_shift_registration(request):
# Gestion des binômes # Gestion des binômes
def get_member_info(request,coop_id): def get_member_info(request, id):
"""Retrieve information about a member.""" """Retrieve information about a member."""
res = {} res = {}
is_connected_user = CagetteUser.are_credentials_ok(request) is_connected_user = CagetteUser.are_credentials_ok(request)
...@@ -438,7 +438,8 @@ def get_member_info(request,coop_id): ...@@ -438,7 +438,8 @@ def get_member_info(request,coop_id):
'parent_name', 'parent_name',
"makeups_to_do" "makeups_to_do"
] ]
member = api.search_read('res.partner', [['barcode_base', '=', coop_id]], fields) cond = [['id', '=', id]]
member = api.search_read('res.partner', cond, fields)
if member: if member:
res['member'] = member[0] res['member'] = member[0]
...@@ -448,7 +449,6 @@ def get_member_info(request,coop_id): ...@@ -448,7 +449,6 @@ def get_member_info(request,coop_id):
else: else:
res['message'] = "Unauthorized" res['message'] = "Unauthorized"
response = JsonResponse(res, status=403) response = JsonResponse(res, status=403)
print(response.content)
return response return response
...@@ -476,7 +476,7 @@ def create_pair(request): ...@@ -476,7 +476,7 @@ def create_pair(request):
child_id = data['child']['id'] child_id = data['child']['id']
# create attached account for child # create attached account for child
fields = [ fields = [
# "birthdate", "birthdate",
"city", "city",
"commercial_partner_id", "commercial_partner_id",
"company_id", "company_id",
...@@ -498,10 +498,32 @@ def create_pair(request): ...@@ -498,10 +498,32 @@ def create_pair(request):
"street", "street",
"street2", "street2",
"zip", "zip",
"nb_associated_people" "nb_associated_people",
"current_template_name"
] ]
child = api.search_read('res.partner', [['id', '=', child_id]], fields)[0] child = api.search_read('res.partner', [['id', '=', child_id]], fields)[0]
parent = api.search_read('res.partner', [['id', '=', parent_id]], ['commercial_partner_id'])[0] parent = api.search_read('res.partner', [['id', '=', parent_id]],
['commercial_partner_id',
'nb_associated_people',
'parent_id'])[0]
errors = []
if child['nb_associated_people'] > 0:
# le membre est déjà titulaire d'un binôme
errors.append("Le membre suppléant sélectionné est titulaire d'un bînome")
# le membre suppléant fait parti du commité?
if child['current_template_name'] == "Services des comités":
errors.append("Le membre suppléant séléctionné fait parti du comité")
# le membre titulaire a déjà un/des suppléants?
if parent['nb_associated_people'] >= 1:
# On récupère le/s suppléant(s)
associated_members = api.search_read('res.partner', [['parent_id', '=', parent_id]], ['id', 'age'])
# le suppléant est un mineur?
for m in associated_members:
if m['age'] > 18:
errors.append("Le membre titulaire sélectionné a déjà un suppléant")
if errors:
return JsonResponse({"errors": errors}, status=409)
del child["id"] del child["id"]
for field in child.keys(): for field in child.keys():
if field.endswith("_id"): if field.endswith("_id"):
......
...@@ -15,7 +15,6 @@ const possible_cooperative_state = { ...@@ -15,7 +15,6 @@ const possible_cooperative_state = {
* Load member infos * Load member infos
*/ */
function load_member_infos(divId, memberId) { function load_member_infos(divId, memberId) {
console.log(memberId)
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: "/members/get_member_info/" + memberId, url: "/members/get_member_info/" + memberId,
...@@ -23,8 +22,6 @@ function load_member_infos(divId, memberId) { ...@@ -23,8 +22,6 @@ function load_member_infos(divId, memberId) {
traditional: true, traditional: true,
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
success: function(data) { success: function(data) {
console.log(data)
console.log(divId)
if (divId === 'parentInfo') { if (divId === 'parentInfo') {
parentId = data.member.id parentId = data.member.id
} else if (divId === 'childInfo') { } else if (divId === 'childInfo') {
...@@ -104,11 +101,14 @@ function display_member_infos(divId, memberData) { ...@@ -104,11 +101,14 @@ function display_member_infos(divId, memberData) {
* Display table of attached members * Display table of attached members
*/ */
function display_attached_members() { function display_attached_members() {
if (attached_members_table) {
$('#attached_members_table').off(); // load_attached_members()
attached_members_table.clear().destroy(); // var attached_members_table = $('#attached_members_table')
$('#attached_members_table').empty(); // if (attached_members_table) {
} // $('#attached_members_table').off();
// attached_members_table.clear().destroy();
// $('#attached_members_table').empty();
// }
attached_members_table = $('#attached_members_table').DataTable({ attached_members_table = $('#attached_members_table').DataTable({
data: attached_members, data: attached_members,
...@@ -208,7 +208,7 @@ $(document).ready(function() { ...@@ -208,7 +208,7 @@ $(document).ready(function() {
response($.map(data.res, function(item) { response($.map(data.res, function(item) {
return { return {
label: item.barcode_base + ' ' + item.name, label: item.barcode_base + ' ' + item.name,
value: item.barcode_base value: item.id
} }
})) }))
}, },
...@@ -229,8 +229,11 @@ $(document).ready(function() { ...@@ -229,8 +229,11 @@ $(document).ready(function() {
}, },
minLength: 1, minLength: 1,
select: function( event, ui ) { select: function( event, ui ) {
event.preventDefault();
if (ui.item) { if (ui.item) {
load_member_infos("parentInfo", ui.item.value) load_member_infos("parentInfo", ui.item.value)
$('#search_member_input').val(ui.item.label)
return false
} }
} }
}) })
...@@ -250,7 +253,7 @@ $(document).ready(function() { ...@@ -250,7 +253,7 @@ $(document).ready(function() {
response($.map(data.res, function(item) { response($.map(data.res, function(item) {
return { return {
label: item.barcode_base + ' ' + item.name, label: item.barcode_base + ' ' + item.name,
value: item.barcode_base value: item.id
} }
})) }))
}, },
...@@ -273,6 +276,8 @@ $(document).ready(function() { ...@@ -273,6 +276,8 @@ $(document).ready(function() {
select: function( event, ui ) { select: function( event, ui ) {
if (ui.item) { if (ui.item) {
load_member_infos("childInfo", ui.item.value) load_member_infos("childInfo", ui.item.value)
$('#search_child_input').val(ui.item.label)
return false
} }
}, },
}) })
...@@ -295,13 +300,15 @@ $(document).ready(function() { ...@@ -295,13 +300,15 @@ $(document).ready(function() {
}, },
error: function(data) { error: function(data) {
err = {msg: "erreur serveur", ctx: 'create pair'}; err = {msg: "erreur serveur", ctx: 'create pair'};
if (typeof data.responseJSON != 'undefined' && typeof data.responseJSON.error != 'undefined') { if (typeof data.responseJSON != 'undefined' && typeof data.responseJSON.errors != 'undefined') {
err.msg += ' : ' + data.responseJSON.error; err.msg += ' : ' + data.responseJSON.errors;
} }
report_JS_error(err, 'members.admin'); report_JS_error(err, 'members.admin');
closeModal(); closeModal();
alert('Erreur lors de création du binôme.'); var message = 'Erreur lors de création du binôme.'
data.responseJSON.errors.map(function(error){ message += ('\n' + error)})
alert(message);
} }
}) })
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment