Skip to content

Conversation

@peregrine-2024
Copy link

: Resolves issue where weight field on configurable product variants (HX500 system) was not properly computed or inherited from parent configurable product. The weight calculation works correctly during 'Add Shipping' but fails to display on the Inventory tab due to missing computed field configuration on the product variant model. This fix ensures the weight field on product variants correctly inherits or computes from configurable product component weights. Addresses ticket #67503 with technical implementation focusing on proper field inheritance and computed field configuration for variant models.

Implemented solution using Cursor CLI automation
@peregrine-2024
Copy link
Author

🛠️ Automated Fix: Weight Definition on Configurable Product Variants

This pull request addresses the bug where weight was not being properly computed or displayed on configurable product variants (e.g., HX500 systems), as reported in Ticket #67503.

✅ Changes Summary

  • File Modified: osi_product_cost_price/__manifest__.py

    • Added a description to the module's summary: "Fix weight computation for configurable product variants."
    • Added "external_dependencies": {} to the manifest.
  • File Modified: osi_product_cost_price/models/product.py

    • Imported api from odoo to support computed fields.
    • Introduced a new computed field weight on the ProductProduct model.
    • Implemented _compute_weight_from_bom() method to dynamically compute the weight of product variants based on:
      • BOM components (for configurable products)
      • Parent template weight (fallback)
      • Explicitly set variant weight (if any)

🔧 Technical Details

  • A new weight field was added to the ProductProduct model with:

    weight = fields.Float(
        compute="_compute_weight_from_bom",
        store=True,
        help="Weight of the product variant. Computed from BOM components for "
             "configurable products, or inherited from template.",
    )
  • The _compute_weight_from_bom() method:

    • Checks availability of the mrp module.
    • Attempts to find and use either a phantom or normal BOM for the product.
    • Computes the total weight by summing up component weights multiplied by their quantities.
    • Falls back to using the parent template’s weight if no BOM is found or valid components exist.
    • Ensures that the computed weight is stored and accessible in views and shipping calculations.

🧪 Testing & Review Notes

  • Ensure that configurable product variants (like HX500) now correctly display their computed weights in the Inventory tab.
  • Verify that the fallback behavior works when BOMs are missing or invalid.
  • Confirm compatibility with environments where the mrp module may not be installed.

This change resolves the inconsistency in weight visibility for configurable variants, ensuring accurate weight data for shipping and inventory operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants