Ejemplo n.º 1
0
    def post(self, request):
        text = request.POST['upload-lc-register'].strip()

        if text:
            for row in json.loads(text):
                if not UploadedFormM.objects.filter(
                        mf=row['mf'], ba=row['ba'], ccy=row['ccy'],
                        validity_type=row['validity_type'], status=row['status']).exists():
                    UploadedFormM.objects.create(**row)
        return redirect(admin_url(UploadedFormM))
Ejemplo n.º 2
0
    def post(self, request):
        uploaded_text = request.POST["upload-ti-posting-status-text"]
        self.date_format = request.POST["date-format"]

        if uploaded_text:
            uploaded_text = uploaded_text.strip(" \n\r")

            if uploaded_text:
                self.parse(StringIO(uploaded_text.encode("utf-8", "ignore")))

        return redirect(admin_url(TIPostingStatusReport))
Ejemplo n.º 3
0
    def post(self, request):
        uploaded_text = request.POST['upload-lc-register-text'].strip(' \n\r')
        date_format = request.POST['date-format']
        logger.info("Raw data received from client:\n%s" % uploaded_text)

        if uploaded_text:
            parser_utility = UploadCSVParserUtility()
            lc_classes = LCClass.objects.values_list('prod_code', flat=True)

            for data in json.loads(uploaded_text):
                logger.info('About to create or update lc using raw data from client:\n%s' % data)

                data["expiry_date"] = parser_utility.normalize_date(data["expiry_date"], date_format)
                data["estb_date"] = parser_utility.normalize_date(data["estb_date"], date_format)
                data['ccy_obj'] = Currency.objects.get(code=data['ccy_obj'].strip(' \n\r'))
                data["lc_amt_org_ccy"] = round(float(data["lc_amt_org_ccy"].strip(' \n\r').replace(',', '')), 2)
                data["os_amount"] = round(float(data["os_amount"].strip(' \n\r').replace(',', '')), 2)

                logger.info('About to create or update lc after raw data from client cleaned up:\n%s' % data)

                lc_number = data['lc_number'].strip(' \n\r')
                data['lc_number'] = lc_number

                if 'GTE-' in lc_number:
                    continue

                logger.info("Checking if LC %s exists in database" % lc_number)
                lc_qs = LCRegister.objects.filter(lc_number=lc_number)

                if not lc_qs.exists():
                    ref_class = lc_number[:7]
                    if ref_class in lc_classes:
                        data['lc_class'] = ref_class
                    logger.info('LC "%s" does not exist in database, it will be created', lc_number)
                    lc_obj = LCRegister.objects.create(**data)
                    logger.info('LC "%s" successfully created.' % lc_number)

                else:
                    logger.info(
                            "LC %s exists in database, it will be updated if at least one attribute value has changed" %
                            lc_number)

                    lc_obj = self.update_only_if_lc_changed(lc_number, lc_qs, data)

                form_m_qs = FormM.objects.filter(number=data['mf'].strip(' \n\r'), lc__isnull=True)

                if form_m_qs.exists():
                    logger.info('LC %s: if form M was not previously attached, form M "%s" will now be attached.' % (
                        lc_number, data['mf']))
                    form_m_qs[0].attach_lc(lc=lc_obj)

        return redirect(admin_url(LCRegister))
Ejemplo n.º 4
0
    def post(self, request):
        uploaded_text = request.POST["update-lc-register-text"].strip(" \n\r")

        if uploaded_text:
            parser_utility = UploadCSVParserUtility()

            for data in json.loads(uploaded_text):
                lc_obj = LCRegister.objects.filter(lc_number=data["lc_number"])
                if lc_obj.exists():
                    lc_obj = lc_obj[0]
                    del data["lc_number"]
                    data["expiry_date"] = parser_utility.normalize_date(data["expiry_date"])

                    for key in data:
                        if hasattr(lc_obj, key) and data[key]:
                            setattr(lc_obj, key, data[key])
                    lc_obj.save()

        return redirect(admin_url(LCRegister))