From da6fddbda902f368cd8d733294ba1940c9bf394f Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Sun, 25 Mar 2018 11:43:35 +0200 Subject: [PATCH] [WIP] welcome screen: add a new field on partner can_shop, add the new screen codebar capable field --- beesdoo_shift/models/cooperative_status.py | 14 +++++- beesdoo_shift_welcome_screen/__init__.py | 2 + beesdoo_shift_welcome_screen/__openerp__.py | 23 ++++++++++ .../models/__init__.py | 2 + .../models/welcome.py | 39 +++++++++++++++++ .../views/welcome.xml | 43 +++++++++++++++++++ 6 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 beesdoo_shift_welcome_screen/__init__.py create mode 100644 beesdoo_shift_welcome_screen/__openerp__.py create mode 100644 beesdoo_shift_welcome_screen/models/__init__.py create mode 100644 beesdoo_shift_welcome_screen/models/welcome.py create mode 100644 beesdoo_shift_welcome_screen/views/welcome.xml diff --git a/beesdoo_shift/models/cooperative_status.py b/beesdoo_shift/models/cooperative_status.py index c5045e5..0f6334f 100644 --- a/beesdoo_shift/models/cooperative_status.py +++ b/beesdoo_shift/models/cooperative_status.py @@ -139,7 +139,7 @@ class CooperativeStatus(models.Model): #Check for holidays; Can be in holidays even in alert or other mode ? elif self.today >= self.holiday_start_time and self.today <= self.holiday_end_time: self.status = 'holiday' - self.can_shop = True + self.can_shop = False elif ok or (not self.alert_start_time and self.sr >= 0): self.status = 'ok' self.can_shop = True @@ -172,7 +172,7 @@ class CooperativeStatus(models.Model): #Check for holidays; Can be in holidays even in alert or other mode ? elif self.today >= self.holiday_start_time and self.today <= self.holiday_end_time: self.status = 'holiday' - self.can_shop = True + self.can_shop = False elif ok or (not self.alert_start_time and self.sr >= 0): self.status = 'ok' self.can_shop = True @@ -305,6 +305,16 @@ class ResPartner(models.Model): 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') + can_shop = fields.Boolean(compute="_get_can_shop") + + @api.multi + def _get_can_shop(self): + for rec in self: + can_shop = False + if rec.cooperator_type in ('share_a', 'share_b'): + if rec.cooperative_status_ids: + can_shop = rec.cooperative_status_ids[0].can_shop + rec.can_shop = can_shop @api.multi def coop_subscribe(self): diff --git a/beesdoo_shift_welcome_screen/__init__.py b/beesdoo_shift_welcome_screen/__init__.py new file mode 100644 index 0000000..89d26e2 --- /dev/null +++ b/beesdoo_shift_welcome_screen/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +import models diff --git a/beesdoo_shift_welcome_screen/__openerp__.py b/beesdoo_shift_welcome_screen/__openerp__.py new file mode 100644 index 0000000..2cdd5f8 --- /dev/null +++ b/beesdoo_shift_welcome_screen/__openerp__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +{ + 'name': "Beescoop Shift Management - Welcome Screen", + + 'summary': """ + Volonteer Timetable Management""", + + 'description': """ + + """, + + 'author': "Thibault Francois", + 'website': "https://github.com/beescoop/Obeesdoo", + + 'category': 'Cooperative management', + 'version': '0.1', + + 'depends': ['beesdoo_shift', 'barcodes'], + + 'data': [ + "views/welcome.xml", + ], +} diff --git a/beesdoo_shift_welcome_screen/models/__init__.py b/beesdoo_shift_welcome_screen/models/__init__.py new file mode 100644 index 0000000..92a7cb1 --- /dev/null +++ b/beesdoo_shift_welcome_screen/models/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +import welcome diff --git a/beesdoo_shift_welcome_screen/models/welcome.py b/beesdoo_shift_welcome_screen/models/welcome.py new file mode 100644 index 0000000..6b1f8de --- /dev/null +++ b/beesdoo_shift_welcome_screen/models/welcome.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- + +from openerp import models, fields, api, _ +from openerp.exceptions import UserError + +class TaskType(models.TransientModel): + _name = 'beesdoo.shift.welcome' + + _inherit = ['barcodes.barcode_events_mixin'] + + partner_id = fields.Many2one('res.partner', string="Cooperator") + message = fields.Html("Message") + can_shop = fields.Boolean(related='partner_id.can_shop', readonly=True) + + def on_barcode_scanned(self, barcode): + self._barcode_scanned = '' + self.message = '' + + if barcode.startswith('42'): + barcode = '0' + barcode + if not barcode.startswith('042'): + self.message = 'invalid barcode' + return + #0 at the begining of the code bar seems not to be scanned + partner_ids = self.env['res.partner'].search([('barcode', '=', barcode)]) + if not partner_ids: + self.message = "Member does not exist" + elif len(partner_ids) > 1: + self.message = "more then one member found with this barcode" + else: + self.partner_id = partner_ids[0] + + @api.onchange('partner_id') + def _onchange_partner(self): + values = { + 'rec': self + } + html_res = self.env.ref("beesdoo_shift_welcome_screen.welcome_message").render(values) + self.message = html_res \ No newline at end of file diff --git a/beesdoo_shift_welcome_screen/views/welcome.xml b/beesdoo_shift_welcome_screen/views/welcome.xml new file mode 100644 index 0000000..66b39d1 --- /dev/null +++ b/beesdoo_shift_welcome_screen/views/welcome.xml @@ -0,0 +1,43 @@ + + + Shift Type + beesdoo.shift.welcome + form + inline + + + + + + Shift Welcome Screen + beesdoo.shift.welcome + +
+ + + +

+ +

+ + + + +
+
+
+
+ + + +