[ADD] product_origin_char: Free text origin field per supplier

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
This commit is contained in:
snt 2026-02-25 18:42:54 +01:00
parent 1a8f92a01e
commit c8b83cc333
24 changed files with 1071 additions and 0 deletions

View file

@ -0,0 +1,114 @@
# 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:**
1. **product.supplierinfo** - Base model with the `origin_text` field
- 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
2. **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`
3. **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`
### 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_id` is a `res.partner` record
- `origin_text` is stored in `product.supplierinfo` records
- 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_id` computed field for products
### Relationship to product_origin
This module is a replacement/alternative to the OCA `product_origin` module:
- `product_origin` provides structured fields (country_id, state_id)
- `product_origin_char` provides 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=False` are calculated on-the-fly
- Performance is acceptable because the computation is simple (filter + get first)
- If performance becomes an issue, consider:
- Adding `store=True` with proper dependencies
- Adding database indexes on frequently searched fields
- Caching strategies
### Testing Strategy
Tests cover:
1. **Basic field storage** - Create supplierinfo with origin_text
2. **Computed field** - Verify product shows main vendor's origin
3. **Main vendor change** - Verify origin updates when main vendor changes
4. **Translation** - Verify field is translatable (multilingual support)
5. **Empty cases** - Product without vendors, vendor without origin
### Future Improvements
Potential enhancements:
- Add migration script from `product_origin` to 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