【发布时间】:2017-12-18 13:48:48
【问题描述】:
我正在尝试将数据从 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 实际上是 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')
上面的这个模型是我进行导入的单独模型,应该从这个模型创建针对客户的所有订单。
【问题讨论】:
-
您是否尝试直接从订单行导入客户数据?您是在使用我们在另一个问题中告诉您的方法来创建新的虚拟字段还是新的瞬态模型?
-
如果您要覆盖 create 方法来创建订单行,然后验证客户在数据库中没有重复
-
请在问题中添加create方法检查是否正确
-
请看我的问题更新,我添加了所有相关代码。
标签: csv import openerp odoo-10 odoo-view