Skip to Content
Menu
This question has been flagged
1 Reply
3842 Views

I am trying to create record in my newly created model. 

here is my model 

 class EtaDocumentTypes(models.Model):

    _name = "eta.document.types"
_description = "ETA Documents Types for invoicing"


eta_id=fields.Integer('Document Type ID')
name=fields.Char("Name")
description=fields.Char("Description")
activeFrom=fields.Datetime("Active From",default=None)
activeTo=fields.Datetime("Active To",default=None)

I had writtne a function that works on button click and save records
here is my code

def get_eta_document_types(self):
_create_unverified_https_context = ssl._create_unverified_context
url = "https://api.preprod.invoicing.eta.gov.eg/api/v1/documenttypes"
eta_api_model = self.search([("client_id", "=", self.client_id)])
access_token=str(eta_api_model.access_token)
payload = {}
headers = {
'Accept-Language': 'ar',
'Accept': 'application/json',
'Content-type': 'application/json',
'Authorization': "Bearer 2343"
}

response = requests.request("GET", url, headers=headers, data=payload,verify=False)
self.env['eta.document.types'].sudo().create({

'eta_id': '1',
'name': 'dsad',
'description': 'dsad',
'activeFrom': "2021-03-30 10:50:23",
'activeTo': "2021-03-30 10:50:23"

})

So this code either gives any error nor create record in my model.I am trying it with super user right now.
Thanks Best Regards
Avatar
Discard
Best Answer
self.env['eta.document.types'].sudo().create({

'name': 'dsad',
'description': 'dsad',
'activeFrom': "2021-03-30 10:50:23",
'activeTo': "2021-03-30 10:50:23"

})

Try this, specifying the id would create record in that id
Avatar
Discard
Related Posts Replies Views Activity
1
Jun 21
1937
0
Jan 22
3042
1
Nov 24
1487
1
Nov 24
1198
2
Sep 24
1047