【问题标题】:Odoo Prevent Selected Duplicate Record in One2many FieldOdoo 防止在 One2many 字段中选择重复记录
【发布时间】:2022-01-22 20:41:41
【问题描述】:

我想阻止所选记录再次显示在组合框中。

如您所见,710 - Maleo 在我之前选择该记录后再次显示。

One2many 字段的字段声明

class RMReservationOrderLine(models.Model):
    _name = "rm.reservation.order.line"
    _description = "Reservation Order Line"

    room_line_ids = fields.One2many('rm.reservation.room.line', 'order_id', string='Rooms')

One2many 字段的模型类

class RMReservationRoomLine(models.Model):
    _name = "rm.reservation.room.line"
    _description = "Reservation Room Line"

    order_id = fields.Many2one('rm.reservation.order.line', string='Order', required=True, ondelete='cascade')
    room_id = fields.Many2one('rm.room', string='Room', required=True)

更新

由于One2many 字段的模型类只有一个字段room_id,因此我只需将One2many 字段更改为Many2many。因为默认Many2many字段防止重复记录。

但是如果我使用One2many 字段,我仍然想知道如何防止重复记录,以防我在One2many 的模型类中有多个字段。

【问题讨论】:

    标签: odoo erp odoo-14


    【解决方案1】:

    我认为这与您想要的情况相同。

    我已经修改了销售订单,所以当销售订单行中的产品已经被选中时,该产品将不会再次显示在所选产品中。

    我用odoo-14,继承sales.order.line,修改函数product_id_change()变成:

    @api.onchange('product_id')
    def product_id_change(self):
        values = super(SaleOrderLine, self).product_id_change()
        filter_product_ids = [data.product_id.id for data in self.order_id.order_line]
        if values is None:
            values = {}
        values['domain'] = {'product_id' : [('id', 'not in', filter_product_ids)]}
        return values
    

    【讨论】:

    • 这不起作用:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-04
    相关资源
    最近更新 更多