Commit d5d72a5a by François C.

Change to consider shift_type in LaCagette Membership, instead of admitting…

Change to consider shift_type in LaCagette Membership, instead of admitting everybody has subscribed ftop type shift templates
parent 7e9aa8a0
<?xml version="1.0"?> <?xml version="1.0"?>
<odoo noupdate="1"> <odoo noupdate="1">
<record id="points_limit_to_get_suspended" model="ir.config_parameter"> <record id="points_limit_to_get_suspended" model="ir.config_parameter">
<field name="key">lacagette_membership.points_limit_to_get_suspended</field> <field name="key">lacagette_membership.points_limit_to_get_suspended</field>
<field name="value">-2</field> <field name="value">-2</field>
......
...@@ -21,7 +21,7 @@ class ResPartner(models.Model): ...@@ -21,7 +21,7 @@ class ResPartner(models.Model):
target_status = fields.Selection( target_status = fields.Selection(
selection=TARGET_STATUS_SELECTION, default='') selection=TARGET_STATUS_SELECTION, default='')
@api.model @api.model
def run_process_target_status(self): def run_process_target_status(self):
"""Method called by cron task""" """Method called by cron task"""
...@@ -31,24 +31,28 @@ class ResPartner(models.Model): ...@@ -31,24 +31,28 @@ class ResPartner(models.Model):
for p in self.env['res.partner']\ for p in self.env['res.partner']\
.search([('target_status', '!=', "")]): .search([('target_status', '!=', "")]):
new_values = {'target_status': "", "date_alert_stop": False} try:
if p.final_ftop_point < 0: new_values = {'target_status': "", "date_alert_stop": False}
new_values['cooperative_state'] = p.target_status final_points = p.final_ftop_point if p.shift_type == "ftop" else p.final_standard_point
if new_values['cooperative_state'] == "unsubscribed": if final_points < 0:
new_values['makeups_to_do'] = 2 if absence_status == 'absent' else 1 new_values['cooperative_state'] = p.target_status
new_values['final_ftop_point'] = -2 if new_values['cooperative_state'] == "unsubscribed":
new_values['display_ftop_points'] = -2 new_values['makeups_to_do'] = 2 if absence_status == 'absent' else 1
""" new_values['final_' + p.shift_type + '_point'] = -2
unlink model: "shift.template.registration" new_values['display_' + p.shift_type + '_points'] = -2
to delete all future shifts linked to this coop. """
""" unlink model: "shift.template.registration"
for streg in self.env['shift.template.registration']\ to delete all future shifts linked to this coop.
.search([('partner_id', '=', p.id)]): """
streg.unlink() for streg in self.env['shift.template.registration']\
mail_template = self.env.ref('coop_membership.unsubscribe_email') .search([('partner_id', '=', p.id)]):
if mail_template: streg.unlink()
mail_template.send_mail(p.id) mail_template = self.env.ref('coop_membership.unsubscribe_email')
p.update(new_values) if mail_template:
mail_template.send_mail(p.id)
p.update(new_values)
except Exception as e:
_logger.error("run_process_target_status : %s", str(e))
#@api.onchange('cooperativestate') : could be used only if it is called from client #@api.onchange('cooperativestate') : could be used only if it is called from client
@api.model @api.model
...@@ -89,7 +93,7 @@ class ResPartner(models.Model): ...@@ -89,7 +93,7 @@ class ResPartner(models.Model):
else: else:
# need to load data # need to load data
member = self.env['res.partner'].search([('id', '=', self.id)])[0] member = self.env['res.partner'].search([('id', '=', self.id)])[0]
# should exist an other way to do it , but haven't found it # should exist an other way to do it , but haven't found it
if member.cooperative_state != "up_to_date": if member.cooperative_state != "up_to_date":
answer = False answer = False
else: else:
...@@ -103,11 +107,11 @@ class ResPartner(models.Model): ...@@ -103,11 +107,11 @@ class ResPartner(models.Model):
@api.model @api.model
def update(self, vals): def update(self, vals):
#_logger.info("valeurs reçues pour update partner = %s", str(vals)) _logger.info("valeurs reçues pour update partner = %s", str(vals))
state_to_record = "" state_to_record = ""
if 'cooperative_state' in vals: if 'cooperative_state' in vals:
state_to_record = vals['cooperative_state'] state_to_record = vals['cooperative_state']
elif 'current_cooperative_state' in vals: elif 'current_cooperative_state' in vals:
state_to_record = vals['current_cooperative_state'] state_to_record = vals['current_cooperative_state']
del vals['current_cooperative_state'] del vals['current_cooperative_state']
...@@ -116,11 +120,11 @@ class ResPartner(models.Model): ...@@ -116,11 +120,11 @@ class ResPartner(models.Model):
return super(ResPartner, self).update(vals) return super(ResPartner, self).update(vals)
@api.model @api.model
def write(self, vals): def write(self, vals):
# _logger.info("valeurs reçues pour write partner = %s", str(vals)) _logger.info("valeurs reçues pour write partner = %s", str(vals))
if 'cooperative_state' in vals: if 'cooperative_state' in vals:
self._write_state_change(vals['cooperative_state']) self._write_state_change(vals['cooperative_state'])
return super(ResPartner, self).write(vals) return super(ResPartner, self).write(vals)
\ No newline at end of file
...@@ -17,18 +17,19 @@ class ShiftCounterEvent(models.Model): ...@@ -17,18 +17,19 @@ class ShiftCounterEvent(models.Model):
if vals['point_qty'] < 0: if vals['point_qty'] < 0:
res_partner = self.env['res.partner'].search([('id', '=', vals['partner_id'])]) res_partner = self.env['res.partner'].search([('id', '=', vals['partner_id'])])
if res_partner: if res_partner:
points_before_removing_points = res_partner[0].final_ftop_point p = res_partner[0]
points_before_removing_points = p.final_ftop_point if p.shift_type == "ftop" else p.final_standard_point
points_after_removal = points_before_removing_points + vals['point_qty'] points_after_removal = points_before_removing_points + vals['point_qty']
_logger.info("points_after_removal = %s", str(points_after_removal)) _logger.info("points_after_removal = %s", str(points_after_removal))
if points_after_removal <= suspension_limit or points_after_removal <= unsubscribe_limit: if points_after_removal <= suspension_limit or points_after_removal <= unsubscribe_limit:
if (points_after_removal <= suspension_limit if (points_after_removal <= suspension_limit
and and
res_partner[0].cooperative_state != 'delay'): p.cooperative_state != 'delay'):
target_status = 'suspended' target_status = 'suspended'
if points_after_removal <= unsubscribe_limit: if points_after_removal <= unsubscribe_limit:
target_status = 'unsubscribed' target_status = 'unsubscribed'
res_partner[0].update({'target_status': target_status, p.update({'target_status': target_status,
'current_cooperative_state': res_partner[0].cooperative_state}) 'current_cooperative_state': p.cooperative_state})
@api.model @api.model
def write(self, vals): def write(self, vals):
...@@ -43,4 +44,3 @@ class ShiftCounterEvent(models.Model): ...@@ -43,4 +44,3 @@ class ShiftCounterEvent(models.Model):
_logger.info("Vals reçues creation = %s", str(vals)) _logger.info("Vals reçues creation = %s", str(vals))
return super(ShiftCounterEvent, self).create(vals) return super(ShiftCounterEvent, self).create(vals)
\ No newline at end of file
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