product-variant icon indicating copy to clipboard operation
product-variant copied to clipboard

[16.0] product_variant_configurator: field 'product_id' in module 'product.configurator' breaks inventory valuation report

Open JordiBForgeFlow opened this issue 1 year ago • 5 comments

After installing product_variant_configurator, if you go to 'Inventory > Reporting > Valuation' the following error message appears:

  File "/opt/odoo/odoo/addons/base/models/ir_ui_view.py", line 1318, in _postprocess_tag_groupby
    self._postprocess_view(node, field.comodel_name, editable=False, parent_name_manager=name_manager)
  File "/opt/odoo/odoo/addons/base/models/ir_ui_view.py", line 1144, in _postprocess_view
    if model_name not in self.env:
  File "/opt/odoo/odoo/api.py", line 538, in __contains__
    return model_name in self.registry
  File "/usr/lib/python3.10/_collections_abc.py", line 830, in __contains__
    self[key]
RecursionError: maximum recursion depth exceeded

Seems that the problem is caused by the field 'product_id' in the model 'product.configurator'. https://github.com/OCA/product-variant/blob/16.0/product_variant_configurator/models/product_configurator.py#L34

If we remove the field, the problem disappears. If we remove this line from the stock valuation tree view, https://github.com/odoo/odoo/blob/16.0/addons/stock_account/views/stock_valuation_layer_views.xml#L57 the problem disappears.

So, it seems to me that when odoo tries to render the it messes up because the model 'product.product' now has a field 'product_id' (inherited from 'product.configurator').

Perhaps the simplest approach is to rename the field 'product_id' to 'product_variant_id'.

cc @pedrobaeza

JordiBForgeFlow avatar Jan 10 '24 14:01 JordiBForgeFlow

Not so direct I'm afraid, as the configurator is inherited by for example sale.order.line, and the product_id field is put on purpose. What we can try to do is to parametrize the field to use for the "variant", defaulting to product_id, but possible to be changed per model inheriting the mixin, and see if we can change all the computes to use the proper dependency.

pedrobaeza avatar Jan 10 '24 17:01 pedrobaeza

image

JordiBForgeFlow avatar Jan 10 '24 18:01 JordiBForgeFlow

@pedrobaeza The problem is that the product.product model cannot have a field 'product_id' defined. So, it should not be inherited from product.configurator in the first place. Another option is to define two mixins.

JordiBForgeFlow avatar Jan 10 '24 18:01 JordiBForgeFlow

That inheritance was done for being able to create a variant (when you have configured to not pre-create them) selecting the values, so it's useful. Doing 2 mixin can be very confusing, having to split the logic depending if you need the product variant field or not.

pedrobaeza avatar Jan 10 '24 20:01 pedrobaeza

There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.

github-actions[bot] avatar Jul 14 '24 12:07 github-actions[bot]