找到多个匹配字段'订单行'

时间:2017-12-18 13:48:48

标签: csv import openerp odoo-10 odoo-view

我正在尝试将数据从csv导入Order_line表单,我看到了这个警告

Found multiple matches for field 'Order Line' (2 matches) between rows 2 and 6 (4 more)
  Found multiple matches for field 'Order Line' (2 matches) between rows 2 and 6
  Found multiple matches for field 'Order Line' (2 matches) between rows 2 and 6
  Found multiple matches for field 'Order Line' (2 matches) between rows 2 and 6
  Found multiple matches for field 'Order Line' (2 matches) between rows 2 and 6

由于这个原因,所有的order_lines都是针对同一个用户创建的,但是如果你看到我的csv的第一列是account_number。我们有两个不同的栏目。

CSV

customer/account_number,customer/first_name,customer/last_name,customer/account_type,order/transaction_id,order/product_code,order/quantity
1160925,Charles L.,Richards,Segregated,10981036,G108P70NG,50
1160925,Charles L.,Richards,Segregated,10981037,G108P70NG,150
1160925,Charles L.,Richards,Segregated,10981038,G108P70NG,250
1160925,Charles L.,Richards,Segregated,10981039,G11270NG,350
1160243,"Tracy A., Jr.",Tolar,Segregated,23231554,G108P70NG,750

注意

csv标题中的顺序实际上是order_line我们刚刚在客户端的csv模板中重命名的场景。

Order_line创建方法

@api.model
def create(self, vals):
    product_id = False
    product_code = vals.get('product_code')
    if product_code:
        product = self.env['amgl.products'].search([
            ('product_code', '=', product_code)
        ])
        if product:
            product_id = product[0].id
        vals.update({
            'products': product_id,
        })
    record = super(OrderLine, self).create(vals)
    if (float(record['total_received_quantity']) > float(record['quantity'])):
        record.state = 'pending'
    return record

订单项次型号

class OrderLine(models.Model):
_name = 'amgl.order_line'
_description = 'Order Lines'

name = fields.Char()
customer_id = fields.Many2one('amgl.customer', string='Customer Name',
                              default=lambda self: self._context.get('customer_id', False),required=True)

导入模型

class CustodianDataImport(models.Model):
_name = 'amgl.custodian_data_import'
_description = 'Custodian Data Import'

customer = fields.One2many('amgl.customer', 'custodian_import_id', string='Customer')
order = fields.One2many('amgl.order_line', 'custodian_import_id', string='Order Line')

上面这个模型是我进行导入的单独模型,从这个模型中应该创建针对客户的所有订单。

1 个答案:

答案 0 :(得分:0)

请记住,如果你这样做:

colorQuantile

您需要创建一个约束,使product = self.env['amgl.products'].search([ ('product_code', '=', product_code) ]) if product: product_id = product[0].id 在数据库中唯一。如果不是,你会遇到重复问题

我建议您创建一个模型并添加您想要导入的字段,但它应该是product_code,因为它只是一个辅助模型而您对存储任何东西都不感兴趣在它。

另一方面,我认为您不应该覆盖原始TransientModel模型的create方法。只需在辅助模型的create方法中添加您需要的所有内容,如下所示:

order_line