Skip to Content
Menu
This question has been flagged

I need to make a 2 way binding between 2 records of 2 different models. the best way I found was using 2 Many2many fields:

https://odoo-development.readthedocs.io/en/latest/dev/py/fields.html#many2many

I tested it between a costume mode and product.prduct it worked prefectly. but when I tested between 2 costume models it didn't work. the tables are there but they are not connected in any way

<<< model 1 >>>
class License(models.Model):
    _name="license.license"
    _rec_name = "license_number"
license_number = fields.Char(string="License Number",required=True)
product_ids = fields.Many2many('license.product', "license_product_table_1" "license_to_table_col", "table_to_license_col")

<<< model 2 >>>
class LicenseProduct(models.Model):
    _name="license.product"
    # there a constrains function for the name field
    name = fields.Char(string="Name", default="Draft", readonly=True)

    license_ids = fields.Many2many("license.license", "license_product_table_1",         "table_to_license_col", "license_to_table_col")
I tried everything I could think of to solve it and nothing worked. I'm honestly desperate here.
Thanks for any help in advance.


Avatar
Discard
Author Best Answer

So after a while I found this weird solution, I just used variables and it worked:

<<<<< model 1 >>>>>
product_ids = fields.Many2many(comodel_name='license.product', relation="license_product_table_1", column1="license_to_table_col", column2="table_to_license_col")

<<<<< model 2 >>>>>
license_ids = fields.Many2many(comodel_name="license.license", relation="license_product_table_1", column1="table_to_license_col", column2="license_to_table_col", required=True)



Avatar
Discard
Related Posts Replies Views Activity
2
Jun 24
7241
0
Mar 20
1831
2
Dec 23
29511
1
Jun 24
510
0
Mar 24
379