def _process_field(self, form, getter): if form.xmlns == OPERATEUR_XMLNSES[1]: for item in form.get_data('form/products/item'): if 'is-relevant' not in item: continue item = item['is-relevant'] val = numeric_value(getter(item)) yield { 'date': real_date(form), "value": val, "group_by": [item['product_name'], get_product_id(item['product_name'], get_domain(form))] } else: if 'products' not in form.form: return if 'num_products' in form.form and int(form.form['num_products']) > 1: for product in form.form['products']: if 'real_date' in form.form and form.form['real_date'] and 'product_name' in product: val = numeric_value(getter(product)) yield { 'date': real_date(form), "value": val, "group_by": [product['product_name'], get_product_id(product['product_name'], get_domain(form))] } elif 'real_date' in form.form and form.form['real_date'] and 'product_name' in form.form['products']: yield { 'date': real_date(form), 'value': getter(form.form['products']), 'group_by': [form.form['products']['product_name'], get_product_id(form.form['products']['product_name'], get_domain(form))] }
def livraison(self, form): if 'num_products' in form.form and int(form.form['num_products']) > 1: for product in form.form['products']: if 'real_date' in form.form and form.form[ 'real_date'] and 'product_name' in product: val = numeric_value(product['top_up']['transfer']['entry'] ['value']['@quantity']) yield { 'date': real_date(form), "value": val, 'group_by': [ product['product_name'], get_product_code(product['product_name'], get_domain(form)) ] } elif 'real_date' in form.form and form.form[ 'real_date'] and 'product_name' in form.form['products']: val = numeric_value(form.form['products']['top_up']['transfer'] ['entry']['value']['@quantity']) yield { 'date': real_date(form), 'value': val, 'group_by': [ form.form['products']['product_name'], get_product_code(form.form['products']['product_name'], get_domain(form)) ] }
def total(self, form): if 'num_products' in form.form and form.form['num_products'] > 1: products = form.form['products'] for product in products: if 'productName' in product and 'receivedMonthInner' in product and product[ 'receivedMonthInner']: yield { 'date': product['receivedMonthInner'], 'value': product['amountReceived'], 'group_by': [ product['productName'], get_product_code(product['productName'], get_domain(form)) ] } elif 'productName' in form.form['products'] and \ 'receivedMonthInner' in form.form['products'] and \ form.form['products']['receivedMonthInner']: yield { 'date': form.form['products']['receivedMonthInner'], 'value': form.form['products']['amountOrdered'], 'group_by': [ form.form['products']['productName'], get_product_code(form.form['products']['productName'], get_domain(form)) ] }
def display_total_stock(self, form): if 'num_products' in form.form and int(form.form['num_products']) > 1: for product in form.form['products']: if 'real_date' in form.form and form.form[ 'real_date'] and 'product_name' in product: val = numeric_value(product['display_total_stock']) yield { 'date': real_date(form), "value": val, 'group_by': [ product['product_name'], get_product_code(product['product_name'], get_domain(form)) ] } elif 'real_date' in form.form and form.form[ 'real_date'] and 'product_name' in form.form['products']: yield { 'date': real_date(form), 'value': form.form['products']['display_total_stock'], 'group_by': [ form.form['products']['product_name'], get_product_code(form.form['products']['product_name'], get_domain(form)) ] }
def _process_field(self, form, getter): if form.xmlns == OPERATEUR_XMLNSES[1]: for item in form.get_data('form/products/item'): if 'is-relevant' not in item: continue item = item['is-relevant'] val = numeric_value(getter(item)) yield { 'date': real_date(form), "value": val, "group_by": [item['product_name'], get_product_id(item['product_name'], get_domain(form))] } else: if 'products' not in form.form: return if 'num_products' in form.form and int(form.form['num_products']) > 1: for product in form.form['products']: if 'real_date' in form.form and form.form['real_date'] and 'product_name' in product: val = numeric_value(getter(product)) yield { 'date': real_date(form), "value": val, "group_by": [product['product_name'], get_product_id(product['product_name'], get_domain(form))] } elif 'real_date' in form.form and form.form['real_date'] and 'product_name' in form.form['products']: yield { 'date': real_date(form), 'value': getter(form.form['products']), 'group_by': [form.form['products']['product_name'], get_product_id(form.form['products']['product_name'], get_domain(form))] }
def outside_receipts_amount(self, form): if 'num_products' in form.form and int(form.form['num_products']) > 1: for product in form.form['products']: if 'real_date' in form.form and form.form[ 'real_date'] and 'product_name' in product: val = numeric_value(product['outside_receipts_amt']) yield { "date": real_date(form), "value": val, 'group_by': [ product['product_name'], get_product_code(product['product_name'], get_domain(form)) ] } elif 'real_date' in form.form and form.form[ 'real_date'] and 'product_name' in form.form['products']: yield { 'date': real_date(form), 'value': form.form['products']['outside_receipts_amt'], 'group_by': [ form.form['products']['product_name'], get_product_code(form.form['products']['product_name'], get_domain(form)) ] }
def billed_consumption(self, form): if 'num_products' in form.form and int(form.form['num_products']) > 1: for product in form.form['products']: if 'real_date' in form.form and form.form[ 'real_date'] and 'product_name' in product: val = numeric_value(product['billed_consumption']) yield { 'date': real_date(form), "value": val, 'group_by': [ product['product_name'], get_product_code(product['product_name'], get_domain(form)) ] } elif 'real_date' in form.form and form.form[ 'real_date'] and 'product_name' in form.form['products']: yield { 'date': real_date(form), 'value': form.form['products']['billed_consumption'], 'group_by': [ form.form['products']['product_name'], get_product_code(form.form['products']['product_name'], get_domain(form)) ] }
def pps_restant(self, form): if 'num_products' in form.form and int(form.form['num_products']) > 1: for product in form.form['products']: if 'real_date' in form.form and form.form[ 'real_date'] and 'product_name' in product: val = numeric_value(product['pps_stock']) yield { 'date': real_date(form), "value": val if val >= 0 else 0, 'group_by': [ product['product_name'], get_product_code(product['product_name'], get_domain(form)) ] } elif 'real_date' in form.form and form.form[ 'real_date'] and 'product_name' in form.form['products']: yield { 'date': real_date(form), 'value': form.form['products']['pps_stock'], 'group_by': [ form.form['products']['product_name'], get_product_code(form.form['products']['product_name'], get_domain(form)) ] }
def total(self, form): if 'num_products' in form.form and form.form['num_products'] > 1: for product in form.form['products']: if 'real_date' in form.form and form.form[ 'real_date'] and 'product_name' in product: yield { 'date': real_date(form), 'value': product[self.field], 'group_by': [ product['product_name'], get_product_code(product['product_name'], get_domain(form)) ] } elif 'real_date' in form.form and form.form[ 'real_date'] and 'product_name' in form.form['products']: yield { 'date': real_date(form), 'value': form.form['products'][self.field], 'group_by': [ form.form['products']['product_name'], get_product_code(form.form['products']['product_name'], get_domain(form)) ] }
def loss_amt(self, form): if 'num_products' in form.form and int(form.form['num_products']) > 1: for product in form.form['products']: if 'real_date' in form.form and form.form['real_date'] and 'product_name' in product\ and product['loss_amt']: yield { 'date': real_date(form), "value": int(product['loss_amt']), 'group_by': [ product['product_name'], get_product_code(product['product_name'], get_domain(form)) ] } elif 'real_date' in form.form and form.form[ 'real_date'] and 'product_name' in form.form['products']: yield { 'date': real_date(form), 'value': form.form['products']['loss_amt'], 'group_by': [ form.form['products']['product_name'], get_product_code(form.form['products']['product_name'], get_domain(form)) ] }
def total(self, form): if 'num_products' in form.form and form.form['num_products'] > 1: for product in form.form['products']: if 'real_date' in form.form and form.form['real_date'] and 'product_name' in product: yield { 'date': real_date(form), 'value': product[self.field], 'group_by': [product['product_name'], get_product_code(product['product_name'], get_domain(form))] } elif 'real_date' in form.form and form.form['real_date'] and 'product_name' in form.form['products']: yield { 'date': real_date(form), 'value': form.form['products'][self.field], 'group_by': [form.form['products']['product_name'], get_product_code(form.form['products']['product_name'], get_domain(form))] }
def display_total_stock(self, form): if 'num_products' in form.form and form.form['num_products'] > 1: for product in form.form['products']: if 'real_date' in form.form and form.form['real_date'] and 'product_name' in product: val = numeric_value(product['display_total_stock']) yield { 'date': real_date(form), "value": val, 'group_by': [product['product_name'], get_product_code(product['product_name'], get_domain(form))] } elif 'real_date' in form.form and form.form['real_date'] and 'product_name' in form.form['products']: yield { 'date': real_date(form), 'value': form.form['products']['display_total_stock'], 'group_by': [form.form['products']['product_name'], get_product_code(form.form['products']['product_name'], get_domain(form))] }
def loss_amt(self, form): if 'num_products' in form.form and form.form['num_products'] > 1: for product in form.form['products']: if 'real_date' in form.form and form.form['real_date'] and 'product_name' in product\ and product['loss_amt']: yield { 'date': real_date(form), "value": int(product['loss_amt']), 'group_by': [product['product_name'], get_product_code(product['product_name'], get_domain(form))] } elif 'real_date' in form.form and form.form['real_date'] and 'product_name' in form.form['products']: yield { 'date': real_date(form), 'value': form.form['products']['loss_amt'], 'group_by': [form.form['products']['product_name'], get_product_code(form.form['products']['product_name'], get_domain(form))] }
def pps_restant(self, form): if 'num_products' in form.form and form.form['num_products'] > 1: for product in form.form['products']: if 'real_date' in form.form and form.form['real_date'] and 'product_name' in product: val = numeric_value(product['pps_stock']) yield { 'date': real_date(form), "value": val if val >= 0 else 0, 'group_by': [product['product_name'], get_product_code(product['product_name'], get_domain(form))] } elif 'real_date' in form.form and form.form['real_date'] and 'product_name' in form.form['products']: yield { 'date': real_date(form), 'value': form.form['products']['pps_stock'], 'group_by': [form.form['products']['product_name'], get_product_code(form.form['products']['product_name'], get_domain(form))] }
def billed_consumption(self, form): if 'num_products' in form.form and form.form['num_products'] > 1: for product in form.form['products']: if 'real_date' in form.form and form.form['real_date'] and 'product_name' in product: val = numeric_value(product['billed_consumption']) yield { 'date': real_date(form), "value": val, 'group_by': [product['product_name'], get_product_code(product['product_name'], get_domain(form))] } elif 'real_date' in form.form and form.form['real_date'] and 'product_name' in form.form['products']: yield { 'date': real_date(form), 'value': form.form['products']['billed_consumption'], 'group_by': [form.form['products']['product_name'], get_product_code(form.form['products']['product_name'], get_domain(form))] }
def outside_receipts_amount(self, form): if 'num_products' in form.form and form.form['num_products'] > 1: for product in form.form['products']: if 'real_date' in form.form and form.form['real_date'] and 'product_name' in product: val = numeric_value(product['outside_receipts_amt']) yield { "date": real_date(form), "value": val, 'group_by': [product['product_name'], get_product_code(product['product_name'], get_domain(form))] } elif 'real_date' in form.form and form.form['real_date'] and 'product_name' in form.form['products']: yield { 'date': real_date(form), 'value': form.form['products']['outside_receipts_amt'], 'group_by': [form.form['products']['product_name'], get_product_code(form.form['products']['product_name'], get_domain(form))] }
def old_stock_pps(self, form): if 'num_products' in form.form and int(form.form['num_products']) > 1: for product in form.form['products']: if 'real_date' in form.form and form.form['real_date'] and 'product_name' in product: val = numeric_value(product['old_stock_pps']) yield { 'date': real_date(form), "value": val, 'group_by': [product['product_name'], get_product_id(product['product_name'], get_domain(form))] } elif 'real_date' in form.form and form.form['real_date'] and 'product_name' in form.form['products']: yield { 'date': real_date(form), 'value': form.form['products']['old_stock_pps'], 'group_by': [form.form['products']['product_name'], get_product_id(form.form['products']['product_name'], get_domain(form))] }
def total(self, form): if 'num_products' in form.form and form.form['num_products'] > 1: products = form.form['products'] for product in products: if 'productName' in product and 'receivedMonthInner' in product and product['receivedMonthInner']: yield { 'date': product['receivedMonthInner'], 'value': product['amountOrdered'], 'group_by': [product['productName'], get_product_code(product['productName'], get_domain(form))] } elif 'productName' in form.form['products'] and 'receivedMonthInner' in form.form['products']\ and form.form['products']['receivedMonthInner']: yield { 'date': form.form['products']['receivedMonthInner'], 'value': form.form['products']['amountOrdered'], 'group_by': [form.form['products']['productName'], get_product_code(form.form['products']['productName'], get_domain(form))] }
def in_3_months(self, form): if 'payee_trois_mois' in form.form: value = form.form['payee_trois_mois'] yield { 'date': form.form['date_du'], 'value': value, 'group_by': [form.form['district'], get_domain(form)] }
def in_year(self, form): if 'payee_un_an' in form.form: value = form.form['payee_un_an'] yield { 'date': form.form['date_du'], 'value': value, 'group_by': [form.form['district'], get_domain(form)] }
def amount_paid(self, form): if 'montant_payer' in form.form: value = form.form['montant_paye'] yield { 'date': form.form['date_du'], 'value': value, 'group_by': [form.form['district'], get_domain(form)] }
def in_30_days(self, form): if 'payee_trent_jour' in form.form: value = form.form['payee_trent_jour'] yield { 'date': form.form['date_du'], 'value': value, 'group_by': [form.form['district'], get_domain(form)] }
def livraison(self, form): if 'num_products' in form.form and form.form['num_products'] > 1: for product in form.form['products']: if 'real_date' in form.form and form.form['real_date'] and 'product_name' in product: val = numeric_value(product['top_up']['transfer']['entry']['value']['@quantity']) yield { 'date': real_date(form), "value": val, 'group_by': [product['product_name'], get_product_code(product['product_name'], get_domain(form))] } elif 'real_date' in form.form and form.form['real_date'] and 'product_name' in form.form['products']: val = numeric_value(form.form['products']['top_up']['transfer']['entry']['value']['@quantity']) yield { 'date': real_date(form), 'value': val, 'group_by': [form.form['products']['product_name'], get_product_code(form.form['products']['product_name'], get_domain(form))] }
def amount_to_pay(self, form): if 'quantite_reale_a_payer' in form.form: value = form.form['quantite_reale_a_payer'] yield { 'date': form.form['date_du'], 'value': value, 'group_by': [form.form['district'], get_domain(form)] }
def _process_v2_form(self, form): for product in (form.get_data('form/products/item') or []): received_month_inner = product.get('receivedMonthInner') amount_ordered = numeric_value(get_value_from_path(product, 'qlist/{}'.format(self.property_name))) product_name = product.get('productName') if received_month_inner is not None and amount_ordered is not None and product_name is not None: yield { 'date': received_month_inner, 'value': amount_ordered, 'group_by': [product_name, get_product_id(product_name, get_domain(form))] }
def _process_v1_form(self, form): num_products = numeric_value(form.get_data('form/num_products')) if num_products > 1: for product in (form.get_data('form/products') or []): received_month_inner = product.get('receivedMonthInner') amount_ordered = numeric_value(product.get(self.property_name)) product_name = product.get('productName') if received_month_inner and amount_ordered is not None and product_name: yield { 'date': received_month_inner, 'value': amount_ordered, 'group_by': [product_name, get_product_id(product_name, get_domain(form))] } else: received_month_inner = form.get_data('form/products/receivedMonthInner') amount_ordered = numeric_value(form.get_data('form/products/{}}'.format(self.property_name))) product_name = form.get_data('form/products/productName') if received_month_inner and amount_ordered and product_name: yield { 'date': received_month_inner, 'value': amount_ordered, 'group_by': [product_name, get_product_id(product_name, get_domain(form))] }
def _process_v1_form(self, form): num_products = numeric_value(form.get_data('form/num_products')) if num_products > 1: for product in (form.get_data('form/products') or []): received_month_inner = product.get('receivedMonthInner') amount_ordered = numeric_value(product.get(self.property_name)) product_name = product.get('productName') if received_month_inner and amount_ordered is not None and product_name: yield { 'date': received_month_inner, 'value': amount_ordered, 'group_by': [product_name, get_product_id(product_name, get_domain(form))] } else: received_month_inner = form.get_data('form/products/receivedMonthInner') amount_ordered = numeric_value(form.get_data('form/products/{}}'.format(self.property_name))) product_name = form.get_data('form/products/productName') if received_month_inner and amount_ordered and product_name: yield { 'date': received_month_inner, 'value': amount_ordered, 'group_by': [product_name, get_product_id(product_name, get_domain(form))] }
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.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
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
def _process_v1_form(self, form): if 'num_products' in form.form and form.form['num_products'] > 1: for product in form.form['products']: if 'real_date' in form.form and form.form['real_date'] and 'product_name' in product: yield { 'date': real_date(form), 'value': product[self.field], 'group_by': [product['product_name'], get_product_id(product['product_name'], get_domain(form))] } elif 'real_date' in form.form and form.form['real_date'] and 'product_name' in form.form['products']: yield { 'date': real_date(form), 'value': form.form['products'][self.field], 'group_by': [form.get_data('form/products/product_name'), get_product_id(form.get_data('form/products/product_name'), get_domain(form))] }
def _process_v1_form(self, form): if 'products' not in form.form: return if 'num_products' in form.form and numeric_value(form.form['num_products']) > 1: for product in form.form['products']: if 'real_date' in form.form and form.form['real_date'] and 'product_name' in product: yield { 'date': real_date(form), 'value': product[self.field], 'group_by': [product['product_name'], get_product_id(product['product_name'], get_domain(form))] } elif 'real_date' in form.form and form.form['real_date'] and 'product_name' in form.form['products']: yield { 'date': real_date(form), 'value': form.form['products'][self.field], 'group_by': [form.get_data('form/products/product_name'), get_product_id(form.get_data('form/products/product_name'), get_domain(form))] }
def _process_v2_form(self, form): real_date = form.get_data('form/real_date') if not real_date: return for item in form.get_data('form/products/item', []): yield { 'date': real_date, 'value': numeric_value(get_value_from_path(item, 'is-relevant/{}'.format(self.field))), 'group_by': [item['product_name'], get_product_id(item['product_name'], get_domain(form))] }