New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: create opportunity upon org validation in CRM #10222
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #10222 +/- ##
==========================================
+ Coverage 49.54% 49.75% +0.20%
==========================================
Files 67 72 +5
Lines 20650 21119 +469
Branches 4980 5057 +77
==========================================
+ Hits 10231 10507 +276
- Misses 9131 9317 +186
- Partials 1288 1295 +7 ☔ View full report in Codecov by Sentry. |
if not defined add_contact_to_company($crm_user_id, $crm_org_id); | ||
|
||
die "Failed to create opportunity" | ||
if not defined create_opportunity($user_ref, $org_ref); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe store the opportunity id as well, so that we can update it later, for instance if the org imports products.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work !
I did a quick review and added a comment !
}; | ||
|
||
# find country code id in odoo | ||
my $user_country_code = uc $country_codes_reverse{$user_ref->{country}} || 'EN'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer the use of parenthesis for every function call (clearer for many contributors)
|
||
=cut | ||
|
||
sub create_contact ($user_ref) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine it comes with another PR but it would be important to check user existence for the email in odoo.
Duplicates on contact are really annoying to the producers team.
my $odoo_lang = odoo('res.lang', 'search_read', [[['iso_code', '=', $user_ref->{preferred_language}]]], { 'fields' => ['code']}); | ||
my $found_lang = $odoo_lang->[0]; | ||
$contact->{lang} = $found_lang->{code} // 'en_US'; # default to english | ||
if(defined $found_lang->{id}) { | ||
$contact->{x_off_languages} = [$found_lang->{id}]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a problem with Odoo because it will refuse to display a non-activated language in many to many fields (that's deep in the code), that's why I also created the x_off_languages_str field to store language values directly
=cut | ||
|
||
sub create_opportunity ($user_ref, $org_ref) { | ||
my $opportunity_id = odoo('crm.lead', 'create', [{name => "$org_ref->{name} - new org", partner_id => $user_ref->{crm_user_id}}]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to check titles, etc with Manon
use Data::Dumper; | ||
use feature 'say'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Data::Dumper
and say
aren't actually used, right? If they are, it might be better to use a proper $log
method call instead
|
||
sub odoo(@params) { | ||
if(not defined $xmlrpc) { | ||
my $api_url = $ENV{ODOO_CRM_URL} . '//xmlrpc/2/'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really use $ENV
for dynamic configuration like this, outside of Config2_docker.pm
. The "proper" way to add optional odoo configuration is probably adding it to Config.pm
and to Config2.pm
$xmlrpc = XML::RPC->new($api_url . 'common'); | ||
}; | ||
if($@) { | ||
$log->warn("odoo", {error => $@, reason => "Could not connect to Odoo CRM"}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For local development or some test environments, we won't always have "odoo" installed or configured. It might be a good idea to guard against the object being created again and again if no odoo connection is configured. For example during integration tests, this could avoid some noisy error logging (and possibly reduce execution duration)
Quality Gate passedIssues Measures |
What
When an organization is validated on the pro platform, associated contact and org are created in the Odoo CRM and linked to a new opportunity.
Related issue(s)