def _update_tarif(heb_pk, type, subtype, min, max, cmt, valid): """ Verify that the values in DB are different then insert new line If to_confirm with same value valid = True return If to_confirm with different value valid = False If tarif exists with same value do nothing If tarif does not exists with same value insert new tarif """ to_confirm_exist = Tarifs.get_hebergement_tarif_to_confirm_with_value( heb_pk=heb_pk, type=type, subtype=subtype, min=min, max=max, cmt=cmt) if to_confirm_exist: to_confirm_exist.valid = True to_confirm_exist.save() return if type == 'CHARGES': to_confirm = Tarifs.get_hebergement_tarif_to_confirm(heb_pk, type) else: to_confirm = Tarifs.get_hebergement_tarif_to_confirm(heb_pk, type, subtype) if to_confirm: to_confirm.valid = False to_confirm.save() exist = Tarifs.exists_tarifs(heb_pk=heb_pk, type=type, subtype=subtype, min=min, max=max, cmt=cmt) if not exist: # Insert new tarifs line tarif = Tarifs(heb_pk=heb_pk, type=type, subtype=subtype, min=min, max=max, cmt=cmt, date=datetime.now(), user=api.user.get_current().id, valid=valid) tarif.add()
def test_exists_tarifs(self): tarif_not_valid = Tarifs.exists_tarifs(heb_pk=84, type='LOW_SEASON', subtype='WEEKEND', min='550', max='650', cmt=None) self.assertEqual(tarif_not_valid, False) tarif_wrong_value = Tarifs.exists_tarifs(heb_pk=84, type='LOW_SEASON', subtype='WEEKEND', min='251', max='260', cmt=None) self.assertEqual(tarif_wrong_value, False) tarif = Tarifs.exists_tarifs(heb_pk=84, type='LOW_SEASON', subtype='WEEKEND', min='250', max='260', cmt=None) self.assertEqual(tarif, True)