Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ Hint: Look at Extra Tips (at the bottom of README) for a more detailed guide on

```

[//]: # (has_booked_call )
[//]: # (has_signed_up )
support_call_count: Numerical
sales_call_count: Numerical
tc2_status: Large text
tc2_cligency_url: Large text
hermes_id: Numerical
Expand Down
3 changes: 2 additions & 1 deletion app/admin/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ class CompanyResource(Model):
'paid_invoice_count',
'estimated_income',
'currency',
'has_booked_call',
'sales_call_count',
'support_call_count',
'has_signed_up',
'utm_campaign',
'utm_source',
Expand Down
3 changes: 0 additions & 3 deletions app/callbooker/_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ async def get_or_create_contact_company(event: CBSalesCall) -> tuple[Company, Co
await company.save()
contact = contact or await get_or_create_contact(company, event)
app_logger.info(f'Got company {company} and contact {contact} from {event}')

company.has_booked_call = True
await company.save()
return company, contact


Expand Down
4 changes: 4 additions & 0 deletions app/callbooker/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ async def sales_call(event: CBSalesCall, tasks: BackgroundTasks):
else:
meeting.deal = deal
await meeting.save()
company.sales_call_count += 1
await company.save()
tasks.add_task(pd_post_process_sales_call, company=company, contact=contact, deal=deal, meeting=meeting)
return {'status': 'ok'}

Expand All @@ -59,6 +61,8 @@ async def support_call(event: CBSupportCall, tasks: BackgroundTasks):
return JSONResponse({'status': 'error', 'message': str(e)}, status_code=400)
else:
await meeting.save()
company.support_call_count += 1
await company.save()
tasks.add_task(pd_post_process_support_call, contact=contact, meeting=meeting)
return {'status': 'ok'}

Expand Down
3 changes: 2 additions & 1 deletion app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ class Company(HermesModel):
paid_invoice_count = fields.IntField(default=0)
estimated_income = fields.CharField(max_length=255, null=True)
currency = fields.CharField(max_length=255, null=True)
has_booked_call = fields.BooleanField(default=False)
sales_call_count = fields.IntField(default=0)
support_call_count = fields.IntField(default=0)
has_signed_up = fields.BooleanField(default=False)
utm_campaign = fields.CharField(max_length=255, null=True)
utm_source = fields.CharField(max_length=255, null=True)
Expand Down
7 changes: 5 additions & 2 deletions app/pipedrive/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ async def pd_post_process_sales_call(company: Company, contact: Contact, meeting

async def pd_post_process_support_call(contact: Contact, meeting: Meeting):
"""
Called after a support call is booked. Creates the activity if the contact have a pipedrive id
Called after a support call is booked. Creates/updates the Org & Person in pipedrive,
Creates the activity if the contact have a pipedrive id
"""
with logfire.span('pd_post_process_support_call'):
if (await contact.company).pd_org_id:
company = await contact.company
if company and company.pd_org_id:
await get_and_create_or_update_organisation(company)
await get_and_create_or_update_person(contact)
await create_activity(meeting)

Expand Down
15 changes: 15 additions & 0 deletions migrations/models/8_20240913013916_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
return """
ALTER TABLE "company" ADD "support_call_count" INT NOT NULL DEFAULT 0;
ALTER TABLE "company" ADD "sales_call_count" INT NOT NULL DEFAULT 0;
ALTER TABLE "company" DROP COLUMN "has_booked_call";"""


async def downgrade(db: BaseDBAsyncClient) -> str:
return """
ALTER TABLE "company" ADD "has_booked_call" BOOL NOT NULL DEFAULT False;
ALTER TABLE "company" DROP COLUMN "support_call_count";
ALTER TABLE "company" DROP COLUMN "sales_call_count";"""
31 changes: 30 additions & 1 deletion patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from app.tc2.tasks import update_client_from_company
from tortoise.expressions import Q
from tortoise import Tortoise
from app.models import Company
from app.models import Company, Meeting
import logfire

async def init():
Expand Down Expand Up @@ -91,6 +91,35 @@ async def update_pd_org_price_plans():
print(f'Updated {companies_updated} companies')


@command
async def update_call_counts():
"""
This patch updates the call counts for companies, by searching though all meetings
"""
meetings = await Meeting.all()
print(f'Updating call counts from {len(meetings)} meetings')
for meeting in meetings:
deal = await meeting.deal
if not deal:
continue
company = await deal.company
if company:
if meeting.meeting_type == Meeting.TYPE_SALES:
company.sales_call_count += 1
print(f'Incremented company {company.id} with {company.sales_call_count} sales call count')
elif meeting.meeting_type == Meeting.TYPE_SUPPORT:
company.support_call_count += 1
print(f'Incremented company {company.id} with {company.support_call_count} support call count')
await company.save()

# send a task to update the Organisation in Pipedrive
print(f'Sending task to update company {company.id} in Pipedrive')
await get_and_create_or_update_organisation(company)





# End of patch commands

@click.command()
Expand Down
Loading
Loading