添加行而不覆盖现有

时间:2017-10-20 14:04:17

标签: openerp odoo-8 odoo-9

例如,我有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

1 个答案:

答案 0 :(得分:2)

当您在任何write字段上运行x2many时,您说“这是该字段中应该唯一的内容。请删除其他内容。”

您想要添加其他行,因此您必须使用the method described here填充该字段。

shoes.service_ids = [(4, {ID of record to link})]