def test_get_hebergement_tarif_to_confirm_with_value(self): tarif = Tarifs.get_hebergement_tarif_to_confirm_with_value( heb_pk=84, type='LOW_SEASON', subtype='WEEKEND', min='550', max='650', cmt=None) self.assertNotEqual(tarif, None) self.assertEqual(tarif.pk, 7) tarif = Tarifs.get_hebergement_tarif_to_confirm_with_value( heb_pk=84, type='LOW_SEASON', subtype='WEEKEND', min='551', max='651', cmt=None) self.assertEqual(tarif, None)
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()