Commit aee62659 by Damien Moulard

add points instead of forcing points counter when unbsuscribing partner

parent d5e94325
...@@ -56,11 +56,29 @@ class ResPartner(models.Model): ...@@ -56,11 +56,29 @@ class ResPartner(models.Model):
new_values['cooperative_state'] = p.target_status new_values['cooperative_state'] = p.target_status
if new_values['cooperative_state'] == "unsubscribed": if new_values['cooperative_state'] == "unsubscribed":
new_values['makeups_to_do'] = makeups_todo_after_unsubscribed new_values['makeups_to_do'] = makeups_todo_after_unsubscribed
new_values['final_' + p.shift_type + '_point'] = -2
if p.shift_type == 'standard': # Get points difference to set points to -2
new_values['display_std_points'] = -2 current_points = p['final_' + p.shift_type + '_point']
else: target_points = -2
new_values['display_ftop_points'] = -2
points_diff = abs(current_points - target_points)
if points_diff != 0:
if current_points > target_points:
points_update = - points_diff
else:
points_update = points_diff
data = {
'name': "Désinscription : passage à -2 pts",
'shift_id': False,
'type': p.shift_type,
'partner_id': p.id,
'point_qty': points_update
}
self.env['shift.counter.event'].create(data)
""" """
unlink model: "shift.template.registration" unlink model: "shift.template.registration"
to delete all future shifts linked to this coop. to delete all future shifts linked to this coop.
...@@ -73,16 +91,20 @@ class ResPartner(models.Model): ...@@ -73,16 +91,20 @@ class ResPartner(models.Model):
.search([('partner_id', '=', p.id), .search([('partner_id', '=', p.id),
('date_begin', '>', now)]): ('date_begin', '>', now)]):
sreg.unlink() sreg.unlink()
# Close extensions
# Close extensions
for ext in self.env['shift.extension']\ for ext in self.env['shift.extension']\
.search([('partner_id', '=', p.id), .search([('partner_id', '=', p.id),
('date_start', '<=', now), ('date_start', '<=', now),
('date_stop', '>=', now)]): ('date_stop', '>=', now)]):
ext.update({'date_stop': now}) ext.update({'date_stop': now})
mail_template = self.env.ref('coop_membership.unsubscribe_email')
if mail_template: try:
mail_template.send_mail(p.id) mail_template = self.env.ref('coop_membership.unsubscribe_email')
if mail_template:
mail_template.send_mail(p.id)
except Exception as e:
_logger.error("run_process_target_status - send mail : %s - Process not interrupted", str(e))
p.update(new_values) p.update(new_values)
except Exception as e: except Exception as e:
_logger.error("run_process_target_status : %s", str(e)) _logger.error("run_process_target_status : %s", str(e))
...@@ -148,7 +170,7 @@ class ResPartner(models.Model): ...@@ -148,7 +170,7 @@ class ResPartner(models.Model):
@api.multi @api.multi
def update(self, vals): def update(self, vals):
_logger.info("valeurs reçues pour update partner = %s", str(vals)) _logger.info("valeurs recues 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']
...@@ -164,7 +186,7 @@ class ResPartner(models.Model): ...@@ -164,7 +186,7 @@ class ResPartner(models.Model):
@api.multi @api.multi
def write(self, vals): def write(self, vals):
_logger.info("valeurs reçues pour write partner = %s", str(vals)) _logger.info("valeurs recues 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)
......
...@@ -36,13 +36,13 @@ class ShiftCounterEvent(models.Model): ...@@ -36,13 +36,13 @@ class ShiftCounterEvent(models.Model):
@api.model @api.model
def write(self, vals): def write(self, vals):
res = super(ShiftCounterEvent, self).write(vals) res = super(ShiftCounterEvent, self).write(vals)
_logger.info("Vals reçues = %s", str(vals)) _logger.info("Vals recues = %s", str(vals))
self._update_partner_target_status(vals) self._update_partner_target_status(vals)
return res return res
@api.model @api.model
def create(self, vals): def create(self, vals):
self._update_partner_target_status(vals) self._update_partner_target_status(vals)
_logger.info("Vals reçues creation = %s", str(vals)) _logger.info("Vals recues creation = %s", str(vals))
return super(ShiftCounterEvent, self).create(vals) return super(ShiftCounterEvent, self).create(vals)
...@@ -12,7 +12,7 @@ class ShiftTemplateRegistrationLine(models.Model): ...@@ -12,7 +12,7 @@ class ShiftTemplateRegistrationLine(models.Model):
def create(self, vals): def create(self, vals):
super_res = super(ShiftTemplateRegistrationLine, self.with_context( super_res = super(ShiftTemplateRegistrationLine, self.with_context(
dict(self.env.context, **{'creation_in_progress': True}))).create(vals) dict(self.env.context, **{'creation_in_progress': True}))).create(vals)
#_logger.info("valeurs reçues pour create shift.template.registration.line = %s", str(vals)) #_logger.info("valeurs recues pour create shift.template.registration.line = %s", str(vals))
if 'partner_id' in vals and 'shift_ticket_id' in vals: if 'partner_id' in vals and 'shift_ticket_id' in vals:
conf = self.env['ir.config_parameter'] conf = self.env['ir.config_parameter']
......
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