I am adding a supplier for Lunch via the back-end (via a module ofcourse) because it auto-updates with the vendor. The whole auto-update shazam seems to work.
I have been struggling to find the correct code to get my module to create the supplier. The code that searches a specific vendor works. I also have code that creates catogories depending on the tags in the json data, and that all works.
The vendors name is not in the data, has to be specified in this piece of code. For privacy reasons I just named it Vendor123.
I made 4 attempts that I will be sharing here (plz note, all of them do not work, almost all of them give error for Partner_id, so it seems that is the problem.). Plz help.
(Vendor123_Supid is a model I made to just inherit lunch.supplier, thats it.)
class LunchSupplier(models.Model):
_inherit = 'lunch.supplier'
Vendor123_Supid = fields.Text('Vendor123 Supid')
These are my 4 attempts.
supplier = self.env['lunch.supplier'].search([('name', '=', 'Vendor123')])
if not supplier:
supplier = self.env['lunch.supplier'].create({'name': 'Vendor123',
'partner_id': cron.ir_actions_server_id.id}) #1
supplier = {
'supplier_id': supplier_id.create('Vendor123'),
'supplier_name': 'Vendor123',
} #2
supplier = supplier.create({'Vendor123_Supid': params['partner_id'],
'name': 'Vendor123'}) #3
supplier = self.env['res.partner'].create({'id': 123, 'name': 'Vendor123'})
supplier_data = {
'name': 'Vendor123',
}
supplier_id = supplier.create(supplier_data)
print(supplier_id.id) #4