Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
odoo
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
0
Merge Requests
0
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
odoo
Commits
2f19b44e
Commit
2f19b44e
authored
Feb 22, 2022
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add security to ensure points will be added
parent
6f151f38
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
21 deletions
+25
-21
shift_counter_event.py
...addons/lacagette_membership/models/shift_counter_event.py
+25
-21
No files found.
lacagette_addons/lacagette_membership/models/shift_counter_event.py
View file @
2f19b44e
...
...
@@ -11,27 +11,31 @@ class ShiftCounterEvent(models.Model):
def
_update_partner_target_status
(
self
,
vals
):
"""actions when points are removed or added"""
conf
=
self
.
env
[
'ir.config_parameter'
]
suspension_limit
=
int
(
conf
.
get_param
(
"lacagette_membership.points_limit_to_get_suspended"
))
unsubscribe_limit
=
int
(
conf
.
get_param
(
"lacagette_membership.points_limit_to_get_unsubscribed"
))
if
vals
[
'point_qty'
]
!=
0
:
res_partner
=
self
.
env
[
'res.partner'
]
.
search
([(
'id'
,
'='
,
vals
[
'partner_id'
])])
if
res_partner
:
p
=
res_partner
[
0
]
points_before_removing_points
=
p
.
final_ftop_point
if
p
.
shift_type
==
"ftop"
else
p
.
final_standard_point
points_after_removal
=
points_before_removing_points
+
vals
[
'point_qty'
]
_logger
.
info
(
"points_after_removal =
%
s, current_state =
%
s"
,
str
(
points_after_removal
),
p
.
cooperative_state
)
if
points_after_removal
<=
suspension_limit
or
points_after_removal
<=
unsubscribe_limit
:
target_status
=
None
if
(
points_after_removal
<=
suspension_limit
and
p
.
cooperative_state
!=
'delay'
):
target_status
=
'suspended'
if
points_after_removal
<=
unsubscribe_limit
:
target_status
=
'unsubscribed'
if
target_status
is
not
None
:
p
.
update
({
'target_status'
:
target_status
,
'current_cooperative_state'
:
p
.
cooperative_state
})
try
:
conf
=
self
.
env
[
'ir.config_parameter'
]
suspension_limit
=
int
(
conf
.
get_param
(
"lacagette_membership.points_limit_to_get_suspended"
))
unsubscribe_limit
=
int
(
conf
.
get_param
(
"lacagette_membership.points_limit_to_get_unsubscribed"
))
if
vals
[
'point_qty'
]
!=
0
:
res_partner
=
self
.
env
[
'res.partner'
]
.
search
([(
'id'
,
'='
,
vals
[
'partner_id'
])])
if
res_partner
:
p
=
res_partner
[
0
]
points_before_removing_points
=
p
.
final_ftop_point
if
p
.
shift_type
==
"ftop"
else
p
.
final_standard_point
points_after_removal
=
points_before_removing_points
+
vals
[
'point_qty'
]
_logger
.
info
(
"points_after_removal =
%
s, current_state =
%
s"
,
str
(
points_after_removal
),
p
.
cooperative_state
)
if
points_after_removal
<=
suspension_limit
or
points_after_removal
<=
unsubscribe_limit
:
target_status
=
None
if
(
points_after_removal
<=
suspension_limit
and
p
.
cooperative_state
!=
'delay'
):
target_status
=
'suspended'
if
points_after_removal
<=
unsubscribe_limit
:
target_status
=
'unsubscribed'
if
target_status
is
not
None
:
p
.
update
({
'target_status'
:
target_status
,
'current_cooperative_state'
:
p
.
cooperative_state
})
except
Exception
as
e
:
# don't block process if an error occurs here
_logger
.
error
(
"Error during _update_partner_target_status :
%
s"
,
str
(
e
))
@api.model
def
write
(
self
,
vals
):
...
...
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