Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
4762 Lượt xem

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
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
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
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 6 21
2815
0
thg 1 22
3958
1
thg 7 25
2273
2
thg 7 25
7747
2
thg 7 25
4166