Skip to content

Commit

Permalink
feat: add a button to open the CRM page of the company / contact (#10441
Browse files Browse the repository at this point in the history
)

* feat: add a button to open the crm linked company of the org

* feat: add button to open contact in crm from pro platform

* update test results

* link noopener
  • Loading branch information
4nt0ineB authored Jun 17, 2024
1 parent 29c8734 commit 687cbbb
Show file tree
Hide file tree
Showing 10 changed files with 1,128 additions and 1,047 deletions.
2 changes: 2 additions & 0 deletions cgi/org.pl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use ProductOpener::Orgs qw/:all/;
use ProductOpener::Tags qw/canonicalize_tag_link/;
use ProductOpener::Text qw/remove_tags_and_quote/;
use ProductOpener::CRM qw/get_company_url/;

use CGI qw/:cgi :form escapeHTML charset/;
use URI::Escape::XS;
Expand Down Expand Up @@ -467,6 +468,7 @@
$template_data_ref->{current_user_id} = $User_id;

$template_data_ref->{main_contact} = $org_ref->{main_contact};
$template_data_ref->{crm_company_url} = get_company_url($org_ref);

process_template('web/pages/org_form/org_form.tt.html', $template_data_ref, \$html)
or $html = "<p>template error: " . $tt->error() . "</p>";
Expand Down
2 changes: 2 additions & 0 deletions cgi/user.pl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use ProductOpener::Lang qw/$lc %Lang lang/;
use ProductOpener::Orgs qw/org_name retrieve_org/;
use ProductOpener::Text qw/remove_tags_and_quote/;
use ProductOpener::CRM qw/get_contact_url/;

use CGI qw/:cgi :form escapeHTML charset/;
use URI::Escape::XS;
Expand Down Expand Up @@ -429,6 +430,7 @@
$template_data_ref->{debug} = $debug;
$template_data_ref->{userid} = $userid;
$template_data_ref->{type} = $type;
$template_data_ref->{crm_contact_url} = get_contact_url($user_ref);

if (($type eq "edit_owner") and ($action eq "process")) {
$log->info("redirecting to / after changing owner", {}) if $log->is_info();
Expand Down
32 changes: 32 additions & 0 deletions lib/ProductOpener/CRM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ BEGIN {
&change_company_main_contact
&update_last_import_date
&update_last_export_date
&get_company_url
&get_contact_url
);
%EXPORT_TAGS = (all => [@EXPORT_OK]);

Expand Down Expand Up @@ -572,6 +574,36 @@ sub update_company_last_action_date($org_id, $time, $field) {
return make_odoo_request('res.partner', 'write', [[$org_ref->{crm_org_id}], {$field => $date_string}]);
}

=head2 get_company_url ($org_ref)
Returns the URL of the company in the CRM
=head3 Arguments
=head4 $org_ref
=head3 Return values
the URL of the company in the CRM or undef if the company is not linked to the CRM
=cut

sub get_company_url($org_ref) {
if ($ProductOpener::Config2::crm_url and defined $org_ref->{crm_org_id}) {
return $ProductOpener::Config2::crm_url
. "/web#id=$org_ref->{crm_org_id}&menu_id=111&action=139&model=res.partner&view_type=form";
}
return;
}

sub get_contact_url($user_ref) {
if ($ProductOpener::Config2::crm_url and defined $user_ref->{crm_user_id}) {
return $ProductOpener::Config2::crm_url
. "/web#id=$user_ref->{crm_user_id}&menu_id=111&action=139&model=res.partner&view_type=form";
}
return;
}

=head2 make_odoo_request (@params)
Calls Odoo's API with the given parameters
Expand Down
4 changes: 3 additions & 1 deletion lib/ProductOpener/Config2_docker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ BEGIN {
%server_options
$build_cache_repo
$rate_limiter_blocking_enabled
$crm_url
$crm_api_url
$crm_username
$crm_db
Expand Down Expand Up @@ -152,7 +153,8 @@ $build_cache_repo = $ENV{BUILD_CACHE_REPO};
$rate_limiter_blocking_enabled = $ENV{RATE_LIMITER_BLOCKING_ENABLED} // "0";

# Odoo CRM
$crm_api_url = $ENV{ODOO_CRM_URL} . '//xmlrpc/2/' if $ENV{ODOO_CRM_URL};
$crm_url = $ENV{ODOO_CRM_URL};
$crm_api_url = $crm_url . '//xmlrpc/2/' if $crm_url;
$crm_username = $ENV{ODOO_CRM_USER};
$crm_db = $ENV{ODOO_CRM_DB};
$crm_pwd = $ENV{ODOO_CRM_PASSWORD};
Expand Down
4 changes: 4 additions & 0 deletions po/common/common.pot
Original file line number Diff line number Diff line change
Expand Up @@ -7005,3 +7005,7 @@ msgstr "AQUA/WATER, SODIUM LAURETH SULFATE, DISODIUM COCOAMPHODIACETATE, GLYCOL
msgctxt "report_problem_navigation"
msgid "Report a problem"
msgstr "Report a problem"

msgctxt "open_in_crm"
msgid "Open in CRM"
msgstr "Open in CRM"
4 changes: 3 additions & 1 deletion po/common/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -6944,4 +6944,6 @@ msgctxt "cant_delete_main_contact"
msgid "You cannot remove the main contact. Change it first."
msgstr "You cannot remove the main contact. Change it first."


msgctxt "open_in_crm"
msgid "Open in CRM"
msgstr "Open in CRM"
11 changes: 11 additions & 0 deletions scss/_off.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1893,3 +1893,14 @@ a.panel_title {
visibility: visible;
}

div.open-in-crm {
display:flex;
justify-content: center;
align-items: center;

& > input {
width:auto;
flex-grow: 1;
margin: 0 1em 0 0;
}
}
8 changes: 7 additions & 1 deletion templates/web/pages/org_form/org_form.tt.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,13 @@ <h2>[% lang("organization_members") %]</h2>
<p>[% field.description %]</p>
[% END %]

[% IF field.type == 'text' %]
[% IF field.field == 'crm_org_id' AND crm_company_url != "" %]
<label for="[% field.field %]">[% field.label %]</label>
<div class="open-in-crm">
<input type="text" id="[% field.field %]" name="[% field.field %]" value="[% field.value %]"/>
<a type="button" class="button" id="crm_button" href="[% crm_company_url %]" target="_blank" rel="noopener">[% lang("open_in_crm") %]</a>
</div>
[% ELSIF field.type == 'text' %]
<label for="[% field.field %]">[% field.label %]</label>
<input type="text" id="[% field.field %]" name="[% field.field %]" value="[% field.value %]" />
[% ELSIF field.type == 'textarea' %]
Expand Down
111 changes: 59 additions & 52 deletions templates/web/pages/user_form/user_form_page.tt.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,62 +64,69 @@
<div class="form-wrapper">
<div class="form-container" style="width: 80%;margin-right: 20px;">
[% FOREACH field IN section.fields %]
[% IF field.field == 'userid' %]
[% IF type == 'edit' %]
<label for="[% field.field %]"> [% field.label %]</label>
<p id="userid"><a href="/editor/[% field.value %]">[% field.value %]</a></p>
[% ELSE %]
<label for="[% field.field %]"> [% lang(field.label) %] [% lang('username_info') %]</label>
<input type="text" id="[% field.field %]" name="[% field.field %]" value="[% field.value %]" autocomplete="username" onkeyup="normalize_string_value(this)" />
[% END %]
[% ELSIF field.type == 'text' %]
<div [% IF section.id == "professional" %] class="pro_org_display" [% END %]>
<label for="[% field.field %]">[% field.label %]</label>
<input type="text" id="[% field.field %]" name="[% field.field %]" value="[% field.value %]" [% IF section.id == "teams" %] onkeyup="normalize_string_value(this)" [% END %]/>
</div>
[% ELSIF field.type == 'password' %]
<label for="[% field.field %]">[% lang(field.label) %]</label>
<div class="password-container">
<input type="password" id="[% field.field %]" name="[% field.field %]" value="[% field.value %]" autocomplete="new-password"/>
<span class="toggle-password" onclick="togglePasswordVisibility('[% field.field %]')">
<span class="material-icons material-symbols-visibility">visibility_off</span>
</span>
</div>
[% ELSIF field.type == 'email' %]
<label for="[% field.field %]"> [% field.label %]</label>
<input type="email" id="[% field.field %]" name="[% field.field %]" value = "[% field.value %]" autocomplete="email"/>
[% IF server_options_producers_platform %]
<div style="color: red; font-weight: 600;">🚨 [% lang('email_warning') %]</div>
[% END %]
[% ELSIF field.type == 'select' %]
<label for="[% field.field %]"> [% lang(field.label) %]</label>
<select name="[% field.field %]" id="[% field.field %]-select">
<option value=""></option>
[% FOREACH item IN field.options %]
<option value="[% item.value %]" [% IF item.value == field.selected %]selected[% END %]> [% item.label %]</option>
[% END %]
</select>
[% ELSIF field.type == 'checkbox' %]
[% IF accepted_organization && section.id == "professional" %]
<p>[% f_lang('f_this_is_a_pro_account_for_org', {'org' => accepted_organization}) %]</p>
[% ELSE %]
<label for="[% field.field %]">
<input type="checkbox" id="[% field.field %]" name="[% field.field %]" [% IF field.value == 'on' %]checked="checked"[% END %] />
[% field.label %]
</label>
[% END %]
[% ELSIF field.type == 'honeypot' %]
[%# this is a honey pot for spammers, it should be left empty %]
<div style="display:none">
<label for="[% field.field %]">[% field.label %]</label>
<input type="text" id="[% field.field %]" name="[% field.field %]" value="[% field.value %]"/>

[% IF field.field == 'crm_user_id' AND crm_contact_url != "" %]
<label for="[% field.field %]">[% field.label %]</label>
<div class="open-in-crm">
<input type="text" id="[% field.field %]" name="[% field.field %]" value="[% field.value %]"/>
<a type="button" class="button" id="crm_button" href="[% crm_contact_url %]" target="_blank" rel="noopener">[% lang("open_in_crm") %]</a>
</div>
[% ELSIF field.field == 'userid' %]
[% IF type == 'edit' %]
<label for="[% field.field %]"> [% field.label %]</label>
<p id="userid"><a href="/editor/[% field.value %]">[% field.value %]</a></p>
[% ELSE %]
<label for="[% field.field %]"> [% lang(field.label) %] [% lang('username_info') %]</label>
<input type="text" id="[% field.field %]" name="[% field.field %]" value="[% field.value %]" autocomplete="username" onkeyup="normalize_string_value(this)" />
[% END %]
[% ELSIF field.type == 'text' %]
<div [% IF section.id == "professional" %] class="pro_org_display" [% END %]>
<label for="[% field.field %]">[% field.label %]</label>
<input type="text" id="[% field.field %]" name="[% field.field %]" value="[% field.value %]" [% IF section.id == "teams" %] onkeyup="normalize_string_value(this)" [% END %]/>
</div>
[% ELSIF field.type == 'hidden' %]
<label for="pro">
<input type="hidden" name="[% field.field %]" value="[% field.value %]">
[% ELSIF field.type == 'password' %]
<label for="[% field.field %]">[% lang(field.label) %]</label>
<div class="password-container">
<input type="password" id="[% field.field %]" name="[% field.field %]" value="[% field.value %]" autocomplete="new-password"/>
<span class="toggle-password" onclick="togglePasswordVisibility('[% field.field %]')">
<span class="material-icons material-symbols-visibility">visibility_off</span>
</span>
</div>
[% ELSIF field.type == 'email' %]
<label for="[% field.field %]"> [% field.label %]</label>
<input type="email" id="[% field.field %]" name="[% field.field %]" value = "[% field.value %]" autocomplete="email"/>
[% IF server_options_producers_platform %]
<div style="color: red; font-weight: 600;">🚨 [% lang('email_warning') %]</div>
[% END %]
[% ELSIF field.type == 'select' %]
<label for="[% field.field %]"> [% lang(field.label) %]</label>
<select name="[% field.field %]" id="[% field.field %]-select">
<option value=""></option>
[% FOREACH item IN field.options %]
<option value="[% item.value %]" [% IF item.value == field.selected %]selected[% END %]> [% item.label %]</option>
[% END %]
</select>
[% ELSIF field.type == 'checkbox' %]
[% IF accepted_organization && section.id == "professional" %]
<p>[% f_lang('f_this_is_a_pro_account_for_org', {'org' => accepted_organization}) %]</p>
[% ELSE %]
<label for="[% field.field %]">
<input type="checkbox" id="[% field.field %]" name="[% field.field %]" [% IF field.value == 'on' %]checked="checked"[% END %] />
[% field.label %]
</label>
[% END %]
[% ELSIF field.type == 'honeypot' %]
[%# this is a honey pot for spammers, it should be left empty %]
<div style="display:none">
<label for="[% field.field %]">[% field.label %]</label>
<input type="text" id="[% field.field %]" name="[% field.field %]" value="[% field.value %]"/>
</div>
[% ELSIF field.type == 'hidden' %]
<label for="pro">
<input type="hidden" name="[% field.field %]" value="[% field.value %]">
</label>
[% END %]
[% END %]
</div>
<!-- show video about account creation beside user form section-->
[% IF server_options_producers_platform AND section.id == "user" AND type != "edit" %]
Expand Down
Loading

0 comments on commit 687cbbb

Please sign in to comment.