Claude
Skills
Sign in
Back

odoo-feature-enhancer

Included with Lifetime
$97 forever

Extends existing Odoo 16.0 modules with new features, fields, views, business logic, wizards, and reports. This skill should be used when the user requests enhancements to existing functionality, such as "Add a field to track serial numbers in stock.picking" or "Create a wizard for bulk invoice generation" or "Add a report for vendor bill analysis".

Sales & CRM

What this skill does


# Odoo Feature Enhancer

## Overview

This skill enables extension of existing Odoo 16.0 modules by adding new fields, views, business logic, wizards, reports, and automated actions. It follows module inheritance patterns and ensures proper integration with existing functionality.

## Enhancement Categories

When a user requests a feature enhancement, identify the category and follow the appropriate workflow:

### 1. Field Additions
Add new fields to existing models (stored, computed, related).

### 2. View Modifications
Extend existing views (tree, form, kanban, calendar, pivot, graph) using XML inheritance.

### 3. Business Logic
Add computed methods, onchange handlers, constraints, and custom business rules.

### 4. Wizards
Create transient models for user interactions and batch operations.

### 5. Reports
Generate PDF (QWeb) or Excel reports with custom data aggregation.

### 6. Server Actions
Create automated actions, scheduled actions (cron jobs), and workflow automations.

### 7. Buttons and Actions
Add action buttons to forms and tree views.

## Enhancement Workflow

### Step 1: Identify the Enhancement Type

Ask clarifying questions based on the request:

**For Field Additions:**
- Field technical name (snake_case)
- Field type (Char, Integer, Float, Boolean, Selection, Many2one, One2many, Many2many, Date, Datetime, Text, Html, Binary, Monetary)
- Field label and help text
- Required or optional?
- Computed field or stored?
- Should it appear in specific views?

**For View Modifications:**
- Which view(s) to modify? (form, tree, search, kanban)
- Which model?
- Where to add the element? (header, group, notebook page, after specific field)
- Any conditional visibility?

**For Business Logic:**
- Trigger condition (onchange, compute, constraint, button click)
- Dependencies (which fields trigger the logic)
- Expected behavior

**For Wizards:**
- Wizard purpose (batch update, data export, configuration, etc.)
- Input fields needed
- Target models to affect
- Where to trigger (menu, button on form, action)

**For Reports:**
- Report format (PDF or Excel)
- Data to include
- Grouping and aggregation
- Filters needed

### Step 2: Create or Identify Extension Module

Determine if enhancement goes in:
- New extension module (e.g., `stock_picking_serial_tracking`)
- Existing extension module

If creating new module, provide:
- Module name: `[base_module]_[feature]` (e.g., `stock_picking_enhancements`)
- Dependencies: base module being extended
- Target directory: appropriate `addons-*` folder

### Step 3: Implement the Enhancement

Follow the appropriate implementation pattern below.

## Implementation Patterns

### Pattern 1: Adding Fields to Existing Models

Create model inheritance file:

```python
from odoo import models, fields, api
from odoo.exceptions import ValidationError
import logging

_logger = logging.getLogger(__name__)


class StockPickingInherit(models.Model):
    """Extend stock.picking with additional fields."""

    _inherit = 'stock.picking'

    # Simple stored field
    serial_number = fields.Char(
        string='Serial Number',
        index=True,
        tracking=True,
        help='Serial number for tracking purposes'
    )

    # Selection field
    priority_level = fields.Selection([
        ('low', 'Low'),
        ('medium', 'Medium'),
        ('high', 'High'),
        ('urgent', 'Urgent'),
    ], string='Priority Level', default='medium', required=True)

    # Many2one field
    responsible_id = fields.Many2one(
        'res.users',
        string='Responsible Person',
        default=lambda self: self.env.user,
        tracking=True
    )

    # Computed field (stored)
    total_weight = fields.Float(
        string='Total Weight',
        compute='_compute_total_weight',
        store=True,
        digits=(10, 2)
    )

    # Computed field (non-stored, real-time)
    is_urgent = fields.Boolean(
        string='Is Urgent',
        compute='_compute_is_urgent'
    )

    # Related field (from related record)
    partner_country_id = fields.Many2one(
        'res.country',
        string='Partner Country',
        related='partner_id.country_id',
        store=True,
        readonly=True
    )

    @api.depends('move_line_ids', 'move_line_ids.qty_done', 'move_line_ids.product_id.weight')
    def _compute_total_weight(self):
        """Compute total weight from move lines."""
        for picking in self:
            total = sum(
                line.qty_done * line.product_id.weight
                for line in picking.move_line_ids
                if line.product_id.weight
            )
            picking.total_weight = total

    @api.depends('priority_level', 'scheduled_date')
    def _compute_is_urgent(self):
        """Determine if picking is urgent."""
        from datetime import datetime, timedelta
        for picking in self:
            is_urgent = picking.priority_level == 'urgent'
            if picking.scheduled_date:
                due_soon = picking.scheduled_date <= datetime.now() + timedelta(hours=24)
                is_urgent = is_urgent or due_soon
            picking.is_urgent = is_urgent

    @api.onchange('partner_id')
    def _onchange_partner_id(self):
        """Auto-fill fields when partner changes."""
        if self.partner_id and self.partner_id.user_id:
            self.responsible_id = self.partner_id.user_id

    @api.constrains('serial_number')
    def _check_serial_number(self):
        """Validate serial number format."""
        for picking in self:
            if picking.serial_number and len(picking.serial_number) < 5:
                raise ValidationError('Serial number must be at least 5 characters long!')
```

Create view inheritance to display the new fields:

```xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Extend stock.picking form view -->
    <record id="view_picking_form_inherit" model="ir.ui.view">
        <field name="name">stock.picking.form.inherit</field>
        <field name="model">stock.picking</field>
        <field name="inherit_id" ref="stock.view_picking_form"/>
        <field name="arch" type="xml">
            <!-- Add fields in header -->
            <xpath expr="//header" position="after">
                <div class="alert alert-danger" role="alert" attrs="{'invisible': [('is_urgent', '=', False)]}">
                    <strong>URGENT:</strong> This picking requires immediate attention!
                </div>
            </xpath>

            <!-- Add field after existing field -->
            <xpath expr="//field[@name='partner_id']" position="after">
                <field name="responsible_id"/>
                <field name="serial_number"/>
            </xpath>

            <!-- Add field inside existing group -->
            <xpath expr="//group[@name='other_info']//field[@name='origin']" position="after">
                <field name="priority_level"/>
                <field name="total_weight"/>
            </xpath>

            <!-- Add new notebook page -->
            <xpath expr="//notebook" position="inside">
                <page string="Tracking Info">
                    <group>
                        <field name="serial_number"/>
                        <field name="is_urgent"/>
                        <field name="partner_country_id"/>
                    </group>
                </page>
            </xpath>
        </field>
    </record>

    <!-- Extend tree view -->
    <record id="view_picking_tree_inherit" model="ir.ui.view">
        <field name="name">stock.picking.tree.inherit</field>
        <field name="model">stock.picking</field>
        <field name="inherit_id" ref="stock.view_picking_internal_search"/>
        <field name="arch" type="xml">
            <xpath expr="//tree" position="attributes">
                <attribute name="decoration-danger">is_urgent</attribute>
            </xpath>
            <xpath expr="//field[@name='name']" position="after">
                <field name="serial_number"/>
                <

Related in Sales & CRM