Ejemplo n.º 1
0
    def post(self, request: Request, _=None):
        ret = {"status": "FAIL", "message": "Unknown Error", "data": []}
        data = request.data
        if "password" in data and "file" in data:
            password = data["password"]
            if not isinstance(password, str):
                ret.update(message="Invalid password")
                raise ValidationError(detail={"message": ret["message"]})

            try:
                output = casparser.read_cas_pdf(data["file"],
                                                password,
                                                sort_transactions=True)
                return Response({
                    "status": "OK",
                    "message": "Success",
                    "data": output
                })
            except Exception as e:
                ret["message"] = str(e)
        return Response(ret)
Ejemplo n.º 2
0
def cas_importer(password, input_file):
    logger = logging.getLogger(__name__)

    logger.info("Reading CAS PDF")
    pdf_data = casparser.read_cas_pdf(input_file, password)
    period = pdf_data["statement_period"]
    email = pdf_data["investor_info"]["email"]
    click.echo("CAS file type " +
               click.style(pdf_data["file_type"], fg="green", bold=True))
    click.echo("CAS statement period: " +
               click.style(period["from"], fg="green", bold=True) + " to " +
               click.style(period["to"], fg="green", bold=True))
    click.echo("Email : " + click.style(email, fg="green", bold=True))
    try:
        result = import_cas(pdf_data, 1)
    except ValueError as e:
        click.style("Error while importing CAS :: %s" % str(e),
                    bold=True,
                    fg="red")
    else:
        click.echo("Total Transactions : " + click.style(
            f"{result['transactions']['total']}", fg="green", bold=True))
        click.echo("Imported : " + click.style(
            f"{result['transactions']['total']}", fg="green", bold=True))
Ejemplo n.º 3
0
 def read_pdf(self, filename, password, output="dict"):
     use_pdfminer = self.mode == "pdfminer"
     return read_cas_pdf(filename, password, output=output, force_pdfminer=use_pdfminer)
Ejemplo n.º 4
0
    def get_transactions(self):
        if isfile(self.filename):
            data = casparser.read_cas_pdf(self.filename, self.passwd)
            print(data)
            if data['cas_type'] != 'DETAILED':
                print(
                    f'failed to add mutual fund transactions since document is not detailed'
                )
                return list()
            for folio in data['folios']:
                folio_num = folio['folio'].replace(' ', '')
                if folio_num.endswith('/0'):
                    folio_num = folio_num.replace('/0', '')
                for scheme in folio['schemes']:
                    if scheme['advisor'] == 'INA200005166' or scheme[
                            'advisor'] == '000000-0':
                        broker = 'KUVERA'
                    elif scheme['advisor'] == 'INZ000031633':
                        broker = 'COIN ZERODHA'
                    elif scheme['advisor'] == 'INA200011107':
                        broker = 'SCRIPBOX'
                    elif scheme['advisor'] == 'INA100009859':
                        broker = 'PAYTM MONEY'
                    elif scheme['advisor'] == 'INA000006651':
                        broker = 'NIYO MONEY'
                    elif scheme['advisor'] == 'INZ000208032':
                        broker = 'GROWW'
                    elif scheme['advisor'] == 'INA100006898':
                        broker = 'ET MONEY'
                    else:
                        broker = scheme['advisor']

                    isin = scheme['isin']
                    amfi_code = scheme['amfi']
                    fund, description = self._get_fund(isin, folio_num)
                    if not fund:
                        create_alert(summary='Folio:' + folio_num +
                                     ' Failure to add transactions',
                                     content=description,
                                     severity=Severity.error,
                                     alert_type="Action")
                        continue
                    for trans in scheme['transactions']:
                        if 'tax' in trans['type'].lower():
                            continue
                        trans_date = trans['date']
                        if 'redemption' in trans['type'].lower():
                            trans_type = 'Sell'
                        elif 'purchase' in trans['type'].lower():
                            trans_type = 'Buy'
                        else:
                            print(
                                f"ignoring transaction of type {trans['type']}"
                            )
                        units = trans['units']
                        nav = trans['nav']
                        trans_value = trans['amount']
                        yield {
                            'folio': folio_num,
                            'trans_date': trans_date,
                            'fund': fund,
                            'trans_type': trans_type,
                            'units': float(units),
                            'nav': float(nav),
                            'trans_value': float(trans_value),
                            'broker': broker
                        }

        else:
            print(f'{self.filename} is not a file or doesnt exist')