从 Odoo 中的 one2many 字段删除记录时出现问题

问题描述 投票:0回答:1

我有一个“选举”模型,与其他相关模型“成员”有 3 个不同的 one2many 字段。这些 One2Many 字段之间的区别在于每个字段都有不同的域。问题是,当我尝试使用选举表单(使用树列表)从 one2many 字段之一删除一名成员时,当我单击选举表单中的“保存”按钮时,明显删除的记录会再次显示。也许这与存在 2 个不同的 one2many 关系这一事实有关,并且当您从一个关系中删除一个元素(成员)时,其他 One2many 字段中的引用完好无损。我正在使用 Odoo 17

member_ids = fields.One2many('elections.member', 'election_id', 字符串='成员',
域=[('is_observer','=', False )])

observer_ids = fields.One2many('elections.member', 'election_id', 字符串='观察员',
域=[('is_observer','=', True ), ('is_candidate','=', False )])

all_member_ids = fields.One2many('elections.member', 'election_id', string='所有成员(包括观察员和候选人)')

表格内

 <notebook>
            <page name="members" string="Members">
                <field name="member_ids" readonly='state != "draft"'  domain="[('is_observer','=', False ), ('is_candidate','=', False )]" context="{'default_is_observer': 0, 'default_is_candidate': 0, 'from_o2m': 1}">
                  <tree>
                    <field name="name" />
                    <field name="specialty_certificate" />
                    <field name="membership_status" />
                    <field name="is_candidate" />
                    <button name="action_send_email_with_qr_code" type="object" string="Email with QR"
                            invisible="membership_status!='college'"
                            icon="fa-envelope"/>
                    <button name="viixoo_cmim_elections.small_qr_report" type="action" string="Print QR" 
                            invisible="membership_status != 'college'"
                            icon="fa-print"/>
                  </tree>
                </field>
            </page>
            <page name="observers" string="Observers">
                <field name="observer_ids" readonly='state != "draft"'  string="Observer" domain="[('is_observer','=', True ), ('is_candidate','=', False )]" context="{'default_is_observer': 1, 'default_is_candidate': 0, 'from_o2m': 1}">
                <tree>
                    <field name="name" />
                    <field name="specialty_certificate" />
                    <field name="membership_status" />
                    <field name="is_president" />
                    <button name="action_send_email_with_qr_code" type="object" string="Email with QR"
                            invisible="membership_status!='college'"
                            icon="fa-envelope"/>
                    <button name="viixoo_cmim_elections.small_qr_report" type="action" string="Print QR" 
                            invisible="membership_status!='college'"
                            icon="fa-print"/>
                  </tree>
                </field>
            </page>
 </notebook>
odoo odoo-17
1个回答
0
投票

因为一个 O2M 字段总是涉及关联代码模型中的一个 M2O 字段,所以除了创建 M2M 字段(可以在数据库中创建 3 个不同的关系表来存储 3 种类型的关系)之外,您别无选择:

member_ids = fields.Many2many(comodel_name='elections.member', 
relation='mbrnotobs_election_table' column1='mbrnotobserver_id', column_2='election_id', string='Members',                                
domain=[('is_observer','=', False )])        
 
observer_ids=fields.One2many(
comodel_name='elections.member', 
relation='mbrobs_election_table' column1='mbrobserver_id', 
column_2='election_id',
string='Observers', domain=[('is_observer','=', True ), ('is_candidate','=', False )])  

all_member_ids=fields.One2many(
comodel_name='elections.member', 
relation='mbrall_election_table',
column1='mbrall_id', 
column_2='election_id',
string='All members (including observers and candidates)')

© www.soinside.com 2019 - 2024. All rights reserved.