예제 #1
0
def test_create_activities():
    activity_id = activitylib.add('member_management', 'member_created', member_data, datetime.datetime.now())

    activity_id = activitylib.add('member_management', 'member_updated', member_updt_data, datetime.datetime.now())

    activity_ctx = ['BizPlace:3', dbaccess.stores.member_store.ref(member_data2['id'])]
    activity_id = activitylib.add('member_management','member_created', member_data2, datetime.datetime.now())
    env.context.pgcursor.connection.commit()
예제 #2
0
    def update(self, owner, **mod_data):
        invoicepref_store.update_by(dict(owner=owner), **mod_data)

        bizplace_name = bizplace_store.get(owner, fields=['name'])
        data = dict(name=bizplace_name, attrs=', '.join(attr for attr in mod_data))
        activity_id = activitylib.add('invoicepref_management', 'invoicepref_updated', data)
        return True
예제 #3
0
파일: member.py 프로젝트: Cowoop/cowspa3
    def new(self, email, username=None, password=None, first_name=None, enabled=True, language='en', last_name=None, name=None, interests=None, expertise=None, address=None, city=None, province=None, country=None, pincode=None, work=None, home=None, mobile=None, fax=None, skype=None, website=None, short_description=None, long_description=None, twitter=None, facebook=None, blog=None, linkedin=None, use_gravtar=None, theme="default", mtype="individual", organization=None, company_no=None, number=None, created=None, enc_password=None,  biz_type='', introduced_by='', tariff_id=None, bizplace_id=0):

        if not name: name = first_name + ' ' + (last_name or '')
        created = created if created else datetime.datetime.now() # migration specific
        user_id = userlib.new(username, password, enabled, enc_password)

        data = dict(member=user_id, language=language, theme=theme)
        memberpref_store.add(**data)

        #owner = user_id
        data = dict(member=user_id, first_name=first_name, last_name=last_name, name=name, short_description=short_description, long_description=long_description, interests=interests, expertise=expertise, website=website, twitter=twitter, facebook=facebook, blog=blog, linkedin=linkedin, use_gravtar=use_gravtar, id=user_id, email=email, address=address, city=city, country=country, pincode=pincode, work=work, home=home, mobile=mobile, fax=fax, skype=skype, created=created, enabled=enabled, type=mtype, province=province, biz_type=biz_type, introduced_by=introduced_by)

        if number: data['number'] = number # migration specific
        member_store.add(**data)

        search_d = dict(id=user_id, name=name, short_description=short_description, long_description=long_description, username=username)
        #searchlib.add(search_d)

        invoicepreflib.invoicepref_collection.new(**dict(owner=user_id))

        new_roles = ['member'] if bizplace_id else ['registered']
        rolelib.new_roles(user_id=user_id, roles=['member'], context=bizplace_id)

        data = dict(name=name, id=user_id)
        member_activities = dict(individual=dict(category='member_management', name='member_created'),
                                 organization=dict(category='organization_management', name='organization_created'))
        activity_id = activitylib.add(member_activities[mtype]['category'], member_activities[mtype]['name'], data, created)

        return user_id
예제 #4
0
    def update(self, member, **mod_data):

        if mod_data['mode'] == modes.other and mod_data['billto'] == member:
            mod_data['mode'] = modes.self
            mod_data['billto'] = None
        invoicepref_store.update_by(dict(owner=member), **mod_data)

        data = dict(name=member_store.get(member, ['name']), member_id=member)
        activity_id = activitylib.add('billingpref_management', 'billingpref_updated', data)

        return True
예제 #5
0
파일: resource.py 프로젝트: Cowoop/cowspa3
    def new(self, name, short_description, type, owner, default_price=None, enabled=True, calendar=False, host_only=False, long_description=None, calc_mode=CalcMode.monthly, archived=False, picture=None, accnt_code=None):
        #TODO make default_price parameter mandatory post migration
        created = datetime.datetime.now()
        data = dict(name=name, owner=owner, created=created, short_description=short_description, enabled=enabled, calendar=calendar, host_only=host_only, long_description=long_description, type=type, calc_mode=calc_mode, archived=archived, picture=picture, accnt_code=accnt_code)
        res_id = resource_store.add(**data)

        data = dict(id=res_id, name=name, bizplace_name=dbaccess.oid2name(owner), bizplace_id=owner, user_id=env.context.user_id, created=created, type=type)
        if type == 'tariff':
            activity_id = activitylib.add('tariff_management', 'tariff_created', data, created)
        else:
            activity_id = activitylib.add('resource_management', 'resource_created', data, created)

        if default_price is not None:
            default_tariff_id = bizplace_store.get(owner, fields=['default_tariff'], hashrows=False)
            # default_tariff_id would be None when we are creating default_tariff for a new location. This is because we are adding location and there is no default_tariff yet. Now this tariff is a resource so further we need to create pricing for it. In pricing we need to specify some tariff so tariff refers itself as default_tariff.
            if default_tariff_id is None:
                default_tariff_id = res_id

            signals.send_signal('resource_created', res_id, default_tariff_id, None, default_price)
            # TODO this is not right way to send signals

        return res_id
예제 #6
0
파일: member.py 프로젝트: Cowoop/cowspa3
    def update(self, member_id, **mod_data):
        if 'username' in mod_data or 'password' in mod_data:
            userlib.update(member_id, **mod_data)
        elif 'theme' in mod_data or 'language' in mod_data:
            memberpref_store.update_by(dict(member=member_id), **mod_data)
        else:
            member_store.update(member_id, **mod_data)

        name, mtype = member_store.get(member_id, fields=['name', 'type'], hashrows=False)
        data = dict(id=member_id, name=name, attrs=', '.join(attr for attr in mod_data))
        member_activities = dict(individual=dict(category='member_management', name='member_updated'),\
                                 organization=dict(category='organization_management', name='organization_updated'))
        activity_id = activitylib.add(member_activities[mtype]['category'], member_activities[mtype]['name'], data)
예제 #7
0
파일: invoice.py 프로젝트: Cowoop/cowspa3
    def m_new(self, issuer, member, po_number, start_date, end_date, created, total, sent=None, notice='', usages=[], new_usages=[], state=0, number=None):
        for usage in new_usages:
            usage['member'] = member
            usages.append(usagelib.usage_collection.new(**usage))

        created = datetime.datetime.now()
        data = dict(issuer=issuer, member=member, usages=usages, sent=sent, total=total, tax_dict={}, start_date=start_date, end_date=end_date, state=state, created=created, notice=notice, po_number=po_number)
        if number: data['number'] = number

        invoice_id = invoice_store.add(**data)

        mod_data = dict(invoice=invoice_id)
        usage_store.update_many(usages, **mod_data)

        data = dict(name=member_store.get(member, ['name']), issuer=bizplace_store.get(issuer, ['name']), invoice_id=invoice_id, member_id=member)
        activity_id = activitylib.add('invoice_management', 'invoice_created', data, created)

        return invoice_id
예제 #8
0
파일: bizplace.py 프로젝트: Cowoop/cowspa3
    def new(self, name, address, city, country, email, short_description, province=None, long_description=None, tags=None, website=None,
        blog=None, twitter=None, facebook=None, linkedin=None, phone=None, fax=None, skype=None, mobile=None, currency='USD',
        host_email=None, booking_email=None, tz='UTC', skip_default_tariff=False, add_dummy_data=False):

        created = datetime.datetime.now()
        bizplace_id = dbaccess.OidGenerator.next("BizPlace")
        data = dict(id=bizplace_id, name=name, created=created,
                short_description=short_description,
                long_description=long_description, tags=tags, website=website,
                blog=blog, twitter=twitter, facebook=facebook, address=address,
                city=city, country=country, email=email, phone=phone, fax=fax,
                skype=skype, mobile=mobile, currency=currency, province=province,
                host_email=host_email, booking_email=booking_email, tz=tz)
        bizplace_store.add(**data)

        if not env.context.name == env.config.system_username:
            rolelib.new_roles(user_id=env.context.user_id, roles=['director', 'host'], context=bizplace_id)

        start_number=dbaccess.generate_invoice_start_number()
        invoicepreflib.invoicepref_collection.new(**dict(owner=bizplace_id, start_number=start_number))

        if not skip_default_tariff: # migration specific code. don't use skip_default_tariff otherwise
            default_tariff_id = resourcelib.resource_collection.new_tariff('Guest Tariff', 'Guest Tariff', bizplace_id, 0)
            bizplace_store.update(bizplace_id, default_tariff=default_tariff_id)

        data = dict(name=name, id=bizplace_id)
        activity_id = activitylib.add('bizplace_management', 'bizplace_created', data, created)

        if add_dummy_data:
# name, short_description, type, owner, default_price=None, enabled=True, calendar=False, host_only=False, long_description=None, calc_mode=CalcMode.monthly
            resource_id = resourcelib.resource_collection.new(name="Sunshine Room (Sample)", short_description="Room with nice windows. Can accomodate twenty people. _Sample resource_", type="room", owner=bizplace_id, default_price=100, calendar=True, calc_mode=resourcelib.CalcMode.time_based)
            # Sample usage 1
            now = datetime.datetime.now()
            start_time = datetime.datetime(now.year, now.month, now.day, 9, 0, 0)
            end_time = datetime.datetime(now.year, now.month, now.day, 12, 0, 0)
            usagelib.usage_collection.new(resource_id=resource_id, resource_name="Sunshin Room (Sample)", resource_owner=bizplace_id, member=env.context.user_id, start_time=start_time, end_time=end_time)
            # Sample usage 2
            start_time = datetime.datetime(now.year, now.month, now.day, 12, 0, 0)
            end_time = datetime.datetime(now.year, now.month, now.day, 15, 0, 0)
            usagelib.usage_collection.new(resource_id=resource_id, resource_name="Sunshin Room (Sample)", resource_owner=bizplace_id, member=env.context.user_id, start_time=start_time, end_time=end_time)
            tariff_id = resourcelib.resource_collection.new_tariff(name="Starter Plan (Sample)", short_description="_Sample membership plan_ Great plan for startups", type="tariff", owner=bizplace_id, default_price=299)

        return bizplace_id
예제 #9
0
파일: invoice.py 프로젝트: Cowoop/cowspa3
    def new(self, issuer, member, po_number=None, start_date=None, end_date=None, notice='', usages=[], new_usages=[], state=0):
        """
        usages --> The list of existing usage_ids
        new_usages --> The list of usage data which needs to create
        """
        end_date = commonlib.helpers.iso2date(end_date)
        for usage in new_usages:
            usage['member'] = member
            usages.append(usagelib.usage_collection.new(**usage))

        created = datetime.datetime.now()
        usages_linked = usage_store.get_many(usages, ['id', 'resource_id', 'member', 'quantity', 'cost', 'start_time', 'end_time', 'tax_dict', 'total'])

        # safe guard
        tax_exemption_applicable = issuer in (invoicepref_store.get_by({'owner':member}, fields=['tax_exemptions_at'])[0].tax_exemptions_at or [])
        usages_updated = False
        for usage in usages_linked:
            if (None in (usage.total, usage.cost)) or (tax_exemption_applicable and usage.tax_dict['total']):
                usagelib.usage_resource.update(usage.id, recalculate=True)
                usages_updated = True
        usages_linked = usage_store.get_many(usages, ['id', 'resource_id', 'member', 'quantity', 'cost', 'start_time', 'end_time', 'total'])

        # below test does not take billto settings in account hence commenting out for now
        #if not all((usage.member == member) for usage in usages_linked):
        #    msg = "One of the usages %s does not have member_id matching %s" % (str(usages), member)
        #    raise Exception(msg)

        total = decimal.Decimal(sum(usage.total for usage in usages_linked))
        start_date = start_date or min(usage.start_time.date() for usage in usages_linked)
        end_date = end_date or min((usage.end_time or usage.start_time).date() for usage in usages_linked)
        data = dict(issuer=issuer, member=member, usages=usages, sent=None, total=total, tax_dict={}, start_date=start_date, end_date=end_date, state=state, created=created, notice=notice, po_number=po_number)
        invoice_id = invoice_store.add(**data)

        mod_data = dict(invoice=invoice_id)
        usage_store.update_many(usages, **mod_data)

        data = dict(name=member_store.get(member, ['name']), issuer=bizplace_store.get(issuer, ['name']), invoice_id=invoice_id, member_id=member)
        activity_id = activitylib.add('invoice_management', 'invoice_created', data, created)

        create_invoice_pdf(invoice_id)

        return invoice_id
예제 #10
0
파일: usage.py 프로젝트: Cowoop/cowspa3
    def new(self, resource_id, resource_name, resource_owner, member, start_time, end_time=None, quantity=1, cost=None, tax_dict={}, invoice=None, cancelled_against=None, calculated_cost=None, notes=None, usages=[], name=None, description=None, no_of_people=0, suppress_notification=False, public=False, repetition_id=None):
        # TODO shouldn't we name the parameter member_id and not member

        if quantity is None: quantity = 1
        if not end_time: end_time = start_time

        resource = resourcelib.resource_resource.info(resource_id) if resource_id else None
        member_dict = member_store.get(member, ['id', 'first_name', 'name', 'email'])
        if resource:
            resource_owner = resource.owner
            if not resource.enabled or resource.archived:
                raise be.errors.ErrorWithHint('Resource is either not enabled or is archived')

        if end_time < start_time:
            raise be.errors.ErrorWithHint('Start time is less than end time')
        created = datetime.datetime.now()

        if cancelled_against:
            total = cost + costlib.to_decimal(tax_dict.get('total', 0))
        else:
            result = pricinglib.calculate_cost(member_id=member, resource_id=resource_id, resource_owner=resource_owner, quantity=quantity, starts=start_time, ends=end_time, cost=cost, return_taxes=True)
            calculated_cost = result['calculated_cost']
            total = result['total']
            tax_dict = result['taxes']
            if cost is None:
                cost = calculated_cost

        pricing = pricinglib.pricings.get(member, resource_id, start_time) if resource_id else None
        data = dict(resource_id=resource_id, resource_name=resource_name, resource_owner=resource_owner, quantity=quantity, calculated_cost=calculated_cost, cost=cost, total=total, tax_dict=tax_dict, invoice=invoice, start_time=start_time, end_time=end_time, member=member, created_by=env.context.user_id, created=created, cancelled_against=cancelled_against, pricing=pricing, notes=notes, name=name, description=description, no_of_people=no_of_people, public=public, repetition_id=repetition_id)
        if resource and (resource.calc_mode == resourcelib.CalcMode.quantity_based):
            data['end_time'] == start_time
        else:
            data['quantity'] == 1

        if not cancelled_against and not resource_id == 0:
            usages_dict = dict((usage['resource_id'], usage) for usage in usages)
            relations = resourcelib.resource_resource.get_relations(resource_id)
            contained_usages_data = []
            suggested_usages_data = []

            for res in relations[True]:
                usage = usages_dict.get(res.id, {})
                new_data = dict(resource_id=res.id,
                    resource_name=res.name,
                    resource_owner=resource_owner,
                    member=member,
                    suppress_notification=True,
                    start_time=start_time,
                    end_time=start_time if res.calc_mode == resourcelib.CalcMode.quantity_based else data['end_time'],
                    quantity=usage.get('quantity', 1))
                contained_usages_data.append(new_data)

            contained_usage_ids = [self.new(**new_data) for new_data in contained_usages_data]
            suggested_usage_ids = add_suggested_usages(resource['owner_id'], data, relations[False], usages)

            also_booked_text = ', '.join(res.name for res in relations[False] if res.id in usages_dict)

            data['usages_contained'] = contained_usage_ids
            data['usages_suggested'] = suggested_usage_ids

        usage_id = usage_store.add(**data)


        if resource and resource.calc_mode == resourcelib.CalcMode.time_based:
            reserve_slots(usage_id, resource.id, start_time, end_time)

        suppress_email = cancelled_against or suppress_notification or resource_id == 0 or \
            (resource and resource.calc_mode != resourcelib.CalcMode.time_based)
        if not suppress_email:
            owner = bizplace_store.get(resource_owner, ['id', 'name', 'booking_email', 'currency', 'host_email', 'phone'])

            also_booked_text = 'Also booked: ' + also_booked_text if also_booked_text else ''
            email_data = dict(LOCATION=owner.name, MEMBER_EMAIL=member_dict.email, BOOKING_CONTACT=owner.booking_email or owner.host_email, MEMBER_FIRST_NAME=member_dict.first_name, RESOURCE=resource_name, BOOKING_START=commonlib.helpers.time4human(start_time), BOOKING_END=commonlib.helpers.time4human(end_time), BOOKING_DATE=commonlib.helpers.date4human(start_time), CURRENCY=owner.currency, COST=cost, HOSTS_EMAIL=owner.host_email, LOCATION_PHONE=owner.phone)
            mailtext = messagecustlib.get(owner.id, 'booking_confirmation')
            notification = commonlib.messaging.messages.booking_confirmation(email_data, overrides=dict(plain=mailtext, bcc='*****@*****.**'))
            notification.build()
            notification.email()

        a_data = dict(resource_id=resource_id, resource_name=resource_name, resource_owner=resource_owner, member_id=member_dict.id, member_name=member_dict.name, start_time=start_time, end_time=end_time, actor_id=env.context.user_id, actor_name=env.context.name, created=created)
        activity_id = activitylib.add('booking', 'booking_created', a_data, created)

        return usage_id
예제 #11
0
파일: bizplace.py 프로젝트: Cowoop/cowspa3
    def update(self, bizplace_id, **mod_data):
        bizplace_store.update(bizplace_id, **mod_data)

        bizplace_name = bizplace_store.get(bizplace_id, fields=['name'])
        data = dict(id=bizplace_id, name=bizplace_name, attrs=', '.join(attr for attr in mod_data))
        activity_id = activitylib.add('bizplace_management', 'bizplace_updated', data)