Commit b0c615b8 by Félicie

Merge branch 'evolution_bdm' of gl.cooperatic.fr:cooperatic-foodcoops/third-party into ticket_1733

parents d25e5e1e e0e7021d
...@@ -357,13 +357,31 @@ def update_members_makeups(request): ...@@ -357,13 +357,31 @@ def update_members_makeups(request):
res["res"].append(cm.update_member_makeups(member_data)) res["res"].append(cm.update_member_makeups(member_data))
if "decrement_pts" in member_data and member_data["decrement_pts"] is True: # Update member standard points, for standard members only
if member_data["member_shift_type"] == "standard":
# Set points to minus the number of makeups to do (limited to -2)
target_points = - int(member_data["target_makeups_nb"])
if (target_points < -2) :
target_points = -2
member_points = cm.get_member_points("standard")
points_diff = abs(member_points - target_points)
# Don't update if no change
if points_diff == 0:
continue
if member_points > target_points:
points_update = - points_diff
else:
points_update = points_diff
data = { data = {
'name': "Ajout manuel d'un rattrapage depuis l'admin BDM", 'name': "Modif manuelle des rattrapages depuis l'admin BDM",
'shift_id': False, 'shift_id': False,
'type': member_data["member_shift_type"], 'type': member_data["member_shift_type"],
'partner_id': int(member_data["member_id"]), 'partner_id': int(member_data["member_id"]),
'point_qty': -1 'point_qty': points_update
} }
cm.update_member_points(data) cm.update_member_points(data)
......
...@@ -61,6 +61,18 @@ class CagetteMember(models.Model): ...@@ -61,6 +61,18 @@ class CagetteMember(models.Model):
image = res[0]['image_medium'] image = res[0]['image_medium']
return image return image
def get_member_points(self, shift_type):
points_field = 'final_standard_point' if shift_type == "standard" else 'final_ftop_point'
cond = [['id', '=', self.id]]
fields = ['id', points_field]
res = self.o_api.search_read('res.partner', cond, fields)
if res and len(res) == 1:
return res[0][points_field]
else:
return None
def update_member_points(self, data): def update_member_points(self, data):
""" """
ex: ex:
......
...@@ -165,7 +165,7 @@ function display_makeups_members() { ...@@ -165,7 +165,7 @@ function display_makeups_members() {
openModal( openModal(
`Enlever un rattrapage à ${member.name} ?`, `Enlever un rattrapage à ${member.name} ?`,
() => { () => {
decrement_makeups([member_id]); update_members_makeups([member_id], "decrement");
}, },
"Confirmer", "Confirmer",
false false
...@@ -182,7 +182,7 @@ function display_makeups_members() { ...@@ -182,7 +182,7 @@ function display_makeups_members() {
openModal( openModal(
`Ajouter un rattrapage à ${member.name} ?`, `Ajouter un rattrapage à ${member.name} ?`,
() => { () => {
increment_makeups([member_id]); update_members_makeups([member_id], "increment");
}, },
"Confirmer", "Confirmer",
false false
...@@ -212,7 +212,7 @@ function display_makeups_members() { ...@@ -212,7 +212,7 @@ function display_makeups_members() {
openModal( openModal(
`Enlever un rattrapage aux membres sélectionnés ?`, `Enlever un rattrapage aux membres sélectionnés ?`,
() => { () => {
decrement_makeups(selected_rows); update_members_makeups(selected_rows, "decrement");
}, },
"Confirmer", "Confirmer",
false false
...@@ -228,64 +228,25 @@ function display_makeups_members() { ...@@ -228,64 +228,25 @@ function display_makeups_members() {
/** /**
* Send request to update members nb of makeups to do * Send request to update members nb of makeups to do
*
* @param {Array} member_ids * @param {Array} member_ids
* @param {String} action increment | decrement
*/ */
function decrement_makeups(member_ids) { function update_members_makeups(member_ids, action) {
openModal(); openModal();
data = []; data = [];
for (mid of member_ids) { for (mid of member_ids) {
member_index = makeups_members.findIndex(m => m.id == mid); member_index = makeups_members.findIndex(m => m.id == mid);
makeups_members[member_index].makeups_to_do -= 1; if (action === "increment") {
makeups_members[member_index].makeups_to_do += 1;
data.push({ } else {
member_id: mid, makeups_members[member_index].makeups_to_do -= 1;
target_makeups_nb: makeups_members[member_index].makeups_to_do
});
}
$.ajax({
type: 'POST',
url: "/members/update_members_makeups",
data: JSON.stringify(data),
dataType:"json",
traditional: true,
contentType: "application/json; charset=utf-8",
success: function() {
selected_rows = [];
display_makeups_members();
closeModal();
},
error: function(data) {
err = {msg: "erreur serveur pour décrémenter les rattrapages", ctx: 'decrement_makeups'};
if (typeof data.responseJSON != 'undefined' && typeof data.responseJSON.error != 'undefined') {
err.msg += ' : ' + data.responseJSON.error;
}
report_JS_error(err, 'members_admin');
closeModal();
alert('Erreur serveur pour décrémenter les rattrapages. Ré-essayez plus tard.');
} }
});
}
/**
* Send request to update members nb of makeups to do
* @param {Array} member_ids
*/
function increment_makeups(member_ids) {
openModal();
data = [];
for (mid of member_ids) {
member_index = makeups_members.findIndex(m => m.id == mid);
makeups_members[member_index].makeups_to_do += 1;
console.log(makeups_members[member_index]);
data.push({ data.push({
member_id: mid, member_id: mid,
target_makeups_nb: makeups_members[member_index].makeups_to_do, target_makeups_nb: makeups_members[member_index].makeups_to_do,
decrement_pts: (makeups_members[member_index].makeups_to_do == 1),
member_shift_type: makeups_members[member_index].shift_type member_shift_type: makeups_members[member_index].shift_type
}); });
} }
...@@ -303,14 +264,14 @@ function increment_makeups(member_ids) { ...@@ -303,14 +264,14 @@ function increment_makeups(member_ids) {
closeModal(); closeModal();
}, },
error: function(data) { error: function(data) {
err = {msg: "erreur serveur pour incrémenter les rattrapages", ctx: 'increment_makeups'}; err = {msg: "erreur serveur pour décrémenter les rattrapages", ctx: 'decrement_makeups'};
if (typeof data.responseJSON != 'undefined' && typeof data.responseJSON.error != 'undefined') { if (typeof data.responseJSON != 'undefined' && typeof data.responseJSON.error != 'undefined') {
err.msg += ' : ' + data.responseJSON.error; err.msg += ' : ' + data.responseJSON.error;
} }
report_JS_error(err, 'members_admin'); report_JS_error(err, 'members_admin');
closeModal(); closeModal();
alert('Erreur serveur pour incrémenter les rattrapages. Ré-essayez plus tard.'); alert('Erreur serveur pour crémenter les rattrapages. Ré-essayez plus tard.');
} }
}); });
} }
...@@ -360,7 +321,7 @@ function display_possible_members() { ...@@ -360,7 +321,7 @@ function display_possible_members() {
openModal( openModal(
`Ajouter un rattrapage à ${member.name} ?`, `Ajouter un rattrapage à ${member.name} ?`,
() => { () => {
increment_makeups([member.id]); update_members_makeups([member.id], "increment");
members_search_results = []; members_search_results = [];
$('#search_member_input').val(''); $('#search_member_input').val('');
$('.search_member_results_area').hide(); $('.search_member_results_area').hide();
......
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