diff --git a/__manifest__.py b/__manifest__.py index c8d93f64a3c6082d46b831f802f734e9382232b9..f8390e613b2c4be7cb37a810ae3cc5010232570b 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -24,8 +24,12 @@ "views/res_company.xml", "views/res_partner.xml", "views/ur_financial_system.xml", + "views/ur_month_timesheet.xml", "views/ur_regional_convention.xml", "report/report_hr_timesheet.xml", "datas/cgscop_timesheet_code_data.xml", - ] + ], + 'qweb': [ + 'static/src/xml/*.xml', + ], } diff --git a/models/__init__.py b/models/__init__.py index 035a9fe80a994b8bff66ad6ad19afdba37d676b1..92cffcb6e6c253460b413c48e7f75802c9ca0e6d 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -8,5 +8,6 @@ from . import project from . import res_company from . import res_partner from . import ur_financial_system +from . import ur_month_timesheet from . import ur_regional_convention diff --git a/models/ur_month_timesheet.py b/models/ur_month_timesheet.py new file mode 100644 index 0000000000000000000000000000000000000000..11f9c4df6392a0be2e8b31ddf6227692c67fa306 --- /dev/null +++ b/models/ur_month_timesheet.py @@ -0,0 +1,73 @@ +# © 2019 Le Filament (<http://www.le-filament.com>) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models, fields, api + + +def get_years(): + year_list = [] + for i in range(2019, 2030): + year_list.append((i, str(i))) + return year_list + +MONTHS = [(1, 'Janv'), (2, 'Fév'), (3, 'Mars'), (4, 'Avr'), + (5, 'Mai'), (6, 'Juin'), (7, 'Juil'), (8, 'Août'), + (9, 'Sept'), (10, 'Oct'), (11, 'Nov'), (12, 'Dec')] + + +class ScopMonthTimesheet(models.Model): + _name = "ur.month.timesheet" + _description = "Heures theoriques mensuelles" + _order = 'year, month' + + def _default_ur(self): + return self.env['res.company']._ur_default_get() + + year = fields.Selection( + selection=get_years(), + string='Année', + default=fields.Date.today().year) + month = fields.Selection( + selection=MONTHS, + string='Année') + company_id = fields.Many2one( + comodel_name='res.company', + string='Société', + default=lambda self: self.env.user.company_id) + ur_id = fields.Many2one( + 'union.regionale', + string='Union Régionale', + index=True, + on_delete='restrict', + default=_default_ur) + working_time = fields.Integer('Heures théoriques') + + _sql_constraints = [( + 'month_year_uniq', + 'UNIQUE (year, month, ur_id)', + 'Cette date a déjà été renseignée.' + )] + + @api.model + def get_month_values(self): + month_values = self.search([ + '&', '|', '&', + ('year', '<', fields.Date.today().year), + ('month', '>', fields.Date.today().month), + '&', + ('year', '<', fields.Date.today().year + 1), + ('month', '<=', fields.Date.today().month + 1), + ('ur_id', '=', self.env.user.ur_id.id)], + limit=12, + order='year desc, month desc').sorted(reverse=False) + return { + 'month': month_values.mapped(lambda x: { + 'year': x.year, + 'num_month': x.month, + 'month': self._fields['month'].selection[x.month-1][1]}), + 'values': month_values.mapped('working_time'), + 'today': { + 'year': fields.Date.today().year, + 'month': fields.Date.today().month + } + } diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv index ee179f43f7f56b388c3405d95b4bbaf70ef1815b..f06ad99844520e7ef4513f2ebe1028fc3bd07adb 100644 --- a/security/ir.model.access.csv +++ b/security/ir.model.access.csv @@ -12,3 +12,6 @@ access_cgscop_timesheet_sheet_user,access_cgscop_timesheet_sheet_user,model_cgsc access_ur_regional_convention,access_ur_regional_convention,model_ur_regional_convention,base.group_user,1,0,0,0 access_ur_regional_convention_ur_manager,access_ur_regional_convention_ur,model_ur_regional_convention,cgscop_partner.group_ur_list_modif,1,1,1,1 access_ur_regional_convention_cg_manager,access_ur_regional_convention_cg,model_ur_regional_convention,cgscop_partner.group_cg_administrator,1,1,1,1 +access_ur_month_timesheet,access_ur_month_timesheet,model_ur_month_timesheet,base.group_user,1,0,0,0 +access_ur_month_timesheet_ur_manager,access_ur_month_timesheet_ur,model_ur_month_timesheet,cgscop_partner.group_ur_list_modif,1,1,1,1 +access_ur_month_timesheet_cg_manager,access_ur_month_timesheet_cg,model_ur_month_timesheet,cgscop_partner.group_cg_administrator,1,1,1,1 \ No newline at end of file diff --git a/static/src/js/ur_month_timesheet.js b/static/src/js/ur_month_timesheet.js new file mode 100644 index 0000000000000000000000000000000000000000..216d43b42b2a43bf2c927be61f0259486c36d432 --- /dev/null +++ b/static/src/js/ur_month_timesheet.js @@ -0,0 +1,40 @@ + // © 2019 Le Filament (<http://www.le-filament.com>) + // License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +odoo.define('cgscop_timesheet.ur_month_timesheet', function (require) { + "use strict"; + + var core = require('web.core'); + var session = require('web.session'); + var AbstractAction = require('web.AbstractAction'); + var QWeb = core.qweb; + + var ScopMonthTimesheet = AbstractAction.extend({ + template: 'ScopMonthTimesheet', + + willStart: function() { + var deferred = new jQuery.Deferred(); + var self = this; + this.values = {}; + this._rpc({ + model: 'ur.month.timesheet', + method: 'get_month_values', + args: [], + }) + .then(function(results) { + self.values = results; + deferred.resolve(); + }); + return jQuery.when(this._super.apply(this, arguments),deferred); + }, + + start: function() { + }, + + }); + + core.action_registry.add('cgscop_timesheet.ur_month_timesheet', ScopMonthTimesheet); + + +}); + diff --git a/static/src/xml/month_timesheet.xml b/static/src/xml/month_timesheet.xml new file mode 100644 index 0000000000000000000000000000000000000000..32cce8df75efc81efcd04e97110c126a9baf2eab --- /dev/null +++ b/static/src/xml/month_timesheet.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Copyright 2019 Le Filament (<https://www.le-filament.com>) + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> + +<templates xml:space="preserve"> + <t t-name="ScopMonthTimesheet"> + <table class="table"> + <thead> + <tr> + <t t-foreach="widget.values.month" t-as="m"> + <t t-if="m.num_month == widget.values.today.month and m.year == widget.values.today.year"> + <th class="text-success"> + <t t-esc="m.month"/> <t t-esc="m.year"/> + </th> + </t> + <t t-else=""> + <th> + <t t-esc="m.month"/> <t t-esc="m.year"/> + </th> + </t> + </t> + </tr> + </thead> + <tbody> + <tr> + <t t-foreach="widget.values.values" t-as="v"> + <td><t t-esc="v"/> h</td> + </t> + </tr> + </tbody> + </table> + + </t> +</templates> diff --git a/views/assets.xml b/views/assets.xml index 42189756117331fdde2cafb09506b3dcbf439e2d..d74beefa4c7986ba3a2b5e1f49d65a4229af73d9 100644 --- a/views/assets.xml +++ b/views/assets.xml @@ -7,6 +7,8 @@ <template id="cgscop_assets_backend" name="account assets" inherit_id="web.assets_backend"> <xpath expr="." position="inside"> <link rel="stylesheet" type="text/css" href="/cgscop_timesheet/static/src/css/style.css"/> + + <script type="text/javascript" src="/cgscop_timesheet/static/src/js/ur_month_timesheet.js"></script> </xpath> </template> diff --git a/views/ur_month_timesheet.xml b/views/ur_month_timesheet.xml new file mode 100644 index 0000000000000000000000000000000000000000..cc2eb3f3aad283a1e7207dd01ba060883ad7664a --- /dev/null +++ b/views/ur_month_timesheet.xml @@ -0,0 +1,47 @@ +<?xml version="1.0"?> +<!-- Copyright 2019 Le Filament + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> + +<odoo> + <data> + <record id="view_ur_month_timesheet_tree" model="ir.ui.view"> + <field name="name">ur.month.timesheet.tree</field> + <field name="model">ur.month.timesheet</field> + <field name="arch" type="xml"> + <tree editable='top'> + <field name="year" required="1"/> + <field name="month" required="1"/> + <field name="working_time" required="1"/> + <field name="ur_id" options="{'no_open': True, 'no_create': True}" readonly="1"/> + </tree> + </field> + </record> + + <record id="action_ur_month_timesheet" model="ir.actions.act_window"> + <field name="name">Temps de travail mensuel</field> + <field name="res_model">ur.month.timesheet</field> + <field name="view_mode">tree</field> + </record> + + <record id="action_ur_month_timesheet_show" model="ir.actions.client"> + <field name="name">Temps de travail théorique</field> + <field name="tag">cgscop_timesheet.ur_month_timesheet</field> + <field name="target">new</field> + <field name="binding_model_id" ref="model_ur_month_timesheet"/> + <field name="binding_type">action</field> + </record> + + <menuitem id="menu_ur_month_timesheet" + name="Temps de travail mensuel" + parent="hr_timesheet.hr_timesheet_menu_configuration" + action="action_ur_month_timesheet" + sequence="50" + groups="cgscop_partner.group_ur_list_modif"/> + + <menuitem id="menu_ur_month_timesheet_show" + parent="hr_timesheet.menu_hr_time_tracking" + action="action_ur_month_timesheet_show" + sequence="50"/> + + </data> +</odoo> \ No newline at end of file