Customize odoo modules - python

if self.move_to == 'company':
self.employee_id.service_state = 'out_service'
# self. current_company.employee_id = self.env['hr.employee','res.company'].search([('company_id', '=', self.id)])
# self. current_company.employee_id.service_state = 'out_service'
self. current_company.employee_id .active = True
employee = self.env['hr.employee']
vals = {
'first_name': self.employee_id.first_name,
'second_name': self.employee_id.second_name,
'third_name': self.employee_id.third_name,
'last_name': self.employee_id.last_name,
'job_joining_date': self.employee_id.job_joining_date,
'company_id': self.employee_id.company_id.id,
'resource_calendar_id': self.employee_id.resource_calendar_id.id,
'tz': self.employee_id.tz,
'joining_date': self.employee_id.joining_date,
'name': self.employee_id.name,
'department_id': self.employee_id.department_id.id,
'gender': self.employee_id.gender,
'birthday': self.employee_id.birthday,
'employee_type': self.employee_id.employee_type,
'contract_type': employee.contract_type,
'first_employmment_date': self.employee_id.first_employmment_date,
'job_id': employee.job_id
}
employee.create(vals)
self.employee_id.write({'company_id': self.move_company,
'department_id': self.move_department.id,
'job_id': self.move_job.id,
'movement_date': fields.Date.today()})
this my code. I would like if the employee move to other company change employee state in current_company to out_service and archive the employee profile in current_company.
How can I do it?

Related

How to interate for loop in dictionaries python

i am new to python. I am working on a project in which i need to add agents in a room then the user can call to the available agents. But i am struck on how to add agents.
i need to add agents in dict like:
{1: {'fkb1bDXXF_qh7AgyAAAD': {'Type': 'Agent', 'First_Name': '', 'Last_Name': '', 'Data': ''}}, 2: {'Ttr-d9HWdzkgaPrsAAAB': {'Type': 'Agent', 'First_Name': '', 'Last_Name': '', 'Data': ''}}}
agents no. and session_id is different for all agents. But i am getting output like this:
{1: {'fkb1bDXXF_qh7AgyAAAD': {'Type': 'Agent', 'First_Name': '', 'Last_Name': '', 'Data': ''}}}
{1: {'Ttr-d9HWdzkgaPrsAAAB': {'Type': 'Agent', 'First_Name': '', 'Last_Name': '', 'Data': ''}}}
need help on this.
import socketio
sio = socketio.Server()
app = socketio.WSGIApp(sio, static_files={
'/': './public/'
})
agents = {}
total_agents = 0
def add_agents(sid):
total_agents = 0
global total_rooms
global users
global sid_room_identifier
for key in agents.keys():
agents[key][sid] = {}
agents[key][sid] = {
'Type': 'Agent',
'First_Name': '',
'Last_Name': '',
'Data': ''
}
if (total_agents == 0):
total_agents += 1
agents[total_agents] = {
sid: {
'Type': 'Agent',
'First_Name': '',
'Last_Name': '',
'Data': ''
}
}
print(total_agents)
print(agents)
return total_agents
return agents
#sio.event
def connect(sid, environ):
print(sid, 'connected')
add_agents(sid)
#sio.event
def disconnect(sid):
print(sid, 'disconnected')

Remove item in JSON if key has value

I have tried everything I can possible come up with, but the value wont go away.
I have a JSON user and if user['permissions'] have key permission = "DELETE PAGE" remove that index of del user['permissions'][1] (in this example)
I want to have a list of possible values as "DELETE PAGE" and so on. If value in key, then delete that index.
Then return the users json without those items found.
I have tried del user['permission][x] and .pop() and so on but it is still there.
{
'id': 123,
'name': 'My name',
'description': 'This is who I am',
'permissions': [{
'id': 18814,
'holder': {
'type': 'role',
'parameter': '321',
'projectRole': {
'name': 'Admin',
'id': 1,
}
},
'permission': 'VIEW PAGE'
}, {
'id': 18815,
'holder': {
'type': 'role',
'parameter': '123',
'projectRole': {
'name': 'Moderator',
'id': 2
}
},
'permission': 'DELETE PAGE'
}]
}
Here's the code:
perm = a['permissions']
for p in perm:
if p['permission'] == 'DELETE PAGE':
perm.remove(p)
print(a)
Output:
{'id': 123, 'name': 'My name', 'description': 'This is who I am', 'permissions': [{'id': 18814, 'holder': {'type': 'role', 'parameter': '321', 'projectRole': {'name': 'Admin', 'id': 1}}, 'permission': 'VIEW PAGE'}]}

API connection and getting the returned result

I'm sorry for my bad english
Hello, I am using a brokerage firm for payment instrument. The API connection is successful and I get the result. But I can't use the returned result information.
payment_card = {
'cardHolderName': kartisim,
'cardNumber': kartno,
'expireMonth': kartskt_ay,
'expireYear': '2030',
'cvc': karcvc,
'registerCard': '0'
}
buyer = {
'id': adres.id,
'name': adres.adres_uye.username,
'surname': 'Doe',
'gsmNumber': '+905350000000',
'email': adres.adres_uye.email,
'identityNumber': '74300864791',
'lastLoginDate': '2015-10-05 12:43:35',
'registrationDate': '2013-04-21 15:12:09',
'registrationAddress': adres.adres_detay,
'ip': '85.34.78.112',
'city': 'Istanbul',
'country': 'Turkey',
'zipCode': '34732'
}
address = {
'contactName': 'Jane Doe',
'city': 'Istanbul',
'country': 'Turkey',
'address': 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1',
'zipCode': '34732'
}
basket_items = []
for bas in uye:
basa = {
'id': str(bas.id),
'name': str(bas.sepet_urun.urun_baslik),
'category1': str(bas.sepet_urun.urun_anakategori.anakategori_baslik),
'category2': str(bas.sepet_urun.urun_altkategori.altkategori_baslik),
'itemType': 'VIRTUAL',
'price': str(bas.sepet_fiyat)
}
basket_items.append(basa)
print(basket_items)
request_payload = {
'locale': 'tr',
'conversationId': '123456789',
'price': str(sepetf),
'paidPrice': str(sepetf),
'currency': 'TRY',
'installment': '1',
'basketId': str(sepetid),
'paymentChannel': 'WEB',
'paymentGroup': 'PRODUCT',
'paymentCard': payment_card,
'buyer': buyer,
'shippingAddress': address,
'billingAddress': address,
'basketItems': basket_items
}
payment = iyzipay.Payment().create(request_payload, options)
print(payment.read().decode('utf-8'))
return HttpResponse(payment["status"])
I cannot use the returned result information. The returned result is as follows
The error I get is as follows:
'HTTPResponse' object is not subscriptable
Looks like the issue is here.
return HttpResponse(payment["status"])
payment returns an HTTPResponse response object and you cannot directly index the status. Instead you should use .status attribute.
If your intention is to return JSON back as response you could use JsonResponse class from django.http module.
return JsonResponse(json.loads(payment.read().decode('utf-8')))

Python steamlit select box menu returns string, but I need dict or list

Stack on this case, Python steamlit select box menu returns string, but I need dict or list, to use it further in my code.
I want to see company1, company2, company3 in dropdown menu, and if user's choice was for example 'company2' get ['ID': 'zxc222’, 'NAME': 'company2','DESC': 'comp2'].
BaseObject = [{
'ID': 'zxc123',
'NAME': 'company1',
'DESC': 'comp1'
}, {
'ID': 'zxc222',
'NAME': 'company2',
'DESC': 'comp2'
}, {
'ID': 'zxc345',
'NAME': 'company3',
'DESC': 'comp3'
}]
lenbo = len(BaseObject)
options = []
for i in range(0, lenbo):
options.append((BaseObject[i])['NAME'])
st.selectbox('Subdivision:', options)
You can do the conversion to a dict after the selectbox:
import streamlit as st
BaseObject = [{
'ID': 'zxc123',
'NAME': 'company1',
'DESC': 'comp1'
}, {
'ID': 'zxc222',
'NAME': 'company2',
'DESC': 'comp2'
}, {
'ID': 'zxc345',
'NAME': 'company3',
'DESC': 'comp3'
}]
lenbo = len(BaseObject)
options = []
for i in range(0, lenbo):
options.append((BaseObject[i])['NAME'])
choice = st.selectbox('Subdivision:', options)
chosen_base_object = None
for base_object in BaseObject:
if base_object["NAME"] == choice:
chosen_base_object = dict(base_object)
print(chosen_base_object) # {'ID': 'zxc345', 'NAME': 'company3', 'DESC': 'comp3'}

1 sock.execute transaction with 2 data structures

I have read that it is possible to record a partner and their addresses, all in a single call to the web service. The examples always call 2 sock.execute
partner = {
'name': 'Fabien Pinckaers',
'lang': 'fr_FR',
}
partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', partner)
address = {
'partner_id': partner_id,
'type' : 'default',
'street': 'Chaussée de Namur 40',
'zip': '1367',
'city': 'Grand-Rosière',
'phone': '+3281813700',
'fax': '+3281733501',
}
address_id = sock.execute(dbname, uid, pwd, 'res.partner.address', 'create', address)
But how do i call this as 1 transaction in 1 sock.execute?
Try like this:
partner = {
'name': 'Fabien Pinckaers',
'lang': 'fr_FR',
'address': [(0,0,{
'type': 'default',
'street': 'Chaussée de Namur 40',
'zip': '1367',
'city': 'Grand-Rosière',
'phone': '+3281813700',
'fax': '+3281733501',
})]
}
or try like this:
address = {
'type' : 'default',
'street': 'Chaussée de Namur 40',
'zip': '1367',
'city': 'Grand-Rosière',
'phone': '+3281813700',
'fax': '+3281733501',
}
partner = {
'name': 'Fabien Pinckaers',
'lang': 'fr_FR',
}
partner.update({'address': [(0,0,address)]})
Hope this helpful

Categories

Resources