Commit 2f19b44e by Damien Moulard

add security to ensure points will be added

parent 6f151f38
......@@ -11,27 +11,31 @@ class ShiftCounterEvent(models.Model):
def _update_partner_target_status(self, vals):
"""actions when points are removed or added"""
conf = self.env['ir.config_parameter']
suspension_limit = int(conf.get_param("lacagette_membership.points_limit_to_get_suspended"))
unsubscribe_limit = int(conf.get_param("lacagette_membership.points_limit_to_get_unsubscribed"))
if vals['point_qty'] != 0:
res_partner = self.env['res.partner'].search([('id', '=', vals['partner_id'])])
if res_partner:
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']
_logger.info("points_after_removal = %s, current_state = %s", str(points_after_removal), p.cooperative_state)
if points_after_removal <= suspension_limit or points_after_removal <= unsubscribe_limit:
target_status = None
if (points_after_removal <= suspension_limit
and
p.cooperative_state != 'delay'):
target_status = 'suspended'
if points_after_removal <= unsubscribe_limit:
target_status = 'unsubscribed'
if target_status is not None:
p.update({'target_status': target_status,
'current_cooperative_state': p.cooperative_state})
try:
conf = self.env['ir.config_parameter']
suspension_limit = int(conf.get_param("lacagette_membership.points_limit_to_get_suspended"))
unsubscribe_limit = int(conf.get_param("lacagette_membership.points_limit_to_get_unsubscribed"))
if vals['point_qty'] != 0:
res_partner = self.env['res.partner'].search([('id', '=', vals['partner_id'])])
if res_partner:
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']
_logger.info("points_after_removal = %s, current_state = %s", str(points_after_removal), p.cooperative_state)
if points_after_removal <= suspension_limit or points_after_removal <= unsubscribe_limit:
target_status = None
if (points_after_removal <= suspension_limit
and
p.cooperative_state != 'delay'):
target_status = 'suspended'
if points_after_removal <= unsubscribe_limit:
target_status = 'unsubscribed'
if target_status is not None:
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
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