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

I have models A and B:

class A (models.Model):
    _name = 'example.a'

    name = fields.Char(string="Model A")

    b_id = fields.Many2one('example.b', string='Model B')

class B (models.Model):

   _name = 'example.b'

   name = fields.Char(string="Model B")

    a_ids = fields.One2many('example.a', 'b_id', string="Models A")

I want to Add an item in a_ids from the existing records of A, not create new ones, how can this be achieved ? the autogenerated view for a_ids field only allows me to insert new records everytime I click Add an item, How can I show a list of existing records from the Many2One b_id field in model A. I though odoo will automagically show me a list of such values since the declaration of the field explicitly names the field in the Many2One relationship, thanks in advance

아바타
취소
베스트 답변

Try this on your view to show existing records when u click Add an item

<field name="a_ids" widget="many2many"/>

아바타
취소
베스트 답변

Actually what you wrote must work. I have something very similar in my extension of res.partner:

wo_ids = fields.One2many('inspection_tech.work_order',
                             inverse_name = "customer",
                             string="Work Orders", 
                             readonly=True)

In my partner view I have added the work order view in a tab:

<notebook position="inside">
                    <page string="Work Orders">
                        <field name="wo_ids"/>
 And it works as a charm. Are you sure you have  example.a records with b_id point to the viewed example.b instance?     

아바타
취소