Exemplo n.º 1
0
    def test_format_gorr(self):

        self.assertEqual('', format_gorr(None))
        self.assertEqual('', format_gorr(''))
        self.assertEqual(
            'Based On: Monthly Prod; (<=250: 2.5%); (<=300: 3.0%); (<=400: 4.0%); (<=500: 5.0%); (>500: 6.0%);',
            format_gorr('mprod,250,%.025,300,%.03,400,%.04,500,%.05,0,%.06'))
        self.assertEqual(
            'Based On: Monthly Prod; (<=250: 2.5%); (<=300: 3.0%); (<=400: 4.0%); (<=500: 5.0%); (>500: 6.0%);',
            format_gorr('mprod,250,%.025,300,%.03,400,%.04,500,%.05,0,%.06'))

        self.assertEqual(
            'Based On: Monthly Prod; (<=250: 2.5%); (<=300: 3.0%); (<=400: 4.0%); (<=500: 5.0%); (>500: 6.0%);',
            format_gorr('mprod,250,%.025,300,%.03,400,%.04,500,%.05,0,%.06'))
        self.assertEqual(
            'Based On: Daily Prod; (<=250: 2.5%); (<=300: 3.0%); (<=400: 4.0%); (<=500: 5.0%); (>500: 6.0%);',
            format_gorr('dprod,250,%.025,300,%.03,400,%.04,500,%.05,0,%.06'))
        self.assertEqual(
            'Based On: Revenue; (<=250: 2.5%); (<=300: 3.0%); (<=400: 4.0%); (<=500: 5.0%); (>500: 6.0%);',
            format_gorr('rev,250,%.025,300,%.03,400,%.04,500,%.05,0,%.06'))
        self.assertEqual(
            'Based On: =(prod - sales + gj); (<=250: 2.5%); (<=300: 3.0%); (<=400: 4.0%); (<=500: 5.0%); (>500: 6.0%);',
            format_gorr(
                '=(prod - sales + gj),250,%.025,300,%.03,400,%.04,500,%.05,0,%.06'
            ))

        self.assertEqual(
            'Based On: Revenue; (<=250: $100.01); (<=300: $300.01); (>300: $1,000.01);',
            format_gorr('rev,250,$100.01,300,$300.01,0,$1000.01'))
def generate_worksheet(well_id, prod_month, rpba):
    try:
        db = config.get_database()
        product = "OIL"
        well = db.select1('WellRoyaltyMaster', ID=well_id)
        well_lease_link_array = db.select('WellLeaseLink', WellID=well_id)
        if len(well_lease_link_array) == 0:
            raise AppError("There were no well_lease_link records for " + str(well_id) + str(prod_month))
        well_lease_link = well_lease_link_array[0]
        royalty = db.select1('LeaseRoyaltyMaster', ID=well_lease_link.LeaseID)
        royalty.format_gorr = format_gorr(royalty.Gorr)
        lease = db.select1('Lease', ID=well_lease_link.LeaseID)

        if rpba:
            monthly_array = db.select('Monthly', WellID=well_id, prodMonth=prod_month, product=product, RPBA=rpba)
        else:
            monthly_array = db.select('Monthly', WellID=well_id, prodMonth=prod_month, product=product)
        if len(monthly_array) == 0:
            raise AppError("There were no monthly records for " + str(well_id) + str(prod_month) + product)
        monthly = monthly_array[0] # if there are multiple pick the first one

        ba = db.select1('BAInfo',BAid=monthly.RPBA)
        calc = db.select1('Calc', WellID=well_id, ProdMonth=prod_month,RPBA=monthly.RPBA)
        rtp_info = db.select1('RTPInfo', WellEvent=well.WellEvent, Product=product, Payer=monthly.RPBA,
                                   Date=prod_month_to_date(prod_month))
        # calc = calc_array[0]
        # print(monthly)
        return render_template('worksheet/calc_worksheet.html',
                               well=well, rm=royalty, m=monthly, lease=lease,
                               calc=calc, well_lease_link=well_lease_link, ba=ba, rtp_info=rtp_info)
    except Exception as e:
        print('views.worksheet: ***Error:', e)
        traceback.print_exc(file=sys.stdout)
        return "<h2>Error displaying worksheet for well %s</h2><br>" % well_id + str(e)
Exemplo n.º 3
0
def generate_pdfworksheet_from_calc(calc):
    try:
        db = config.get_database()
        if calc.Entity == 'Well':
            well = db.select1('WellRoyaltyMaster', ID=calc.EntityID)
        else:
            well = None
        entity_lease_link_array = db.select('EntityLeaseLink', Entity=calc.Entity, EntityID=calc.EntityID)
        if len(entity_lease_link_array) == 0:
            raise AppError("There were no well_lease_link records for " + str(calc.WellID) + str(calc.ProdMonth))
        entity_lease_link = entity_lease_link_array[0]
        royalty = db.select1('LeaseRoyaltyMaster', ID=calc.LeaseID)
        lease = db.select1('Lease', ID=calc.LeaseID)

        history = db.select_sql("""SELECT ID, ExtractDate, BaseNetRoyaltyValue, GorrNetRoyaltyValue
                   from Calc
                   WHERE ProdMonth = "{}" and LeaseID = "{}" and Entity = "{}" and EntityID = "{}"
                   and Product = "{}" and RPBA = "{}"
                   order by ExtractDate""".format(calc.ProdMonth, calc.LeaseID, calc.Entity, calc.EntityID,
                                                  calc.Product, calc.RPBA))

        prev_BaseNetRoyaltyValue = 0.0
        prev_GorrNetRoyaltyValue = 0.0
        for h in history:
            h.BookedBaseNetRoyaltyValue = h.BaseNetRoyaltyValue - prev_BaseNetRoyaltyValue
            h.BookedGorrNetRoyaltyValue = h.GorrNetRoyaltyValue - prev_GorrNetRoyaltyValue
            h.Booked = h.BookedBaseNetRoyaltyValue + h.BookedGorrNetRoyaltyValue
            prev_BaseNetRoyaltyValue = h.BaseNetRoyaltyValue
            prev_GorrNetRoyaltyValue = h.GorrNetRoyaltyValue

        monthly_array = db.select('Monthly', ExtractDate=calc.ExtractDate, Entity=calc.Entity, EntityID=calc.EntityID,
                                  prodMonth=calc.ProdMonth, product=calc.Product, RPBA=calc.RPBA)
        if len(monthly_array) == 0:
            raise AppError("There were no monthly records for well: " + str(calc.WellID) + " ProdDate: " +
                           str(calc.ProdMonth) + " Product: " + calc.Product)
        monthly = monthly_array[0]  # if there are multiple pick the first one

        ba = db.select1('BAInfo', BAid=monthly.RPBA, BAType='RTP')

        calc_specific = DataStructure(calc.RoyaltySpecific)
        rtp_info = db.select1('RTPInfo', WellEvent=well.WellEvent, Product=calc.Product, Payer=monthly.RPBA,
                              Date=prod_month_to_date(calc.ProdMonth))

        royalty.format_gorr = format_gorr(calc.Gorr)

        return render_template('worksheet/pdfcalc_worksheet.html',
                               well=well, rm=royalty, m=monthly, lease=lease,
                               calc=calc, calc_sp=calc_specific, entity_lease_link=entity_lease_link,
                               ba=ba, rtp_info=rtp_info, history=history)
    except Exception as e:
        print('views.worksheet: ***Error:', e)
        traceback.print_exc(file=sys.stdout)
        tb = traceback.format_exc()
        return "<h2>Error displaying worksheet for " + calc.Entity + " %s</h2><br>" % calc.EntityID + str(e) + \
               '<plaintext>' + tb + '</plaintext>'
    def test_format_gorr(self):

        self.assertEqual('', format_gorr(None))
        self.assertEqual('', format_gorr(''))
        self.assertEqual('Monthly Prod: (0.0-250:.02%) (250-300:.03%) (300-400:.04%) (400-500:.05%)(>500:.06%)',
                         format_gorr('mprod,250,.02,300,.03,400,.04,500,.05,0,.06'))
Exemplo n.º 5
0
def generate_worksheet_from_calc(calc, with_js='y'):
    """
    Generate html for the calc row that is passed
    :param calc: a full calc record
    :param with_js: default is 'y' only other option is 'n' and should only be used to work around a
                    pdf generation issue
    :return: html of the worksheet for the calc record
    """
    try:
        db = config.get_database()
        if calc.Entity == 'Well':
            well = db.select1('WellRoyaltyMaster', ID=calc.EntityID)
        else:
            well = None
        entity_lease_link_array = db.select('EntityLeaseLink', Entity=calc.Entity, EntityID=calc.EntityID)
        if len(entity_lease_link_array) == 0:
            raise AppError("There were no well_lease_link records for " + str(calc.WellID) + str(calc.ProdMonth))
        entity_lease_link = entity_lease_link_array[0]
        royalty = db.select1('LeaseRoyaltyMaster', ID=calc.LeaseID)
        lease = db.select1('Lease', ID=calc.LeaseID)

        history = db.select_sql("""SELECT *
                   from Calc
                   WHERE ProdMonth = "{}" and LeaseID = "{}" and Entity = "{}" and EntityID = "{}"
                   and Product = "{}" and RPBA = "{}"
                   order by ExtractDate""".format(calc.ProdMonth, calc.LeaseID, calc.Entity, calc.EntityID,
                                                  calc.Product, calc.RPBA))
        # history = db.select_sql("""SELECT ID, ExtractDate, BaseNetRoyaltyValue, GorrNetRoyaltyValue
        #            from Calc
        #            WHERE ProdMonth = "{}" and LeaseID = "{}" and Entity = "{}" and EntityID = "{}"
        #            and Product = "{}" and RPBA = "{}"
        #            order by ExtractDate""".format(calc.ProdMonth, calc.LeaseID, calc.Entity, calc.EntityID,
        #                                           calc.Product, calc.RPBA))

        prev_BaseNetRoyaltyValue = 0.0
        prev_GorrNetRoyaltyValue = 0.0
        i = 0
        for h in history:
            h.BookedBaseNetRoyaltyValue = h.BaseNetRoyaltyValue - prev_BaseNetRoyaltyValue
            h.BookedGorrNetRoyaltyValue = h.GorrNetRoyaltyValue - prev_GorrNetRoyaltyValue
            h.Booked = h.BookedBaseNetRoyaltyValue + h.BookedGorrNetRoyaltyValue
            prev_BaseNetRoyaltyValue = h.BaseNetRoyaltyValue
            prev_GorrNetRoyaltyValue = h.GorrNetRoyaltyValue
            # Set the original calc record to the history record the one before this one
            if h.ExtractDate == calc.ExtractDate and i > 0:
                calc.original(history[i-1])

            i += 1

        monthly_array = db.select('Monthly', ExtractDate=calc.ExtractDate, Entity=calc.Entity, EntityID=calc.EntityID,
                                  prodMonth=calc.ProdMonth, product=calc.Product, RPBA=calc.RPBA)
        if len(monthly_array) == 0:
            raise AppError("There were no monthly records for well: " + str(calc.WellID) + " ProdDate: " +
                           str(calc.ProdMonth) + " Product: " + calc.Product)
        monthly = monthly_array[0]  # if there are multiple pick the first one

        ba = db.select1('BAInfo', BAid=monthly.RPBA, BAType='RTP')

        calc_specific = DataStructure(calc.RoyaltySpecific)
        rtp_info = db.select1('RTPInfo', WellEvent=well.WellEvent, Product=calc.Product, Payer=monthly.RPBA,
                              Date=prod_month_to_date(calc.ProdMonth))

        royalty.format_gorr = format_gorr(calc.Gorr)

        return render_template('worksheet/calc_worksheet.html',
                               with_js=with_js,
                               well=well, rm=royalty, m=monthly, lease=lease,
                               calc=calc, calc_sp=calc_specific, entity_lease_link=entity_lease_link,
                               ba=ba, rtp_info=rtp_info, history=history)
    except Exception as e:
        print('views.worksheet: ***Error:', e)
        traceback.print_exc(file=sys.stdout)
        tb = traceback.format_exc()
        return "<h2>Error displaying worksheet for " + calc.Entity + " %s</h2><br>" % calc.EntityID + str(e) + \
               '<plaintext>' + tb + '</plaintext>'