How to import csv file with multiple 'order_lines'?
Meantime I was doing some research and actually I found that I do not need to create import method but just add a condition which will check how many products is in the order.
Sales record number | User id | name | email | item | price |
1 | Miriam234 | Ted Butcher | tedbut@gmail.co | ||
1 | VW Polo | 12345.00 | |||
1 | Alloys 18" | 4321.00 | |||
2 | Fariam554 | Frank Pitchka | pitchka@yahoo.jp | Pencil "Bravo" | 1.20 |
So we have 2 orders with two different form. Order 1 is multiple and 2 is single.
Based on this how can I using API create a sale_order with multiple order_lines ?
Something like that ..
def order_sort(self):
records = self.env['iprodstep.log'].search([('state','=','draft')])
for record in records:
if record is False:
raise except_orm('Nothing to sort')
record.write({'image_url': ''.join(map(str,(record.item_id,'.jpg')))})
record.write({'item_id': record.item_id})
print ' '
print ' '
print ' '
print '== record ======================================================================'
print ' ',record.id
if record.sales_record_number:
a = 1
customer = self.env['res.partner'].search([('name','ilike',record.buyer_full_name)])
print ' '
print '.. Customer ....................................................................'
if not customer:
#if record.buyer_postcode:
postcode = "%s %s" %(record.buyer_postcode[:-3].strip(), record.buyer_postcode[-3:])
self.env['res.partner'].create({'name': record.buyer_full_name.title(), 'city': record.buyer_city.title(), 'zip': postcode.upper(),'email': record.buyer_email.lower(), 'phone': record.buyer_phone_number})
print record.buyer_full_name.title()
print record.buyer_email.lower()
print record.buyer_address_1.title()
print record.buyer_city.title()
print postcode.upper()
else:
#if record.buyer_postcode:
postcode = "%s %s" %(record.buyer_postcode[:-3].strip(), record.buyer_postcode[-3:])
print record.buyer_full_name.title()
print record.buyer_email.lower()
print record.buyer_address_1.title()
print record.buyer_city.title()
print postcode.upper()
items = self.env['iprodstep.log'].search([('sales_record_number','=',record.sales_record_number)])
print '.. order .......................................................................'
for item in items:
if item.item_id:
print ' ',a,'. ',item.item_id
a = a + 1
partner_id = self.env['res.partner'].search([['name', '=', record.buyer_full_name], ['zip','=', postcode]])
print '.. partner_id ..................................................................'
print ' ',partner_id.id
print '================================================================================'