<<

NAME

ProductOpener::CRM - manages integration with the Odoo CRM

SYNOPSIS

ProductOpener::CRM contains functions to interact with the Odoo CRM

DESCRIPTION

For clarity: - user/org refers to the pro platform side - contact/company refers to the CRM side, where: contact => Odoo partner is an 'individual' company => Odoo partner is a 'company'

        - tags => crm.tag
        - category => res.partner.category

Requirements before enabling CRM sync: - check required_tag_labels and required_category_labels

find_or_create_contact ($user_ref)

Attempts to find a contact, and if it doesn't exist, creates it

Arguments

$user_ref

the user to which a 'contact' in the CRM should be linked

Return values

the id of the contact, or undef if an error occur

link_user_with_contact ($org_ref, $contact_id = undef)

Set the off_username field of a contact to the user_id

Arguments

$user_ref

$contact_id

Return values

1 if success, undef otherwise

find_contact ($user_ref)

Finds a contact that has the user_id or same email as the given user_ref

Arguments

$user_ref

Return values

the contact id or undef

create_contact ($user_ref)

Creates a new contact in Odoo from a user

Arguments

$org_ref

Return values

the id of the created contact

find_or_create_company ($org_ref, $contact_id = undef)

Attempts to find a company, and if it doesn't exist, creates it

Arguments

$org_ref

the organization to which a 'company' in the CRM should be linked

$contact_id

Helps the strategy to find the company

Return values

The id of the contact, or undef if an error occurred

link_org_with_company ($org_ref, $company_id)

Set the off_org field of a contact to the org_id

Arguments

$org_ref

$company_id

Return values

1 if success, undef otherwise

find_company ($name)

Finds the oldest company following this strategy:

1. if the company has the corresponding off_org_id, use this one 2. if the contact_id is defined and the company he belongs to has no off_org_id, use this one 3. if there is a company with the exact same name, use this one

Arguments

$user_ref

$org_ref

Return values

the company if found, undef otherwise

create_company ($org_ref)

Creates a new company in Odoo from an org

Arguments

$org_ref

Return values

the id of the created company

add_contact_to_company ($org_ref)

Add a contact to a company in Odoo

Arguments

$contact_id

$company_id

Return values

1 if success, undef otherwise

create_onboarding_opportunity ($name, $company_id, $contact_id)

create an opportunity attached to a

Arguments

$name

The name of the opportunity

$partner_id

The id of the partner to attach the opportunity to. It can be a contact or a company

$salesperson_id

The id of the salesperson to assign the opportunity to

Return values

the id of the created opportunity

add_user_to_company ($user_id, $company_id)

Add a user to a company in Odoo. Attempts to find the contact, create it if it doesn't exist, and add it to the company.

side effect: update user_ref with the corresponding CRM contact_id

Arguments

$user_id

$company_id

Return values

the contact_id, undef if an error occurred while getting the contact_id

change_company_main_contact ($org_ref, $user_id)

Change the main contact of a company Will also update the main contact of the opportunity associated with the org.

If the user is not linked to a contact in the CRM, it will try to find or create it.

Arguments

$org_ref

The given organization must have a crm_org_id

$user_id

id of a member of the organization

Return values

1 if success, undef otherwise

add_category_to_company ($org_id, $label)

Add a category to a company in Odoo

Arguments

$org_id

$label

Return values

1 if success, undef otherwise

update_company_last_import_type ($org_id, $data_source)

Update the last import type of a company in Odoo

$data_source

must match one of the values in CRM.pm @data_source

get_company_url ($org_ref)

Returns the URL of the company in the CRM

Arguments

$org_ref

Return values

the URL of the company in the CRM or undef if the company is not linked to the CRM

make_odoo_request (@params)

Calls Odoo's API with the given parameters

Return values

the response or undef if an error occurred

init_crm_data()

Initialize the CRM data from Odoo. It is called by lib/startup_apache.pl startup script

die if CRM data cannot be loaded

Die if CRM environment variables are set but required data can't be fetched from CRM nor be loaded from cache

<<