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
33e5c6d2
Commit
33e5c6d2
authored
Sep 10, 2021
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create a 6 month delay when suspended
parent
23dc1296
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
11 deletions
+81
-11
members-space-my-shifts.css
members_space/static/css/members-space-my-shifts.css
+7
-0
members-space-header.js
members_space/static/js/members-space-header.js
+8
-0
members-space-home.js
members_space/static/js/members-space-home.js
+50
-2
models.py
shifts/models.py
+9
-8
views.py
shifts/views.py
+7
-1
No files found.
members_space/static/css/members-space-my-shifts.css
View file @
33e5c6d2
...
@@ -73,3 +73,9 @@ table.dataTable.display tbody tr.row_partner_late {
...
@@ -73,3 +73,9 @@ table.dataTable.display tbody tr.row_partner_late {
table
.dataTable.display
tbody
tr
.row_partner_absent
{
table
.dataTable.display
tbody
tr
.row_partner_absent
{
background-color
:
#ff847b
;
background-color
:
#ff847b
;
}
}
table
.dataTable.display
tbody
tr
.row_partner_ok
td
,
table
.dataTable.display
tbody
tr
.row_partner_late
td
,
table
.dataTable.display
tbody
tr
.row_partner_absent
td
{
border-bottom
:
1px
solid
rgb
(
100
,
99
,
99
);
border-top
:
1px
solid
rgb
(
100
,
99
,
99
);
}
\ No newline at end of file
members_space/static/js/members-space-header.js
View file @
33e5c6d2
...
@@ -13,15 +13,23 @@ function toggleHeader() {
...
@@ -13,15 +13,23 @@ function toggleHeader() {
$
(
document
).
ready
(
function
()
{
$
(
document
).
ready
(
function
()
{
// Navbar redirections
// Navbar redirections
$
(
'#nav_home'
).
on
(
'click'
,
function
()
{
$
(
'#nav_home'
).
on
(
'click'
,
function
()
{
if
(
current_location
!==
"home"
)
{
goto
(
'home'
);
goto
(
'home'
);
}
});
});
$
(
'#nav_my_info'
).
on
(
'click'
,
function
()
{
$
(
'#nav_my_info'
).
on
(
'click'
,
function
()
{
if
(
current_location
!==
"my_info"
)
{
goto
(
'mes-infos'
);
goto
(
'mes-infos'
);
}
});
});
$
(
'#nav_my_shifts'
).
on
(
'click'
,
function
()
{
$
(
'#nav_my_shifts'
).
on
(
'click'
,
function
()
{
if
(
current_location
!==
"my_shifts"
)
{
goto
(
'mes-services'
);
goto
(
'mes-services'
);
}
});
});
$
(
'#nav_shifts_exchange'
).
on
(
'click'
,
function
()
{
$
(
'#nav_shifts_exchange'
).
on
(
'click'
,
function
()
{
if
(
current_location
!==
"shifts_exchange"
)
{
goto
(
'echange-de-services'
);
goto
(
'echange-de-services'
);
}
});
});
});
});
members_space/static/js/members-space-home.js
View file @
33e5c6d2
...
@@ -7,6 +7,51 @@ const possible_cooperative_state = {
...
@@ -7,6 +7,51 @@ const possible_cooperative_state = {
delay
:
"En délai"
delay
:
"En délai"
}
}
/**
* Request a 6 month delay
*/
function
request_delay
()
{
return
new
Promise
((
resolve
)
=>
{
let
today
=
new
Date
();
const
delay_start
=
today
.
getFullYear
()
+
'-'
+
(
today
.
getMonth
()
+
1
)
+
'-'
+
today
.
getDate
();
let
today_plus_six_month
=
new
Date
();
today_plus_six_month
.
setMonth
(
today_plus_six_month
.
getMonth
()
+
6
);
const
diff_time
=
Math
.
abs
(
today_plus_six_month
-
today
);
const
diff_days
=
Math
.
ceil
(
diff_time
/
(
1000
*
60
*
60
*
24
));
$
.
ajax
({
type
:
'POST'
,
url
:
"/shifts/request_delay"
,
dataType
:
"json"
,
data
:
{
verif_token
:
partner_data
.
verif_token
,
idPartner
:
partner_data
.
partner_id
,
start_date
:
delay_start
,
duration
:
diff_days
},
success
:
function
()
{
partner_data
.
cooperative_state
=
'delay'
;
partner_data
.
date_delay_stop
=
today
.
getFullYear
()
+
'-'
+
(
today
.
getMonth
()
+
1
)
+
'-'
+
today
.
getDate
();
resolve
();
},
error
:
function
(
data
)
{
err
=
{
msg
:
"erreur serveur lors de la création du délai"
,
ctx
:
'request_delay'
};
if
(
typeof
data
.
responseJSON
!=
'undefined'
&&
typeof
data
.
responseJSON
.
error
!=
'undefined'
)
{
err
.
msg
+=
' : '
+
data
.
responseJSON
.
error
;
}
report_JS_error
(
err
,
'members_space.home'
);
closeModal
();
// TODO Notify
alert
(
'Erreur lors de la création du délai.'
);
}
});
});
}
function
init_my_shifts_tile
()
{
function
init_my_shifts_tile
()
{
if
(
incoming_shifts
.
length
===
0
)
{
if
(
incoming_shifts
.
length
===
0
)
{
$
(
"#home_tile_my_services #home_incoming_services"
).
text
(
"Aucun service à venir..."
)
$
(
"#home_tile_my_services #home_incoming_services"
).
text
(
"Aucun service à venir..."
)
...
@@ -28,6 +73,8 @@ function init_my_shifts_tile() {
...
@@ -28,6 +73,8 @@ function init_my_shifts_tile() {
}
}
function
init_my_info_tile
()
{
function
init_my_info_tile
()
{
$
(
"#home_choose_makeups"
).
off
();
// Status related
// Status related
$
(
"#home_tile_my_info #home_member_status"
)
$
(
"#home_tile_my_info #home_member_status"
)
.
text
(
possible_cooperative_state
[
partner_data
.
cooperative_state
])
.
text
(
possible_cooperative_state
[
partner_data
.
cooperative_state
])
...
@@ -43,9 +90,11 @@ function init_my_info_tile() {
...
@@ -43,9 +90,11 @@ function init_my_info_tile() {
// If the member is suspended & doesn't have a delay
// If the member is suspended & doesn't have a delay
$
(
"#home_choose_makeups"
).
on
(
'click'
,
()
=>
{
$
(
"#home_choose_makeups"
).
on
(
'click'
,
()
=>
{
// Create 6 month delay
// Create 6 month delay
request_delay
()
.
then
(()
=>
{
// Then redirect to calendar
// Then redirect to calendar
goto
(
'echange-de-services'
);
goto
(
'echange-de-services'
);
})
});
});
}
else
{
}
else
{
$
(
"#home_choose_makeups"
).
on
(
'click'
,
()
=>
{
$
(
"#home_choose_makeups"
).
on
(
'click'
,
()
=>
{
...
@@ -53,7 +102,6 @@ function init_my_info_tile() {
...
@@ -53,7 +102,6 @@ function init_my_info_tile() {
});
});
}
}
}
}
// date_delay_stop : if exists: 2021-09-22 ; else: False
$
(
"#home_tile_my_info #home_member_shift_name"
).
text
(
partner_data
.
regular_shift_name
);
$
(
"#home_tile_my_info #home_member_shift_name"
).
text
(
partner_data
.
regular_shift_name
);
...
...
shifts/models.py
View file @
33e5c6d2
...
@@ -173,21 +173,23 @@ class CagetteShift(models.Model):
...
@@ -173,21 +173,23 @@ class CagetteShift(models.Model):
coop_logger
.
error
(
"Reopen shift :
%
s"
,
str
(
e
))
coop_logger
.
error
(
"Reopen shift :
%
s"
,
str
(
e
))
return
response
return
response
def
create_delay
(
self
,
data
):
def
create_delay
(
self
,
data
,
duration
=
28
):
"""Create a delay for a member.
"""
A delay is 28 days from the given start_date.
Create a delay for a member.
If no duration is specified, a delay is by default 28 days from the given start_date.
If the partner already has a current extension: extend it by
28
days.
If the partner already has a current extension: extend it by
[duration]
days.
Else, create a 28 days delay.
Else, create a 28 days delay.
Args:
Args:
idPartner: int
idPartner: int
start_date: string date at iso format (eg. "2019-11-19")
start_date: string date at iso format (eg. "2019-11-19")
Date from which the
28 days delay
is calculated
Date from which the
delay end date
is calculated
(optionnal) extension_beginning: string date at iso format
(optionnal) extension_beginning: string date at iso format
If specified, will be the actual starting date of the extension.
If specified, will be the actual starting date of the extension.
Should be inferior than start_date.
Should be inferior than start_date.
(at creation only: odoo ignores delays if today's not inside)
(at creation only: odoo ignores delays if today's not inside)
duration: nb of days
"""
"""
action
=
'create'
action
=
'create'
...
@@ -218,7 +220,7 @@ class CagetteShift(models.Model):
...
@@ -218,7 +220,7 @@ class CagetteShift(models.Model):
# Update current extension
# Update current extension
if
action
==
'update'
:
if
action
==
'update'
:
ext_date_stop
=
datetime
.
datetime
.
strptime
(
extension
[
'date_stop'
],
'
%
Y-
%
m-
%
d'
)
.
date
()
ext_date_stop
=
datetime
.
datetime
.
strptime
(
extension
[
'date_stop'
],
'
%
Y-
%
m-
%
d'
)
.
date
()
ext_new_date_stop
=
(
ext_date_stop
+
datetime
.
timedelta
(
days
=
28
))
ext_new_date_stop
=
(
ext_date_stop
+
datetime
.
timedelta
(
days
=
duration
))
update_data
=
{
update_data
=
{
'date_stop'
:
ext_new_date_stop
.
isoformat
()
'date_stop'
:
ext_new_date_stop
.
isoformat
()
...
@@ -235,12 +237,11 @@ class CagetteShift(models.Model):
...
@@ -235,12 +237,11 @@ class CagetteShift(models.Model):
ext_type_id
=
val
[
'id'
]
ext_type_id
=
val
[
'id'
]
starting_date
=
datetime
.
datetime
.
strptime
(
data
[
'start_date'
],
'
%
Y-
%
m-
%
d'
)
.
date
()
starting_date
=
datetime
.
datetime
.
strptime
(
data
[
'start_date'
],
'
%
Y-
%
m-
%
d'
)
.
date
()
ending_date
=
(
starting_date
+
datetime
.
timedelta
(
days
=
28
))
ending_date
=
(
starting_date
+
datetime
.
timedelta
(
days
=
duration
))
if
'extension_beginning'
in
data
:
if
'extension_beginning'
in
data
:
starting_date
=
datetime
.
datetime
.
strptime
(
data
[
'extension_beginning'
],
'
%
Y-
%
m-
%
d'
)
.
date
()
starting_date
=
datetime
.
datetime
.
strptime
(
data
[
'extension_beginning'
],
'
%
Y-
%
m-
%
d'
)
.
date
()
#TODO : bloquer si nextmonth > date_end_alert+5months ? (blocage js)
fields
=
{
fields
=
{
"partner_id"
:
data
[
'idPartner'
],
"partner_id"
:
data
[
'idPartner'
],
"type_id"
:
ext_type_id
,
"type_id"
:
ext_type_id
,
...
...
shifts/views.py
View file @
33e5c6d2
...
@@ -231,6 +231,7 @@ def add_shift(request):
...
@@ -231,6 +231,7 @@ def add_shift(request):
def
request_delay
(
request
):
def
request_delay
(
request
):
if
'verif_token'
in
request
.
POST
:
if
'verif_token'
in
request
.
POST
:
if
Verification
.
verif_token
(
request
.
POST
.
get
(
'verif_token'
),
int
(
request
.
POST
.
get
(
'idPartner'
)))
is
True
:
if
Verification
.
verif_token
(
request
.
POST
.
get
(
'verif_token'
),
int
(
request
.
POST
.
get
(
'idPartner'
)))
is
True
:
cs
=
CagetteShift
()
cs
=
CagetteShift
()
data
=
{
data
=
{
"idPartner"
:
int
(
request
.
POST
[
'idPartner'
]),
"idPartner"
:
int
(
request
.
POST
[
'idPartner'
]),
...
@@ -239,10 +240,15 @@ def request_delay(request):
...
@@ -239,10 +240,15 @@ def request_delay(request):
if
(
'extension_beginning'
in
request
.
POST
):
if
(
'extension_beginning'
in
request
.
POST
):
data
[
'extension_beginning'
]
=
request
.
POST
[
'extension_beginning'
]
data
[
'extension_beginning'
]
=
request
.
POST
[
'extension_beginning'
]
if
(
'duration'
in
request
.
POST
):
duration
=
int
(
request
.
POST
[
'duration'
])
else
:
duration
=
None
response
=
{
'result'
:
False
}
response
=
{
'result'
:
False
}
try
:
try
:
new_id
=
cs
.
create_delay
(
data
)
new_id
=
cs
.
create_delay
(
data
,
duration
)
if
(
new_id
):
if
(
new_id
):
response
=
{
'result'
:
True
}
response
=
{
'result'
:
True
}
else
:
else
:
...
...
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