콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
3403 화면

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


아바타
취소

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


작성자

I did that but it gave me empty recordset everytime.

베스트 답변

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

아바타
취소
관련 게시물 답글 화면 활동
1
9월 21
26173
2
7월 20
3708
1
1월 23
2543
1
6월 22
6024
1
6월 22
2973