Skip to content

Odoo 18 Validated by Field: Unlock Seamless Sales Order Control with This Powerful Tutorial

odoo 18 validated by field

In the dynamic world of business, efficiency, accountability, and transparent workflows are paramount. For organizations leveraging Odoo 18, the ability to customize and enhance core processes directly impacts operational success. One such critical enhancement is the introduction of a “Validated By” field within your Sales Orders. This Odoo 18 validated by field offers an immediate boost to your approval processes, ensuring every sales order has a clear audit trail and confirming who officially confirmed it.

This tutorial will guide you through the process of adding a custom “Validated By” field to your Odoo 18 Sales Order form. We’ll cover everything from extending the Odoo model to integrating the field into the user interface, complete with detailed explanations and best practices. By the end, you’ll have a clear understanding of how to implement this powerful feature, enhancing your Odoo experience and bringing greater control to your sales operations.

Why an Odoo 18 Validated by Field is Indispensable for Your Business

Before diving into the technical steps, let’s understand why implementing an Odoo 18 validated by field is more than just a cosmetic addition – it’s a strategic move for operational excellence:

  1. Enhanced Accountability: Clearly identifies who reviewed and approved a sales order, leaving no room for ambiguity. This is crucial for internal auditing and performance tracking.
  2. Improved Workflow Transparency: Provides immediate visibility into the approval status, allowing teams to quickly ascertain if an order is ready for the next stage (e.g., delivery, invoicing).
  3. Compliance and Audit Trails: For businesses operating under strict regulations, a robust audit trail showing who validated an order and when is essential for compliance. This field provides a direct link to the responsible user.
  4. Error Reduction: By assigning a specific validation step, you introduce a checkpoint that can catch potential errors before they escalate, saving time and resources.
  5. Simplified Reporting: You can easily generate reports showing all sales orders validated by a specific user or within a particular timeframe, offering valuable insights into team performance and workload distribution.

By incorporating this simple yet powerful customization, you transform your sales order process from a linear transaction into a controlled and auditable workflow.

Prerequisites for Implementing Your Odoo 18 Validated By Field

To follow this tutorial effectively, ensure you have the following:

  • An Odoo 18 Instance: Access to a running Odoo 18 environment.
  • Developer Mode Enabled: This is essential for inspecting Odoo views and understanding underlying field names. To enable it, go to Settings, scroll down to “Developer Tools” and click “Activate the developer mode.”
  • Basic Python Knowledge: Understanding of classes, objects, and Odoo’s ORM concepts.
  • Basic XML Knowledge: Familiarity with XML structure for view customization.
  • A Custom Odoo Module: It’s best practice to implement all customizations within a dedicated custom module. If you don’t have one, create a new module first. For instance, we’ll refer to my_custom_module. For guidance on creating a new Odoo module, you can refer to the Odoo documentation on creating a new module.

Let’s begin the hands-on process of adding your Odoo 18 validated by field.

Step 1: Setting Up Your Custom Module Structure

If you already have a custom module, ensure it has the standard models and views directories. If not, create them within your module’s root directory (e.g., my_custom_module).

Your module’s structure should look something like this:

my_custom_module/
├── __init__.py
├── __manifest__.py
├── models/
│   └── __init__.py
├── views/
│ 

For the purpose of this tutorial, we will primarily focus on models/sales_order.py and views/sales_order_view.xml.

Step 2: Extending the Sales Order Model to Add the Odoo 18 Validated By Field

The first crucial step is to define the validated_id field within the sale.order model. We achieve this through model inheritance, which allows us to add new fields without modifying Odoo’s core files.

  1. Create the Model File:
    Inside your my_custom_module/models/ directory, create a new Python file named sales_order.py.
  2. Add the Python Code:
    Open sales_order.py and add the following code:

    from odoo import models, fields, api
    
    class SaleOrder(models.Model):
        _inherit = 'sale.order'
    
        validated_id = fields.Many2one(
            'res.users',
            string='Validated By',
            help='The user who validated this Sales Order.',
            default=lambda self: self.env.user # Automatically sets the current user as default
        )
    

    Code Explanation:

    • from odoo import models, fields, api: Imports the necessary Odoo components to define models and fields.
    • class SaleOrder(models.Model):: Defines a new Python class that will extend an Odoo model.
    • _inherit = 'sale.order': This line is vital. It tells Odoo that our SaleOrder class is not a new model, but rather an extension of the existing sale.order model. This allows us to add new fields to it.
    • validated_id = fields.Many2one(...): This defines our new Odoo 18 validated by field.
      • validated_id: This is the technical name of your field. You’ll use this name when referring to the field in XML views or other Python code.
      • 'res.users': Specifies that this is a Many-to-One relationship. The field will link to records in the res.users model, which represents all users in Odoo. This allows you to select a user from the list.
      • string='Validated By': This is the human-readable label that will appear in the Odoo user interface.
      • help='...': Provides a tooltip for the field, enhancing user experience.
      • default=lambda self: self.env.user: This is a powerful feature! It automatically sets the current logged-in user as the default value for the validated_id field when a new Sales Order is created or when the field is first populated. This simplifies the user’s task and ensures initial accountability.
  3. Update the __init__.py in models Directory:
    Inside my_custom_module/models/, open the __init__.py file and add the following line to ensure your new model file is loaded:

    from . import sales_order
    

Step 3: Integrating the Odoo 18 Validated By Field into the Sales Order Form View

Now that the field is defined in the model, we need to make it visible and editable on the Sales Order form. We do this by inheriting the existing Sales Order form view and injecting our new field.

  1. Locate the Original View’s inherit_id:
    • Navigate to a Sales Order in Odoo (Sales > Orders > Sales Orders).
    • With Developer Mode enabled, hover over the “bug” icon (Developer Tools) in the top-right corner.
    • Click “Edit View: Form”.
    • A pop-up window will appear, showing the details of the form view. Look for the External ID or ID field, which will likely be sale.view_order_form. Copy this ID, as we will use it for inherit_id.
  2. Create the View XML File:
    Inside your my_custom_module/views/ directory, create a new XML file named sales_order_view.xml.
  3. Add the XML Code:
    Open sales_order_view.xml and add the following code:

    <?xml version="1.0" encoding="utf-8"?>
    <odoo>
        <data>
            <record id="sale_order_form_view_validated_by_field" model="ir.ui.view">
                <field name="name">sale.order.form.validated.by.field</field>
                <field name="model">sale.order</field>
                <field name="inherit_id" ref="sale.view_order_form"/>
                <field name="arch" type="xml">
                    <xpath expr="//field[@name='user_id']" position="after">
                        <field name="validated_id"/>
                    </xpath>
                </field>
            </record>
        </data>
    </odoo>
    

    XML Explanation:

    • <record id="..." model="ir.ui.view">: This defines a new view record in Odoo.
      • id="sale_order_form_view_validated_by_field": A unique identifier for your inherited view. Use a descriptive name.
      • model="ir.ui.view": Specifies that this record is an Odoo view.
    • <field name="name">sale.order.form.validated.by.field</field>: A human-readable name for your view.
    • <field name="model">sale.order</field>: Links this view to the sale.order model.
    • <field name="inherit_id" ref="sale.view_order_form"/>: Crucial: This tells Odoo that this XML snippet is meant to modify the standard Sales Order form view, whose external ID we found earlier.
    • <field name="arch" type="xml">: Contains the actual XML structure that defines the modifications to the inherited view.
    • <xpath expr="//field[@name='user_id']" position="after">: This is an XPath expression, a powerful tool for precisely targeting elements within an XML structure.
      • //field[@name='user_id']: Selects the field with the technical name user_id (which is typically the “Salesperson” field) anywhere in the form.
      • position="after": Instructs Odoo to insert our new field immediately after the user_id field. This ensures a logical placement, often near other user-related fields.
    • <field name="validated_id"/>: This line simply adds our Odoo 18 validated by field to the form at the specified position.
  4. Update Your Module’s Manifest File:
    Open the __manifest__.py file in your my_custom_module root directory. You need to ensure that Odoo loads your new XML file when the module is installed or updated.

    Make sure your __manifest__.py includes sale in depends and your XML file in data:

    {
        'name': 'My Custom Sales Enhancements',
        'version': '1.0',
        'category': 'Sales',
        'summary': 'Adds a "Validated By" field to Sales Orders for enhanced accountability.',
        'description': """
            This module extends the Sales Order functionality in Odoo 18
            by adding a 'Validated By' field, improving workflow and audit trails.
        """,
        'author': 'Your Company Name',
        'website': 'https://yourcompany.com',
        'depends': ['sale'], # Make sure 'sale' is included here
        'data': [
            'views/sales_order_view.xml', # Ensure this line is present
        ],
        'installable': True,
        'application': False,
        'auto_install': False,
        'license': 'LGPL-3',
    }
    

    Manifest Explanation:

    • 'depends': ['sale']: Declares that your module relies on Odoo’s core sale module. Without this, your module might fail to install or function correctly as it extends sale.order.
    • 'data': ['views/sales_order_view.xml']: This list tells Odoo to load all the XML files specified here upon module installation or update. It’s crucial for your view changes to take effect.

Step 4: Installing and Upgrading Your Module

With the model and view changes in place, it’s time to apply them to your Odoo instance.

  1. Update Apps List:
    • Go to the “Apps” module in Odoo.
    • Click “Update Apps List” (you might need to remove the “Apps” filter first if it’s active). This ensures Odoo recognizes any new modules or changes to manifest files.
  2. Install or Upgrade Your Module:
    • Search for your custom module (e.g., “My Custom Sales Enhancements”).
    • If your module is not installed, click “Install.”
    • If it’s already installed, click “Upgrade.” Upgrading is vital as it reapplies all your module’s data and view definitions, incorporating the new changes.

Troubleshooting Common Issues:

  • Module Not Found: Ensure your my_custom_module directory is placed within Odoo’s addons_path. Check your Odoo configuration file (odoo.conf) for the addons_path setting.
  • Syntax Errors: Odoo will usually throw an error during module installation/upgrade if there are syntax issues in your Python or XML files. Carefully review the error message for clues (e.g., line numbers).
  • Field Not Appearing:
    • Double-check the inherit_id in your XML (sale.view_order_form). Make sure it exactly matches the external ID of the base view.
    • Verify the XPath expression. Use Developer Mode to inspect the actual structure of the user_id field in the form view to ensure your xpath is correct.
    • Ensure your module was successfully upgraded. Sometimes, browser cache or server cache can cause issues. Clear your browser cache or restart your Odoo service.

Step 5: Testing Your New Odoo 18 Validated By Field

Once the module upgrade is complete, it’s time to see your new field in action!

  1. Navigate to Sales Orders:
    • Go to Sales > Orders > Sales Orders.
  2. Open or Create a Sales Order:
    • Open an existing sales order or create a new one.
  3. Verify the Odoo 18 Validated By Field:
    • You should now see the “Validated By” field prominently displayed below the “Salesperson” field.
    • When creating a new sales order, observe that the validated_id field is automatically populated with your user’s name (thanks to default=lambda self: self.env.user).
    • You can manually change the user in the “Validated By” field if needed.
    • Save the Sales Order and verify that the selected user persists.

Congratulations! You have successfully added an Odoo 18 validated by field to your Sales Orders.

Beyond the Basics: Leveraging Your Odoo 18 Validated By Field

Adding the field is just the beginning. Here’s how you can further harness its potential:

  • Automation: You can extend this functionality by adding an automated action in Odoo. For example, configure a server action or a custom method to automatically populate the validated_id with the current user when the sales order status changes to “Confirmed.” This eliminates manual input and ensures that the validator is always the one who confirms the order.
  • Reporting and Analysis: Create custom reports or pivot tables to analyze sales orders by validator. This can provide insights into team performance, workload, and potential bottlenecks in the sales process. You can even filter orders that haven’t been validated yet.
  • Access Rights: Implement specific access rights related to this field. For instance, only certain user groups might be allowed to edit the “Validated By” field, or perhaps only the validator themselves can modify the order after it’s been validated. For more on Odoo security rules, explore the Odoo documentation on security and access rights.
  • Print Layouts: As mentioned in the original context, this field can now be included in your Sales Order print layouts. Modify your report templates (QWeb reports) to display the “Validated By” user’s name directly on printed sales orders, ensuring all official documents reflect the validation.

Conclusion: Empowering Your Odoo 18 Workflows

Implementing an Odoo 18 validated by field is a prime example of how targeted Odoo customization can significantly enhance business processes. By following this tutorial, you’ve not only added a crucial field for accountability and transparency but also gained valuable experience in extending Odoo’s core functionality through model and view inheritance. This powerful capability ensures your sales operations are not just efficient, but also auditable and fully controlled.

Keep experimenting with Odoo’s flexible architecture. The more you customize, the more Odoo will perfectly align with your unique business needs, turning challenges into opportunities for streamlined operations. Ready to take your Odoo 18 customization further? Start exploring other ways to optimize your workflows today!


Discover more from teguhteja.id

Subscribe to get the latest posts sent to your email.

1 thought on “Odoo 18 Validated by Field: Unlock Seamless Sales Order Control with This Powerful Tutorial”

  1. Pingback: Amazing Odoo Field Service 19: 5 New Features

Leave a Reply

WP Twitter Auto Publish Powered By : XYZScripts.com