Commit 2f19b44e by Damien Moulard

add security to ensure points will be added

parent 6f151f38
...@@ -11,27 +11,31 @@ class ShiftCounterEvent(models.Model): ...@@ -11,27 +11,31 @@ class ShiftCounterEvent(models.Model):
def _update_partner_target_status(self, vals): def _update_partner_target_status(self, vals):
"""actions when points are removed or added""" """actions when points are removed or added"""
conf = self.env['ir.config_parameter'] try:
suspension_limit = int(conf.get_param("lacagette_membership.points_limit_to_get_suspended")) conf = self.env['ir.config_parameter']
unsubscribe_limit = int(conf.get_param("lacagette_membership.points_limit_to_get_unsubscribed")) suspension_limit = int(conf.get_param("lacagette_membership.points_limit_to_get_suspended"))
if vals['point_qty'] != 0: unsubscribe_limit = int(conf.get_param("lacagette_membership.points_limit_to_get_unsubscribed"))
res_partner = self.env['res.partner'].search([('id', '=', vals['partner_id'])]) if vals['point_qty'] != 0:
if res_partner: res_partner = self.env['res.partner'].search([('id', '=', vals['partner_id'])])
p = res_partner[0] if res_partner:
points_before_removing_points = p.final_ftop_point if p.shift_type == "ftop" else p.final_standard_point p = res_partner[0]
points_after_removal = points_before_removing_points + vals['point_qty'] points_before_removing_points = p.final_ftop_point if p.shift_type == "ftop" else p.final_standard_point
_logger.info("points_after_removal = %s, current_state = %s", str(points_after_removal), p.cooperative_state) points_after_removal = points_before_removing_points + vals['point_qty']
if points_after_removal <= suspension_limit or points_after_removal <= unsubscribe_limit: _logger.info("points_after_removal = %s, current_state = %s", str(points_after_removal), p.cooperative_state)
target_status = None if points_after_removal <= suspension_limit or points_after_removal <= unsubscribe_limit:
if (points_after_removal <= suspension_limit target_status = None
and if (points_after_removal <= suspension_limit
p.cooperative_state != 'delay'): and
target_status = 'suspended' p.cooperative_state != 'delay'):
if points_after_removal <= unsubscribe_limit: target_status = 'suspended'
target_status = 'unsubscribed' if points_after_removal <= unsubscribe_limit:
if target_status is not None: target_status = 'unsubscribed'
p.update({'target_status': target_status, if target_status is not None:
'current_cooperative_state': p.cooperative_state}) p.update({'target_status': target_status,
'current_cooperative_state': p.cooperative_state})
except Exception as e:
# don't block process if an error occurs here
_logger.error("Error during _update_partner_target_status : %s", str(e))
@api.model @api.model
def write(self, vals): def write(self, vals):
......
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