Commit 562b349f by François C.

Add LaCagette shifts to custom shifts data thru API calls

parent 28ab4fb6
# -*- coding: utf-8 -*-
from . import models
# -*- coding: utf-8 -*-
{
'name': "La Cagette - Shifts",
'summary': """
Specific actions related to Shifts""",
'description': """
Actions currently implemented:
- Retrieve all shifts, counting for each of them only active registrations
""",
'author': "damien.moulard",
'website': "https://lacagette-coop.fr",
# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml
# for the full list
'category': 'Uncategorized',
'version': '0.0.1',
# any module necessary for this one to work correctly
'depends': ['base'],
# always loaded
'data': [
],
'installable': True,
}
# -*- coding: utf-8 -*-
from . import lacagette_shifts
# -*- coding: utf-8 -*-
from openerp import _, api, models, fields
class LaCagetteShifts(models.Model):
_name = "lacagette_shifts"
@api.model
def get_active_shifts(self):
""" Get shifts, counting active registrations to each of them"""
# Get registrations which:
# - belong to an active shift
# - are in an accepted state
# - begin before now
# - don't have an end date OR end after now
# Group by shift and count
sql = """SELECT str.shift_template_id, COUNT(str.shift_template_id) AS seats_active_registration
FROM shift_template st
LEFT JOIN shift_template_registration str ON str.shift_template_id = st.id
LEFT JOIN shift_template_registration_line strl ON strl.registration_id = str.id
WHERE active IS TRUE
AND str.state IN ('draft', 'open', 'done', 'replacing')
AND strl.date_begin < NOW()
AND (strl.date_end IS NULL OR strl.date_end >= NOW())
GROUP BY str.shift_template_id"""
self.env.cr.execute(sql)
res = self.env.cr.dictfetchall()
return (res)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment