Commit 2ce57329 by Thibault Grandjean

update modal and create

parent b073169b
Pipeline #1945 passed with stage
in 1 minute 30 seconds
......@@ -436,13 +436,18 @@ def get_member_info(request, id):
'parent_id',
'is_associated_people',
'parent_name',
"makeups_to_do"
"makeups_to_do",
"barcode_base"
]
cond = [['id', '=', id]]
member = api.search_read('res.partner', cond, fields)
if member:
res['member'] = member[0]
member = member[0]
parent = None
if member['parent_id']:
parent = api.search_read('res.partner', [['id', '=', int(member['parent_id'][0])]], ['barcode_base'])[0]
member['parent_barcode_base'] = parent['barcode_base']
res['member'] = member
response = JsonResponse(res)
else:
response = JsonResponse({"message": "Not found"}, status=404)
......@@ -451,8 +456,6 @@ def get_member_info(request, id):
response = JsonResponse(res, status=403)
return response
def create_pair(request):
"""Create pair
......@@ -502,12 +505,14 @@ def create_pair(request):
"current_template_name",
"parent_id",
"is_associated_people",
"makeups_to_do"
]
child = api.search_read('res.partner', [['id', '=', child_id]], fields)[0]
parent = api.search_read('res.partner', [['id', '=', parent_id]],
['commercial_partner_id',
'nb_associated_people',
'current_template_name',
'makeups_to_do',
'parent_id'])[0]
errors = []
if child['nb_associated_people'] > 0:
......@@ -542,17 +547,27 @@ def create_pair(request):
child[field] = False
child['is_associated_people'] = True
child['parent_id'] = parent['id']
# fusion des rattrapages
if child["makeups_to_do"] <= 2:
api.update("res.partner", [parent_id], {"makeups_to_do": parent['makeups_to_do'] + child['makeups_to_do']})
# remise à zéro du compte suppléant
api.update("res.partner", [child_id], {"makeups_to_do": 0})
else:
api.update("res.partner", [parent_id], {"makeups_to_do": 2})
# remise à zéro du compte suppléant
api.update("res.partner", [child_id], {"makeups_to_do": 0})
# update child base account state
api.execute("res.partner", "set_special_state", {"id": child_id, 'state': "associated"})
# suppression du créneau pour le compte de base
shift_registration = api.search_read("shift.template.registration", [['partner_id', '=', child_id]], ['id'])
api.delete("shift.template.registration", [x['id'] for x in shift_registration])
# suppression des rattrapages ?
# get barcode rule id
bbcode_rule = api.search_read("barcode.rule", [['for_associated_people', "=", True]], ['id'])[0]
child['barcode_rule_id'] = bbcode_rule["id"]
# TODO: le compte rattaché doit être ajouté dans le créneau du titulaire
child.pop("makeups_to_do")
attached_account = api.create('res.partner', child)
# generate_base
api.execute('res.partner', 'generate_base', [attached_account])
......
var parentId = null;
var childId = null;
var parentName = null;
var childName = null;
const possible_cooperative_state = {
suspended: "Rattrapage",
exempted: "Exempté.e",
......@@ -8,7 +11,8 @@ const possible_cooperative_state = {
up_to_date: "À jour",
unsubscribed: "Désinscrit.e des créneaux",
delay: "En délai",
gone: "Parti.e"
gone: "Parti.e",
associated: "En binôme"
};
/**
......@@ -22,10 +26,13 @@ function load_member_infos(divId, memberId) {
traditional: true,
contentType: "application/json; charset=utf-8",
success: function(data) {
console.log(data.member)
if (divId === 'parentInfo') {
parentId = data.member.id;
parentName = data.member.barcode_base + ' ' + data.member.name
} else if (divId === 'childInfo') {
childId = data.member.id;
childName = data.member.barcode_base + ' ' + data.member.name
}
display_member_infos(divId, data.member);
},
......@@ -88,7 +95,7 @@ function load_attached_members() {
if (typeof data.responseJSON != 'undefined' && typeof data.responseJSON.error != 'undefined') {
err.msg += ' : ' + data.responseJSON.error;
}
report_JS_error(err, 'orders');
report_JS_error(err, 'members');
closeModal();
alert('Erreur serveur lors de la récupération des membres en binôme. Ré-essayez plus tard.');
......@@ -216,7 +223,13 @@ function delete_pair(childId) {
function confirmDeletion(childId) {
var modalContent = $("#confirmModal").html()
var modalContent = $('#confirmModal')
modalContent.find("#parentName").text(parentName)
modalContent.find("#childName").text(childName)
modalContent = modalContent.html();
openModal(modalContent, () => {
if (is_time_to('delete_pair')) {
delete_pair(childId)
......@@ -376,7 +389,10 @@ $(document).ready(function() {
"child": {"id": childId}
};
var modalContent = $('#confirmModal').html();
var modalContent = $('#confirmModal')
modalContent.find("#parentName").text(parentName)
modalContent.find("#childName").text(childName)
modalContent = modalContent.html();
openModal(modalContent, () => {
if (is_time_to('create_pair')) {
create_pair(payload)
......@@ -390,7 +406,28 @@ $(document).ready(function() {
$(document).on('click', '.delete_pair', function (event) {
var childId = event.target.id.split('_').slice(-1)[0];
$.ajax({
type: 'GET',
url: "/members/get_member_info/" + childId,
dataType:"json",
traditional: true,
contentType: "application/json; charset=utf-8",
success: function(data) {
console.log(data.member)
parentName = data.member.parent_barcode_base + ' - ' + data.member.parent_name
childName = data.member.barcode_base + ' - ' + data.member.name
confirmDeletion(childId);
},
error: function(data) {
err = {msg: "erreur serveur lors de la récupération des infos du membre", ctx: 'load_member_infos'};
if (typeof data.responseJSON != 'undefined' && typeof data.responseJSON.error != 'undefined') {
err.msg += ' : ' + data.responseJSON.error;
}
report_JS_error(err, 'members.admin');
confirmDeletion(childId);
closeModal();
alert('Erreur lors de la récupération des infos du membre.');
}
});
});
});
......@@ -18,7 +18,8 @@
<div id="confirmModal">
<h3>Le binôme est sur le point d'être créé</h3>
<br/>
<p>Êtes-vous sur de vouloir continuer</p>
<p>Voulez-vous vraiment créer le binôme avec comme titulaire <b><span id="parentName"></span></b> et comme suppléant <b><span id="childName"></span></b>
<p>Êtes-vous sur de vouloir continuer ?</p>
<hr/>
</div>
</div>
......@@ -44,7 +45,7 @@
</form>
</div>
<div id="parentInfo" style="display:none;">
<div class="tile_title">
<i class="fas fa-user tile_icon"></i>
<span class="member_info member_name"></span>
......@@ -95,7 +96,7 @@
<span class="member_shift_name member_info"></span>
</div>
</div>
</div>
</div>
</div>
......
......@@ -19,7 +19,9 @@
<div class="mconfirm">
<h3>Le binôme est sur le point d'être désolidarisé</h3>
<br />
<p>Êtes-vous sur de vouloir continuer</p>
<p>Êtes-vous sur de vouloir désolidariser <b><span id="parentName"></span></b> et
<b><span id="childName"></span></b>
</p>
<hr/>
</div>
</div>
......@@ -42,10 +44,10 @@
</div>
<div class="table_area">
<table id="attached_members_table" class="display" cellspacing="0" width="100%"></table>
</div>
</div>
</div>
</div>
<script src='{% static "js/all_common.js" %}?v='></script>
<script src='{% static "js/admin/manage_attached.js" %}?v='></script>
{% endblock %}
\ No newline at end of file
{% endblock %}
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