Issue is your logic
prod_location = location.id
Then the following if statement is never entered, and you move to
val['location_id'] = prod_location.id
And the error is thrown
Answer from OneCricketeer on Stack OverflowIssue is your logic
prod_location = location.id
Then the following if statement is never entered, and you move to
val['location_id'] = prod_location.id
And the error is thrown
Yes correct. Some location don't exist on the system. That's it throws error. To avoid such error, you can use following trick.
prod_location = self.location and self.location.id or False
Means if system has location then prod_location variable set value with id of location otherwise False
NOTE:
In model declaration, location_id field set with required=False otherwise you can not create record with location_id=False It will give you integrity error.
AttributeError: 'int' object has no attribute 'id' on odoo 9
AttributeError: 'int' object has no attribute 'id'
AttributeError: 'int' object has no attribute 'id'
python - int object has no attribute id - Stack Overflow
Videos
As time = 3 is declared as an integer,
time.time doesn't have any sense since time is int variable (that isn't a class but a primitive data type). I suppose that you expected to call time (module) writing time but, since you're redefining it as an integer, this last definition shadows the time module
Change time variable name to something else, like myTime
Error messages are usefull, you should read them. Often the answer is contained directly into this errors/warning messages
You have variable time:
time = 3
and you have previously imported package time:
import time
When you try to do
time.time()
it seems that you try to call method time() of variable time (that contains int).
You should rename it and it will figure out conflicts with package name.
I'm creating frequency dicts of lemmas and words, but have encountered this error and have no clue on what's going on, can anyone help me make sense of this?
If there's a better way of doing this please do tell!
https://imgur.com/a/sUR7DEJ
freq = defaultdict(dict)
def spcy(content, dir):
code = str(dir.lower())
model = code + "_core_news_sm"
models = spacy.util.get_installed_models()
if model in models:
#try:
nlp = spacy.load(model)
#print(model)
spcy = nlp(content)
for word in spcy:
if word.text.isalpha():
print(word)
print(type(freq.get(word.lemma_,{})))
freq[word.lemma_][word.text] = freq.get(word.lemma_,{}).get(word.text, 0) + 1
#except:
#print("exception")
#print(freq)
elif not model in models:
nlp = spacy.blank(code)
spcy = nlp(content)
for word in spcy:
if word.text.isalpha():
#does work...
freq[word.text] = freq.get(word.text, 0) + 1 # type: ignore
print(freq)