跳至内容
菜单
此问题已终结
1 回复
2796 查看

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
25203
2
7月 20
3193
1
1月 23
2149
1
6月 22
5151
1
6月 22
2554