Skip to Content
Menu
This question has been flagged
4 Replies
1743 Views
classKkitSappl(models.Model):
    _inherit = 'product.template'
    _name = "kkit.sappl"    _description = "Produit kit"   
    lu =  fields.Char('LU')   
​send_number = fields.Char('Send No')   
​ckd_pnr = fields.Char('CKD-PNR')         
​ckd_modele = fields.Char('CKD Prod No')   
​comm_nos = fields.Char('Commission No')     
​lot_number = fields.Char('Lot No')    
​vin = fields.Char('Vehicule Ident Number')
   
Odoo Server Error
Traceback (most recent call last):
  File "/opt/odoo14/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
    result = request.dispatch()
  File "/opt/odoo14/odoo/odoo/http.py", line 685, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo14/odoo/odoo/http.py", line 361, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo14/odoo/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo14/odoo/odoo/http.py", line 349, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo14/odoo/odoo/http.py", line 908, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo14/odoo/odoo/http.py", line 533, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo14/odoo/addons/web/controllers/main.py", line 1376, in call_button
    action = self._call_kw(model, method, args, kwargs)
  File "/opt/odoo14/odoo/addons/web/controllers/main.py", line 1364, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo14/odoo/odoo/api.py", line 399, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/opt/odoo14/odoo/odoo/api.py", line 386, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "", line 2, in button_immediate_install
  File "/opt/odoo14/odoo/odoo/addons/base/models/ir_module.py", line 74, in check_and_log
    return method(self, *args, **kwargs)
  File "/opt/odoo14/odoo/odoo/addons/base/models/ir_module.py", line 478, in button_immediate_install
    return self._button_immediate_function(type(self).button_install)
  File "/opt/odoo14/odoo/odoo/addons/base/models/ir_module.py", line 596, in _button_immediate_function
    modules.registry.Registry.new(self._cr.dbname, update_module=True)
  File "/opt/odoo14/odoo/odoo/modules/registry.py", line 89, in new
    odoo.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/opt/odoo14/odoo/odoo/modules/loading.py", line 459, in load_modules
    processed_modules += load_marked_modules(cr, graph,
  File "/opt/odoo14/odoo/odoo/modules/loading.py", line 347, in load_marked_modules
    loaded, processed = load_module_graph(
  File "/opt/odoo14/odoo/odoo/modules/loading.py", line 198, in load_module_graph
    registry.setup_models(cr)
  File "/opt/odoo14/odoo/odoo/modules/registry.py", line 276, in setup_models
    model._setup_fields()
  File "/opt/odoo14/odoo/odoo/models.py", line 2845, in _setup_fields
    field.setup_full(self)
  File "/opt/odoo14/odoo/odoo/fields.py", line 399, in setup_full
    self._setup_regular_full(model)
  File "/opt/odoo14/odoo/odoo/fields.py", line 3475, in _setup_regular_full
    raise TypeError(msg % (self, field))
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/odoo14/odoo/odoo/http.py", line 641, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo14/odoo/odoo/http.py", line 317, in _handle_exception
    raise exception.with_traceback(None) from new_cause
TypeError: Many2many fields kkit.sappl.taxes_id and product.template.taxes_id use the same table and columns





Avatar
Discard
Author

I want to create another model which inherit from product.template somme information to manage our product with custom fields.

So i don't undestant how to create anoter model with taxes_id with a new relational table name for the many2many field.

Can you please give me more details 

Thanks a lot

see the updated answer

taxes_id = fields.Many2many('account.tax', 'kkit_sappl_taxes_rel', 'prod_id', 'tax_id', help="Default taxes used when selling the product.", string='Customer Taxes',
domain=[('type_tax_use', '=', 'sale')], default=lambda self: self.env.company.account_sale_tax_id)

Author

Hi, 

thank you a lot for your response, after i used the definition given in my model i had another msg error.

Traceback (most recent call last):
  File "/opt/odoo14/odoo/odoo/http.py", line 641, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo14/odoo/odoo/http.py", line 317, in _handle_exception
    raise exception.with_traceback(None) from new_cause
TypeError: Many2many fields kkit.sappl.supplier_taxes_id and product.template.supplier_taxes_id use the same table and columns

Thanks in advance

see the changes i have done for taxed_id field and similarly apply for new fields

Author

Hi all

Unfortunately i still have the same error message when applying the requested changes.


did you redefine the supplier_taxes_id field in your model ?

Best Answer

Hi,

Not sure what you are trying to achieve, if you need to add new fields to product.template model, you can remove the _name attribute from the model class and just keep the inherit attribute .

class ProductTemplate(models.Model):
_inherit = 'product.template'


  lu = fields.Char('LU')


And as per your requirement if you need a new model, then to resolve the above error, you have copy the taxes_id field from product.template model and redefine it inside your model with a new relational table name for the many2many field.


Update:

add this field in your model

taxes_id = fields.Many2many('account.tax', 'kkit_sappl_taxes_rel', 'prod_id', 'tax_id', help="Default taxes used when selling the product.", string='Customer Taxes',
domain=[('type_tax_use', '=', 'sale')], default=lambda self: self.env.company.account_sale_tax_id)



Thanks

Avatar
Discard
Author Best Answer

Thanks a lot for your response,

I applied what you have described but i can't find how i can research for all field in relation with product.template.

I Had another error msg with another fields:  route_ids

  File "/opt/odoo14/odoo/odoo/http.py", line 317, in _handle_exception
    raise exception.with_traceback(None) from new_cause
TypeError: Many2many fields kit.sappl.route_ids and product.template.route_ids use the same table and columns

Best Regards

Avatar
Discard
Best Answer

Hi,

The issue is because of product.template and your custom class kkit.sappl using the same table (product_taxes_rel) so that it is throwing an error. To avoid that we have to create a new table of relationship (kkit_sappl_taxes_rel). Create one more many2many fields in your custom module. like the following:

    taxes_id = fields.Many2many('account.tax', 'kkit_sappl_taxes_rel', 'prod_id', 'tax_id', string='Customer Taxes',
        domain=[('type_tax_use', '=', 'sale')])
    supplier_taxes_id = fields.Many2many('account.tax', 'kkit_sappl_supplier_taxes_rel', 'prod_id', 'tax_id', string='Vendor Taxes',        domain=[('type_tax_use', '=', 'purchase')])

You do the same thing for other Many2many relationships.
Ideally, you have to use the same class (product.template) to manage stages of a vin (Kit, cabine, produit fini) with a selection field like this
    stage = fields.Selection([
        ('kit', _('Kit')),
        ('cabine', _('Cabine')),
        ('fini', _('Produit fini'))], string='Stage', default='kit')


You can do so by making this definition :


class ProductTemplate(models.Model):
_inherit = 'product.template'

    stage = fields.Selection([
        ('kit', _('Kit')),
        ('cabine', _('Cabine')),
        ('fini', _('Produit fini'))], string='Stage', default='kit')
    # Other fields ...
    lu =  fields.Char('LU')    
    send_number = fields.Char('Send No')    
    ckd_pnr = fields.Char('CKD-PNR')          
    ckd_modele = fields.Char('CKD Prod No')    
    comm_nos = fields.Char('Commission No')      
    lot_number = fields.Char('Lot No')    
    vin = fields.Char('Vehicle Ident Number')


Regards

Avatar
Discard
Best Answer

you need to modify the definition of either kkit.sappl.taxes_id or product.template.taxes_id to use different table and column names. Here's an example of how you can modify the kkit.sappl.taxes_id field:

class KkitSappl(models.Model):
_inherit = 'product.template'
_name = "kkit.sappl"
_description = "Produit kit"

lu = fields.Char('LU')
send_number = fields.Char('Send No')
ckd_pnr = fields.Char('CKD-PNR')
ckd_modele = fields.Char('CKD Prod No')
comm_nos = fields.Char('Commission No')
lot_number = fields.Char('Lot No')
vin = fields.Char('Vehicule Ident Number')
 
# Rename taxes_id field to use a different table and columns
kkit_taxes_id = fields.Many2many(
comodel_name='account.tax',
relation='kkit_sappl_taxes_rel',
column1='kkit_id',
column2='tax_id',
string='Taxes'
)
In the example above, the kkit.sappl.taxes_id field has been renamed to kkit_taxes_id and the relation table and columns have been specified as 'kkit_sappl_taxes_rel', 'kkit_id', and 'tax_id' respectively. This ensures that the field has its own separate table and columns, resolving the conflict with the product.template.taxes_id field.

After making the necessary modifications, try installing the module again and the error should no longer occur.

Avatar
Discard