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
42f1607b
Commit
42f1607b
authored
Jan 13, 2025
by
Yvon Kerdoncuff
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refacto code related to registrations and exempted people in cagette services
parent
dd86a31c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
40 deletions
+30
-40
models.py
shifts/models.py
+30
-40
No files found.
shifts/models.py
View file @
42f1607b
...
...
@@ -826,32 +826,17 @@ class CagetteServices(models.Model):
[
'state'
,
'='
,
'open'
]]
fields
=
[
'state'
,
'partner_id'
,
'date_begin'
,
'shift_id'
]
res
=
api
.
search_read
(
'shift.registration'
,
cond
,
fields
)
ids
=
[]
partner_ids
=
[]
excluded_partner
=
[]
canceled_reg_ids
=
[]
# for exempted people
shift_ids
=
[]
for
r
in
res
:
partner_ids
.
append
(
int
(
r
[
'partner_id'
][
0
]))
shift_id
=
int
(
r
[
'shift_id'
][
0
])
if
shift_id
not
in
shift_ids
:
shift_ids
.
append
(
shift_id
)
cond
=
[[
'id'
,
'in'
,
partner_ids
],
[
'cooperative_state'
,
'in'
,
[
'exempted'
]]]
fields
=
[
'id'
]
res_exempted
=
api
.
search_read
(
'res.partner'
,
cond
,
fields
)
for
r
in
res_exempted
:
excluded_partner
.
append
(
int
(
r
[
'id'
]))
for
r
in
res
:
if
not
(
int
(
r
[
'partner_id'
][
0
])
in
excluded_partner
):
d_begin
=
r
[
'date_begin'
]
(
d
,
h
)
=
d_begin
.
split
(
' '
)
(
_h
,
_m
,
_s
)
=
h
.
split
(
':'
)
if
int
(
_h
)
<
21
:
ids
.
append
(
int
(
r
[
'id'
]))
else
:
canceled_reg_ids
.
append
(
int
(
r
[
'id'
]))
# coop_logger.info("Traitement absences shift_registration ids %s", ids)
#TODO : improve name of following method
canceled_reg_ids
,
excluded_partner
,
ids
=
CagetteServices
.
fetch_registrations_infos_excluding_exempted_people
(
api
,
partner_ids
,
res
)
f
=
{
'state'
:
absence_status
,
'date_closed'
:
now
.
isoformat
()}
update_shift_reg_result
=
{
'update'
:
False
,
'reg_shift'
:
res
,
'errors'
:
[]}
individual_update_result
=
{}
...
...
@@ -878,6 +863,28 @@ class CagetteServices(models.Model):
return
update_shift_reg_result
@staticmethod
def
fetch_registrations_infos_excluding_exempted_people
(
api
,
partner_ids
,
res
):
#TODO : document this method
ids
=
[]
excluded_partner
=
[]
canceled_reg_ids
=
[]
# for exempted people
cond
=
[[
'id'
,
'in'
,
partner_ids
],
[
'cooperative_state'
,
'in'
,
[
'exempted'
]]]
fields
=
[
'id'
]
res_exempted
=
api
.
search_read
(
'res.partner'
,
cond
,
fields
)
for
r
in
res_exempted
:
excluded_partner
.
append
(
int
(
r
[
'id'
]))
for
r
in
res
:
if
not
(
int
(
r
[
'partner_id'
][
0
])
in
excluded_partner
):
d_begin
=
r
[
'date_begin'
]
(
d
,
h
)
=
d_begin
.
split
(
' '
)
(
_h
,
_m
,
_s
)
=
h
.
split
(
':'
)
if
int
(
_h
)
<
21
:
ids
.
append
(
int
(
r
[
'id'
]))
else
:
canceled_reg_ids
.
append
(
int
(
r
[
'id'
]))
return
canceled_reg_ids
,
excluded_partner
,
ids
@staticmethod
def
close_ftop_service
():
...
...
@@ -1080,30 +1087,13 @@ class CagetteService(models.Model):
[
'state'
,
'='
,
'open'
]]
fields
=
[
'state'
,
'partner_id'
,
'date_begin'
]
res
=
self
.
o_api
.
search_read
(
'shift.registration'
,
cond
,
fields
)
ids
=
[]
partner_ids
=
[]
excluded_partner
=
[]
canceled_reg_ids
=
[]
# for exempted people
for
r
in
res
:
partner_ids
.
append
(
int
(
r
[
'partner_id'
][
0
]))
cond
=
[[
'id'
,
'in'
,
partner_ids
],
[
'cooperative_state'
,
'in'
,
[
'exempted'
]]]
fields
=
[
'id'
]
res_exempted
=
self
.
o_api
.
search_read
(
'res.partner'
,
cond
,
fields
)
for
r
in
res_exempted
:
excluded_partner
.
append
(
int
(
r
[
'id'
]))
for
r
in
res
:
if
not
(
int
(
r
[
'partner_id'
][
0
])
in
excluded_partner
):
d_begin
=
r
[
'date_begin'
]
(
d
,
h
)
=
d_begin
.
split
(
' '
)
(
_h
,
_m
,
_s
)
=
h
.
split
(
':'
)
if
int
(
_h
)
<
21
:
ids
.
append
(
int
(
r
[
'id'
]))
else
:
canceled_reg_ids
.
append
(
int
(
r
[
'id'
]))
# coop_logger.info("Traitement absences shift_registration ids %s", ids)
#TODO : improve name of following method
canceled_reg_ids
,
excluded_partner
,
ids
=
CagetteServices
.
fetch_registrations_infos_excluding_exempted_people
(
api
,
partner_ids
,
res
)
f
=
{
'state'
:
absence_status
,
'date_closed'
:
now
.
isoformat
()}
update_shift_reg_result
=
{
'update'
:
self
.
o_api
.
update
(
'shift.registration'
,
ids
,
f
),
'reg_shift'
:
res
,
'errors'
:
[]}
if
update_shift_reg_result
[
'update'
]
is
True
:
...
...
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