AttributeError: 'bool' object has no attribute 'split' in python odoo - python-2.7

I need to get the entered name in odoo model and get the first letters of each word in upper case. Ex: MTA Flushing from that I need to create MF as output. I tried it. But it gives the error "AttributeError: 'bool' object has no attribute 'split' "
Here is my code
my_name = self.env['my_details'].search([('id', '=',so_id )]).name
my_d_name = "".join([i[0].upper() for i in depot_name.split()])
Any idea to solve this???

i[0] is False for some value in your database.
This should work:
my_d_name = "".join([i[0].upper() for i in depot_name.split() if i[0]])

Thanks for help..
In my case first have to convert the name that searched into string and then we can apply the code without getting errors.
my_name = self.env['my_details'].search([('id', '=',so_id )]).name
str_name = str(my_name)
my_d_name = "".join([i[0].upper() for i in my_name.split()])

Related

'NoneType' object is not iterable: Loop for a list

I am trying to convert a loop for a list, but i'm getting the 'NoneType' object is not iterable' error.
assets = input("What assets you desire to analyze?v: ").upper().split(",")
for ticker in assets:
assets1 = print(ticker + ".SA")
When i print "assets1", i get a output like this:
PGMN3.SA
COGN3.SA
TASA4.SA
PCAR3.SA
PETZ3.SA
But i wish to make this loop as a list, to do a WebScraping after, but when put "assets1" for webscraping, i get the message error: 'NoneType' object is not iterable'
How can i fix it?
Thanks!
print() function return None - so you're only printing the tickers, not storing them in anything. This example uses list-comprehension to add .SA to each ticker and store it in a list names assets:
assets = input("What assets you desire to analyze?").upper().split(",")
assets = [ticker + ".SA" for ticker in assets]
print(assets)
Prints (for example):
What assets you desire to analyze?PGMN3,COGN3,TASA4,PCAR3,PETZ3
['PGMN3.SA', 'COGN3.SA', 'TASA4.SA', 'PCAR3.SA', 'PETZ3.SA']

Django QuerySet Count() Returns NoneType

In views, I have the following snippet:
try:
count = MembershipPurchaseHistory.objects.filter(user=self.request.user).count()
except:
count = 0
But somehow I got an error saying count has a NoneType value?
How is this possible?
Edit:
I wrote something like this:
if count > 0:
# do something
Traceback Error:
'>' not supported between instances of 'NoneType' and 'int'
Edit 2:
Sorry. I found the error. It was referring to an installed lib, which compares a variable (which defaults to None) to an int. I omitted the variable and this happened.
from django.db.models import Count
count = MembershipPurchaseHistory.objects.filter(user=self.request.user).aggregate(Count('id'))['id__count']
You can try this method, this has better performance as described in this answer

TypeError: expected string or bytes-like object User.id

I'm trying to register an new Transaction object on the DB using Django, but I'm having TypeError: expected string or bytes-like object when I try to do user_id = user.id I can't really understand why this is happening, since I do the same steps when registering a new Bank object (as shown on prints below). I've tried to debug and the local variables have the correct value, I've also tried to cast user.id with string or int, but none of them worked.
traceback console error create Transaction method create Bank method
models.py
Firstly, please don't post code or errors as images; they are text, they should be posted as text in the question.
However I don't see anything in any of those snippets that suggest the error is with the user - that line is probably highlighted because it's the last in that multi-line call.
Rather, the error looks to be in the reference to date.today - if that's the datetime.date class, then today is a method, which you would need to call:
Transaction.objects.create(date=date.today(), ... )
Or, since that field has a default anyway, you could leave out the date attribute from the create call altogether.

python-jira unable to return JIRA object key

I am working on a tool for Jira using the python-jira library.
def find_ticket_key_by_name(search_string):
global jira
result = jira.search_issues('project=FSA and status != Done and summary ~ "HOST TESTER-APP:SERVICE1-SERVICECOUNT" order by createdDate', maxResults=1)
return result
The function above successfully returns a jira object
[<JIRA Issue: key=u'FSA-11', id=u'119060'>]
however if I attempt to print the key value
result.key
I get this error
AttributeError: 'ResultList' object has no attribute 'key'
I found the problem and posting solution in case somebody gets stuck like me.
In my case I am only returning one result and I assumed it will return one object.
This is not the case as indicated by the "ResultList" error. Even if you return 1 result the function will still return a list with 1 result.
What you are getting is a List in python, so try the following:-
result[0].key to get the key value
result[0].id to get id value.
You can always check type any data using type keyword, in your case it will be class 'jira.client.ResultList' which is a List object
If you want to get the key of issue you searched,
if result:
for issue in result:
print(issue.key)
It should help.

django - 'int' object has no attribute 'keys'

t_cat_id = t_cat.id
cursor.execute("select offered_item,offered_item_category_id from foundation_swaptable where accepted_item = %s", t_cat.id)
the code above throws the exception below:
'int' object has no attribute 'keys'
when I surround t_cat.id with square brackets as below:
cursor.execute("select offered_item,offered_item_category_id from foundation_swaptable where accepted_item = %s", [t_cat.id])
the error is gone.
where t_cat is an mptt category object which I fetch as below:
MpttCategory.objects.get(category_name=t_category)
and it has an id column in DB representation which is integer.
can anyone tell me why I get this exception. I just can't associate a meaning with the error.
please tell me if more info is needed..
ps. I am a little drunk :)
Like the documentation says, the second argument must be a sequence or mapping.