Commit e6707456 by Thibault Grandjean

update data retrieving

parent 4cdc5f30
...@@ -463,11 +463,6 @@ def get_member_info(request, member_id): ...@@ -463,11 +463,6 @@ def get_member_info(request, member_id):
def create_pair(request): def create_pair(request):
template = loader.get_template('members/admin/manage_attached_create_pair.html')
context = {'title': 'BDM - Binômes',
'module': 'Membres'}
return HttpResponse(template.render(context, request))
"""Create pair """Create pair
payload example: payload example:
...@@ -476,82 +471,95 @@ def create_pair(request): ...@@ -476,82 +471,95 @@ def create_pair(request):
"child": {"id": 3067} "child": {"id": 3067}
} }
""" """
if request.method != 'POST': if request.method == 'GET':
return JsonResponse({"message": "Method not available"}) template = loader.get_template('members/admin/manage_attached_create_pair.html')
if CagetteUser.are_credentials_ok(request): context = {'title': 'BDM - Binômes',
api = OdooAPI() 'module': 'Membres'}
data = json.loads(request.body.decode()) return HttpResponse(template.render(context, request))
parent_id = data['parent']['id']
child_id = data['child']['id'] if request.method == 'POST':
# create attached account for child if CagetteUser.are_credentials_ok(request):
fields = [ api = OdooAPI()
"birthdate", data = json.loads(request.body.decode())
"city", parent_id = data['parent']['id']
"commercial_partner_id", child_id = data['child']['id']
"company_id", # create attached account for child
"company_type", fields = [
"cooperative_state", # "birthdate",
"barcode_rule_id", "city",
"country_id", "commercial_partner_id",
"customer", "company_id",
"department_id", "company_type",
"email", "cooperative_state",
"employee", "barcode_rule_id",
"image", "country_id",
"image_medium", "customer",
"image_small", "department_id",
"mobile", "email",
"name", "employee",
"phone", "image",
"sex", "image_medium",
"street", "image_small",
"street2", "mobile",
"zip", "name",
"nb_associated_people" "phone",
] "sex",
child = api.search_read('res.partner', [['id', '=', child_id]], fields)[0] "street",
parent = api.search_read('res.partner', [['id', '=', parent_id]], ['commercial_partner_id'])[0] "street2",
del child["id"] "zip",
for field in child.keys(): "nb_associated_people"
if field.endswith("_id"): ]
child[field] = child[field][0] child = api.search_read('res.partner', [['id', '=', child_id]], fields)[0]
child['is_associated_people'] = True parent = api.search_read('res.partner', [['id', '=', parent_id]], ['commercial_partner_id'])[0]
child['parent_id'] = parent['commercial_partner_id'][0] del child["id"]
# get barcode rule id for field in child.keys():
bbcode_rule = api.search_read("barcode.rule", [['for_associated_people', "=", True]], ['id'])[0] if field.endswith("_id"):
child['barcode_rule_id'] = bbcode_rule["id"] child[field] = child[field][0]
attached_account = api.create('res.partner', child) child['is_associated_people'] = True
# generate_base child['parent_id'] = parent['commercial_partner_id'][0]
api.execute('res.partner', 'generate_base', [attached_account]) child['cooperative_state'] = "associated"
response = JsonResponse({"message": "Succesfuly paired members"}, status=200) # get barcode rule id
bbcode_rule = api.search_read("barcode.rule", [['for_associated_people', "=", True]], ['id'])[0]
child['barcode_rule_id'] = bbcode_rule["id"]
attached_account = api.create('res.partner', child)
# generate_base
api.execute('res.partner', 'generate_base', [attached_account])
response = JsonResponse({"message": "Succesfuly paired members"}, status=200)
else:
response = JsonResponse({"message": "Unauthorized"}, status=403)
return response
else: else:
response = JsonResponse({"message": "Unauthorized"}, status=403) return JsonResponse({"message": "Method Not Allowed"}, status=405)
return response
def delete_pair(request): def delete_pair(request):
""" Administration des binômes membres """
template = loader.get_template('members/admin/manage_attached_delete_pair.html')
context = {'title': 'BDM - Binômes',
'module': 'Membres'}
return HttpResponse(template.render(context, request))
"""Delete pair
payload example:
{
"parent": {"id": 3075}
}
""" """
if request.method != 'POST': Administration des binômes membres
return JsonResponse({"message": "Method not available"}) Delete pair
if CagetteUser.are_credentials_ok(request): GET:
api = OdooAPI() Return template
data = json.loads(request.body.decode()) POST:
parent_id = data['parent']['id'] payload example:
# get attached account {
child = api.search_read('res.partner', [['parent_id', '=', parent_id]], ['id'])[0] "parent": {"id": 3075}
api.delete('res.partner', [child['id']]) }
response = JsonResponse({"message": "Succesfuly unpaired members"}, status=200) """
if request.method == 'GET':
template = loader.get_template('members/admin/manage_attached_delete_pair.html')
context = {'title': 'BDM - Binômes',
'module': 'Membres'}
return HttpResponse(template.render(context, request))
elif request.method == 'POST':
if CagetteUser.are_credentials_ok(request):
api = OdooAPI()
data = json.loads(request.body.decode())
parent_id = data['parent']['id']
# get attached account
child = api.search_read('res.partner', [['parent_id', '=', parent_id]], ['id'])[0]
api.delete('res.partner', [child['id']])
response = JsonResponse({"message": "Succesfuly unpaired members"}, status=200)
else:
response = JsonResponse({"message": "Unauthorized"}, status=403)
return response
else: else:
response = JsonResponse({"message": "Unauthorized"}, status=403) return JsonResponse({"message": "Method Not Allowed"}, status=405)
return response
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
function load_member_infos() { function load_member_infos() {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: "/members_space/my_info/" + selected_member.id, url: "/members/get_member_info/" + selected_member.id,
dataType:"json", dataType:"json",
traditional: true, traditional: true,
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
success: function(data) { success: function(data) {
incoming_shifts = data; console.log(data)
display_member_infos(); display_member_infos(data.member);
}, },
error: function(data) { error: function(data) {
err = {msg: "erreur serveur lors de la récupération des infos du membre", ctx: 'load_member_infos'}; err = {msg: "erreur serveur lors de la récupération des infos du membre", ctx: 'load_member_infos'};
...@@ -30,7 +30,15 @@ function load_member_infos() { ...@@ -30,7 +30,15 @@ function load_member_infos() {
*/ */
function display_member_shifts() { function display_member_shifts() {
} }
/**
* Display table of member future shifts
*/
function display_member_infos(memberData) {
console.log(memberData)
shifts = memberData.incoming_shifts
}
/** /**
* Display the members from the search result * Display the members from the search result
......
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