Exemplo n.º 1
0
    def save_new_policy_benefits(self, *args, **kwargs):
        product_id = kwargs.get('product_id')
        td = TypeDict()

        #Product Benefit
        product_benefits = ProductBenefit.by_attr_all(
            'product_id',
            product_id,
        )
        for benefit in product_benefits:
            policy_benefit_id = self.write_new_policy_benefit({
                'policy_id':
                policy_id,
                'product_benefit_id':
                benefit.id,
                'claims_left':
                benefit.number_of_claims
            })
            #Product Benefit Cover
            self.save_new_policy_benefit_cover(
                policy_benefit_id, benefit.product_benefit_cover_link_id)
            #Product Benefit exclusions
            self.save_new_policy_benefit_exclusions(policy_benefit_id,
                                                    benefit.id)
        return 'true'
Exemplo n.º 2
0
 def get_policy_list_html_tbl(self, *args, **kwargs):
     usernow = request.identity['user']
     dbase_query = self.get_active_policy_list(*args, **kwargs)
     outputlist = []
     td = TypeDict()
     for item in dbase_query:
         print('Placeholder: get person name here.')
         print('Placeholder: for fake data stuff removal.')
         member_holder = Member.by_id(item.policy_holder_id)
         policy_holder = 'Soap, Josephine'
         member_owner = Member.by_id(item.policy_owner_id)
         policy_owner = 'Sizpack, Frederick'
         #product = Product.by_id(item.product_id)
         #product_name = product.name
         product_name = 'ACME Product Name'
         #policy_state = td.get_pretty_name('policy_state_type', policy.policy_state_type_id)
         policy_state = td.get_pretty_name(
             'policy_state_type',
             td.get_id_of_name('policy_state_type', 'proposal'))
         outputlist.append({
             'policy_number':
             "<div class='edit entity_edit' policy_id='{1}'>{0}</div>".
             format(item.policy_number, item.id),
             'policy_holder':
             policy_holder,
             'policy_owner':
             policy_owner,
             'product':
             product_name,
             'state':
             policy_state,
         })
     theadlist = [
         'Policy Number', 'Policy Holder', 'Policy Owner', 'Product',
         'State'
     ]
     dbcolumnlist = [
         'policy_number',
         'policy_holder',
         'policy_owner',
         'product',
         'state',
     ]
     tdclasslist = [
         'action_link',
         'text-left',
         'text-left',
         'text-left',
         'text-left',
     ]
     return build_html_table(outputlist, dbcolumnlist, theadlist,
                             "policy_table", tdclasslist)
Exemplo n.º 3
0
    def save_new_policy(self, *args, **kwargs):
        product_id = kwargs.get('product_id')

        td = TypeDict()
        individual = td.get_id_of_name('policy_type', 'individual')
        proposal_date = td.get_id_of_name('policy_date_type', 'proposal')
        proposal_state = td.get_id_of_name('policy_state_type', 'proposal')

        product = Product.by_id(product_id)
        policy_number = self.generate_new_policy_number(product_id)
        product_frequency_type_id = kwargs.get('product_frequency_type_id')
        #Save Policy
        policy_id = self.write_new_policy({
            'policy_number':
            policy_number,
            'policy_type_id':
            individual,
            'product_id':
            policy_id,
            'policy_owner_id':
            kwargs.get('member_id'),
            'policy_holder_id':
            kwargs.get('member_id'),
            'application_form_serial_no':
            kwargs.get('application_form_serial_no'),
            'intermediary_id':
            kwargs.get('intermediary_id'),
        })
        policy_state_id = self.write_new_policy_state(
            **{
                'policy_id': policy_id,
                'policy_state_type_id': proposal_state
            })
        self.write_new_policy_date({
            'policy_id': policy_id,
            'policy_date_type_id': proposal_date,
            'date': now.today(),
        })
        return str(policy_id)
Exemplo n.º 4
0
    def get_new_policy_html(self, *args, **kwargs):
        product_id = kwargs.get('product_id', None)
        product = Product.by_id(product_id)
        td = TypeDict()
        print('Placehodler: Fake date hereunder for removal')
        if product:  # Initial protective code. Testing only.
            product_type_id = product.product_type_id
        else:
            product_type_id = td.get_id_of_name('product_type', 'voucher')

        if product_type_id == td.get_id_of_name('product_type', 'voucher'):
            #Then do Voucher stuff
            return self.get_new_voucher_policy_html(*args, **kwargs)
        if product_type_id == td.get_id_of_name('product_type', 'traditional'):
            #Then do Traditional stuff
            return self.get_new_traditional_policy_html(*args, **kwargs)
        if product_type_id == td.get_id_of_name('product_type', 'term_life'):
            #Then do Term Life stuff
            return self.get_new_term_life_policy_html(*args, **kwargs)
        if product_type_id == td.get_id_of_name('product_type', 'credit_life'):
            #Then do Credit Life stuff
            return self.get_new_credit_life_policy_html(*args, **kwargs)
        return ''
Exemplo n.º 5
0
def bootstrap(command, conf, vars):

    ##################################################################################################################
    #   AUTHENTICATION
    ##################################################################################################################
    timestart = datetime.now()
    try:

        u, u1 = None, None

        FIRST = 'Developer'
        devexists = model.DBSession.query(model.User). \
                filter(model.User.username==FIRST). \
                first()
        if not devexists:
            u = model.User()
            u.username = FIRST
            u.name = FIRST
            u.email = '*****@*****.**'
            u.password = '******'
            u.expires = datetime.now()
            u.added_by = 1
            model.DBSession.add(u)
            print(f'Adding USER: {FIRST}')
        else:
            u = devexists

        SECOND = 'User'
        userexists = model.DBSession.query(model.User). \
                filter(model.User.username==SECOND). \
                first()
        if not userexists:
            u1 = model.User()
            u1.username = SECOND
            u1.name = SECOND
            u1.email = '*****@*****.**'
            u1.password = '******'
            u1.expires = datetime.now()
            u1.added_by = 1
            model.DBSession.add(u1)
            print(f'Adding USER: {SECOND}')
        else:
            u1 = userexists

        model.DBSession.flush()
        transaction.commit()

        devrolexists = model.DBSession.query(model.Role). \
                filter(model.Role.name==FIRST). \
                first()
        if not devrolexists:
            dev_g = model.Role()
            dev_g.name = FIRST
            dev_g.users.append(u)
            model.DBSession.add(dev_g)
            print(f'Adding ROLES: {FIRST}')

            dev_p = model.Permission()
            dev_p.name = FIRST
            dev_p.description = f'Permission for {FIRST} Access'
            dev_p.roles.append(dev_g)
            model.DBSession.add(dev_p)

            model.DBSession.flush()
            transaction.commit()

    except IntegrityError:
        print(
            'Warning, there was a problem adding your auth data, it may have already been added: '
        )

        print(traceback.format_exc())
        transaction.abort()
        print('Continuing with bootstrapping...')
    timeend = datetime.now()
    ##################################################################################################################
    #  ROLES
    ##################################################################################################################

    timestart_roles = datetime.now()
    role_list = [
        'Sales',
        'Administrator',
        'Business Process',
        'Catalog Maintenance',
        'Claims Approval',
        'Claims Management',
        'Claims Registration',
        'Contact Centre',
        'Financial Reports',
        'Membership',
        'Product Setup',
        'Statistical Reports',
        'Users And Access',
    ]
    try:
        for new_role in role_list:

            exists = model.DBSession.query(model.Role). \
                    filter(model.Role.name==new_role). \
                    first()

            if not exists:
                print('Adding ROLES: {0}'.format(new_role))
                role = model.Role()
                role.name = new_role
                role.users.append(u)
                role.users.append(u1)
                model.DBSession.add(role)

                perm = model.Permission()
                perm.name = new_role
                perm.description = 'Permission for {0} Access'.format(
                    new_role.capitalize())
                perm.roles.append(role)
                model.DBSession.add(perm)

                model.DBSession.flush()
                transaction.commit()
    except IntegrityError:
        print(
            "Warning, there was a problem adding LIST OF ROLES, it may have already been added: "
        )

        print(traceback.format_exc())
        transaction.abort()
        print('Continuing with bootstrapping...')

    dotxml_userlist = [
        {
            'username': '******',
            'name': 'Deon Bezuidenhout',
            'email': '*****@*****.**'
        },
        {
            'username': '******',
            'name': 'Lucas Greyling',
            'email': '*****@*****.**'
        },
        {
            'username': '******',
            'name': 'JP Bezuidenhout',
            'email': '*****@*****.**'
        },
        {
            'username': '******',
            'name': 'Trevor Joubert',
            'email': '*****@*****.**'
        },
        {
            'username': '******',
            'name': 'Tjaart Swanepoel',
            'email': '*****@*****.**'
        },
        {
            'username': '******',
            'name': 'Hannes Toerien',
            'email': '*****@*****.**'
        },
        {
            'username': '******',
            'name': 'Camilla Buys',
            'email': '*****@*****.**'
        },
    ]

    timeend_roles = datetime.now()

    ##################################################################################################################
    #  TEXT MERGE
    ##################################################################################################################

    mergelist = [
        {
            'code': 'policy_number',
            'name': 'Policy Number'
        },
        {
            'code': 'customer_name',
            'name': 'Customer Name'
        },
        {
            'code': 'cover_type',
            'name': 'Cover Type'
        },
        {
            'code': 'life_assured_type',
            'name': 'Life Assured Type'
        },
        {
            'code': 'description',
            'name': 'Product Description'
        },
        {
            'code': 'price',
            'name': 'Product Price'
        },
        {
            'code': 'sum_assured',
            'name': 'Sum Assured'
        },
        {
            'code': 'currency',
            'name': 'Currency'
        },
        {
            'code': 'start_date',
            'name': 'Start Date'
        },
        {
            'code': 'waiting_period',
            'name': 'Waiting Period'
        },
        {
            'code': 'active_period',
            'name': 'Active Period'
        },
        {
            'code': 'end_date',
            'name': 'End Date'
        },
        {
            'code': 'benefits',
            'name': 'Benefits'
        },
    ]
    try:
        for merge in mergelist:
            name = merge.get('name')
            code = merge.get('code')
            exists = model.DBSession.query(model.MailMerge). \
                filter(model.MailMerge.name == name). \
                first()
            if not exists:
                merge = model.MailMerge()
                merge.name = name
                merge.code = code
                merge.added_by = 1
                model.DBSession.add(merge)
                model.DBSession.flush()
                transaction.commit()
    except IntegrityError:
        print(
            "Warning, there was a problem adding LIST OF MailMerge, it may have already been added:"
        )
        import traceback
        print(traceback.format_exc())
        transaction.abort()
        print('Continuing with bootstrapping...')

##################################################################################################################
#  TYPES
##################################################################################################################

    from rocket.lib.type_utils import create_type_tables
    timestart_types = datetime.now()

    dict_of_types = RawTypeDictionary().raw_dictionary_of_types
    create_type_tables(DBSession=model.DBSession, dict_of_types=dict_of_types)

    from rocket.lib.type_utils import TypeDictionary as TypeDict
    from rocket.lib.type_utils import create_cover_link_tables
    coverlist = TypeDict().get_dict_of_types('cover_and_exclusion_type')
    create_cover_link_tables(DBSession=model.DBSession, dictlist=coverlist)

    #import rocket.public.csv.test_member_import
    timeend_types = datetime.now()

    ##################################################################################################################
    #  ISO Utils
    ##################################################################################################################

    timestart_iso = datetime.now()
    from rocket.lib.iso_utils import create_currencies, create_languages, create_countries
    create_currencies(model.DBSession)
    create_languages(model.DBSession)
    create_countries(model.DBSession)
    timeend_iso = datetime.now()

    ##################################################################################################################
    #  Output
    ##################################################################################################################

    print(f"Total Time Normal Bootstraps: {timeend-timestart}")
    print(f"Total Time Roles: {timeend_roles-timestart_roles}")
    print(f"Total Time Types: {timeend_types-timestart_types}")
    print(f"Total Time ISO: {timeend_iso-timestart_iso}")
    print(f"Total Time All Bootstrap: {timeend_iso-timestart}")
Exemplo n.º 6
0
    def save_new_policy_dates(self, *args, **kwargs):
        product_id = kwargs.get('product_id')
        td = TypeDict()
        print('Placeholder: for fake data removal.')
        #product_frequency_type_id = kwargs.get('product_frequency_type_id')
        product_frequency_type_id = td.get_id_of_name('product_frequency_type',
                                                      'monthly')

        #Save Policy Dates
        wait_period = 0
        wait_period_type_id = None
        cover_period = 0
        cover_period_type_id = None
        cover_from_date = date.today()
        cover_to_date = None

        outputlist = ProductPeriod.by_attr_all('product_id', product_id)
        for item in outputlist:
            #Period Effect
            if item.product_period_effect_type_id == td.get_id_of_name(
                    'product_period_effect_type', 'active'):
                #Cover period can get set here..
                cover_period = item.time_period
                cover_period_type_id = item.product_period_type_id

            elif item.product_period_effect_type_id == td.get_id_of_name(
                    'product_period_effect_type', 'waiting'):
                #Set Wait period here
                wait_period = item.time_period
                wait_period_type_id = item.product_period_type_id

        #Evaluate the periods
        cover_from_date = self.set_cover_from_date(cover_from_date,
                                                   wait_period,
                                                   wait_period_type_id)
        cover_to_date = self.set_cover_to_date(cover_from_date, cover_period)
        #Default vaules
        accepted_date = date.today()
        policy_date = date.today()
        valid_from_date = cover_from_date
        valid_to_date = cover_to_date
        maturatity_date = None
        member_age = kwargs.get("memberage", None)
        # Maturity
        if product.maturity_age and member_age:
            #Then we can set the maturity date by obtaining the difference between the mmebers current age and the maturity age
            maturatity_date = add_months_to_date(
                date.today(), ((product.maturity_age - member_age) + 1))

        #Save away the various dates as needed.
        if accepted_date:
            policy_date_id = self.write_new_policy_date({
                'policy_id':
                policy_id,
                'policy_date_type_id':
                td.get_id_of_name('policy_date_type', 'accepted'),
                'date':
                accepted_date,
            })

        if policy_date:
            policy_date_id = self.write_new_policy_date({
                'policy_id':
                policy_id,
                'policy_date_type_id':
                td.get_id_of_name('policy_date_type', 'policy'),
                'date':
                policy_date,
            })

        if valid_from_date:
            policy_date_id = self.write_new_policy_date({
                'policy_id':
                policy_id,
                'policy_date_type_id':
                td.get_id_of_name('policy_date_type', 'valid_from'),
                'date':
                valid_from_date,
            })

        if valid_to_date:
            policy_date_id = self.write_new_policy_date({
                'policy_id':
                policy_id,
                'policy_date_type_id':
                td.get_id_of_name('policy_date_type', 'valid_to'),
                'date':
                valid_to_date,
            })

        if maturatity_date:
            policy_date_id = self.write_new_policy_date({
                'policy_id':
                policy_id,
                'policy_date_type_id':
                td.get_id_of_name('policy_date_type', 'maturatity'),
                'date':
                maturatity_date,
            })
        return 'true'
Exemplo n.º 7
0
    def get_policy_card_header_html(self, policy_id=None, *args, **kwargs):
        print('Placeholder: remove comment next line')
        #if not policy_id: return ''
        policy = Policy.by_id(policy_id)
        print('Placeholder: remove comment next line')
        #if not policy: return ''
        member = Member.by_id(policy.policy_owner_id) if policy else None
        print('Placeholder: remove comment next line')
        #if not member: return ''
        product = Product.by_id(policy.product_id) if policy else None
        print('Placeholder: remove comment next line')
        #if not product: return ''

        #Get the person from Vault
        print('Placeholder: for vault.')

        print('Placeholder: left typedict here for sequenc.')
        td = TypeDict()

        print('Placeholder: for fake data removal.')
        person = 'Placeholder for vault'
        identity_number = '1234567890123'
        name = 'Joe'
        surname = 'Soap'

        this_person = surname + ', ' + name + ' (' + identity_number + ')'
        print('Placeholder: for fake data removel.')
        if product:  # Initial protective code. Testing only.
            product_type_id = product.product_type_id
            product_code = product.code
            product_name = product.name
            product_owner_id = product.product_owner_id
            product_insurer_id = product.insurer_id
            product_life_assured_type_id = product.product_life_assured_type_id
            currency_id = product.currency_id
        else:
            product_type_id = td.get_id_of_name('product_type', 'voucher')
            product_code = 'TEST001'
            product_name = 'Test Product Number 001'
            product_owner_id = 1
            product_insurer_id = 2
            product_life_assured_type_id = td.get_id_of_name(
                'product_life_assured_type', 'member_and_family')
            product_currency_id = 1

        traditional = td.get_id_of_name('product_type', 'traditional')
        fixed_price = td.get_id_of_name('product_price_initial_setup_type',
                                        'fixed_price')
        product_type = td.get_pretty_name('product_type', product_type_id)
        life_assured_type = td.get_pretty_name('product_life_assured_type',
                                               product_life_assured_type_id)

        html = f"""
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header">
                        <div class="row d-flex">
                            <div class="col-md-9">
                                <h4 class="card-title">Create new Policy for: </h4>
                                <h3 class="card-title">{this_person}</h3>
                            </div>
                            <div class="col-md-3 text-right">
                                <button id="return_to_policy_list" class="btn btn-primary ml-auto">Return to Policy List</button>
                            </div>
                        </div>
                        <hr>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-md-7">
                                    <div class="form-group row">
                                        <label class="col-md-3 col-form-label">{product_code} - </label>
                                        <label class="col-md-3 col-form-label">{product_name}</label>
                                    </div>
                                    <div class="form-group row">
                                        <label class="col-md-3 col-form-label">{_('Life(s) Assured: ')}</label>
                                        <label class="col-md-3 col-form-label">{life_assured_type}</label>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        """
        return html
Exemplo n.º 8
0
    def get_new_voucher_policy_html(self, *args, **kwargs):
        policy_id = kwargs.get('policy_id', None)
        if not policy_id: return 'false'
        policy = Policy.by_id(policy_id)
        member = Member.by_id(policy.policy_holder_id) if policy else None
        product = Product.by_id(policy.product_id) if policy else None
        td = TypeDict()
        #product_type_id = product.product_type_id
        product_type_id = td.get_id_of_name('product_type', 'voucher')
        product_type = td.get_pretty_name('product_type', product_type_id)

        # HEADER
        card_header = self.get_policy_card_header_html(policy_id)
        # TAB 1
        card_premium_and_dates = self.get_show_policy_premium_dates_html(
            policy_id)
        # TAB 2
        card_beneficiary = self.get_show_policy_beneficiary_html(policy_id)
        # TAB 3
        card_loaders = self.get_show_policy_loaders_html(policy_id)
        # TAB 4
        card_policy_summary = self.get_show_policy_summary_html(policy_id)
        # TAB 5
        card_policy_accept = self.get_show_policy_accept_html(policy_id)

        form_show_tab1 = f"""
        <form id='form_edit_voucher_product'>
            {card_premium_and_dates}
        </form>
        """

        form_show_tab2 = f"""
        <form id='form_edit_voucher_product'>
            {card_beneficiary}
        </form>
        """

        form_show_tab3 = f"""
        <form id='form_edit_voucher_product'>
            {card_loaders}
        </form>
        """

        form_show_tab4 = f"""
        <form id='form_edit_voucher_product'>
            {card_policy_summary}
        </form>
        """

        form_show_tab5 = f"""
        <form id='form_edit_voucher_product'>
            {card_policy_accept}
        </form>
        """

        html = f"""
        {card_header}
        <div class="row">
            <div class="col-md-12 ml-auto mr-auto">
                <div class="col-md-12 ml-auto mr-auto">
                    <ul class="nav nav-pills nav-pills-primary justify-content-center" role="tablist">
                        <li class="nav-item">
                            <a class="nav-link active" data-toggle="tab" href="#tab1" role="tablist">
                                Premium and Dates
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" data-toggle="tab" href="#tab2" role="tablist">
                                Beneficiaries
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" data-toggle="tab" href="#tab3" role="tablist">
                                Loaders
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" data-toggle="tab" href="#tab4" role="tablist">
                                Summary
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" data-toggle="tab" href="#tab5" role="tablist">
                                Acceptance
                            </a>
                        </li>
                    </ul>
                </div>

                <div class="tab-content tab-space tab-subcategories">
                    <div class="tab-pane active" id="tab1">
                        {form_show_tab1}
                    </div>
                    <div class="tab-pane" id="tab2">
                        {form_show_tab2}
                    </div>
                    <div class="tab-pane" id="tab3">
                        {form_show_tab3}
                    </div>
                    <div class="tab-pane" id="tab4">
                        {form_show_tab4}
                    </div>
                    <div class="tab-pane" id="tab5">
                        {form_show_tab5}
                    </div>
                </div>
            </div>
        </div>
        """
        return html