添加行而不覆盖现有的

adding lines without overwriting existing

例如,我有 DICT 数据,其中有一些行。我想更新其他模型中的记录行,我使用此代码。其他模型记录有一些初始化行,我想从 DATAS 添加新行。我的代码只是覆盖了已经存在的行。我怎样才能添加到现有行,而不是覆盖?

 datas = safe_eval(self.datas)
 domain = [('quatation_id', '=', self.id)]
 shoes = self.env['shoes.order'].search(domain, limit=1)
 for line in datas['lines']:
                    line = line and line[2]
                    vals = {
                        u'product_id': line.get('product_id'),
                        u'amount_total': line.get('price'),

                    }

                shoes.service_ids.write(vals)



class ShoesOrderService(models.Model):
    _name = 'shoes.order.service'
    _rec_name = 'product_id'

    product_id = fields.Many2one(
        'product.product', 'Service',
        domain=[('type', '=', 'service')],
    )
    price = fields.Float()
    order_id = fields.Many2one(
        'shoes.order', 'Shoes Order')

 class ShoesOrder(models.Model):

_name = 'shoes.order'

 service_ids = fields.One2many(
    'shoes.order.service', 'order_id', string='Additional Services',
    copy=True

当您在任何 x2many 字段上 运行 write 时,您说的是 "This is the only thing that should be on that field. Erase anything else."

您想要添加额外的行,因此您必须使用 .

填写该字段
shoes.service_ids = [(4, {ID of record to link})]