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
591893b7
Commit
591893b7
authored
Mar 02, 2022
by
François C.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix wrong usage of partner_id when associated people id is used in affect_shift process
parent
f96b09f0
Pipeline
#1866
passed with stage
in 1 minute 30 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
5 deletions
+18
-5
models.py
shifts/models.py
+15
-5
views.py
shifts/views.py
+3
-0
No files found.
shifts/models.py
View file @
591893b7
...
...
@@ -178,20 +178,30 @@ class CagetteShift(models.Model):
def
affect_shift
(
self
,
data
):
"""Affect shift to partner, his associate or both"""
response
=
None
cond
=
[[
'partner_id'
,
'='
,
int
(
data
[
'idPartner'
])],
# partner_id can be 'associated_people' one, which is never use as shift partner_id reference
# So, let's first retrieved data about the res.partner involved
cond
=
[[
'id'
,
'='
,
int
(
data
[
'idPartner'
])]]
fields
=
[
'parent_id'
]
partner
=
self
.
o_api
.
search_read
(
'res.partner'
,
cond
,
fields
,
1
)
if
partner
:
if
partner
[
0
][
'parent_id'
]:
partner_id
=
partner
[
0
][
'parent_id'
][
0
]
else
:
partner_id
=
int
(
data
[
'idPartner'
])
cond
=
[[
'partner_id'
,
'='
,
partner_id
],
[
'id'
,
'='
,
int
(
data
[
'idShiftRegistration'
])]]
fields
=
[
'id'
]
try
:
print
(
cond
)
# make sure there is coherence between shift.registration id and partner_id (to avoid forged request
)
shit_to_affect
=
self
.
o_api
.
search_read
(
'shift.registration'
,
cond
,
fields
,
1
)
print
(
shit_to_affect
)
if
(
len
(
shit_to_affect
)
==
1
):
shift_res
=
shit_to_affect
[
0
]
print
(
shift_res
)
fieldsDatas
=
{
"associate_registered"
:
data
[
'affected_partner'
]}
response
=
self
.
o_api
.
update
(
'shift.registration'
,
[
shift_res
[
'id'
]],
fieldsDatas
)
except
Exception
as
e
:
coop_logger
.
error
(
"Reopen shift :
%
s"
,
str
(
e
))
coop_logger
.
error
(
"Model affect shift :
%
s"
,
str
(
e
))
else
:
coop_logger
.
error
(
"Model affect shift nobody found :
%
s"
,
str
(
cond
))
return
response
def
cancel_shift
(
self
,
idsRegisteur
):
...
...
shifts/views.py
View file @
591893b7
...
...
@@ -239,11 +239,14 @@ def affect_shift(request):
if
Verification
.
verif_token
(
request
.
POST
.
get
(
'verif_token'
),
int
(
request
.
POST
.
get
(
'idPartner'
)))
is
True
:
cs
=
CagetteShift
()
if
'idShiftRegistration'
in
request
.
POST
and
'affected_partner'
in
request
.
POST
:
# if request is made by associated people, idPartner is it's id, not "master" res.partner
# it's will be handled in model's method (affect_shift)
data
=
{
"idPartner"
:
int
(
request
.
POST
[
'idPartner'
]),
"idShiftRegistration"
:
int
(
request
.
POST
[
'idShiftRegistration'
]),
"affected_partner"
:
request
.
POST
[
'affected_partner'
],
}
st_r_id
=
None
try
:
st_r_id
=
cs
.
affect_shift
(
data
)
except
Exception
as
e
:
...
...
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