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
7e7468ec
Commit
7e7468ec
authored
Aug 07, 2023
by
Yvon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extract core of method delete_pair and call it after set_cooperative_state('gone')
parent
b76bd834
Pipeline
#2870
failed with stage
in 1 minute 5 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
10 deletions
+33
-10
admin.py
members/admin.py
+33
-10
No files found.
members/admin.py
View file @
7e7468ec
...
...
@@ -552,6 +552,13 @@ def delete_shift_template_registration(request):
if
permanent_unsuscribe
is
True
:
res
[
"set_done"
]
=
cm
.
set_cooperative_state
(
"gone"
)
if
res
[
"set_done"
]:
""" Delete pair(s?) of partner if it is a parent to improve statistics (#4810) """
api
=
OdooAPI
()
associated_members
=
api
.
search_read
(
'res.partner'
,
[[
'parent_id'
,
'='
,
partner_id
]],
[
'id'
])
for
am
in
associated_members
:
data
=
{
"child"
:
{
"id"
:
am
[
"id"
]},
"gone"
:
[
"parent"
,
"child"
]}
delete_pair_core
(
data
)
except
Exception
as
e
:
res
[
"error"
]
=
str
(
e
)
...
...
@@ -895,14 +902,38 @@ def delete_pair(request):
return
HttpResponse
(
template
.
render
(
context
,
request
))
elif
request
.
method
==
'POST'
:
if
CagetteUser
.
are_credentials_ok
(
request
):
api
=
OdooAPI
()
data
=
json
.
loads
(
request
.
body
.
decode
())
delete_pair_core
(
data
)
response
=
JsonResponse
({
"message"
:
"Succesfuly unpaired members"
},
status
=
200
)
else
:
response
=
JsonResponse
({
"message"
:
"Unauthorized"
},
status
=
403
)
return
response
else
:
return
JsonResponse
({
"message"
:
"Method Not Allowed"
},
status
=
405
)
def
delete_pair_core
(
data
):
"""
Core of delete_pair
argument example :
{
"child": {
"id": "1620"
},
"gone": [
"parent",
"child"
]
}
"""
api
=
OdooAPI
()
child_id
=
int
(
data
[
'child'
][
'id'
])
child
=
api
.
search_read
(
'res.partner'
,
[[
'id'
,
'='
,
child_id
]],
[
'email'
,
'id'
,
'parent_id'
])[
0
]
child_accounts
=
api
.
search_read
(
'res.partner'
,
[[
'email'
,
'='
,
child
[
'email'
]]],
[
'id'
,
'email'
])
prev_child
=
[
x
[
'id'
]
for
x
in
child_accounts
if
x
[
'id'
]
!=
child_id
]
parent
=
api
.
search_read
(
'res.partner'
,
[[
'id'
,
'='
,
child
[
'parent_id'
][
0
]]],
[
'cooperative_state'
])[
0
]
api
.
update
(
'res.partner'
,
[
child_id
],
{
"parent_id"
:
False
,
"is_associated_people"
:
False
,
"active"
:
False
,
"is_former_associated_people"
:
True
})
api
.
update
(
'res.partner'
,
[
child_id
],
{
"parent_id"
:
False
,
"is_associated_people"
:
False
,
"active"
:
False
,
"is_former_associated_people"
:
True
})
child_update_fields
=
{
'cooperative_state'
:
"unsubscribed"
,
"is_former_associated_people"
:
True
}
if
'gone'
in
data
and
'child'
in
data
[
'gone'
]:
child_update_fields
[
'cooperative_state'
]
=
"gone"
...
...
@@ -910,11 +941,3 @@ def delete_pair(request):
api
.
update
(
"res.partner"
,
[
id
],
child_update_fields
)
if
'gone'
in
data
and
'parent'
in
data
[
'gone'
]:
api
.
update
(
"res.partner"
,
[
parent
[
'id'
]],
{
'cooperative_state'
:
"gone"
,
"is_former_associated_people"
:
True
})
response
=
JsonResponse
({
"message"
:
"Succesfuly unpaired members"
},
status
=
200
)
else
:
response
=
JsonResponse
({
"message"
:
"Unauthorized"
},
status
=
403
)
return
response
else
:
return
JsonResponse
({
"message"
:
"Method Not Allowed"
},
status
=
405
)
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