Skip to content

Odoo 18 Purchase Validator: Unlock Powerful Approval Workflows in 7 Steps

Odoo Purchase Validator

In the dynamic world of business, efficient and accountable procurement processes are paramount. A well-structured purchase approval system ensures budgetary control, prevents unauthorized spending, and maintains clear audit trails. While Odoo is an incredibly powerful ERP, sometimes specific needs, like clearly identifying who approved a purchase order, require a touch of customization.

This comprehensive guide will walk you through implementing a custom Odoo Purchase Validator field. We’ll show you how to extend the standard Purchase Order (PO) module to include a dedicated “Validator” field, similar to how one might track a validator in a Sales Order. This tutorial combines persuasive insights into why this is crucial with clear, step-by-step instructions, complete with code examples.

Note: The original source material for this article was a transcript discussing Odoo field customization. As no direct video link was provided within the context, we are unable to include it here.

Why a Dedicated Odoo Purchase Validator is Crucial for Your Business

Imagine a scenario where dozens, or even hundreds, of purchase orders flow through your system daily. Without a clear mechanism to identify the person responsible for final approval, you risk:

  1. Lack of Accountability: If an issue arises with a purchase, pinpointing who signed off on it can be a challenge. A designated Odoo Purchase Validator provides an undeniable audit trail.
  2. Compliance Issues: Many industries and internal policies require documented approvals for spending. A custom validator field helps meet these regulatory demands effortlessly.
  3. Fraud Prevention: By clearly assigning approval responsibility, you add an extra layer of security, making it harder for unauthorized purchases to slip through the cracks.
  4. Process Efficiency: While initial creation is important, the final validation often dictates the speed of the procurement cycle. Tracking the validator can help analyze bottlenecks.
  5. Improved Reporting: Knowing who validates allows for richer business intelligence. You can analyze approval workloads, identify key decision-makers, and optimize resource allocation.

The standard Odoo Purchase Order already tracks the create_uid, indicating who initiated the order. However, as observed in our source context, there isn’t an out-of-the-box field for the specific approver or “validator” of the purchase itself. This gap can be easily bridged with Odoo’s robust customization capabilities.

The Odoo Challenge: Default PO Approval Mechanisms

Odoo, by default, offers a powerful workflow for Purchase Orders, including states like “RFQ,” “RFQ Sent,” “Purchase Order,” and “Locked.” You can configure approval rules based on user groups or amounts. However, the direct assignment of a specific “approver user” to a field that is visible and trackable on the PO form itself is often desired for clarity and detailed reporting, beyond just knowing if it was approved.

This is where implementing an Odoo Purchase Validator field comes into play. It gives you explicit control and visibility over who made the final sign-off, moving beyond just the system state.

Introducing Your Custom Odoo Purchase Validator Field

Let’s dive into the practical steps to add a custom “Validator” field to your Odoo Purchase Validator module. This process involves creating a new Odoo module, extending the existing purchase.order model, and modifying its form view to display the new field.

Prerequisites for Your Odoo Purchase Validator Implementation

Before you begin, ensure you have:

  • Odoo 18 Installation: A running instance of Odoo 18.
  • Developer Mode Enabled: This grants access to technical menus.
  • Basic Odoo Knowledge: Familiarity with Odoo modules, models, and XML views.
  • Text Editor: For writing Python and XML code.

Step-by-Step Tutorial: Implementing the Odoo Purchase Validator

Follow these 7 detailed steps to integrate your custom validator field.

Step 1: Activate Developer Mode

The first crucial step for any Odoo customization is activating developer mode. This unlocks technical menus that are essential for inspecting and modifying Odoo’s underlying structure.

  • Go to Settings.
  • Scroll down to the very bottom of the page.
  • Click on “Activate the developer mode” (or “Activate the developer mode (with assets)” if you need more advanced debugging).
  • Your Odoo interface will refresh, and you’ll notice a small debug icon in the top right corner, confirming developer mode is active.

Step 2: Navigate to Purchase Order Model Definition

With developer mode active, you can now explore Odoo’s database structure.

  • Go to Settings -> Technical -> Database Structure -> Models.
  • In the search bar, type purchase.order and press Enter.
  • Click on the Purchase Order model (technical name: purchase.order) to open its definition. This page lists all the fields currently associated with the Purchase Order object.

Step 3: Observe Existing Fields

Take a moment to review the fields. You’ll find standard fields like name (the PO reference), partner_id (the vendor), date_order, and create_uid (the user who created the record). As noted in the context, while create_uid is present, there’s no equivalent field for a designated “approver” or “validator.” This confirms the need for our custom Odoo Purchase Validator field.

Step 4: Create the Custom Module and Field

This is where we’ll add the new validator_id field. We’ll create a new Odoo module to encapsulate our customizations, ensuring your changes are upgrade-safe and easy to manage.

  1. Create a New Module:
    • In your Odoo custom addons path (e.g., a folder named custom_addons in your Odoo installation), create a new folder for your module, for example: purchase_validator_ext.
    • Inside purchase_validator_ext, create the following files and folders:
      • __init__.py (leave empty for now)
      • __manifest__.py
      • models/ (create this folder)
      • models/__init__.py (inside models/)
      • models/purchase_order.py (inside models/)
      • views/ (create this folder)
      • views/__init__.py (inside views/)
      • views/purchase_order_views.xml (inside views/)
  2. Edit __manifest__.py: This file describes your module to Odoo.
    {
        'name': "Purchase Order Validator Extension",
        'summary': "Adds a dedicated validator field to the Odoo Purchase Order module for enhanced tracking.",
        'version': '1.0',
        'depends': ['purchase'], # Crucially, this module depends on the base 'purchase' module!
        'data': [
            'views/purchase_order_views.xml', # Link to our XML file to modify the view
        ],
        'installable': True,
        'application': False,
        'auto_install': False,
        'license': 'LGPL-3', # Or another appropriate license
    }
  1. Edit models/__init__.py: This file tells Python to load the models defined in this folder.
from . import purchase_order
  1. Edit models/purchase_order.py: This is where we extend the purchase.order model and add our new field.
from odoo import models, fields, api

class PurchaseOrder(models.Model):
    _inherit = 'purchase.order' # We are extending the existing purchase.order model

    # Our new custom field for the Odoo Purchase Validator
    validator_id = fields.Many2one(
        'res.users',
        string='Validator',
        help='User responsible for validating this Purchase Order.',
        tracking=True # To track changes in this field in the chatter
    )
  • _inherit = 'purchase.order': This line is vital. It tells Odoo that our PurchaseOrder class is not a new model, but rather an extension of the existing purchase.order model.
  • validator_id: This is the technical name of our new field.
  • fields.Many2one('res.users', ...): This defines a Many2one relationship, meaning one purchase order can have one validator, and one user can validate many purchase orders. res.users is the Odoo model for all system users.
  • string='Validator': This is the human-readable label for the field in the UI.
  • tracking=True: This helpful attribute ensures that any changes to this field are logged in the Purchase Order’s chatter, providing an excellent audit trail.

Step 5: Create the View (To Display the Field)

Now that the field exists in the database, we need to make it visible on the Odoo form.

  1. Edit views/__init__.py: This tells Python to load the views defined in this folder.
# Leave empty if not loading other Python files in views, otherwise, load them.
# For this simple case, we just need the XML to be listed in __manifest__.py.

(Correction: views/__init__.py is not strictly necessary for simple XML views linked directly in __manifest__.py. You can leave it empty or remove it if no Python logic is there.)

  1. Edit views/purchase_order_views.xml: This XML file will modify the existing Purchase Order form view.
<odoo>
    <record id="view_purchase_order_form_inherit_validator" model="ir.ui.view">
        <field name="name">purchase.order.form.inherit.validator</field>
        <field name="model">purchase.order</field>
        <field name="inherit_id" ref="purchase.purchase_order_form"/>
        <field name="arch" type="xml">
            <!-- Use an XPath expression to place our field after 'date_order' -->
            <xpath expr="//field[@name='date_order']" position="after">
                <field name="validator_id"/>
            </xpath>
            <!-- Alternative placement: If you want it in the header -->
            <!-- <xpath expr="//header" position="inside">
                <field name="validator_id" widget="res_user_many2one"/>
            </xpath> -->
        </field>
    </record>
</odoo>
  • inherit_id="purchase.purchase_order_form": This line specifies that we are inheriting and modifying the standard Purchase Order form view provided by the purchase module.
  • xpath expr="//field[@name='date_order']" position="after": This is an XPath expression that precisely locates the date_order field on the form and instructs Odoo to insert our validator_id field immediately after it. You can adjust the xpath to position the field differently based on your UI preferences. For instance, position="before" would place it before the date_order field.
  • <field name="validator_id"/>: This tag renders our newly created validator_id field on the form.

Step 6: Install the Module

With your module files in place, it’s time to install it in Odoo.

  • Ensure your Odoo server is running and that your custom addons path is correctly configured in your Odoo configuration file (odoo.conf). If you’ve just added the new module folder, you might need to restart your Odoo server.
  • Go to Apps in your Odoo instance.
  • Click on “Update Apps List” (this ensures Odoo scans for new modules).
  • In the search bar, clear any filters and search for “Purchase Order Validator Extension” (or whatever name you gave your module in __manifest__.py).
  • Click the “Install” button next to your module.

Step 7: Test the New Field

Now for the moment of truth!

  • Navigate to Purchase -> Orders -> Purchase Orders.
  • Open an existing Purchase Order or create a new one.
  • You should now see the “Validator” field on the form, typically near the “Order Date.”
  • Click on the field to select a user from the dropdown list.
  • Save the Purchase Order.
  • Check the chatter section at the bottom of the PO. You should see a log entry indicating when the Validator field was set or changed, thanks to tracking=True.

Congratulations! You’ve successfully added a custom Odoo Purchase Validator field to your procurement process.

Beyond the Basics: Enhancing Your Odoo Purchase Validator

Implementing the custom field is a great start, but Odoo’s flexibility allows for even more powerful enhancements:

Workflow Integration for Your Odoo Purchase Validator

  • Conditional Approval Buttons: Modify the “Confirm Order” button to be visible or active only when the validator_id field is set and matches the current user, or if the current user belongs to a specific “Approvers” group.
  • Multi-stage Approvals: For high-value purchases, you might need multiple validators. You could add more Many2one fields (e.g., first_approver_id, second_approver_id) or even create a related object to manage a list of approvers.
  • Automated Status Changes: Once validator_id is filled and conditions are met, automatically transition the PO to a “Validated” or “Approved” state.

Security Considerations

  • Access Rights: Define specific security rules to control who can set or modify the validator_id field. You might want only members of a “Purchase Managers” group to have write access to this field. Learn more about Odoo’s robust security model on the Odoo documentation.
  • Field Visibility: You can make the validator_id field visible only to certain user groups using groups="base.group_user,purchase.group_purchase_manager" attribute in the XML view.

Reporting and Analytics

  • Custom Reports: Leverage Odoo’s reporting tools to build custom pivot tables or graphs based on your validator_id field. Analyze average approval times per validator, total value approved by each user, or identify approval bottlenecks. This deep dive into your procurement data can be invaluable for continuous improvement. For more on Odoo reporting, check out this internal resource on Odoo BI (placeholder for an internal link).

Notifications

  • Email Alerts: Configure automated email notifications to be sent to the selected validator_id when a new Purchase Order requires their attention, or to the creator once the PO has been validated. Odoo’s email templates and automated actions make this simple.

Benefits of a Robust Purchase Approval System with Odoo 18

By implementing an Odoo Purchase Validator and integrating it into your workflow, your organization will experience:

  • Enhanced Financial Control: Better oversight of spending and adherence to budgets.
  • Streamlined Operations: Clear roles and responsibilities minimize confusion and delays.
  • Improved Auditability: A complete, traceable record of every purchase approval.
  • Reduced Risk: Minimized chances of unauthorized purchases and potential fraud.
  • Data-Driven Decisions: Insights from approval data help optimize procurement strategies.

Conclusion

Empowering your procurement team with a clear Odoo Purchase Validator field is a straightforward yet impactful customization. It not only enhances accountability and compliance but also provides a foundation for more sophisticated approval workflows and robust reporting. By following this guide, you’ve taken a significant step towards a more transparent and efficient purchasing process in Odoo 18. Don’t stop here; explore how you can further refine your Odoo system to meet your unique business needs and continue to drive operational excellence.


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