addons-cm/product_origin_char/README_DEV.md
snt 5efe57dc19 [REF] product_origin_char: simplify to template-based origin
- Move origin_text field from product.supplierinfo to product.template
- Add related field in product.product for variant access
- Remove dependency on product_main_seller
- Update views to show field near category (editable)
- Rewrite tests for new architecture
- Update all documentation (README, readme/ fragments)
- Bump version to 18.0.2.0.0
2026-03-06 17:43:20 +01:00

2.8 KiB

Product Origin Text - Developer Notes

Technical Implementation

Architecture

This module adds a simple free-text origin field to products.

Models:

  1. product.template - Base model with the origin_text field

    • Field: origin_text (Char)
    • This is where the actual data is stored
    • Editable directly on the product form
  2. product.product - Related field for variant access

    • Field: origin_text (Char, related to product_tmpl_id.origin_text)
    • readonly=False allows editing from variant views
    • Changes propagate to the template

Why This Architecture?

The origin_text field is stored in product.template because:

  • Origin typically applies to all variants of a product
  • Simplifies data management (one source of truth)
  • Avoids duplication across variants
  • Standard Odoo pattern for product-level attributes

The related field in product.product with readonly=False allows:

  • Seamless access from variant views
  • Editing from either template or variant forms
  • Automatic synchronization between template and variants

Previous Architecture (Deprecated)

The previous version stored origin_text in product.supplierinfo with computed fields in template/product. This was deprecated because:

  • Supplierinfo records don't always exist when products are created
  • Added unnecessary complexity with computed fields
  • Required product_main_seller dependency
  • Origin semantically belongs to the product, not the supplier relationship

Dependencies

  • product - Core product module (only dependency)

Performance Considerations

  • Simple stored field with no computation overhead
  • Related field access is efficient in Odoo ORM
  • No additional queries needed for variant access

Testing Strategy

Tests cover:

  1. Basic field storage - Set origin on template
  2. Related field access - Verify variant sees template origin
  3. Write from variant - Verify changes propagate to template
  4. Empty cases - Products without origin
  5. Multiple products - Independent origins
  6. Variants - All variants share same origin

Code Quality

  • Follows OCA guidelines
  • Black formatted (line length 88)
  • isort for imports
  • Minimal dependencies (only product)

Migration from v1.x

If upgrading from the previous supplier-based architecture:

  1. Data in product.supplierinfo.origin_text will need manual migration
  2. Run migration script to copy main supplier origin to product template
  3. Remove dependency on product_main_seller if no longer needed

Version History

  • 18.0.2.0.0 (2026-03-06) - Simplified architecture

    • Field directly on product.template
    • Related field in product.product
    • Removed dependency on product_main_seller
  • 18.0.1.0.0 (2026-02-25) - Initial release (deprecated)

    • Free-text origin field per supplier
    • Automatic display based on main vendor