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
fb155821
Commit
fb155821
authored
Sep 28, 2021
by
François C.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Membership parameters mangement to fit with many scenarii
parent
a5f1a125
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
128 additions
and
10 deletions
+128
-10
__openerp__.py
lacagette_addons/lacagette_membership/__openerp__.py
+5
-2
ir_config_parameter_data.xml
...ns/lacagette_membership/data/ir_config_parameter_data.xml
+21
-0
__init__.py
lacagette_addons/lacagette_membership/models/__init__.py
+1
-0
member_state_change.py
...addons/lacagette_membership/models/member_state_change.py
+21
-0
res_partner.py
lacagette_addons/lacagette_membership/models/res_partner.py
+62
-1
shift_counter_event.py
...addons/lacagette_membership/models/shift_counter_event.py
+11
-5
shift_registration.py
..._addons/lacagette_membership/models/shift_registration.py
+3
-2
ir.model.access.csv
..._addons/lacagette_membership/security/ir.model.access.csv
+4
-0
No files found.
lacagette_addons/lacagette_membership/__openerp__.py
View file @
fb155821
...
...
@@ -7,6 +7,8 @@
'description'
:
"""
Specific rules are beeing implemented
lacagette_membership.absence_status can be excused or absent
"""
,
'author'
:
"fracolo/cooperatic"
,
...
...
@@ -14,12 +16,13 @@
#
'category'
:
'Uncategorized'
,
'version'
:
'0.0.
4
'
,
'version'
:
'0.0.
5
'
,
# any module necessary for this one to work correctly
'depends'
:
[
'base'
,
'coop_shift'
],
'depends'
:
[
'base'
,
'coop_
membership'
,
'coop_
shift'
],
# always loaded
'data'
:
[
'security/ir.model.access.csv'
,
'data/ir_cron.xml'
,
'data/ir_config_parameter_data.xml'
],
...
...
lacagette_addons/lacagette_membership/data/ir_config_parameter_data.xml
View file @
fb155821
...
...
@@ -4,4 +4,25 @@
<field
name=
"key"
>
lacagette_membership.makeups_to_do_on_shift_missed
</field>
<field
name=
"value"
>
2
</field>
</record>
<record
id=
"points_limit_to_get_suspended"
model=
"ir.config_parameter"
>
<field
name=
"key"
>
lacagette_membership.points_limit_to_get_suspended
</field>
<field
name=
"value"
>
-2
</field>
</record>
<record
id=
"points_limit_to_get_unsubscribed"
model=
"ir.config_parameter"
>
<field
name=
"key"
>
lacagette_membership.points_limit_to_get_unsubscribed
</field>
<field
name=
"value"
>
-3
</field>
</record>
<record
id=
"makeups_to_do_if_missed_id"
model=
"ir.config_parameter"
>
<field
name=
"key"
>
lacagette_membership.absence_status
</field>
<field
name=
"value"
>
excused
</field>
</record>
<record
id=
"extension_duration"
model=
"ir.config_parameter"
>
<field
name=
"key"
>
lacagette_membership.extension_duration
</field>
<field
name=
"value"
>
6 months
</field>
</record>
<record
id=
"max_successive_extensions"
model=
"ir.config_parameter"
>
<field
name=
"key"
>
lacagette_membership.max_successive_extensions
</field>
<field
name=
"value"
>
1
</field>
</record>
</odoo>
lacagette_addons/lacagette_membership/models/__init__.py
View file @
fb155821
...
...
@@ -4,3 +4,4 @@ from . import res_partner
from
.
import
shift_registration
from
.
import
shift_counter_event
from
.
import
shift_shift
from
.
import
member_state_change
lacagette_addons/lacagette_membership/models/member_state_change.py
0 → 100644
View file @
fb155821
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html
from
openerp
import
fields
,
models
class
MembersStateChange
(
models
.
Model
):
_name
=
"member.state.change"
member_id
=
fields
.
Many2one
(
comodel_name
=
'res.partner'
,
ondelete
=
'cascade'
,
index
=
True
)
state
=
fields
.
Char
(
'state'
,
size
=
15
)
lacagette_addons/lacagette_membership/models/res_partner.py
View file @
fb155821
...
...
@@ -2,6 +2,9 @@
from
openerp
import
_
,
api
,
models
,
fields
import
datetime
import
logging
_logger
=
logging
.
getLogger
(
__name__
)
TARGET_STATUS_SELECTION
=
[
(
'unsubscribed'
,
'Unsubscribed'
),
...
...
@@ -26,7 +29,7 @@ class ResPartner(models.Model):
for
p
in
self
.
env
[
'res.partner'
]
\
.
search
([(
'target_status'
,
'!='
,
""
)]):
new_values
=
{
'target_status'
:
""
,
"date_alert_stop"
:
""
}
new_values
=
{
'target_status'
:
""
,
"date_alert_stop"
:
False
}
if
p
.
final_ftop_point
<
0
:
new_values
[
'cooperative_state'
]
=
p
.
target_status
if
new_values
[
'cooperative_state'
]
==
"unsubscribed"
:
...
...
@@ -56,3 +59,60 @@ class ResPartner(models.Model):
today
=
datetime
.
datetime
.
now
()
.
strftime
(
"
%
Y-
%
m-
%
d"
)
for
ext
in
extension_model
.
search
([(
'id'
,
'in'
,
extension_ids
)]):
ext
.
update
({
'date_stop'
:
today
})
@api.multi
def
can_have_extension
(
self
):
"""Return if the member can ask for an extension"""
answer
=
True
conf
=
self
.
env
[
'ir.config_parameter'
]
max_nb
=
int
(
conf
.
get_param
(
"lacagette_membership.max_successive_extensions"
))
if
max_nb
==
1
:
args
=
[(
'member_id'
,
'='
,
self
.
id
)]
states
=
self
.
env
[
'member.state.change'
]
\
.
search
(
args
,
order
=
'write_date DESC'
,
limit
=
2
)
"""
member.state.change may have no record for the current member
"""
if
len
(
states
)
>
0
:
if
(
len
(
states
)
==
1
and
states
[
0
][
'state'
]
==
'delay'
or
len
(
states
)
==
2
and
states
[
1
][
'state'
]
==
'delay'
):
answer
=
False
else
:
# need to load data
member
=
self
.
env
[
'res.partner'
]
.
search
([(
'id'
,
'='
,
self
.
id
)])[
0
]
# should exist an other way to do it , but haven't found it
if
member
.
cooperative_state
!=
"up_to_date"
:
answer
=
False
else
:
# TODO : Must have a look to previous extensions
pass
return
answer
def
_write_state_change
(
self
,
state
):
data
=
{
'member_id'
:
self
.
id
,
'state'
:
state
}
self
.
env
[
'member.state.change'
]
.
create
(
data
)
@api.model
def
update
(
self
,
vals
):
res
=
super
(
ResPartner
,
self
)
.
write
(
vals
)
#_logger.info("valeurs reçues pour update partner = %s", str(vals))
state_to_record
=
""
if
'cooperative_state'
in
vals
:
state_to_record
=
vals
[
'cooperative_state'
]
elif
'current_cooperative_state'
in
vals
:
state_to_record
=
vals
[
'current_cooperative_state'
]
if
len
(
state_to_record
)
>
0
:
self
.
_write_state_change
(
state_to_record
)
return
res
@api.model
def
write
(
self
,
vals
):
res
=
super
(
ResPartner
,
self
)
.
write
(
vals
)
# _logger.info("valeurs reçues pour write partner = %s", str(vals))
if
'cooperative_state'
in
vals
:
self
.
_write_state_change
(
vals
[
'cooperative_state'
])
return
res
\ No newline at end of file
lacagette_addons/lacagette_membership/models/shift_counter_event.py
View file @
fb155821
...
...
@@ -11,29 +11,34 @@ class ShiftCounterEvent(models.Model):
def
_update_partner_target_status
(
self
,
vals
):
"""actions if point_qty is negative"""
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
:
points_before_removing_points
=
res_partner
[
0
]
.
final_ftop_point
points_after_removal
=
points_before_removing_points
+
vals
[
'point_qty'
]
_logger
.
info
(
"points_after_removal =
%
s"
,
str
(
points_after_removal
))
if
points_after_removal
<=
-
2
:
if
points_after_removal
<=
suspension_limit
or
points_after_removal
<=
unsubscribe_limit
:
if
points_after_removal
<=
suspension_limit
:
target_status
=
'suspended'
if
points_after_removal
<
-
2
:
if
points_after_removal
<
=
unsubscribe_limit
:
target_status
=
'unsubscribed'
res_partner
[
0
]
.
update
({
'target_status'
:
target_status
})
res_partner
[
0
]
.
update
({
'target_status'
:
target_status
,
'current_cooperative_state'
:
res_partner
[
0
]
.
cooperative_state
})
@api.model
def
write
(
self
,
vals
):
res
=
super
(
ShiftCounterEvent
,
self
)
.
write
(
vals
)
#
_logger.info("Vals reçues = %s", str(vals))
_logger
.
info
(
"Vals reçues =
%
s"
,
str
(
vals
))
self
.
_update_partner_target_status
(
vals
)
return
res
@api.model
def
create
(
self
,
vals
):
self
.
_update_partner_target_status
(
vals
)
#
_logger.info("Vals reçues creation = %s", str(vals))
_logger
.
info
(
"Vals reçues creation =
%
s"
,
str
(
vals
))
return
super
(
ShiftCounterEvent
,
self
)
.
create
(
vals
)
\ No newline at end of file
lacagette_addons/lacagette_membership/models/shift_registration.py
View file @
fb155821
...
...
@@ -20,10 +20,11 @@ class ShiftRegistration(models.Model):
@api.multi
def
write
(
self
,
vals
):
res
=
super
(
ShiftRegistration
,
self
)
.
write
(
vals
)
if
'state'
in
vals
and
vals
[
'state'
]
==
'excused'
:
conf
=
self
.
env
[
'ir.config_parameter'
]
absence_status
=
conf
.
get_param
(
"lacagette_membership.absence_status"
)
if
'state'
in
vals
and
vals
[
'state'
]
==
absence_status
:
if
self
.
ids
:
# it is the case when called from "absence cron job" run in external third-party
conf
=
self
.
env
[
'ir.config_parameter'
]
to_add
=
conf
.
get_param
(
"lacagette_membership.makeups_to_do_on_shift_missed"
)
for
s
in
self
.
env
[
'shift.registration'
]
\
.
search
([(
'id'
,
'in'
,
self
.
ids
)]):
...
...
lacagette_addons/lacagette_membership/security/ir.model.access.csv
0 → 100644
View file @
fb155821
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
,,,,,,,
,,,,,,,
access_model_member_state_change,access_model_member_state_change,model_member_state_change,coop_shift.group_shift_user,1,1,1,1
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