Skip to content

Mastering Odoo 18 Sales Order Signature: Your Essential Step-by-Step Guide

odoo sales order signature

Are you looking to enhance your Odoo sales documentation with a professional touch? Implementing an Odoo Sales Order Signature section is crucial for formalizing agreements, ensuring accountability, and streamlining your business processes. This comprehensive tutorial will guide you through the powerful process of customizing your Odoo 18 Sales Order reports to include dedicated signature fields for “Created By,” “Validated By,” and “Received By.”

Based on the detailed insights from our internal development context, this guide breaks down complex Odoo customization into actionable, easy-to-follow steps. By the end of this article, you’ll be able to generate Sales Order reports that not only look professional but also provide clear lines of responsibility.

Why an Odoo Sales Order Signature Section is Indispensable

In today’s fast-paced business environment, clarity and formalization of documents are paramount. Adding an Odoo Sales Order Signature block offers several key benefits:

  • Enhanced Professionalism: A dedicated signature section gives your Sales Orders a polished, official appearance, reinforcing trust with your clients.
  • Clear Accountability: Explicit fields for “Created By,” “Validated By,” and “Received By” clearly define who is responsible at each stage of the order process, minimizing disputes and improving internal workflows.
  • Legal Compliance & Record-Keeping: For many businesses, physical or electronic signatures are essential for legal validity and robust record-keeping. While this tutorial focuses on adding the fields, it lays the groundwork for incorporating actual e-signatures or physical sign-offs.
  • Streamlined Auditing: Easily track the approval flow of each Sales Order, making internal and external audits more straightforward and efficient.
  • Improved User Experience: Both internal users and external customers benefit from clear, well-structured documents.

Let’s dive into how you can achieve this powerful customization in Odoo 18.

Prerequisites for Customizing Your Odoo Sales Order Signature

Before we begin modifying your Odoo reports, ensure you have the following:

  • Odoo 18 Development Environment: A running Odoo 18 instance where you have administrative access and the ability to install custom modules.
  • Developer Mode Enabled: Activate “Developer Mode” (also known as “Debug Mode”) in your Odoo instance. You can usually find this option in the Settings or by adding ?debug=1 to your Odoo URL. This mode exposes advanced technical features, including access to views and XML IDs.
  • Basic Odoo Concepts: Familiarity with Odoo modules, views, and reporting (QWeb templates) will be helpful.
  • Basic XML and HTML Knowledge: The customization involves editing XML files that define the report structure, using HTML for layout.
  • Understanding of Python: While not heavily used in this specific report modification, it’s fundamental for creating custom Odoo modules and adding new fields.

Step-by-Step Tutorial: Adding the Signature Section

Our approach leverages Odoo’s powerful inheritance mechanism for report templates. Instead of directly altering core Odoo files (which is risky and not upgrade-safe), we will create a custom add-on module to extend the existing Sales Order report. This is an Odoo best practice for any customization.

1. Create a Custom Add-on Module

First, you need to set up the basic structure for your new Odoo add-on module. This module will house all your customizations.

  1. Navigate to your Odoo Add-ons Path: Locate the addons folder in your Odoo installation directory. This is where all Odoo modules reside.
  2. Create a New Module Directory: Inside the addons folder, create a new directory for your custom module. Name it descriptively, for instance, fit_so_sign. This name will be used internally by Odoo.
  3. Establish Module Structure: Within fit_so_sign, create the following essential files and subdirectories:
    • __init__.py: This empty file signals to Python that fit_so_sign is a package.
    • __manifest__.py: This file defines your module’s metadata, dependencies, and what data files it loads.
    • models/: Create an empty directory named models. While we won’t add Python models in this specific report modification, it’s standard practice to include this directory for future extensibility. Add an empty __init__.py inside models/.
    • report/: Create a directory named report. This will store the XML file defining your report modifications. Add an empty __init__.py inside report/.
      • Inside report/, we will later create so.xml, which contains the actual QWeb report template.

2. Populate __manifest__.py

The __manifest__.py file acts as your module’s identity card. It tells Odoo everything it needs to know about your module. Open the __manifest__.py file you just created and add the following content:

{
    'name': 'SO with Signature',
    'version': '1.0',
    'summary': 'Adds a signature section to the Sales Order report.',
    'description': """
        This module enhances the standard Odoo Sales Order report by adding a
        dedicated signature section at the bottom. It includes fields for
        'Created By', 'Validated By', and 'Received By', improving document
        formalization and accountability.
    """,
    'category': 'Sales',
    'author': 'Your Name or Company',
    'website': 'https://www.yourcompany.com', # Replace with your actual website
    'depends': ['sale'],  # Crucial: Declare dependency on the 'sale' module
    'data': [
        'report/so.xml', # This line tells Odoo to load the XML file for our report customization
    ],
    'installable': True,
    'auto_install': False,
    'application': False,
}

Explanation of Key Fields:

  • name: The display name of your module in the Odoo Apps list.
  • version: The version number of your module.
  • summary: A short, one-line description visible in the Apps list.
  • description: A more detailed explanation of what your module does. This is where you can elaborate on the benefits of the Odoo Sales Order Signature feature.
  • category: Helps categorize your module in the Odoo Apps. Sales is appropriate here.
  • author, website: Your information or your company’s.
  • depends: This is a critical field. ['sale'] indicates that your module relies on the standard Odoo sale module. Since we are modifying the Sales Order report, which is part of the sale module, this dependency is essential. Without it, Odoo wouldn’t know where to find the original template we want to inherit.
  • data: This list specifies all XML and CSV data files that Odoo should load when installing or updating your module. Here, we tell Odoo to load report/so.xml, which contains our report template modifications.
  • installable, auto_install, application: Standard settings for most custom modules.

3. Create the Report XML File: report/so.xml

This is the core of our customization. Inside the report/ directory, create a new file named so.xml and add the following XML code. This file will define how we inherit and modify the existing Sales Order report template to add our Odoo Sales Order Signature block.

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <!-- Template to inherit and add signature section to Sales Order Report -->
        <template id="fit_so_sign" inherit_id="sale.report_saleorder_document">
            <!-- XPath to find the last 'oe_structure' div and insert content after it -->
            <xpath expr="//div[@class='oe_structure'][last()]" position="after">
                <div class="page">
                    <br/> <!-- Add some spacing -->
                    <table class="table table-sm" style="width:100%; border: none;">
                        <thead>
                            <tr style="border: none;">
                                <th style="width:33%; text-align:center; padding: 10px 0;">Created By</th>
                                <th style="width:33%; text-align:center; padding: 10px 0;">Validated By</th>
                                <th style="width:34%; text-align:center; padding: 10px 0;">Received By (Customer)</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr style="height: 120px; border: none;">
                                <td style="vertical-align: bottom; text-align: center; border-top: 1px solid #ddd;">
                                    <span t-field="doc.user_id.name"/>
                                    <br/>
                                    <span t-field="doc.user_id.email" class="text-muted"/>
                                </td>
                                <td style="vertical-align: bottom; text-align: center; border-top: 1px solid #ddd;">
                                    <!-- Placeholder for future Validator field -->
                                    _________________________
                                </td>
                                <td style="vertical-align: bottom; text-align: center; border-top: 1px solid #ddd;">
                                    <!-- Placeholder for Customer Signature -->
                                    _________________________
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <br/>
                </div>
            </xpath>
        </template>
    </data>
</odoo>

Detailed Explanation of report/so.xml:

  1. <odoo><data> Tags: These are standard Odoo XML wrappers for defining data records, including report templates.
  2. <template id="fit_so_sign" inherit_id="sale.report_saleorder_document">:
    • This is the core line for template inheritance.
    • id="fit_so_sign": Assigns a unique ID to our custom template.
    • inherit_id="sale.report_saleorder_document": This crucial attribute tells Odoo that our template fit_so_sign is inheriting from the existing report template with the external ID report_saleorder_document located in the sale module. This is how we extend an existing report without modifying its original source.
  3. <xpath expr="//div[@class='oe_structure'][last()]" position="after">:
    • This is an XPath expression, a powerful tool for navigating and selecting nodes in an XML document. It’s essential for precisely targeting where your new content should be inserted within the inherited template.
    • expr="//div[@class='oe_structure'][last()]": This part of the XPath expression searches for:
      • //div: Any div element anywhere in the document.
      • [@class='oe_structure']: That has a class attribute with the value oe_structure.
      • [last()]: Crucially, it selects only the last occurrence of such a div. This is important because the standard Sales Order report often contains multiple oe_structure divs, and we want our signature section at the very bottom.
    • position="after": This attribute dictates where the content enclosed within the <xpath> tags will be inserted relative to the target element found by the expr. position="after" means our new table will appear immediately after the last div with class='oe_structure'. Other options include before, replace, and inside.
  4. <div class="page">: This wraps our signature table within a div element with the page class. This is a common Odoo QWeb class used to define content that should fit within a single page of the report, helping with proper pagination and layout.
  5. <table class="table table-sm" style="width:100%; border: none;">:
    • This creates an HTML <table> element.
    • class="table table-sm": These are Bootstrap CSS classes (Odoo uses Bootstrap for styling). table provides basic table styling, and table-sm makes it more compact.
    • style="width:100%; border: none;": Inline CSS to ensure the table spans the full width and removes default borders.
  6. <thead>...</thead> and <tbody>...</tbody>: Standard HTML table structure for headers and body content.
  7. <th>Created By</th>, <th>Validated By</th>, <th>Received By (Customer)</th>: These are the column headers for our Odoo Sales Order Signature section.
  8. <tr style="height: 120px; border: none;">: This table row is styled to have a significant height, providing ample space for a physical signature or text.
  9. <span t-field="doc.user_id.name"/>:
    • This is a QWeb directive (t-field) unique to Odoo’s templating engine.
    • t-field: Instructs QWeb to display the value of a specific field.
    • doc: In Odoo report templates, doc is a special variable that represents the current record being processed – in this case, the sale.order record.
    • doc.user_id.name: This accesses the user_id field (which is a Many2one relation to res.users for the user who created the Sales Order) and then retrieves its name attribute. So, it displays the name of the user who created the Sales Order.
    • <span t-field="doc.user_id.email" class="text-muted"/>: Similarly, this displays the creator’s email, styled in a muted color using Bootstrap.
  10. _________________________: These are simple placeholders for where a signature would be placed. For “Validated By” and “Received By,” we’ve added these as placeholders because the sale.order model does not natively have fields for these specific roles. We will discuss how to implement custom fields for these in the “Further Considerations” section.

4. Install and Update the Module

With your module structure and XML report defined, it’s time to install it in Odoo.

  1. Restart Your Odoo Server: Any changes to __manifest__.py or new Python/XML files require an Odoo server restart for the changes to be picked up.
  2. Go to the Odoo Apps Module: Log in to your Odoo instance, navigate to the “Apps” module.
  3. Update Apps List: Click on the “Update Apps List” button. This tells Odoo to scan your add-ons path for any new or updated modules.
  4. Search and Install: In the Apps search bar, type “SO with Signature” (or the name you gave in __manifest__.py). Your custom module should appear. Click “Install.”

If there are any syntax errors in your XML or Python, Odoo will typically display an error message during installation. Review the server logs for more detailed error information.

5. Print the Sales Order Report and Verify

After successful installation, it’s time to see your custom Odoo Sales Order Signature section in action!

  1. Navigate to the Sales Module: From your Odoo dashboard, go to the “Sales” application.
  2. Open a Sales Order: Select any existing Sales Order record (or create a new one if needed).
  3. Print the Report: Click the “Print” button on the Sales Order form and choose “Sales Order” from the dropdown menu.
  4. Review the Generated PDF: Odoo will generate a PDF report. Scroll to the bottom of the document. You should now see your newly added “Signatures” section, clearly showing “Created By” populated with the name of the user who created the Sales Order, and placeholders for “Validated By” and “Received By.”

Congratulations! You’ve successfully customized your Odoo Sales Order report.

Further Considerations and Enhancements for Your Odoo Sales Order Signature

This tutorial provides a solid foundation, but the journey to a fully integrated Odoo Sales Order Signature solution can be extended further:

  1. Implementing “Validated By” and “Received By” Fields:
    The standard sale.order model in Odoo 18 does not include fields for “validated by” or “received by.” To make these fields functional, you’ll need to:

    • Extend the sale.order model: Create a Python file (e.g., models/sale_order.py) in your module. Here, you’ll inherit from sale.order and add new Many2one fields (e.g., validator_id, receiver_id) linked to res.users or res.partner respectively. For example:
      # models/sale_order.py
      from odoo import fields, models
      
      class SaleOrder(models.Model):
          _inherit = 'sale.order'
      
          validator_id = fields.Many2one(
              'res.users',
              string='Validated By',
              readonly=True, # Or make it editable based on workflow
              copy=False,
              help='User who validated this Sales Order.'
          )
          # You might need a method to set this field during workflow
          # For Received By, it might be a text field or a partner field
          # if the customer representative's name is to be stored.
      

      Remember to import this file in models/__init__.py and ensure __init__.py in the root module directory imports the models package.

    • Add fields to Form View: Once created, these new fields need to be added to the Sales Order form view in Odoo so users can input data. This involves another XML inheritance to modify the sale.order.form view.
    • Update the Report Template: After adding the custom fields to the model, you can update your so.xml file. For instance, replace _________________________ under “Validated By” with <span t-field="doc.validator_id.name"/>.
  2. Styling and Layout Refinements:
    • CSS Classes: Experiment with different Bootstrap classes (e.g., text-center, font-weight-bold) and custom CSS in your report template to fine-tune the appearance of the signature block.
    • Conditional Display: Use QWeb’s t-if directive to conditionally display parts of the signature section based on certain conditions (e.g., only show “Validated By” if the field is populated).
  3. Integrating Electronic Signatures (eSignatures):
    While this tutorial adds static signature fields, Odoo also offers a dedicated “Sign” module. You could potentially integrate a workflow where after confirming a Sales Order, it’s sent for electronic signature, and once signed, the actual signature image is displayed in this section. This would involve more advanced development and integration with the Odoo Sign module.
  4. Workflow Automation:
    Consider automating the population of the “Validated By” field based on your Sales Order workflow. For example, when an order changes status to “Sales Order,” a specific user could automatically be set as the validator. This would require custom Python logic within your sale.order model.
  5. External Links and Resources:

Conclusion

By following this step-by-step tutorial, you have successfully implemented a customized Odoo Sales Order Signature section in your Odoo 18 reports. This seemingly small change significantly elevates the professionalism, accountability, and legal integrity of your sales documentation.

Leveraging Odoo’s powerful inheritance and QWeb templating capabilities allows for extensive customization without touching core files, ensuring your system remains upgrade-friendly. Continue exploring the vast possibilities of Odoo customization to tailor your system precisely to your business needs and achieve unparalleled operational efficiency. Happy customizing!


Discover more from teguhteja.id

Subscribe to get the latest posts sent to your email.

Leave a Reply

WP Twitter Auto Publish Powered By : XYZScripts.com