Ejemplo n.º 1
0
def get_product_code(product_name, domain):
    try:
        return SQLProduct.objects.get(name=product_name, domain=domain).code
    except SQLProduct.DoesNotExist:
        k = PRODUCT_NAMES.get(product_name.lower())
        if k:
            return SQLProduct.objects.get(name__iexact=k, domain=domain).code
Ejemplo n.º 2
0
def get_product_code(product_name, domain):
    try:
        return SQLProduct.objects.get(name=product_name, domain=domain).code
    except SQLProduct.DoesNotExist:
        for k, v in PRODUCT_NAMES.iteritems():
            if product_name.lower() in v:
                return SQLProduct.objects.get(name__iexact=k,
                                              domain=domain).code
Ejemplo n.º 3
0
def get_product_id(product_name, domain):
    try:
        return SQLProduct.objects.get(name=product_name, domain=domain).product_id
    except SQLProduct.DoesNotExist:
        k = PRODUCT_NAMES.get(product_name.lower())
        if k:
            return SQLProduct.objects.get(name__iexact=k,
                                          domain=domain).product_id
Ejemplo n.º 4
0
def get_rupture_products_ids(form):
    result = []
    for k, v in six.iteritems(form.form):
        if re.match("^rupture.*hv$", k):
            product_name = PRODUCT_NAMES.get(PRODUCT_MAPPING[k[8:-3]].lower())
            if product_name is not None:
                try:
                    prd = SQLProduct.active_objects.get(
                        name__iexact=product_name, domain=get_domain(form))
                    result.append(prd.product_id)
                except SQLProduct.DoesNotExist:
                    pass
    return result
Ejemplo n.º 5
0
def get_rupture_products_ids(form):
    result = []
    for k, v in form.form.iteritems():
        if re.match("^rupture.*hv$", k):
            product_name = PRODUCT_NAMES.get(PRODUCT_MAPPING[k[8:-3]].lower())
            if product_name is not None:
                try:
                    prd = SQLProduct.active_objects.get(name__iexact=product_name,
                                                        domain=get_domain(form))
                    result.append(prd.product_id)
                except SQLProduct.DoesNotExist:
                    pass
    return result
Ejemplo n.º 6
0
 def total(self, form):
     for k, v in form.form.iteritems():
         if re.match("^rupture.*hv$", k):
             if 'date_rapportage' in form.form and form.form['date_rapportage']:
                 product_name = PRODUCT_NAMES.get(PRODUCT_MAPPING[k[8:-3]].lower())
                 if product_name is not None:
                     try:
                         prd = SQLProduct.objects.get(name__iexact=product_name,
                                                      domain=get_domain(form))
                         yield {
                             'date': form.form['date_rapportage'],
                             'value': v,
                             'group_by': [PRODUCT_MAPPING[k[8:-3]], prd.code]
                         }
                     except SQLProduct.DoesNotExist:
                         pass
Ejemplo n.º 7
0
 def total(self, form):
     for k, v in six.iteritems(form.form):
         if re.match("^rupture.*hv$", k):
             if 'date_rapportage' in form.form and form.form['date_rapportage']:
                 product_name = PRODUCT_NAMES.get(PRODUCT_MAPPING[k[8:-3]].lower())
                 if product_name is not None:
                     try:
                         prd = SQLProduct.active_objects.get(name__iexact=product_name,
                                                             domain=get_domain(form))
                         yield {
                             'date': form.form['date_rapportage'],
                             'value': v,
                             'group_by': [PRODUCT_MAPPING[k[8:-3]], prd.product_id]
                         }
                     except SQLProduct.DoesNotExist:
                         pass
Ejemplo n.º 8
0
def get_products_id(form, property):
    products = []
    if 'products' not in form.form:
        return

    if not isinstance(form.form['products'], list):
        return

    for product in form.form['products']:
        if property not in product:
            continue
        k = PRODUCT_NAMES.get(product[property].lower())
        if k is not None:
            try:
                code = SQLProduct.active_objects.get(
                    name__iexact=k, domain=get_domain(form)).product_id
                products.append(code)
            except SQLProduct.DoesNotExist:
                pass
    return products
Ejemplo n.º 9
0
def get_products_id(form, property):
    products = []
    if 'products' not in form.form:
        return

    if not isinstance(form.form['products'], list):
        return

    for product in form.form['products']:
        if property not in product:
            continue
        k = PRODUCT_NAMES.get(product[property].lower())
        if k is not None:
            try:
                code = SQLProduct.active_objects.get(name__iexact=k,
                                                     domain=get_domain(form)).product_id
                products.append(code)
            except SQLProduct.DoesNotExist:
                pass
    return products