Commit 0c5db861 by François C.

Merge branch 'dev_cooperatic' into meal-voucher-and-label-printer-software-bug

parents 7d9d385a de580bd6
Pipeline #2892 failed with stage
in 1 minute 4 seconds
......@@ -552,6 +552,13 @@ def delete_shift_template_registration(request):
if permanent_unsuscribe is True:
res["set_done"] = cm.set_cooperative_state("gone")
if res["set_done"]:
""" Delete pair(s?) of partner if it is a parent to improve statistics (#4810) """
api = OdooAPI()
associated_members = api.search_read('res.partner', [['parent_id', '=', partner_id]], ['id'])
for am in associated_members:
data = {"child": {"id": am["id"]}, "gone": ["parent", "child"]}
delete_pair_core(data)
except Exception as e:
res["error"] = str(e)
......@@ -895,14 +902,38 @@ def delete_pair(request):
return HttpResponse(template.render(context, request))
elif request.method == 'POST':
if CagetteUser.are_credentials_ok(request):
api = OdooAPI()
data = json.loads(request.body.decode())
delete_pair_core(data)
response = JsonResponse({"message": "Succesfuly unpaired members"}, status=200)
else:
response = JsonResponse({"message": "Unauthorized"}, status=403)
return response
else:
return JsonResponse({"message": "Method Not Allowed"}, status=405)
def delete_pair_core(data):
"""
Core of delete_pair
argument example :
{
"child": {
"id": "1620"
},
"gone": [
"parent",
"child"
]
}
"""
api = OdooAPI()
child_id = int(data['child']['id'])
child = api.search_read('res.partner', [['id', '=', child_id]], ['email', 'id', 'parent_id'])[0]
child_accounts = api.search_read('res.partner', [['email', '=', child['email']]], ['id', 'email'])
prev_child = [x['id'] for x in child_accounts if x['id'] != child_id]
parent = api.search_read('res.partner', [['id', '=', child['parent_id'][0]]], ['cooperative_state'])[0]
api.update('res.partner', [child_id], {"parent_id": False, "is_associated_people": False, "active": False, "is_former_associated_people": True})
api.update('res.partner', [child_id], {"parent_id": False, "is_associated_people": False, "active": False,
"is_former_associated_people": True})
child_update_fields = {'cooperative_state': "unsubscribed", "is_former_associated_people": True}
if 'gone' in data and 'child' in data['gone']:
child_update_fields['cooperative_state'] = "gone"
......@@ -910,11 +941,3 @@ def delete_pair(request):
api.update("res.partner", [id], child_update_fields)
if 'gone' in data and 'parent' in data['gone']:
api.update("res.partner", [parent['id']], {'cooperative_state': "gone", "is_former_associated_people": True})
response = JsonResponse({"message": "Succesfuly unpaired members"}, status=200)
else:
response = JsonResponse({"message": "Unauthorized"}, status=403)
return response
else:
return JsonResponse({"message": "Method Not Allowed"}, status=405)
......@@ -1270,7 +1270,7 @@ function editProductInfo (productToEdit, value = null, batch = false) {
// Check if the product is already in the 'updated' list
var index = searchUpdatedProduct();
var firstUpdate = false;
var isValid = false;
var isValid = false; // "valid" == no change from initial value
let newValue = value;
var addition = false;
......@@ -1349,7 +1349,8 @@ function editProductInfo (productToEdit, value = null, batch = false) {
firstUpdate = (index == -1); //first update
if (productToEdit.product_qty != newValue) {
if (firstUpdate) {
// If no old_qty in productToEdit, product qty wasn't edited before
if (productToEdit.old_qty === undefined) {
productToEdit.old_qty = productToEdit.product_qty;
} else {
//if it is not the first update AND newValue is equal to the validation qty then the product is valid (qty not changed)
......@@ -1418,9 +1419,7 @@ function editProductInfo (productToEdit, value = null, batch = false) {
// If the product info has been updated and for the first time
if (firstUpdate) {
updatedProducts.push(productToEdit);
//if product is validated thru edition -> add to valid_products
//if product is validated thru edition without change -> add to valid_products
if (isValid) {
// Create 'valid_products' list in order if not exists
if (!orders[productToEdit.id_po]['valid_products']) {
......@@ -1428,6 +1427,8 @@ function editProductInfo (productToEdit, value = null, batch = false) {
}
orders[productToEdit.id_po]['valid_products'].push(productToEdit['id']);
} else {
updatedProducts.push(productToEdit);
// Create 'updated_products' list in order if not exists
if (!orders[productToEdit.id_po]['updated_products']) {
orders[productToEdit.id_po]['updated_products'] = [];
......
......@@ -306,13 +306,20 @@ class CagetteShift(models.Model):
cond = [['partner_id', '=', int(data['idPartner'])],
['shift_id', '=', int(data['idShift'])],
['state', '=', 'cancel']]
fields = ['id']
fields = ['id','origin']
try:
canceled_res = self.o_api.search_read('shift.registration', cond, fields, 1)
if (len(canceled_res) == 1):
shift_res = canceled_res[0]
fieldsDatas = { "related_shift_state":'open',
"state": 'open'}
"state": 'open',
"is_makeup":data['is_makeup'],
"origin":canceled_res[0]['origin'] + ' reopened from memberspace'}
"""In case shift to reopen is a makeup, we want the counter to be incremented once shift is done
That is why template_created must be set to false
However if shift to reopen is not a makeup, counter should not be incremented so template_created should not be changed."""
if data["is_makeup"]:
fieldsDatas["template_created"] = False
response = self.o_api.update('shift.registration', [shift_res['id']], fieldsDatas)
except Exception as e:
coop_logger.error("Reopen shift : %s", str(e))
......
......@@ -47,7 +47,7 @@
temporaire, n’oublie pas de recontacter le Bureau des Membres à ton retour pour te
réinscrire sur un créneau. </p>
</div>
<div class="grp_text"><h3><b>Je m'absente plus longtemps pour une autre raison (plus de 4 semaines)</b></h3>
<div class="grp_text"><h3><b>Je m'absente plus longtemps pour une autre raison (plus de 2 mois)</b></h3>
<p class="attached-unblocked"> Envoie un mail au Bureau des Membres
<a href="mailto:bdm@supercafoutch.fr?subject=Incapacité à faire mes services pour cause d'absence prolongée">bdm@supercafoutch.fr</a>
......
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