Skip to Content
Menu
This question has been flagged
4 Replies
4250 Views

I am trying to create new records on a Many2One field with a button, but it doesn't work.
The result is this error: 
TypeError: create() takes exactly 2 arguments (3 given).

I got this two class and my function:

class Line(models.Model):
	_name = 'inebir.line'
	medicament_id = fields.Many2one('inebir.medicament', string="Medicament")
	new_stock = fields.Integer(string="Stock")

class Medicament(models.Model):
	_name = 'inebir.medicament'
	code = fields.Integer(string = "Code",required = True)
	name = fields.Char(string= "Nanme",required=True)
	description = fields.Text(string= "Description")
	stock = fields.Integer(string= "Stock",readonly=True)
	activ = fields.Boolean(string = "Registered")

        @api.multi
	def addLine(self):
            for m in self:
			line_item = {
				'name':m.name,
				'code':m.code,
				'description':m.description,
				'stock':m.stock,
				'activ':m.activ                          
			}
	    _logger.debug("HERE!")
	    _logger.debug(line_item)
	    result = self.env['inebir.line'].create(
						    {'medicament_id':line_item},
                                                    {'new_stock':100}
					           )
	    return result


Avatar
Discard
Best Answer

Dear Joaquin

Try This

       
        @api.multi
	def addLine(self):
            for m in self:
			line_item = {
				'name':m.name,
				'code':m.code,
				'description':m.description,
				'stock':m.stock,
				'activ':m.activ                          
			}
	    _logger.debug("HERE!")
	    _logger.debug(line_item)
	    result = self.env['inebir.line'].create(
						    {'medicament_id':m.id,
                                                    'new_stock':100,}
					           )
	    return result

Avatar
Discard
Author

It works like a charm! Thank you so much!!

Best Answer

Convert this:

result = self.env['inebir.line'].create({'medicament_id':line_item},{'new_stock':100})

to this:

result = self.env['inebir.line'].create({'medicament_id':line_item,'new_stock':100})


Avatar
Discard
Best Answer

Hello Joaquin,

In create() method, you have passed 2 dictionary while creating record for "inebir.line"

Thanks,

Avatar
Discard