Я пытаюсь импортировать данные из 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 для клиента.
Способ создания строки заказа
@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')
Эта модель выше — это отдельная модель, в которой я выполняю импорт, и из этой модели должен быть создан весь заказ для клиента.