
* Add Odoo App and Icon * Add Auth for Odoo * Authorise with API key, the password would also work, but we should encourage an API key. * Odoo Verify Credentials method * Add the xmlrpc dependency so the backend can communicate with Odoo's API. * Add a port to the auth fields to establish a connection that might not be over HTTPS. * Add still verified method * Currently no need to keep uid, so remove it from the auth data. * Await the callback from the xmlrpc method call to ensure we don't verify credentials before the callback has been executed. * Add Odoo create-lead action * Provide basic functionality to create a lead. * Add Odoo type option * Let the user decide if the lead should be a "lead" or "opportunity" in the create-lead action. * Add documentation for Odoo app * Follow project standards * Change indents to 2 spaces * Use single quotes instead of double * Commonise the authentication method (DRY) * Use latest for API doc link * refactor(odoo): abstract and organize implementation --------- Co-authored-by: Ali BARIN <ali.barin53@gmail.com>
104 lines
2.2 KiB
TypeScript
104 lines
2.2 KiB
TypeScript
import defineAction from '../../../../helpers/define-action';
|
|
import { authenticate, asyncMethodCall } from '../../common/xmlrpc-client';
|
|
|
|
export default defineAction({
|
|
name: 'Create Lead',
|
|
key: 'createLead',
|
|
description: '',
|
|
arguments: [
|
|
{
|
|
label: 'Name',
|
|
key: 'name',
|
|
type: 'string' as const,
|
|
required: true,
|
|
description: 'Lead name',
|
|
variables: true,
|
|
},
|
|
{
|
|
label: 'Type',
|
|
key: 'type',
|
|
type: 'dropdown' as const,
|
|
required: true,
|
|
variables: true,
|
|
options: [
|
|
{
|
|
label: 'Lead',
|
|
value: 'lead'
|
|
},
|
|
{
|
|
label: 'Opportunity',
|
|
value: 'opportunity'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
label: "Email",
|
|
key: 'email',
|
|
type: 'string' as const,
|
|
required: false,
|
|
description: 'Email of lead contact',
|
|
variables: true,
|
|
},
|
|
{
|
|
label: "Contact Name",
|
|
key: 'contactName',
|
|
type: 'string' as const,
|
|
required: false,
|
|
description: 'Name of lead contact',
|
|
variables: true
|
|
},
|
|
{
|
|
label: 'Phone Number',
|
|
key: 'phoneNumber',
|
|
type: 'string' as const,
|
|
required: false,
|
|
description: 'Phone number of lead contact',
|
|
variables: true
|
|
},
|
|
{
|
|
label: 'Mobile Number',
|
|
key: 'mobileNumber',
|
|
type: 'string' as const,
|
|
required: false,
|
|
description: 'Mobile number of lead contact',
|
|
variables: true
|
|
}
|
|
],
|
|
|
|
async run($) {
|
|
const uid = await authenticate($);
|
|
const id = await asyncMethodCall(
|
|
$,
|
|
{
|
|
method: 'execute_kw',
|
|
params: [
|
|
$.auth.data.databaseName,
|
|
uid,
|
|
$.auth.data.apiKey,
|
|
'crm.lead',
|
|
'create',
|
|
[
|
|
{
|
|
name: $.step.parameters.name,
|
|
type: $.step.parameters.type,
|
|
email_from: $.step.parameters.email,
|
|
contact_name: $.step.parameters.contactName,
|
|
phone: $.step.parameters.phoneNumber,
|
|
mobile: $.step.parameters.mobileNumber
|
|
}
|
|
]
|
|
],
|
|
path: 'object',
|
|
},
|
|
);
|
|
|
|
$.setActionItem(
|
|
{
|
|
raw: {
|
|
id: id
|
|
}
|
|
}
|
|
)
|
|
}
|
|
});
|