Topview Logo
  • Create viral videos with
    GPT-4o + Ads library
    Use GPT-4o to edit video empowered by Youtube & Tiktok & Facebook ads library. Turns your links or media assets into viral videos in one click.
    Try it free
    gpt video

    Odoo Development Tutorial: Custom Email Template for POS Receipt + AI content generator

    blog thumbnail

    Introduction

    In this tutorial, we will explore the process of creating a custom email template for sales receipts in Odoo's POS (Point of Sale) module. We will address the limitations of the default email design and introduce an AI content generator to create dynamic email content.

    Introduction

    The Odoo POS application has the capability to send sales receipts to customers via email. However, the default design of these emails is quite plain, and there's no option for customization. This tutorial will guide you through creating a module that overrides the default email process to use a more visually appealing template, along with the integration of AI to generate varied content for emails.

    Understanding the Existing Code

    Before we start coding, it's important to understand how the original functionality works. Unfortunately, there's no documentation available, but we can utilize the browser's developer tools to trace the process.

    1. Create an Order: First, we need to create an order since the email-sending process is triggered by the "Send Email" button. Right-click on the button and select “Inspect” to view the related HTML tags.

    2. Find the Relevant Code: Note that there aren’t any ID attributes on the tags; however, we can use the class name send_email, which seems unique and relevant to email. By searching for this class in the codebase, we can find where it is defined and trace it back to the JavaScript and Python files.

    3. Locate the Email Preparation Method: Eventually, we find that the POS order receipt email values come from the prepare_mail_values method of the POSOrder class. Odoo has built-in features for email templates, which we will leverage for our new module.

    Creating the Module

    Directory Structure

    We will create the required directory structure for our module:

    • Module Folder: Create the main directory for your module.
    • Manifest File: Add a manifest file to define module metadata.
    • Init Files: Include init files to initialize the module correctly.
    • Subdirectories: Create models and data subdirectories.

    Override the Email Method

    We will override the action_receipt_to_customer method to send the receipt image without the invoice. Next, we create a new email template that will be utilized every time an email is sent from the module.

    Installation and Testing

    Once the module is completed, we need to install it and set the custom design. For testing, I used an email template developed by Lee Monroe found on GitHub, with some modifications.

    Overcoming Embedded Images Issue

    A challenge encountered during the testing phase was that Gmail does not support embedded base64 images for logos displaying correctly. To resolve this, we need to host the logo image externally.

    Introducing AI Content Generation

    To enhance the experience further, we can generate different email contents using AI. This allows for varied writing styles, making each email more engaging.

    Steps to Implement AI Content Generation

    1. AI Class Creation: We create a new class for the email generator using an AI model.
    2. Email Generation: The AI agent is prompted to rewrite the previous email template, allowing for diverse styles or tones.
    3. Randomization and Experimentation: We can randomize the tone of writing when calling the method and test with different temperature settings for variability.

    Final Testing

    The modified POS order code now utilizes the AI-generated email content, using the updated design we prepared earlier.

    If you don’t have an email server setup, you can still test the module; failed emails will be stored in the database, accessible via the email settings in the technical menu.

    Conclusion

    By following these steps, we successfully customized the email template for the POS receipts in Odoo and integrated AI to generate dynamic content.

    Thank you for watching! Don’t forget to like this video, subscribe for more tutorials, and turn on notifications.


    Keywords

    • Odoo
    • Custom Email Template
    • POS Receipt
    • AI Content Generator
    • Email Sending Process
    • Email Templates
    • Email Design
    • Dynamic Content

    FAQ

    Q1: What is Odoo?
    A: Odoo is an open-source suite of business applications that includes modules for sales, CRM, project management, and more.

    Q2: Can I customize the email templates in Odoo?
    A: Yes, by creating a custom module, you can override the default email sending process and design your own templates.

    Q3: How does the AI content generator work?
    A: The AI content generator rewrites the email template based on parameters like style or tone to produce varied email content.

    Q4: What should I do if my images don’t appear in emails?
    A: If images are not displaying correctly, ensure they are hosted externally, as some email clients do not support embedded images.

    Q5: Can I test the module without an email server?
    A: Yes, you can test the functionality, and any failed emails will be stored in the database for review.

    One more thing

    In addition to the incredible tools mentioned above, for those looking to elevate their video creation process even further, Topview.ai stands out as a revolutionary online AI video editor.

    TopView.ai provides two powerful tools to help you make ads video in one click.

    Materials to Video: you can upload your raw footage or pictures, TopView.ai will edit video based on media you uploaded for you.

    Link to Video: you can paste an E-Commerce product link, TopView.ai will generate a video for you.

    You may also like