Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
third-party
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cooperatic-foodcoops
third-party
Commits
454d9a90
Commit
454d9a90
authored
Apr 26, 2022
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BDM: change members shift template
parent
d893ecc1
Pipeline
#2152
passed with stage
in 1 minute 52 seconds
Changes
6
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
141 additions
and
36 deletions
+141
-36
admin.py
members/admin.py
+25
-4
models.py
members/models.py
+28
-2
manage_regular_shifts.css
members/static/css/admin/manage_regular_shifts.css
+6
-0
manage_attached.js
members/static/js/admin/manage_attached.js
+3
-2
manage_regular_shifts.js
members/static/js/admin/manage_regular_shifts.js
+69
-28
manage_regular_shifts.html
templates/members/admin/manage_regular_shifts.html
+10
-0
No files found.
members/admin.py
View file @
454d9a90
...
...
@@ -470,7 +470,7 @@ def delete_shift_template_registration(request):
res
[
"update_makeups"
]
=
cm
.
update_member_makeups
({
'target_makeups_nb'
:
target_makeup
})
# Delete all shift registrations & shift template registration
res
[
"unsu
scribe_member"
]
=
cm
.
unsu
scribe_member
()
res
[
"unsu
bscribe_member"
]
=
cm
.
unsub
scribe_member
()
if
permanent_unsuscribe
is
True
:
res
[
"set_done"
]
=
cm
.
set_cooperative_state
(
"gone"
)
...
...
@@ -485,7 +485,11 @@ def delete_shift_template_registration(request):
return
response
def
shift_subscription
(
request
):
""" Inscrit un membre désinscrit à un shift template """
"""
Register a member to a shift template.
If the member was already subscribed to a shift template, unsubscribe him.her first
and delete all existing shifts EXCEPT makeups.
"""
res
=
{}
if
CagetteUser
.
are_credentials_ok
(
request
):
data
=
json
.
loads
(
request
.
body
.
decode
())
...
...
@@ -506,9 +510,26 @@ def shift_subscription(request):
shift_template_id
=
CagetteServices
.
get_first_ftop_shift_id
()
m
=
CagetteMember
(
partner_id
)
unsubscribe_first
=
data
[
"unsubscribe_first"
]
if
unsubscribe_first
is
True
:
# If the member is registered to a shift on the shift template, registering to this shift template will fail.
has_makeups_in_new_shift
=
m
.
is_member_registered_to_makeup_shift_template
(
shift_template_id
)
if
has_makeups_in_new_shift
is
True
:
return
JsonResponse
(
{
"message"
:
"A makeup is registered on this shift template"
,
"code"
:
"makeup_found"
},
status
=
409
)
res
[
"unsubscribe_member"
]
=
m
.
unsubscribe_member
(
changing_shift
=
True
)
m
.
create_coop_shift_subscription
(
shift_template_id
,
shift_type
)
# Ret
r
urn necessary data
# Return necessary data
api
=
OdooAPI
()
c
=
[[
'id'
,
'='
,
shift_template_id
]]
f
=
[
'id'
,
'name'
]
...
...
@@ -730,7 +751,7 @@ def create_pair(request):
api
.
execute
(
'res.partner'
,
'run_process_target_status'
,
[])
m
=
CagetteMember
(
child_id
)
.
unsuscribe_member
()
m
=
CagetteMember
(
child_id
)
.
unsu
b
scribe_member
()
# update child base account state
api
.
update
(
"res.partner"
,
[
child_id
],
{
'cooperative_state'
:
"associated"
})
...
...
members/models.py
View file @
454d9a90
...
...
@@ -941,7 +941,30 @@ class CagetteMember(models.Model):
res
=
self
.
o_api
.
search_read
(
"shift.registration"
,
c
,
f
)
return
res
def
unsuscribe_member
(
self
):
def
is_member_registered_to_makeup_shift_template
(
self
,
shift_template_id
):
""" Given a shift template, check if the member is registered to a makeup on this shift template """
try
:
c
=
[[
"partner_id"
,
"="
,
self
.
id
],
[
"is_makeup"
,
"="
,
True
],
[
"state"
,
"="
,
"open"
]]
f
=
[
'shift_id'
]
res_shift_ids
=
self
.
o_api
.
search_read
(
"shift.registration"
,
c
,
f
)
if
res_shift_ids
:
shift_ids
=
[
int
(
d
[
'shift_id'
][
0
])
for
d
in
res_shift_ids
]
c
=
[[
"id"
,
"in"
,
shift_ids
]]
f
=
[
'shift_template_id'
]
stis
=
self
.
o_api
.
search_read
(
"shift.shift"
,
c
,
f
)
for
sti
in
stis
:
if
sti
[
'shift_template_id'
][
0
]
==
shift_template_id
:
return
True
except
Exception
as
e
:
print
(
str
(
e
))
return
False
def
unsubscribe_member
(
self
,
changing_shift
=
False
):
""" If changing_shift, don't delete makeups registrations & don't close extension """
res
=
{}
now
=
datetime
.
datetime
.
now
()
.
isoformat
()
...
...
@@ -957,6 +980,8 @@ class CagetteMember(models.Model):
# Get and then delete shift registrations
c
=
[[
'partner_id'
,
'='
,
self
.
id
],
[
'date_begin'
,
'>'
,
now
]]
if
changing_shift
is
True
:
c
.
append
([
'is_makeup'
,
'!='
,
True
])
f
=
[
'id'
]
res_ids
=
self
.
o_api
.
search_read
(
"shift.registration"
,
c
,
f
)
ids
=
[
d
[
'id'
]
for
d
in
res_ids
]
...
...
@@ -964,7 +989,8 @@ class CagetteMember(models.Model):
if
ids
:
res
[
"delete_shifts_reg"
]
=
self
.
o_api
.
execute
(
'shift.registration'
,
'unlink'
,
ids
)
# Close extensions
if
changing_shift
is
False
:
# Close extensions if just unsubscribing, else keep it
c
=
[[
'partner_id'
,
'='
,
self
.
id
],
[
'date_start'
,
'<='
,
now
],
[
'date_stop'
,
'>='
,
now
]]
f
=
[
'id'
]
res_ids
=
self
.
o_api
.
search_read
(
"shift.extension"
,
c
,
f
)
...
...
members/static/css/admin/manage_regular_shifts.css
View file @
454d9a90
...
...
@@ -76,6 +76,7 @@
/* Actions */
#remove_shift_template_button
,
#change_shift_template_button
,
#subscribe_to_shift_template_button
{
display
:
none
;
margin
:
15px
;
...
...
@@ -88,6 +89,11 @@
margin-right
:
5px
;
}
.error_modal_title
{
color
:
#d9534f
;
font-weight
:
bold
;
}
/* Calendar */
#shifts_calendar_area
{
display
:
none
;
...
...
members/static/js/admin/manage_attached.js
View file @
454d9a90
...
...
@@ -66,6 +66,7 @@ function display_member_infos(divId, memberData) {
.
text
(
memberData
.
makeups_to_do
);
let
member_shift_name
=
memberData
.
current_template_name
===
false
?
'X'
:
memberData
.
current_template_name
;
$
(
"#"
+
divId
).
find
(
".member_shift_name"
)
.
text
(
member_shift_name
);
...
...
@@ -244,10 +245,10 @@ function confirmDeletion(childId) {
modalContent
.
find
(
"#childName"
).
text
(
childName
);
if
(
parentEmail
!=
false
)
{
modalContent
.
find
(
"#parentEmail"
).
text
(
parentEmail
)
modalContent
.
find
(
"#parentEmail"
).
text
(
parentEmail
)
;
}
if
(
childEmail
!=
false
)
{
modalContent
.
find
(
"#childEmail"
).
text
(
childEmail
)
modalContent
.
find
(
"#childEmail"
).
text
(
childEmail
)
;
}
modalContent
=
modalContent
.
html
();
...
...
members/static/js/admin/manage_regular_shifts.js
View file @
454d9a90
...
...
@@ -54,17 +54,21 @@ function remove_from_shift_template() {
}
/**
* Send the request to register a member to a shift template
* Send the request to register a member to a shift template.
* Ask to unsuscribe first if the member was subscribed.
*
* @param {int} shift_type 1 === standard ; 2 === ftop
* @param {int} shift_template_id null for ftop shift type
* @param {String} shift_template_name selected shift template name
*/
function
shift_subscrition
(
shift_type
,
shift_template_id
=
null
)
{
function
shift_subscrition
(
shift_type
,
shift_template_id
=
null
,
shift_template_name
=
null
)
{
openModal
();
let
data
=
{
partner_id
:
selected_member
.
id
,
shift_type
:
shift_type
,
shift_template_id
:
shift_template_id
shift_template_id
:
shift_template_id
,
unsubscribe_first
:
selected_member
.
shift_template_id
!==
undefined
&&
selected_member
.
shift_template_id
!==
null
};
$
.
ajax
({
...
...
@@ -85,8 +89,33 @@ function shift_subscrition(shift_type, shift_template_id = null) {
$
(
"#shifts_calendar_area"
).
hide
();
closeModal
();
setTimeout
(()
=>
{
$
.
notify
(
"Inscription au nouveau service réussie."
,
{
globalPosition
:
"top right"
,
className
:
"success"
});
},
200
);
},
error
:
function
()
{
error
:
function
(
err_data
)
{
if
(
err_data
.
status
==
409
&&
typeof
(
err_data
.
responseJSON
)
!=
"undefined"
&&
err_data
.
responseJSON
.
code
===
"makeup_found"
)
{
let
modal_template
=
$
(
"#modal_error_change_shift_template"
);
modal_template
.
find
(
".shift_template_name"
).
text
(
shift_template_name
);
closeModal
();
openModal
(
modal_template
.
html
(),
()
=>
{},
"Compris !"
,
true
,
false
);
}
else
{
err
=
{
msg
:
"erreur serveur lors de l'inscription du membre au créneau"
,
ctx
:
'members.admin.manage_regular_shifts.shift_subscrition'
...
...
@@ -99,6 +128,7 @@ function shift_subscrition(shift_type, shift_template_id = null) {
className
:
"error"
});
}
}
});
}
...
...
@@ -113,16 +143,48 @@ function display_member_info() {
$
(
"#remove_shift_template_button"
).
hide
();
$
(
"#remove_shift_template_button"
).
off
();
$
(
"#change_shift_template_button"
).
hide
();
$
(
"#change_shift_template_button"
).
off
();
$
(
"#subscribe_to_shift_template_button"
).
hide
();
$
(
"#subscribe_to_shift_template_button"
).
off
();
$
(
"#shifts_calendar_area"
).
hide
();
// Member is unsuscribed
if
(
selected_member
.
shift_template_id
===
undefined
||
selected_member
.
shift_template_id
===
null
)
{
$
(
'.member_shift'
).
text
(
"X"
);
$
(
"#subscribe_to_shift_template_button"
).
show
();
$
(
"#subscribe_to_shift_template_button"
).
on
(
"click"
,
()
=>
{
$
(
"#subscribe_to_shift_template_button"
).
on
(
"click"
,
set_subscription_area
);
}
else
{
$
(
'.member_shift'
).
text
(
selected_member
.
shift_template_id
[
1
]);
$
(
"#remove_shift_template_button"
).
show
();
$
(
"#remove_shift_template_button"
).
on
(
"click"
,
()
=>
{
let
modal_template
=
$
(
"#modal_remove_shift_template"
);
modal_template
.
find
(
".shift_template_name"
).
text
(
selected_member
.
shift_template_id
[
1
]);
openModal
(
modal_template
.
html
(),
remove_from_shift_template
,
"Valider"
,
false
);
});
$
(
"#change_shift_template_button"
).
show
();
$
(
"#change_shift_template_button"
).
on
(
"click"
,
set_subscription_area
);
}
$
(
'#search_member_input'
).
val
();
$
(
'#partner_data_area'
).
css
(
'display'
,
'flex'
);
}
/**
* Set calendar and associated listeners.
*/
function
set_subscription_area
()
{
retrieve_and_draw_shift_tempates
();
$
(
"#shifts_calendar_area"
).
show
();
...
...
@@ -157,34 +219,13 @@ function display_member_info() {
openModal
(
`Inscrire
${
selected_member
.
name
}
au créneau
${
shift_template_name
}
?`
,
()
=>
{
shift_subscrition
(
1
,
parseInt
(
shift_template_id
)
);
shift_subscrition
(
1
,
parseInt
(
shift_template_id
),
shift_template_name
);
},
"Confirmer"
,
false
);
});
},
500
);
});
}
else
{
$
(
'.member_shift'
).
text
(
selected_member
.
shift_template_id
[
1
]);
$
(
"#remove_shift_template_button"
).
show
();
$
(
"#remove_shift_template_button"
).
on
(
"click"
,
()
=>
{
let
modal_template
=
$
(
"#modal_remove_shift_template"
);
modal_template
.
find
(
".shift_template_name"
).
text
(
selected_member
.
shift_template_id
[
1
]);
openModal
(
modal_template
.
html
(),
remove_from_shift_template
,
"Valider"
,
false
);
});
}
$
(
'#search_member_input'
).
val
();
$
(
'#partner_data_area'
).
css
(
'display'
,
'flex'
);
},
1000
);
}
/**
...
...
templates/members/admin/manage_regular_shifts.html
View file @
454d9a90
...
...
@@ -55,6 +55,9 @@
<button
class=
"btn--primary"
id=
"remove_shift_template_button"
>
Désinscrire du créneau
</button>
<button
class=
"btn--primary"
id=
"change_shift_template_button"
>
Changer de créneau
</button>
<button
class=
"btn--primary"
id=
"subscribe_to_shift_template_button"
>
Réinscrire à un créneau
</button>
...
...
@@ -75,6 +78,13 @@
<label
for=
"permanent_unsuscribe"
>
Désinscription définitive
</label>
</div>
</div>
<div
id=
"modal_error_change_shift_template"
>
<h3
class=
"error_modal_title"
""
>
Action impossible
</h3>
<p>
Le ou la membre est inscrit.e à un rattrapage sur le créneau choisi (
<span
class=
"shift_template_name"
></span>
), cela empêche de l'inscrire sur ce créneau.
</p>
<p>
Vous pouvez essayer de l'inscrire sur ce créneau une autre semaine.
</p>
</div>
</div>
</div>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment