I just implemented emails in the purchase request module in Odoo 18, but I don't want followers to be added automatically to my email.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
def action_open_email_wizard(self):
template_id = self.env.ref(
"pr_email_svp.email_template_purchase_request", raise_if_not_found=False
)
compose_form = self.env.ref("mail.email_compose_message_wizard_form", False)
ctx = {
"default_model": "purchase.request",
"default_res_ids": [self.id],
"default_use_template": bool(template_id),
"default_template_id": template_id.id if template_id else False,
"default_composition_mode": "comment",
}
return {
"name": "Enviar correo",
"type": "ir.actions.act_window",
"res_model": "mail.compose.message",
"view_mode": "form",
"view_id": compose_form.id,
"target": "new",
"context": ctx,
}
#This is de code what i used to activate my email template ¿how can i fix the problem?
Hello Alfonso,
Here's the combined solution for preventing automatic follower addition to Purchase Request emails in Odoo 18, covering both the code-based approach and the limited no-code approach:
Goal: Prevent Odoo from automatically adding followers to emails related to Purchase Requests.
Solution 1: Code-Based (Recommended for Full Control)
This solution involves modifying the Python code that sends the emails. It provides the most flexibility and control over the recipient list.
Steps:
- Identify the Code: Locate the Python code that sends the Purchase Request emails. This might be in a model's create() method, a dedicated method for sending emails, or an automated action that executes Python code.
- Modify the mail.mail Creation: In the code, find where the mail.mail record is being created (using self.env['mail.mail'].create()).
- Control partner_ids and email_to:
- email_to: Use the email_to argument to specify the email address to send the email to directly.
- recipient_ids: Use the recipient_ids argument to link the email to specific partner records in Odoo. This is important for tracking and threading, but it doesn't automatically add them as followers.
- Crucially, only include the desired recipients in the recipient_ids list. Do not include entries for followers you want to exclude.
- Example Code:
from odoo import models, fields, api class PurchaseRequest(models.Model): _name = 'purchase.request' _description = 'Purchase Request' # _inherit = ['mail.thread', 'mail.activity.mixin'] # Remove mail.thread if disabling Chatter x_requestor_id = fields.Many2one('res.users', string='Requestor', default=lambda self: self.env.user) # Other fields @api.model def create(self, vals): record = super(PurchaseRequest, self).create(vals) record._send_creation_email() return record def _send_creation_email(self): for rec in self: requestor_email = rec.x_requestor_id.email if requestor_email: mail = self.env['mail.mail'].create({ 'subject': f'New Purchase Request: {rec.display_name}', 'body_html': f'<p>A new purchase request has been created by {rec.x_requestor_id.name}.</p>', 'email_to': requestor_email, 'recipient_ids': [(4, rec.x_requestor_id.partner_id.id)], # Only the requestor 'model': 'purchase.request', 'res_id': rec.id, }) mail.send()
- Explanation:
- email_to: Specifies the email address to send the email to.
- recipient_ids: Specifies the partner records to link to the email. This is important for tracking and threading, but it doesn't automatically add them as followers.
- Important: Do not include a partner_ids entry for the followers you want to exclude.
- Explanation:
Solution 2: No-Code (Limited, Only Works with Mail Templates)
This solution only works if you're sending the emails using a mail template and an automated action. It provides limited control and might not always work as expected.
Steps:
- Identify the Mail Template:
- Go to Settings -> Technical -> Email -> Templates.
- Search for templates related to "Purchase Request" or "New Purchase Request."
- Open the template you're using.
- Remove the "Followers" Recipient (Crucial Step):
- In the "Recipients" section of the mail template, look for a recipient type called "Followers."
- Delete this recipient entry. This is the key to preventing followers from being automatically added.
- Add a Specific Recipient (If Needed):
- If you want to send the email to a specific person (e.g., the requestor), add a new recipient entry:
- Recipient Type: "Related Document"
- Related Field: Select the field that contains the email address of the recipient (e.g., x_requestor_id.email if you have a field called x_requestor_id that links to the user who created the request).
- If you want to send the email to a specific person (e.g., the requestor), add a new recipient entry:
Important Considerations (For Both Solutions)
- mail.thread Inheritance: If you remove mail.thread inheritance, you'll lose all the Chatter functionality, including the ability to manually add followers, log notes, and schedule activities. This is generally not recommended.
- Testing: Thoroughly test your changes to ensure that emails are being sent to the correct recipients and that followers are not being added automatically.
- User Experience: Consider the impact on user experience. If users expect to be automatically added as followers, they might be confused if they don't receive the emails. Provide clear communication about how the email system works.
- Odoo's Default Behavior: Odoo's default behavior is to add followers to email conversations. Even if you implement these solutions, Odoo might still add followers in some cases, especially if other modules or configurations are interfering.
Choosing the Right Solution
- Code-Based (Solution 1): Use this solution if you need full control over the recipient list and want to ensure that followers are not automatically added. This is the recommended approach.
- No-Code (Solution 2): Use this solution only if you absolutely cannot use code and you're using mail templates and automated actions. Be aware that this solution has limitations and might not always work as expected.
By implementing one of these solutions, you should be able to prevent automatic follower addition to your Purchase Request emails in Odoo 18. Remember to test thoroughly and choose the solution that best fits your needs and technical capabilities.
🚀 Did This Solve Your Problem?
If this answer helped you save time, money, or frustration, consider:
✅ Upvoting (👍) to help others find it faster
✅ Marking as "Best Answer" if it resolved your issue
Your feedback keeps the Odoo community strong! 💪
(Need further customization? Drop a comment—I’m happy to refine the solution!)
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
PrijaviRelated Posts | Odgovori | Prikazi | Aktivnost | |
---|---|---|---|---|
|
1
maj 25
|
473 | ||
|
0
apr. 25
|
514 | ||
|
1
apr. 25
|
701 | ||
|
1
mar. 25
|
733 | ||
|
3
feb. 25
|
727 |