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):
# Gestion des binômes
def get_member_info(request,coop_id):
def get_member_info(request, id):
"""Retrieve information about a member."""
res = {}
is_connected_user = CagetteUser.are_credentials_ok(request)
......@@ -438,7 +438,8 @@ def get_member_info(request,coop_id):
'parent_name',
"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:
res['member'] = member[0]
......@@ -448,7 +449,6 @@ def get_member_info(request,coop_id):
else:
res['message'] = "Unauthorized"
response = JsonResponse(res, status=403)
print(response.content)
return response
......@@ -476,7 +476,7 @@ def create_pair(request):
child_id = data['child']['id']
# create attached account for child
fields = [
# "birthdate",
"birthdate",
"city",
"commercial_partner_id",
"company_id",
......@@ -498,10 +498,32 @@ def create_pair(request):
"street",
"street2",
"zip",
"nb_associated_people"
"nb_associated_people",
"current_template_name"
]
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"]
for field in child.keys():
if field.endswith("_id"):
......
......@@ -15,7 +15,6 @@ const possible_cooperative_state = {
* Load member infos
*/
function load_member_infos(divId, memberId) {
console.log(memberId)
$.ajax({
type: 'GET',
url: "/members/get_member_info/" + memberId,
......@@ -23,14 +22,12 @@ function load_member_infos(divId, memberId) {
traditional: true,
contentType: "application/json; charset=utf-8",
success: function(data) {
console.log(data)
console.log(divId)
if (divId === 'parentInfo') {
parentId = data.member.id
} else if (divId === 'childInfo') {
childId = data.member.id
}
display_member_infos(divId, data.member)
if (divId === 'parentInfo') {
parentId = data.member.id
} else if (divId === 'childInfo') {
childId = data.member.id
}
display_member_infos(divId, data.member)
},
error: function(data) {
err = {msg: "erreur serveur lors de la récupération des infos du membre", ctx: 'load_member_infos'};
......@@ -104,11 +101,14 @@ function display_member_infos(divId, memberData) {
* Display table of attached members
*/
function display_attached_members() {
if (attached_members_table) {
$('#attached_members_table').off();
attached_members_table.clear().destroy();
$('#attached_members_table').empty();
}
// load_attached_members()
// var attached_members_table = $('#attached_members_table')
// if (attached_members_table) {
// $('#attached_members_table').off();
// attached_members_table.clear().destroy();
// $('#attached_members_table').empty();
// }
attached_members_table = $('#attached_members_table').DataTable({
data: attached_members,
......@@ -208,7 +208,7 @@ $(document).ready(function() {
response($.map(data.res, function(item) {
return {
label: item.barcode_base + ' ' + item.name,
value: item.barcode_base
value: item.id
}
}))
},
......@@ -229,8 +229,11 @@ $(document).ready(function() {
},
minLength: 1,
select: function( event, ui ) {
event.preventDefault();
if (ui.item) {
load_member_infos("parentInfo", ui.item.value)
$('#search_member_input').val(ui.item.label)
return false
}
}
})
......@@ -250,7 +253,7 @@ $(document).ready(function() {
response($.map(data.res, function(item) {
return {
label: item.barcode_base + ' ' + item.name,
value: item.barcode_base
value: item.id
}
}))
},
......@@ -273,6 +276,8 @@ $(document).ready(function() {
select: function( event, ui ) {
if (ui.item) {
load_member_infos("childInfo", ui.item.value)
$('#search_child_input').val(ui.item.label)
return false
}
},
})
......@@ -295,13 +300,15 @@ $(document).ready(function() {
},
error: function(data) {
err = {msg: "erreur serveur", ctx: 'create pair'};
if (typeof data.responseJSON != 'undefined' && typeof data.responseJSON.error != 'undefined') {
err.msg += ' : ' + data.responseJSON.error;
if (typeof data.responseJSON != 'undefined' && typeof data.responseJSON.errors != 'undefined') {
err.msg += ' : ' + data.responseJSON.errors;
}
report_JS_error(err, 'members.admin');
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