From 07566d25b3c00c39ab2ec31a3c8f82ea0806b98b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Taymans?= Date: Fri, 8 May 2020 19:51:04 +0200 Subject: [PATCH] [MOV] b_shift: res.partner definition in separated file --- beesdoo_shift/models/__init__.py | 1 + beesdoo_shift/models/cooperative_status.py | 78 -------------------- beesdoo_shift/models/res_partner.py | 84 ++++++++++++++++++++++ 3 files changed, 85 insertions(+), 78 deletions(-) create mode 100644 beesdoo_shift/models/res_partner.py diff --git a/beesdoo_shift/models/__init__.py b/beesdoo_shift/models/__init__.py index ddc930b..7b98f32 100644 --- a/beesdoo_shift/models/__init__.py +++ b/beesdoo_shift/models/__init__.py @@ -2,3 +2,4 @@ from . import task from . import planning from . import cooperative_status +from . import res_partner diff --git a/beesdoo_shift/models/cooperative_status.py b/beesdoo_shift/models/cooperative_status.py index 9f369bf..d9e1514 100644 --- a/beesdoo_shift/models/cooperative_status.py +++ b/beesdoo_shift/models/cooperative_status.py @@ -312,81 +312,3 @@ class ShiftCronJournal(models.Model): if not self.user_has_groups('beesdoo_shift.group_cooperative_admin'): raise ValidationError(_("You don't have the access to perform this action")) self.sudo().env['cooperative.status']._cron_compute_counter_irregular(today=self.date) - -class ResPartner(models.Model): - """ - One2many relationship with CooperativeStatus should - be replaced by inheritance. - """ - _inherit = 'res.partner' - - worker_store = fields.Boolean(default=False) - is_worker = fields.Boolean(related="worker_store", string="Worker", readonly=False) - cooperative_status_ids = fields.One2many('cooperative.status', 'cooperator_id', readonly=True) - super = fields.Boolean(related='cooperative_status_ids.super', string="Super Cooperative", readonly=True, store=True) - info_session = fields.Boolean(related='cooperative_status_ids.info_session', string='Information Session ?', readonly=True, store=True) - info_session_date = fields.Date(related='cooperative_status_ids.info_session_date', string='Information Session Date', readonly=True, store=True) - working_mode = fields.Selection(related='cooperative_status_ids.working_mode', readonly=True, store=True) - exempt_reason_id = fields.Many2one(related='cooperative_status_ids.exempt_reason_id', readonly=True, store=True) - state = fields.Selection(related='cooperative_status_ids.status', readonly=True, store=True) - extension_start_time = fields.Date(related='cooperative_status_ids.extension_start_time', string="Extension Start Day", readonly=True, store=True) - subscribed_shift_ids = fields.Many2many('beesdoo.shift.template') - - @api.multi - def coop_subscribe(self): - return { - 'name': _('Subscribe Cooperator'), - 'type': 'ir.actions.act_window', - 'view_type': 'form', - 'view_mode': 'form', - 'res_model': 'beesdoo.shift.subscribe', - 'target': 'new', - } - - @api.multi - def coop_unsubscribe(self): - res = self.coop_subscribe() - res['context'] = {'default_unsubscribed': True} - return res - - @api.multi - def manual_extension(self): - return { - 'name': _('Manual Extension'), - 'type': 'ir.actions.act_window', - 'view_type': 'form', - 'view_mode': 'form', - 'res_model': 'beesdoo.shift.extension', - 'target': 'new', - } - - @api.multi - def auto_extension(self): - res = self.manual_extension() - res['context'] = {'default_auto': True} - res['name'] = _('Trigger Grace Delay') - return res - - @api.multi - def register_holiday(self): - return { - 'name': _('Register Holiday'), - 'type': 'ir.actions.act_window', - 'view_type': 'form', - 'view_mode': 'form', - 'res_model': 'beesdoo.shift.holiday', - 'target': 'new', - } - - @api.multi - def temporary_exempt(self): - return { - 'name': _('Temporary Exemption'), - 'type': 'ir.actions.act_window', - 'view_type': 'form', - 'view_mode': 'form', - 'res_model': 'beesdoo.shift.temporary_exemption', - 'target': 'new', - } - - #TODO access right + vue on res.partner diff --git a/beesdoo_shift/models/res_partner.py b/beesdoo_shift/models/res_partner.py new file mode 100644 index 0000000..2d7138c --- /dev/null +++ b/beesdoo_shift/models/res_partner.py @@ -0,0 +1,84 @@ +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError, UserError + +from datetime import timedelta, datetime +import logging + + +class ResPartner(models.Model): + """ + One2many relationship with CooperativeStatus should + be replaced by inheritance. + """ + _inherit = 'res.partner' + + worker_store = fields.Boolean(default=False) + is_worker = fields.Boolean(related="worker_store", string="Worker", readonly=False) + cooperative_status_ids = fields.One2many('cooperative.status', 'cooperator_id', readonly=True) + super = fields.Boolean(related='cooperative_status_ids.super', string="Super Cooperative", readonly=True, store=True) + info_session = fields.Boolean(related='cooperative_status_ids.info_session', string='Information Session ?', readonly=True, store=True) + info_session_date = fields.Date(related='cooperative_status_ids.info_session_date', string='Information Session Date', readonly=True, store=True) + working_mode = fields.Selection(related='cooperative_status_ids.working_mode', readonly=True, store=True) + exempt_reason_id = fields.Many2one(related='cooperative_status_ids.exempt_reason_id', readonly=True, store=True) + state = fields.Selection(related='cooperative_status_ids.status', readonly=True, store=True) + extension_start_time = fields.Date(related='cooperative_status_ids.extension_start_time', string="Extension Start Day", readonly=True, store=True) + subscribed_shift_ids = fields.Many2many('beesdoo.shift.template') + + @api.multi + def coop_subscribe(self): + return { + 'name': _('Subscribe Cooperator'), + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'beesdoo.shift.subscribe', + 'target': 'new', + } + + @api.multi + def coop_unsubscribe(self): + res = self.coop_subscribe() + res['context'] = {'default_unsubscribed': True} + return res + + @api.multi + def manual_extension(self): + return { + 'name': _('Manual Extension'), + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'beesdoo.shift.extension', + 'target': 'new', + } + + @api.multi + def auto_extension(self): + res = self.manual_extension() + res['context'] = {'default_auto': True} + res['name'] = _('Trigger Grace Delay') + return res + + @api.multi + def register_holiday(self): + return { + 'name': _('Register Holiday'), + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'beesdoo.shift.holiday', + 'target': 'new', + } + + @api.multi + def temporary_exempt(self): + return { + 'name': _('Temporary Exemption'), + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'beesdoo.shift.temporary_exemption', + 'target': 'new', + } + + #TODO access right + vue on res.partner