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

I  have an One2many field on a model and I wanna read the same values from another model. I tried adding a Many2one relation to it but it seems to not read data. Can someone please help me?


the way I have defined one2many:

class OnetoMany(models.Model):
_name = "kestet.lines"

partner_id = fields.Many2one("res.partner")
kestet = fields.Char(string="Emri i Kestit(n)")
vlera = fields.Integer(string="Vlera e Kestit(n)")
data = fields.Date()
sel1 = fields.Selection(
[('kontrate', 'Kontrate'), ('levrim', 'Levrim Kredie'), ('karabina', 'Karabina'), ('hipoteka', 'Hipoteka'),
('Celsat', 'Celsat'), ('Ne Perfundim', 'Ne Perfundim'),
('other', 'Tjeter')], string="Menyra Likujdimit")

pagesa1 = fields.Selection([('Cash', 'Cash'), ('Bank', 'Bank'), ('Klering', 'Klering')], string="Menyra Pageses")
product_template_id = fields.Many2one("product.template")
property_contract_id = fields.Many2one("property.contract")


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

     kestet_ids = fields.One2many('kestet.lines', 'product_template_id', string="Kestet", store=True)


property.contract(where I need it the most):


class PropertyContract(models.Model):
_name = "property.contract"
_order = 'start_date'

     kestet2_id = fields.Many2one('kestet.lines')


everytime it gives me 0 when I do kestet2_id.vlera


Ảnh đại diện
Huỷ bỏ

You need connection between "product.template"  and "property.contract"


Tác giả

I did that but it gave me empty recordset everytime.

Câu trả lời hay nhất

Hi,

You can try this codeclass PropertyContract(models.Model):
    _name = "property.contract"
    _order = 'start_date'

    kestet_ids = fields.One2many('kestet.lines', 'property_contract_id', string="Kestet")
With this change, you can associate multiple kestet.lines records with a single PropertyContract. You can then access the related kestet.lines records from a PropertyContract object using the kestet_ids field.

Hope it helps

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 9 21
26596
2
thg 7 20
3876
1
thg 1 23
2676
1
thg 6 22
6271
1
thg 6 22
3095