Commit 717c2f7d by Damien Moulard

remove 1 pt to members to whom we add the first makeup

parent 6a825fc3
......@@ -345,12 +345,28 @@ def get_makeups_members(request):
return JsonResponse({ 'res' : res })
def update_members_makeups(request):
""" Décrémente les rattrapages des membres passés dans la requête """
""" Met à jour les rattrapages des membres passés dans la requête """
res = {}
is_connected_user = CagetteUser.are_credentials_ok(request)
if is_connected_user is True:
members_data = json.loads(request.body.decode())
res["res"] = CagetteMembers.update_members_makeups(members_data)
res["res"] = []
for member_data in members_data:
cm = CagetteMember(int(member_data["member_id"]))
res["res"].append(cm.update_member_makeups(member_data))
if "decrement_pts" in member_data and member_data["decrement_pts"] is True:
data = {
'name': "Ajout manuel d'un rattrapage depuis l'admin BDM",
'shift_id': False,
'type': member_data["member_shift_type"],
'partner_id': int(member_data["member_id"]),
'point_qty': -1
}
cm.update_member_points(data)
response = JsonResponse(res)
else:
......
......@@ -827,6 +827,19 @@ class CagetteMember(models.Model):
except:
return None
def update_member_makeups(self, member_data):
api = OdooAPI()
res = {}
f = { 'makeups_to_do': int(member_data["target_makeups_nb"]) }
res_item = api.update('res.partner', [self.id], f)
res = {
'mid': self.id,
'update': res_item
}
return res
class CagetteMembers(models.Model):
"""Class to manage operations on all members or part of them."""
......@@ -1052,25 +1065,10 @@ class CagetteMembers(models.Model):
def get_makeups_members():
api = OdooAPI()
cond = [['makeups_to_do','>', 0]]
fields = ['id', 'name', 'makeups_to_do']
fields = ['id', 'name', 'makeups_to_do','shift_type']
res = api.search_read('res.partner', cond, fields)
return res
@staticmethod
def update_members_makeups(members_data):
api = OdooAPI()
res = []
for member_data in members_data:
member_id = int(member_data["member_id"])
f = { 'makeups_to_do': int(member_data["target_makeups_nb"]) }
res_item = api.update('res.partner', [member_id], f)
res.append({
'mid': member_id,
'update': res_item
})
return res
class CagetteServices(models.Model):
"""Class to handle cagette Odoo services."""
......
......@@ -123,7 +123,7 @@ function display_makeups_members() {
"Tout"
]
],
iDisplayLength: -1,
iDisplayLength: 25,
oLanguage: {
"sProcessing": "Traitement en cours...",
"sSearch": "Rechercher dans le tableau",
......@@ -280,9 +280,13 @@ function increment_makeups(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({
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
});
}
......@@ -349,7 +353,8 @@ function display_possible_members() {
makeups_members.unshift({
id: member.id,
name: member.name,
makeups_to_do: 0
makeups_to_do: 0,
shift_type: member.shift_type
});
openModal(
......
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