Browse Source

Merge pull request #19 from houssine78/9.0

change for price_to_weight module
pull/22/head
Houssine BAKKALI 7 years ago
committed by GitHub
parent
commit
2a2591c11d
  1. 3
      beesdoo_shift/__openerp__.py
  2. 12
      beesdoo_shift/data/cron.xml
  3. 7
      beesdoo_shift/data/stage.xml
  4. 12
      beesdoo_shift/data/system_parameter.xml
  5. 182
      beesdoo_shift/models/cooperative_status.py
  6. 64
      beesdoo_shift/models/task.py
  7. 3
      beesdoo_shift/security/ir.model.access.csv
  8. 80
      beesdoo_shift/views/cooperative_status.xml
  9. 21
      beesdoo_shift/views/exempt_reason.xml
  10. 1
      beesdoo_shift/views/planning.xml
  11. 3
      beesdoo_shift/views/task.xml
  12. 3
      beesdoo_shift/wizard/__init__.py
  13. 37
      beesdoo_shift/wizard/extension.py
  14. 26
      beesdoo_shift/wizard/extension.xml
  15. 62
      beesdoo_shift/wizard/subscribe.py
  16. 12
      beesdoo_shift/wizard/subscribe.xml
  17. 4
      pos_price_to_weight/static/src/js/models.js

3
beesdoo_shift/__openerp__.py

@ -20,15 +20,18 @@
'data': [
"data/stage.xml",
"data/system_parameter.xml",
"data/cron.xml",
"security/group.xml",
"security/ir.model.access.csv",
"views/task_template.xml",
"views/task.xml",
"views/planning.xml",
"views/cooperative_status.xml",
"views/exempt_reason.xml",
"wizard/instanciate_planning.xml",
"wizard/batch_template.xml",
"wizard/assign_super_coop.xml",
"wizard/subscribe.xml",
"wizard/extension.xml",
],
}

12
beesdoo_shift/data/cron.xml

@ -0,0 +1,12 @@
<odoo>
<record id="ir_cron_update_today" model="ir.cron">
<field name="name">Update Cooperatoor status base on the date</field>
<field name="interval_number">24</field>
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="model">cooperative.status</field>
<field name="function">_set_today</field>
<field name="args">()</field>
</record>
</odoo>

7
beesdoo_shift/data/stage.xml

@ -3,35 +3,42 @@
<field name="name">Unconfirmed</field>
<field name="sequence">1</field>
<field name="color">0</field>
<field name="code">draft</field>
</record>
<record model="beesdoo.shift.stage" id="open">
<field name="name">Confirmed</field>
<field name="sequence">2</field>
<field name="color">5</field>
<field name="code">open</field>
</record>
<record model="beesdoo.shift.stage" id="done">
<field name="name">Attended</field>
<field name="sequence">3</field>
<field name="color">1</field>
<field name="code">done</field>
</record>
<record model="beesdoo.shift.stage" id="absent">
<field name="name">Absent</field>
<field name="sequence">5</field>
<field name="color">2</field>
<field name="code">absent</field>
</record>
<record model="beesdoo.shift.stage" id="excused">
<field name="name">Excused</field>
<field name="sequence">6</field>
<field name="color">4</field>
<field name="code">excused</field>
</record>
<record model="beesdoo.shift.stage" id="excused_necessity">
<field name="name">Excused - Absolute Necessity</field>
<field name="sequence">6</field>
<field name="color">4</field>
<field name="code">excused_necessity</field>
</record>
<record model="beesdoo.shift.stage" id="cancel">
<field name="name">Cancelled</field>
<field name="sequence">7</field>
<field name="color">8</field>
<field name="code">cancel</field>
</record>
</odoo>

12
beesdoo_shift/data/system_parameter.xml

@ -1,10 +1,18 @@
<odoo noupdate="1">
<record id="seq_solucom_matricule_cabinet" model="ir.config_parameter">
<record id="alert_delay_param" model="ir.config_parameter">
<field name="key">alert_delay</field>
<field name="value">28</field>
</record>
<record id="seq_solucom_matricule_cabinet" model="ir.config_parameter">
<record id="default_grace_delay" model="ir.config_parameter">
<field name="key">default_grace_delay</field>
<field name="value">10</field>
</record>
<record id="default_extension_delay" model="ir.config_parameter">
<field name="key">default_extension_delay</field>
<field name="value">28</field>
</record>
<record id="always_update" model="ir.config_parameter">
<field name="key">always_update</field>
<field name="value">0</field>
</record>
</odoo>

182
beesdoo_shift/models/cooperative_status.py

@ -2,40 +2,182 @@
from openerp import models, fields, api, _
from openerp.exceptions import ValidationError
from datetime import timedelta
def add_days_delta(date_from, days_delta):
if not date_from:
return date_from
next_date = fields.Date.from_string(date_from) + timedelta(days=days_delta)
return fields.Date.to_string(next_date)
class ExemptReason(models.Model):
_name = 'cooperative.exempt.reason'
name = fields.Char(required=True)
class HistoryStatus(models.Model):
_name = 'cooperative.status.history'
_order= 'create_date desc'
status_id = fields.Many2one('cooperative.status')
cooperator_id = fields.Many2one('res.partner')
change = fields.Char()
type = fields.Selection([('status', 'Status Change'), ('counter', 'Counter Change')])
user_id = fields.Many2one('res.users', string="User")
class CooperativeStatus(models.Model):
_name = 'cooperative.status'
_rec_name = 'cooperator_id'
_order = 'cooperator_id'
today = fields.Date(help="Field that allow to compute field and store them even if they are based on the current date")
cooperator_id = fields.Many2one('res.partner')
info_session = fields.Boolean('Information Session ?')
info_session_date = fields.Datetime('Information Session Date')
super = fields.Boolean("Super Cooperative")
sr = fields.Integer("Compteur shift regulier")
sc = fields.Integer("Compteur shift de compensation")
sr = fields.Integer("Compteur shift regulier", default=0)
sc = fields.Integer("Compteur shift de compensation", default=0)
time_holiday = fields.Integer("Holidays Days NB", default=0)
time_extension = fields.Integer("Extension Days NB", default=0) #Durée initial par défault sur ir_config_parameter
time_extension = fields.Integer("Extension Days NB", default=0, help="Addtional days to the automatic extension, 5 mean that you have a total of 15 extension days of default one is set to 10")
holiday_start_time = fields.Date("Holidays Start Day")
alert_start_time = fields.Date("Alert Start Day")
extension_start_time = fields.Date("Extension Start Day")
#Champ compute
status = fields.Selection([('ok', 'Up to Date'), ('holiday', 'Holidays'), ('alert', 'Alerte'), ('unsubscribed', 'Unsubscribed')], compute="_compute_status", string="Cooperative Status")
working_mode = fields.Selection(
[
('regular', 'Regular worker'),
('irregular', 'Irregular worker'),
('exempt', 'Exempted'),
],
string="Working mode",
string="Working mode"
)
exempt_reason_id = fields.Many2one('cooperative.exempt.reason', 'Exempt Reason')
status = fields.Selection([('ok', 'Up to Date'),
('holiday', 'Holidays'),
('alert', 'Alerte'),
('extension', 'Extension'),
('suspended', 'Suspended'),
('unsubscribed', 'Unsubscribed')],
compute="_compute_status", string="Cooperative Status", store=True)
can_shop = fields.Boolean(compute='_compute_status', store=True)
history_ids = fields.One2many('cooperative.status.history', 'status_id', readonly=True)
unsubscribed = fields.Boolean(default=False, help="Manually unsubscribed")
@api.depends('today', 'sr', 'sc', 'time_holiday', 'holiday_start_time', 'time_extension', 'alert_start_time', 'extension_start_time', 'unsubscribed')
def _compute_status(self):
alert_delay = int(self.env['ir.config_parameter'].get_param('alert_delay', 28))
grace_delay = int(self.env['ir.config_parameter'].get_param('default_grace_delay', 10))
update = int(self.env['ir.config_parameter'].get_param('always_update', False))
print update
for rec in self:
rec.status = 'ok'
if update:
rec.status = 'ok'
rec.can_shop = True
continue
ok = rec.sr >= 0 and rec.sc >= 0
grace_delay = grace_delay + rec.time_extension
if rec.sr < -1 or rec.unsubscribed:
rec.status = 'unsubscribed'
rec.can_shop = False
#Transition to alert sr < 0 or stay in alert sr < 0 or sc < 0 and thus alert time is defined
elif not ok and rec.alert_start_time and rec.extension_start_time and rec.today <= add_days_delta(rec.extension_start_time, grace_delay):
rec.status = 'extension'
rec.can_shop = True
elif not ok and rec.alert_start_time and rec.extension_start_time and rec.today > add_days_delta(rec.extension_start_time, grace_delay):
rec.status = 'suspended'
rec.can_shop = False
elif not ok and rec.alert_start_time and rec.today > add_days_delta(rec.alert_start_time, alert_delay):
rec.status = 'suspended'
rec.can_shop = False
elif (rec.sr < 0) or (not ok and rec.alert_start_time):
rec.status = 'alert'
rec.can_shop = True
#Check for holidays; Can be in holidays even in alert or other mode ?
elif rec.today >= rec.holiday_start_time and rec.today < add_days_delta(rec.holiday_start_time, rec.time_holiday):
rec.status = 'holiday'
rec.can_shop = True
elif ok or (not rec.alert_start_time and rec.sr >= 0):
rec.status = 'ok'
rec.can_shop = True
@api.multi
def write(self, vals):
"""
Overwrite write to historize the change
"""
for field in ['sr', 'sc', 'time_extension', 'extension_start_time', 'alert_start_time', 'unsubscribed']:
if not field in vals:
continue
for rec in self:
data = {
'status_id': rec.id,
'cooperator_id': rec.cooperator_id.id,
'type': 'counter',
'user_id': self.env.context.get('real_uid', self.env.uid),
}
if vals.get(field, rec[field]) != rec[field]:
data['change'] = '%s: %s -> %s' % (field.upper(), rec[field], vals.get(field))
self.env['cooperative.status.history'].sudo().create(data)
return super(CooperativeStatus, self).write(vals)
def _state_change(self, new_state, old_stage):
self.ensure_one()
if new_state == 'alert':
self.write({'alert_start_time': self.today, 'extension_start_time': False, 'time_extension': 0})
if new_state == 'ok': #reset alert start time if back to ok
self.write({'alert_start_time': False, 'extension_start_time': False, 'time_extension': 0})
if new_state == 'unsubscribed':
self.cooperator_id.sudo().write({'subscribed_shift_ids' : [(5,0,0)]})
self.env['beesdoo.shift.shift'].sudo().unsubscribe_from_today([self.cooperator_id.id], today=self.today)
@api.multi
def _write(self, vals):
"""
Overwrite write to historize the change of status
and make action on status change
"""
if 'status' in vals:
self._cr.execute('select id, status, sr, sc from "%s" where id in %%s' % self._table, (self._ids,))
result = self._cr.dictfetchall()
old_status_per_id = {r['id'] : r for r in result}
for rec in self:
if old_status_per_id[rec.id]['status'] != vals['status']:
data = {
'status_id': rec.id,
'cooperator_id': rec.cooperator_id.id,
'type': 'status',
'change': "STATUS: %s -> %s" % (old_status_per_id[rec.id]['status'], vals['status']),
'user_id': self.env.context.get('real_uid', self.env.uid),
}
self.env['cooperative.status.history'].sudo().create(data)
rec._state_change(vals['status'], old_status_per_id[rec.id]['status'])
return super(CooperativeStatus, self)._write(vals)
_sql_constraints = [
('cooperator_uniq', 'unique (cooperator_id)', _('You can only set one cooperator status per cooperator')),
]
@api.model
def _set_today(self):
"""
Method call by the cron to update store value base on the date
"""
self.search([]).write({'today': fields.Date.today()})
@api.multi
def clear_history(self):
self.ensure_one()
self.history_ids.unlink()
class ResPartner(models.Model):
_inherit = 'res.partner'
@ -44,7 +186,11 @@ class ResPartner(models.Model):
info_session = fields.Boolean(related='cooperative_status_ids.info_session', string='Information Session ?', readonly=True, store=True)
info_session_date = fields.Datetime(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 {
@ -56,4 +202,28 @@ class ResPartner(models.Model):
'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
#TODO access right + vue on res.partner
#TODO can_shop : Status can_shop ou extempted ou part C

64
beesdoo_shift/models/task.py

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from openerp import models, fields, api
from openerp.exceptions import UserError
class TaskStage(models.Model):
_name = 'beesdoo.shift.stage'
@ -8,6 +9,11 @@ class TaskStage(models.Model):
name = fields.Char()
sequence = fields.Integer()
color = fields.Integer()
code = fields.Char(readonly=True)
@api.multi
def unlink(self):
raise UserError(_("You Cannot delete Task Stage"))
class Task(models.Model):
@ -49,4 +55,60 @@ class Task(models.Model):
'stage_id': _read_group_stage_id,
}
#TODO button to replaced someone
#TODO button to replaced someone
@api.model
def unsubscribe_from_today(self, worker_ids, today=None):
today = today or fields.Date.today()
today = today + ' 00:00:00'
to_unsubscribe = self.search([('worker_id', 'in', worker_ids), ('start_time', '>=', today)])
to_unsubscribe.write({'worker_id': False, 'is_regular': False})
#What about replacement ?
#Remove worker, replaced_id and regular
to_unsubscribe_replace = self.search([('replaced_id', 'in', worker_ids), ('start_time', '>=', today)])
to_unsubscribe_replace.write({'worker_id': False, 'is_regular': False, 'replaced_id': False})
@api.multi
def write(self, vals):
"""
Overwrite write to track stage change
"""
if 'stage_id' in vals:
for rec in self:
if vals['stage_id'] != rec.stage_id.id:
rec._update_stage(rec.stage_id.id, vals['stage_id'])
return super(Task, self).write(vals)
def _update_stage(self, old_stage, new_stage):
self.ensure_one()
update = int(self.env['ir.config_parameter'].get_param('always_update', False))
if not (self.worker_id or self.replaced_id) or update:
return
new_stage = self.env['beesdoo.shift.stage'].browse(new_stage)
if not self.replaced_id: #No replacement case
status = self.worker_id.cooperative_status_ids[0]
else:
status = self.replaced_id.cooperative_status_ids[0]
data = {}
if new_stage == self.env.ref('beesdoo_shift.done') and self.is_regular:
pass
if new_stage == self.env.ref('beesdoo_shift.done') and not self.is_regular:
if status.sr < 0:
data['sr'] = status.sr + 1
elif status.sc < 0:
data['sc'] = status.sc + 1
else:
data['sr'] = status.sr + 1
if new_stage == self.env.ref('beesdoo_shift.absent') and not self.replaced_id:
data['sr'] = status.sr - 1
if status.sr <= 0:
data['sc'] = status.sc -1
if new_stage == self.env.ref('beesdoo_shift.absent') and self.replaced_id:
data['sr'] = status.sr -1
if new_stage == self.env.ref('beesdoo_shift.excused'):
data['sr'] = status.sr -1
status.sudo().write(data)

3
beesdoo_shift/security/ir.model.access.csv

@ -14,4 +14,5 @@ all_config_coopplanning_daynumber,Attendance Read Daynumber,model_beesdoo_shift_
all_config_coopplanning_planning,Attendance Read Planning,model_beesdoo_shift_planning,group_planning_management,1,1,1,1
all_config_coopplanning_task_template,Attendance Read Template,model_beesdoo_shift_template,group_planning_management,1,1,1,1
all_config_coopplanning_task,Attendance Edit Shift,model_beesdoo_shift_shift,group_planning_management,1,1,1,1
exempt_reason_read_all,Exempt Reason Read all ,beesdoo_shift.model_cooperative_exempt_reason,,1,0,0,0
exempt_reason,Exempt Reason Admin,beesdoo_shift.model_cooperative_exempt_reason,beesdoo_shift.group_cooperative_admin,1,1,1,1

80
beesdoo_shift/views/cooperative_status.xml

@ -9,6 +9,24 @@
<button name="coop_subscribe" string="Subscribe to shift" class="oe_highlight"
type="object" groups="beesdoo_shift.group_shift_management"
attrs="{'invisible': [('cooperator_type', '!=', 'share_a')]}"/>
<button name="auto_extension" string="Auto Extension" class="oe_highlight"
type="object" groups="beesdoo_shift.group_shift_management"
attrs="{'invisible': ['|',
('cooperator_type', '!=', 'share_a'),
'|',
('state', '!=', 'suspended'),
('extension_start_time', '!=', False)]}" />
<button name="manual_extension" string="Manual Extension" class="oe_highlight"
type="object" groups="beesdoo_shift.group_shift_management"
attrs="{'invisible': ['|',
('cooperator_type', '!=', 'share_a'),
'|',
('state', '!=', 'suspended'),
('extension_start_time', '=', False)]}" />
<button name="coop_unsubscribe" string="Unsubscribe" class="oe_highlight"
type="object" groups="beesdoo_shift.group_shift_management"
attrs="{'invisible': [('cooperator_type', '!=', 'share_a')]}"/>
<field name="state" widget="statusbar" attrs="{'invisible': [('cooperator_type', '!=', 'share_a')]}" />
</header>
</xpath>
<page name="work" position="inside">
@ -17,9 +35,11 @@
<field name="info_session" />
<field name="info_session_date"
attrs="{'invisible': ['|', ('info_session', '=', False)]}" />
<field name="extension_start_time" attrs="{'invisible': [('extension_start_time', '=', False)]}" />
</group>
<group>
<field name="working_mode" />
<field name="exempt_reason_id" attrs="{'invisible':[('working_mode', '!=', 'exempt')]}"/>
<field name="super" />
</group>
</group>
@ -38,19 +58,42 @@
<field name="status" widget="statusbar" />
</header>
<group>
<field name="cooperator_id" />
<field name="info_session" />
<field name="info_session_date" />
<field name="working_mode" />
<field name="super" />
<field name="sr" />
<field name="sc" />
<field name="time_holiday" />
<field name="time_extension" />
<field name="holiday_start_time" />
<field name="alert_start_time" />
<field name="extension_start_time" />
<group>
<field name="cooperator_id" />
<field name="working_mode" />
<field name="exempt_reason_id" attrs="{'invisible':[('working_mode', '!=', 'exempt')]}"/>
<field name="super" />
</group>
<group>
<field name="info_session" />
<field name="info_session_date" />
<field name="sr" />
<field name="sc" />
<field name="unsubscribed" />
<field name="can_shop" />
</group>
<group>
<field name="time_holiday" />
<field name="time_extension" />
<field name="holiday_start_time" />
<field name="alert_start_time" />
<field name="extension_start_time" />
</group>
</group>
<group groups="base.group_no_one" col="3">
<separator string="For testing purpose only" colspan="3"/>
<field name="today" />
<button name="clear_history" type="object" string="Clear History" />
</group>
<separator string="History" colspan="2"/>
<field name="history_ids">
<tree>
<field name="create_date" string="Date" />
<field name="type" />
<field name="change" />
<field name="user_id" />
</tree>
</field>
</form>
</field>
</record>
@ -84,6 +127,19 @@
groups="beesdoo_shift.group_shift_management" sequence="20" />
<menuitem name="Cooperative Status" id="menu_status" parent="menu_status_top"
action="action_coop_status" groups="beesdoo_shift.group_cooperative_admin" />
<!-- Actions -->
<record model="ir.actions.act_window" id="action_worker">
<field name="name">Worker</field>
<field name="res_model">res.partner</field>
<field name="view_mode">kanban,tree,form</field>
<field name="domain">[('cooperator_type', '=', 'share_a')]</field>
</record>
<menuitem name="Worker" id="menu_worker_top" parent="menu_root"
sequence="1" />
<menuitem name="Worker" id="menu_worker" parent="menu_worker_top"
action="action_worker" />
</odoo>

21
beesdoo_shift/views/exempt_reason.xml

@ -0,0 +1,21 @@
<odoo>
<record model="ir.ui.view" id="exempt_reason_tree_view">
<field name="name">Exempt Reason Tree view</field>
<field name="model">cooperative.exempt.reason</field>
<field name="arch" type="xml">
<tree editable="top">
<field name="name" />
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="action_exempt_reason">
<field name="name">Exempt Reason</field>
<field name="res_model">cooperative.exempt.reason</field>
<field name="view_mode">tree</field>
</record>
<menuitem name="Exempt Reason" id="menu_exempt_reason" parent="menu_status_top"
action="action_exempt_reason" groups="beesdoo_shift.group_cooperative_admin" />
</odoo>

1
beesdoo_shift/views/planning.xml

@ -79,4 +79,5 @@
<menuitem name="Planning Week" id="menu_planning" parent="menu_template_top"
sequence="10" action="action_planning" />
</odoo>

3
beesdoo_shift/views/task.xml

@ -10,6 +10,7 @@
<field name="name" />
<field name="super_coop_id" />
<field name="worker_id" />
<field name="replaced_id" />
<field name="end_time" />
<field name="stage_id" />
</tree>
@ -91,7 +92,7 @@
<field name="task_type_id" />
<field name="super_coop_id" />
<field name="worker_id" />
<field name="replaced_id" />
<field name="replaced_id" attrs="{'invisible': [('is_regular', '!=', True)]}"/>
<field name="is_regular" />
</group>
<group>

3
beesdoo_shift/wizard/__init__.py

@ -1,4 +1,5 @@
import instanciate_planning
import batch_template
import assign_super_coop
import subscribe
import subscribe
import extension

37
beesdoo_shift/wizard/extension.py

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
from openerp import models, fields, api, _
from openerp.exceptions import UserError
class Subscribe(models.TransientModel):
_name = 'beesdoo.shift.extension'
_inherit = 'beesdoo.shift.action_mixin'
def _get_default_extension_delay(self):
return int(self.env['ir.config_parameter'].get_param('default_extension_delay', 28))
extension_start_date = fields.Date(string="Start date for the extension", default=fields.Date.today, readonly=True)
auto = fields.Boolean("Auto Extension", default=False)
extension_days = fields.Integer(default=_get_default_extension_delay)
@api.multi
def auto_ext(self):
self = self._check()
status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)])
status_id.sudo().write({'extension_start_time': self.extension_start_date})
@api.multi
def extension(self):
self = self._check() #maybe a different group
grace_delay = int(self.env['ir.config_parameter'].get_param('default_grace_delay', 10))
status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)])
if not status_id.extension_start_time:
raise UserError(_('You should not make a manual extension when the grace delay has not been triggered yet'))
extension_date = fields.Date.from_string(status_id.extension_start_time)
today = fields.Date.from_string(status_id.today)
today_delay = (today - extension_date).days - grace_delay
if today_delay < 0:
raise UserError(_('You should not start a manual extension during the grace delay'))
status_id.sudo().write({'time_extension': self.extension_days + today_delay})
#TO continue

26
beesdoo_shift/wizard/extension.xml

@ -0,0 +1,26 @@
<odoo>
<record model="ir.ui.view" id="extension_coop_wizard_view_form">
<field name="name">Extension Management</field>
<field name="model">beesdoo.shift.extension</field>
<field name="arch" type="xml">
<form>
<field name="cooperator_id" invisible="1"/>
<field name="auto" invisible="1"/>
<group attrs="{'invisible': [('auto', '=', False)]}">
<field name="extension_start_date" />
</group>
<group attrs="{'invisible': [('auto', '=', True)]}">
<field name="extension_days" />
</group>
<footer>
<button type="object" name="extension"
string="Confirm" class="oe_highlight" attrs="{'invisible': [('auto', '=', True)]}" />
<button type="object" name="auto_ext"
string="Confirm" class="oe_highlight" attrs="{'invisible': [('auto', '=', False)]}" />
or
<button special="cancel" string="Cancel" />
</footer>
</form>
</field>
</record>
</odoo>

62
beesdoo_shift/wizard/subscribe.py

@ -2,8 +2,22 @@
from openerp import models, fields, api, _
from openerp.exceptions import UserError
class StatusActionMixin(models.AbstractModel):
_name = "beesdoo.shift.action_mixin"
cooperator_id = fields.Many2one('res.partner', default=lambda self: self.env['res.partner'].browse(self._context.get('active_id')), required=True)
def _check(self, group='beesdoo_shift.group_shift_management'):
self.ensure_one()
if not self.env.user.has_group(group):
raise UserError(_("You don't have the required access for this operation."))
if self.cooperator_id == self.env.user.partner_id and not self.env.user.has_group('beesdoo_shift.group_cooperative_admin'):
raise UserError(_("You cannot perform this operation on yourself"))
return self.with_context(real_uid=self._uid)
class Subscribe(models.TransientModel):
_name = 'beesdoo.shift.subscribe'
_inherit = 'beesdoo.shift.action_mixin'
def _get_date(self):
date = self.env['res.partner'].browse(self._context.get('active_id')).info_session_date
@ -15,7 +29,9 @@ class Subscribe(models.TransientModel):
def _get_super(self):
return self.env['res.partner'].browse(self._context.get('active_id')).super
cooperator_id = fields.Many2one('res.partner', default=lambda self: self.env['res.partner'].browse(self._context.get('active_id')), required=True)
def _get_mode(self):
return self.env['res.partner'].browse(self._context.get('active_id')).working_mode
info_session = fields.Boolean(string="Followed an information session", default=True)
info_session_date = fields.Date(string="Date of information session", default=_get_date)
super = fields.Boolean(string="Super Cooperator", default=_get_super)
@ -24,29 +40,57 @@ class Subscribe(models.TransientModel):
('regular', 'Regular worker'),
('irregular', 'Irregular worker'),
('exempt', 'Exempted'),
],
], default=_get_mode
)
exempt_reason_id = fields.Many2one('cooperative.exempt.reason', 'Exempt Reason')
shift_id = fields.Many2one('beesdoo.shift.template')
reset_counter = fields.Boolean(default=False)
unsubscribed = fields.Boolean(default=False, string="Are you sure to unsubscribe this cooperator")
@api.multi
def unsubscribe(self):
self = self._check()
if not self.unsubscribed:
return
status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)])
data = {
'unsubscribed': True,
'cooperator_id': self.cooperator_id.id,
}
if status_id:
status_id.sudo().write(data)
else:
self.env['cooperative.status'].sudo().create(data)
@api.multi
def subscribe(self):
if not self.env.user.has_group('beesdoo_shift.group_shift_management'):
raise UserError(_("You don't have the required access for this operation."))
if self.cooperator_id == self.env.user.partner_id and not self.env.user.has_group('beesdoo_shift.group_cooperative_admin'):
raise UserError(_("You cannot subscribe yourself."))
self.ensure_one()
self = self._check()
if self.shift_id and self.shift_id.remaining_worker <= 0:
raise UserError(_('There is no remaining space for this shift'))
if self.shift_id:
self.sudo().shift_id.worker_ids |= self.cooperator_id
#Remove existing shift then subscribe to the new shift
self.cooperator_id.sudo().write({'subscribed_shift_ids' : [(6,0, [self.shift_id.id])]})
if self.working_mode != 'regular':
#Remove existing shift then subscribe to the new shift
self.cooperator_id.sudo().write({'subscribed_shift_ids' : [(5,)]})
data = {
'info_session' : self.info_session,
'info_session_date': self.info_session_date,
'working_mode' : self.working_mode,
'exempt_reason_id' : self.exempt_reason_id.id,
'super' : self.super,
'cooperator_id': self.cooperator_id.id,
'sr' : 0, #set back to 0 if you subscribe a second time
'unsubscribed': False
}
if self.reset_counter:
data['sr'] = 0
data['extension_start_time'] = False
data['alert_start_time'] = False
data['time_extension'] = 0
status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)])
if status_id:

12
beesdoo_shift/wizard/subscribe.xml

@ -4,17 +4,25 @@
<field name="model">beesdoo.shift.subscribe</field>
<field name="arch" type="xml">
<form>
<group>
<group attrs="{'invisible': [('unsubscribed', '=', False)]}">
<separator string="Are you sure to unsubscribe this cooperator ?" />
<field name="unsubscribed" invisible="1" />
</group>
<group attrs="{'invisible': [('unsubscribed', '=', True)]}">
<field name="cooperator_id" />
<field name="info_session" />
<field name="info_session_date" />
<field name="working_mode" />
<field name="exempt_reason_id" attrs="{'invisible':[('working_mode', '!=', 'exempt')]}"/>
<field name="shift_id" domain="[('remaining_worker', '>', 0)]" attrs="{'invisible': [('working_mode', '!=', 'regular')]}"/>
<field name="super" />
<field name="reset_counter" />
</group>
<footer>
<button type="object" name="subscribe"
string="Confirm" class="oe_highlight" />
string="Confirm" class="oe_highlight" attrs="{'invisible': [('unsubscribed', '=', True)]}" />
<button type="object" name="unsubscribe"
string="Confirm" class="oe_highlight" attrs="{'invisible': [('unsubscribed', '=', False)]}" />
or
<button special="cancel" string="Cancel" />
</footer>

4
pos_price_to_weight/static/src/js/models.js

@ -15,7 +15,7 @@ odoo.define('pos_price_to_weight.models', function (require) {
models.PosModel = models.PosModel.extend({
initialize: function (session, attributes) {
// New code
var product_model = _.find(this.models, function(model){
return model.model === 'product.product';
});
@ -41,7 +41,7 @@ odoo.define('pos_price_to_weight.models', function (require) {
if (price !== 0 && product.price !== 0){
// replace the initial line cause this only work for price with
// vat include in the price in the pos.
//quantity = price / product.price;
quantity = price / product.total_with_vat;
}
selectedOrder.add_product(product, {quantity: quantity, merge: false});

Loading…
Cancel
Save