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
7e9aa8a0
Commit
7e9aa8a0
authored
Sep 30, 2021
by
François C.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adaptations pour nouveau cron génération des services (durée paramétrable)
parent
f4db68f7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
137 additions
and
2 deletions
+137
-2
ir_config_parameter_data.xml
...ns/lacagette_membership/data/ir_config_parameter_data.xml
+4
-0
ir_cron.xml
lacagette_addons/lacagette_membership/data/ir_cron.xml
+15
-1
__init__.py
lacagette_addons/lacagette_membership/models/__init__.py
+2
-0
res_partner.py
lacagette_addons/lacagette_membership/models/res_partner.py
+1
-1
shift_template.py
...ette_addons/lacagette_membership/models/shift_template.py
+115
-0
No files found.
lacagette_addons/lacagette_membership/data/ir_config_parameter_data.xml
View file @
7e9aa8a0
...
@@ -25,4 +25,8 @@
...
@@ -25,4 +25,8 @@
<field
name=
"key"
>
lacagette_membership.committees_shift_id
</field>
<field
name=
"key"
>
lacagette_membership.committees_shift_id
</field>
<field
name=
"value"
>
</field>
<field
name=
"value"
>
</field>
</record>
</record>
<record
id=
"shift_creation_days"
model=
"ir.config_parameter"
>
<field
name=
"key"
>
lacagette_membership.shift_creation_days
</field>
<field
name=
"value"
>
180
</field>
</record>
</odoo>
</odoo>
lacagette_addons/lacagette_membership/data/ir_cron.xml
View file @
7e9aa8a0
...
@@ -31,7 +31,7 @@
...
@@ -31,7 +31,7 @@
<field
name=
"active"
eval=
"False"
/>
<field
name=
"active"
eval=
"False"
/>
<field
name=
"priority"
>
1
</field>
<field
name=
"priority"
>
1
</field>
</record>
</record>
<record
forcecreate=
"True"
id=
"cron_close_ftop_shifts"
model=
"ir.cron"
>
<record
forcecreate=
"True"
id=
"cron_close_ftop_shifts"
model=
"ir.cron"
>
<field
name=
"name"
>
Daily close FTOP shifts
</field>
<field
name=
"name"
>
Daily close FTOP shifts
</field>
<field
name=
"user_id"
ref=
"base.user_root"
/>
<field
name=
"user_id"
ref=
"base.user_root"
/>
<field
name=
"interval_number"
>
1
</field>
<field
name=
"interval_number"
>
1
</field>
...
@@ -44,4 +44,17 @@
...
@@ -44,4 +44,17 @@
<field
name=
"active"
eval=
"False"
/>
<field
name=
"active"
eval=
"False"
/>
<field
name=
"priority"
>
1
</field>
<field
name=
"priority"
>
1
</field>
</record>
</record>
<record
forcecreate=
"True"
id=
"cron_shifts_generation"
model=
"ir.cron"
>
<field
name=
"name"
>
Generate shifts (La Cagette version)
</field>
<field
name=
"user_id"
ref=
"base.user_root"
/>
<field
name=
"interval_number"
>
1
</field>
<field
name=
"interval_type"
>
weeks
</field>
<field
name=
"numbercall"
>
-1
</field>
<field
name=
"doall"
eval=
"False"
/>
<field
name=
"model"
eval=
"'lacagette.shift.template'"
/>
<field
name=
"function"
eval=
"'run_shift_creation'"
/>
<field
name=
"args"
eval=
"'()'"
/>
<field
name=
"active"
eval=
"False"
/>
<field
name=
"priority"
>
1
</field>
</record>
</odoo>
</odoo>
\ No newline at end of file
lacagette_addons/lacagette_membership/models/__init__.py
View file @
7e9aa8a0
...
@@ -5,3 +5,4 @@ from . import shift_registration
...
@@ -5,3 +5,4 @@ from . import shift_registration
from
.
import
shift_counter_event
from
.
import
shift_counter_event
from
.
import
shift_shift
from
.
import
shift_shift
from
.
import
member_state_change
from
.
import
member_state_change
from
.
import
shift_template
\ No newline at end of file
lacagette_addons/lacagette_membership/models/res_partner.py
View file @
7e9aa8a0
...
@@ -58,7 +58,7 @@ class ResPartner(models.Model):
...
@@ -58,7 +58,7 @@ class ResPartner(models.Model):
SELECT s.id
SELECT s.id
FROM shift_extension as s
FROM shift_extension as s
WHERE s.date_stop > now()
WHERE s.date_stop > now()
AND partner_id IN (SELECT id FROM res_partner WHERE cooperative_state in ('up_to_date', 'unsubscribed')
AND partner_id IN (SELECT id FROM res_partner WHERE cooperative_state in ('up_to_date', 'unsubscribed')
)
"""
"""
self
.
env
.
cr
.
execute
(
sql
)
self
.
env
.
cr
.
execute
(
sql
)
extension_ids
=
self
.
env
.
cr
.
fetchall
()
extension_ids
=
self
.
env
.
cr
.
fetchall
()
...
...
lacagette_addons/lacagette_membership/models/shift_template.py
0 → 100644
View file @
7e9aa8a0
# -*- coding: utf-8 -*-
from
openerp
import
_
,
api
,
models
,
fields
from
datetime
import
datetime
,
timedelta
from
dateutil.relativedelta
import
relativedelta
import
logging
_logger
=
logging
.
getLogger
(
__name__
)
class
ShiftTemplate
(
models
.
Model
):
_name
=
"lacagette.shift.template"
_inherit
=
'shift.template'
@api.model
def
ng_create_shifts_from_template
(
self
,
instance
=
None
,
after
=
False
,
before
=
False
):
conf
=
self
.
env
[
'ir.config_parameter'
]
shift_creation_days
=
int
(
conf
.
get_param
(
"lacagette_membership.shift_creation_days"
))
if
not
before
:
before
=
fields
.
Datetime
.
to_string
(
datetime
.
today
()
+
timedelta
(
days
=
shift_creation_days
))
for
template
in
instance
:
if
len
(
str
(
template
.
rrule
)
.
strip
())
==
0
:
continue
# It's not a recurring template
after
=
template
.
last_shift_date
rec_dates
=
template
.
get_recurrent_dates
(
after
=
after
,
before
=
before
)
for
rec_date
in
rec_dates
:
start_date_object_tz
=
datetime
.
strptime
(
template
.
start_datetime_tz
,
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
date_begin
=
datetime
.
strftime
(
rec_date
+
timedelta
(
hours
=
(
start_date_object_tz
.
hour
))
+
timedelta
(
minutes
=
(
start_date_object_tz
.
minute
)),
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
if
date_begin
.
split
(
" "
)[
0
]
<=
template
.
last_shift_date
:
continue
end_date_object_tz
=
datetime
.
strptime
(
template
.
end_datetime_tz
,
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
diff_day
=
end_date_object_tz
.
day
-
start_date_object_tz
.
day
diff_month
=
end_date_object_tz
.
month
-
\
start_date_object_tz
.
month
diff_year
=
end_date_object_tz
.
year
-
start_date_object_tz
.
year
date_end
=
datetime
.
strftime
(
rec_date
+
timedelta
(
hours
=
(
end_date_object_tz
.
hour
))
+
timedelta
(
minutes
=
(
end_date_object_tz
.
minute
))
+
relativedelta
(
days
=
diff_day
)
+
relativedelta
(
months
=
diff_month
)
+
relativedelta
(
years
=
diff_year
),
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
rec_date
=
datetime
.
strftime
(
rec_date
,
"
%
Y-
%
m-
%
d"
)
vals
=
{
'shift_template_id'
:
template
.
id
,
'name'
:
template
.
name
,
'user_ids'
:
[(
6
,
0
,
template
.
user_ids
.
ids
)],
'company_id'
:
template
.
company_id
.
id
,
'seats_max'
:
template
.
seats_max
,
'seats_availability'
:
template
.
seats_availability
,
'seats_min'
:
template
.
seats_min
,
'date_begin_tz'
:
date_begin
,
'date_end_tz'
:
date_end
,
'state'
:
'draft'
,
'reply_to'
:
template
.
reply_to
,
'address_id'
:
template
.
address_id
.
id
,
'description'
:
template
.
description
,
'shift_type_id'
:
template
.
shift_type_id
.
id
,
'week_number'
:
template
.
week_number
,
'week_list'
:
template
.
week_list
,
'shift_ticket_ids'
:
None
,
}
shift_id
=
self
.
env
[
'shift.shift'
]
.
create
(
vals
)
for
ticket
in
template
.
shift_ticket_ids
:
vals
=
{
'name'
:
ticket
.
name
,
'shift_id'
:
shift_id
.
id
,
'product_id'
:
ticket
.
product_id
.
id
,
'price'
:
ticket
.
price
,
'deadline'
:
ticket
.
deadline
,
'seats_availability'
:
ticket
.
seats_availability
,
'seats_max'
:
ticket
.
seats_max
,
}
if
ticket
.
product_id
.
shift_type_id
.
is_ftop
:
vals
[
'seats_availability'
]
=
'limited'
vals
[
'seats_max'
]
=
0
ticket_id
=
self
.
env
[
'shift.ticket'
]
.
create
(
vals
)
for
attendee
in
ticket
.
registration_ids
:
state
,
strl_id
=
attendee
.
_get_state
(
rec_date
)
if
state
:
vals
=
{
'partner_id'
:
attendee
.
partner_id
.
id
,
'user_ids'
:
[(
6
,
0
,
template
.
user_ids
.
ids
)],
'state'
:
state
,
'email'
:
attendee
.
email
,
'phone'
:
attendee
.
phone
,
'name'
:
attendee
.
name
,
'shift_id'
:
shift_id
.
id
,
'shift_ticket_id'
:
ticket_id
.
id
,
'tmpl_reg_line_id'
:
strl_id
,
'template_created'
:
True
,
}
self
.
env
[
'shift.registration'
]
.
with_context
(
from_shift_template
=
True
)
.
create
(
vals
)
@api.model
def
run_shift_creation
(
self
):
# This method is called by the cron task
conf
=
self
.
env
[
'ir.config_parameter'
]
shift_creation_days
=
int
(
conf
.
get_param
(
"lacagette_membership.shift_creation_days"
))
#templates = self.env['shift.template'].search([('recurrency', '=', True)])
templates
=
self
.
env
[
'shift.template'
]
.
search
([(
'id'
,
'='
,
60
)])
for
template
in
templates
:
self
.
ng_create_shifts_from_template
(
instance
=
template
,
before
=
fields
.
Datetime
.
to_string
(
datetime
.
today
()
+
timedelta
(
days
=
shift_creation_days
)))
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