M.E.
M.E.

Reputation: 5505

TypeError: create() takes exactly 2 arguments (1 given) while trying to create a new record

I am trying to programmatically create a new purchase order inside a model method invoked by a button.

I do this:

@api.multi
def do_create_purchase_order(self):
    purchase_order = self.env['purchase.order'].create()

But I get:

TypeError: create() takes exactly 2 arguments (1 given)

How can I get a new purchase order created?

Upvotes: 0

Views: 124

Answers (1)

Saumil gauswami
Saumil gauswami

Reputation: 725

I think you missed vals to create purchase order,

because create method take values list which needs for creating record so try this,

purchase_order = self.env['purchase.order'].create({
        'partner_id': your_cusromer'id,
        'currency_id': specific_currency,
        'order_line': [
            (0, 0, {
                'name': product.name,
                'product_id': product.id,
                'product_qty': quantity,
                'product_uom': product.uom_po_id.id,
                'price_unit': price_unit,
                'date_planned': date,
                'taxes_id': [(6, 0, product.supplier_taxes_id.ids)] if set_tax else False,
            })],
         'date_order': fields.Date.today(),
    })

I hope this example fullfilled your requirements.

Thanks.

Upvotes: 1

Related Questions