New addon to replace structured country/state fields with flexible free-text origin descriptions. Features: - Translatable origin_text field in product.supplierinfo - Computed origin field in products based on main_seller_id - Support for creative supplier origin descriptions - Full OCA documentation structure - ES/EU translations included - 8 unit tests (all passing) Replaces product_origin for use cases where suppliers use non-standardized origin descriptions (e.g., 'Valencia, Spain', 'Huerta de...', etc.) Depends on: product, product_main_seller Author: Criptomart Funding: Elika Bilbo
4.1 KiB
4.1 KiB
Product Origin Text - Developer Notes
Technical Implementation
Architecture
This module extends the product origin information system to use free-text fields instead of structured country/state fields.
Models:
-
product.supplierinfo - Base model with the
origin_textfield- Field:
origin_text(Char, translate=True) - This is where the actual data is stored
- Each supplier can have a different origin text for the same product
- Field:
-
product.template - Computed field
- Field:
origin_text(Char, computed, store=False) - Computes from main vendor's supplierinfo
- Depends on:
main_seller_id,variant_seller_ids.origin_text
- Field:
-
product.product - Computed field (variant level)
- Field:
origin_text(Char, computed, store=False) - Computes from main vendor's supplierinfo
- Depends on:
product_tmpl_id.main_seller_id,seller_ids.origin_text
- Field:
Why Computed Fields Instead of Related?
The origin_text field in product.template and product.product cannot be a simple related field because:
main_seller_idis ares.partnerrecordorigin_textis stored inproduct.supplierinforecords- We need to find the supplierinfo record where
partner_id == main_seller_id
This requires a computed field with custom logic to filter and find the correct supplierinfo record.
Translation Support
The origin_text field in product.supplierinfo uses translate=True, which means:
- Each language can have a different value
- Translations are stored in Odoo's translation system
- When switching languages, the field shows the translated value
- If no translation exists, it falls back to the default language value
Store Strategy
The computed fields in product template and product use store=False because:
- The value should always reflect the current main vendor
- If the main vendor changes or its origin text is updated, the product's origin should update automatically
- No need to store redundant data
- Reduces database size and update complexity
Dependencies
- product - Core product module
- product_main_seller - Provides
main_seller_idcomputed field for products
Relationship to product_origin
This module is a replacement/alternative to the OCA product_origin module:
product_originprovides structured fields (country_id, state_id)product_origin_charprovides free-text field (origin_text)- Both cannot be installed simultaneously without potential conflicts
- This module was created because suppliers use creative, non-standardized origin descriptions
Performance Considerations
- Computed fields with
store=Falseare calculated on-the-fly - Performance is acceptable because the computation is simple (filter + get first)
- If performance becomes an issue, consider:
- Adding
store=Truewith proper dependencies - Adding database indexes on frequently searched fields
- Caching strategies
- Adding
Testing Strategy
Tests cover:
- Basic field storage - Create supplierinfo with origin_text
- Computed field - Verify product shows main vendor's origin
- Main vendor change - Verify origin updates when main vendor changes
- Translation - Verify field is translatable (multilingual support)
- Empty cases - Product without vendors, vendor without origin
Future Improvements
Potential enhancements:
- Add migration script from
product_originto convert country/state to text - Add bulk update wizard to set origin for multiple products
- Add origin text to purchase order lines
- Add search/group by origin in product lists
- Add validation rules (max length, format checks)
Code Quality
- Follows OCA guidelines
- Black formatted (line length 88)
- isort sorted imports
- Passes flake8 and pylint checks
- Full test coverage
- Documented with docstrings
- Translatable strings handled correctly (no
_()in field definitions)
Version History
- 18.0.1.0.0 (2026-02-25) - Initial release
- Free-text origin field per supplier
- Automatic display based on main vendor
- Multi-language support
- Full test coverage
- OCA documentation structure