Skip to content
Advertisement

Create multiple saleorder

I am trying to create multiple sale order based on a input field (product_quantity) in crm.lead.

@api.multi
def create_sale(self):
    values = {
        'opportunity_id': self.id,
        'state': 'draft',
        'date_order': datetime.now(),
        'partner_id': self.partner_id.id
    }
    for i in range(0, self.product_quantity):
        res = self.env['sale.order'].create(values)

I am receiving the following error as pop up

Error, a partner cannot follow twice the same object.

Advertisement

Answer

@Khelili, thanks for sharing it. Adding a context worked fine for me. I got it somewhere by googling.

    for i in range(0, self.product_quantity):
        values = {
            'name': self.env['ir.sequence'].next_by_code('sale.order'),
            'opportunity_id': self.id,
            'state': 'draft',
            'date_order': datetime.now(),
            'partner_id': self.partner_id.id,
            'count_total': self.total_count,
            'product_categ': self.product_categ.id
        }
        res = self.env['sale.order'].with_context(mail_create_nosubscribe=True).create(values)
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement