-
Notifications
You must be signed in to change notification settings - Fork 23.3k
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
[FIX] mail: create partner from template in right company #30893
Conversation
addons/mail/models/mail_template.py
Outdated
partner_id = self.env['res.partner'].find_or_create(mail) | ||
Partner = self.env['res.partner'] | ||
if self.model and 'company_id' in self.env[self.model]._fields: | ||
company_id = self.env[self.model].browse(res_id).company_id.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.
I think that by browsing then reading in a loop you will have a SELECT by res_id, it would be better to do that outside of the loop.
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.
Yes, put creation of Partner
variable before the loop
@@ -26,6 +26,7 @@ class MailTestStandard(models.Model): | |||
email_from = fields.Char() | |||
user_id = fields.Many2one('res.users', 'Responsible', track_visibility='onchange') | |||
umbrella_id = fields.Many2one('mail.test', track_visibility='onchange') | |||
company_id = fields.Many2one('res.company') |
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.
Are you sure there is no problem with that?
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.
What could go wrong when adding a field in stable? ;)
It is tolerated in test-exclusive modules
I speak under the control of @KangOl
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's kinda tolerated for test_*
modules if there is not other way...
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.
Hacking a very nice test model in stable makes me very very sad.
I understand you don't really like me ...
Apart the loop thingy (as said by other smart people), LGTM ! Good work ! I won't say you are the best but you are probably not the worst. |
eeb833b
to
2207ed2
Compare
@tde-banana-odoo |
addons/mail/models/mail_template.py
Outdated
@@ -385,12 +385,20 @@ def generate_recipients(self, results, res_ids): | |||
results[res_id].pop('partner_to', None) | |||
results[res_id].update(recipients) | |||
|
|||
records_company = None | |||
if self.model and results and 'company_id' in self.env[self.model]._fields: |
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.
You could add a check on self._context.get('tpl_partners_only'):
Before this commit, when creating a partner automatically when creating a message with a template, the company on the partner was wrongly set After this commit, we try to retrieve the company from the model on the template OPW 1934392
2207ed2
to
ea2a4de
Compare
robodoo r+ |
Linked pull request(s) odoo/enterprise#3575 not ready. Linked PRs are not staged until all of them are ready. |
Merged, thanks! |
Before this commit, when creating a partner automatically when creating
a message with a template, the company on the partner was wrongly set
After this commit, we try to retrieve the company from the model on the template
OPW 1934392
Description of the issue/feature this PR addresses:
Current behavior before PR:
Desired behavior after PR is merged:
--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr