Esempio n. 1
0
def lookupvalues_delete(lookupvalue_id):
    from application.models.lookup import Lookup
    from application.models.lookup import LookupValue
    lookupvalue = LookupValue.find(lookupvalue_id)

    version = lookupvalue.version
    LookupValue.update_version(lookupvalue.lookup_id, version, lookupvalue.id)
    Lookup.update_version(lookupvalue.lookup_id, version)

    lookup = Lookup.find(lookupvalue.lookup_id)

    from werkzeug.datastructures import ImmutableMultiDict
    request.args = ImmutableMultiDict(dict(store_filter=lookup.store_id, lookup_filter=lookup.id))
    return lookupvalues()
Esempio n. 2
0
def add_lookupvalue(lookup_id, version, changevalues):
    from application.models.base import db
    from application.nutils.excel import convert_value_to_code, safe_convert_unicode

    count = 0

    try:
        for changevalue in changevalues:
            if not changevalue['value'] and not changevalue['orders']:
                continue
            lookupvalue = LookupValue.create(
                code=convert_value_to_code(
                    safe_convert_unicode(changevalue['value'])),
                value=safe_convert_unicode(changevalue['value']),
                lookup_id=lookup_id,
                parent_id='-1',
                order=safe_convert_unicode(changevalue['orders']),
                section=safe_convert_unicode(changevalue['section']),
                version=version,
            )
            db.session.add(lookupvalue)
            count += 1
        db.session.commit()
    except Exception as e:
        raise e

    if count == 0: return count

    try:
        Lookup.update_version(lookup_id, version)
        LookupValue.update_version(lookup_id, version)
        db.session.commit()
    except Exception as e:
        raise e

    return count