Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
9503 Lượt xem

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.


Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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)



Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 12 24
6395
2
thg 6 24
11516
0
thg 3 20
2827
2
thg 12 23
31362
1
thg 6 24
2737