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 get_item(self, item): # Get tarif to confirm values type = getattr(item, 'type', '') subtype = getattr(item, 'subtype', '') if not type and not subtype: return u'' to_confirm_item = Tarifs.get_hebergement_tarif_to_confirm(self.table.heb_pk, type, subtype) # Replace tarif to tarif_to_confirm if exists item = to_confirm_item and to_confirm_item or item return item
def test_get_hebergement_tarifs_to_confirm(self): tarif = Tarifs.get_hebergement_tarif_to_confirm(heb_pk=83, type='LOW_SEASON', subtype='WEEK') self.assertNotEqual(tarif, None) self.assertEqual(tarif.pk, 6)