I'm running Odoo 12 and I'd like to set up an automated action after a new Opportunity is created.
This automated action would be some custom Python code which calls a system parameter, gets its value and stores it in a field in the new opportunity's record.
Afterwards, that system parameter should be increased by 1 so another new opportunity doesn't have the same number.
How do you get/set a system parameter from python code?
I've created a system parameter with key "customParameter"and value 10122.
The field where this parameter should be put is called "x_studio_deal_quotation_id", within a new opportunity.
I've got a little experience in Python, so I've no idea how to call upon this parameter. Can someone help me out? Or is there an easier way to achieve the same?
A big thanks in advance.
I managed to find what I'm looking for on my own, this is the code I used:
record[("x_studio_deal_quotation_id")] = record.env['ir.config_parameter'].get_param('customParameter')
var = record.env['ir.config_parameter'].get_param('customParameter')
var = int(var)
var += 1
record.env['ir.config_parameter'].set_param('customParameter', var)
In this function I called my system parameter by using record.env['ir.config_parameter'].get_param('customParameter')
I had to convert it to int because I got some error that the type wasn't right.
Finally, I add 1 to my variable value and write the same system parameter with the new value by using:record.env['ir.config_parameter'].set_param('customParameter', var)
Related
I am trying create a node and set a value using this function:
def createTextureNode(textureNode):
keyword = textureNode
for fname in os.listdir(assetFilePath):
if keyword in fname:
texFilename = fname + ".tex"
newTexNode = NodegraphAPI.CreateNode("PrmanShadingNode", rootNode)
newTexNode.getParameter('name').setValue(assetCode + '_' + textureNode, 0)
newTexNode.getParameter('nodeType').setValue("PxrTexture", 0)
newTexNode = NodegraphAPI.GetNode(assetCode + '_' + textureNode)
if textureNode == "Albedo":
newTexNode.getParameter("parameters.linearize.enable").setValue(True,0)
newTexNode.getParameter("parameters.linearize.value").setValue(True,0)
Its pretty simple, if a particular file exists it will create a node for it. However, I am unable to set the "linearize" value (or any other value under the "parameters" group)
If I manually create a node and manually set it to be a PxrTexture and use this code:
node = NodegraphAPI.GetNode("PrmanShadingNode")
node.getParameter("parameters.linearize.enable").setValue(1,0)
node.getParameter("parameters.linearize.value").setValue(1,0)
Then it works, the check box turns on, but if I set the nodeType via script then it fails. But if I run it a second time it works! The error I keep getting is:
AttributeError: 'NoneType' object has no attribute 'setValue'
I know this means that its returning "None" but the tool tip in Katana says that its "parameters.linearize" and the first two parameters were able to be set... but these are under a Group, I think?
Since it works with the manual create, it must be something I am missing in my script, but I can not figure it out. I have also tried using finalizeValue after setting my nodeType but his has no affect
I am using this as my reference:
Getting and Setting Parameters
GOT IT!
When setting a Dynamic Parameter Pragmatically, you have to run checkDynamicParameters() after you set the value that makes the new parameters appear
This updates the UI Loop and makes the new parameters available. When doing this via the UI, it happens on the fly, and thats why it works when doing it manually
ANSWER REFERENCE
I am trying to build a simple chatbot, but it says "Local variable 'cb_answer' value is not used" for multiple states and "cb_answers"'s. Hence the chatbot doesn't give me an answer, when I run the program. I attached a screenshot from the code.
enter image description here
Local variable 'cb_answer' value is not used is a warning not an error.
The problem is that you are creating a variable inside of your ifs. You won't be able to access it outside of the if you created it in. To fix this put:
cb_answer = None
state = None
At the top of your function.
And like #luk2302 mentioned the return should be one less indented.
I am currently trying to create a program that learns through user input, however it converts to a string automatically.
Here's the code. I use the shelve module to store the commands for the code.
ok = {str(name):func}
asd.update(ok)
print(asd)
data["cmd"] = asd
data.close()
The 'asd' list contains every command which has been extracted from the shelf. I want to update it and store it, so next time it updates when calling a command.
'func' is the variable that stores the name of the function am trying to call, but string objects cannot be called.
How do I solve this?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EDIT:
This has been solved (I totally forgot about eval() )
Not sure what you're trying to achieve here, but from what I've understood you should have a look to eval()
The eval() function evaluates the specified expression, if the expression is a legal Python statement, it will be executed.
More information here
I want to make it so it prints different hints dependent on where the player is in the game. I tried it by setting the value of 'Hint' every time the player went somewhere. Obviously I came across a flaw (as I'm here). The value of Hint = 1 was first in one def and I couldn't manage to summon it when writing the Help/Hint def. My pathetic example:
def Room_Choice():
Hint = 1
(60 lines down)
def Hint():
Choice = input("What would you like?\n")
if Choice == ("Hint"):
if Room_Choice(Hint = 1):
print_normal("blah blah blah\n")
else:
print_normal("HINT-ERROR!\n")
Help_Short()
And obviously as the game developed more and more values of hint would be added.
As you can see I'm relatively new to Python and need help.
You are trying to reach a value that exists in a function scope, and you're doing it wrong (as you're here).
Imagine scopes as boxes of one-way mirrors : when you're inside one, you can see what's in the box and what's outside of the box. But you can't see what's in a box you are not in.
Here, Hint exists within the box of Room_Choice, but not in the box of H... oh wait.
You've called your function Hint too ! If you want to reach Hint in a function called Hint with no Hint defined inside the function, you'll probably get the function. Let's call the function DoHint()
So you can't see Hint from within DoHint, because it's in another box. You have to put it somewhere (over the rainboooow... sorry for that) you can see it.
You might want to put it at the module level (not within a def), or make it an object's attribute (but you'll have to know bits of Oriented Object Programming to understand that).
This is really basic programming skills, I can't really explain further without knowing what you're trying to do and showing you how I would do it, but I hope that helped.
Just one more thing on this line : if Room_Choice(Hint = 1):, here you're trying to check if the result of the Room_Choice function with a value of 1 for the Hint parameter is True. I don't know what you wanted to do, but the Room_Choice function doesn't show it can handle any parameters (you should get an error on that), and will not return a boolean value (it will implicitly return None, which is evaluated as a logical False).
I have noticed a particular feature in Visual Studio and I am wondering if this feature is also available in Eclipse + PyDev.
In Visual Studio, if one were to type a function call and that particular function does not already exist, VS would show a code error and give an option to generate a new empty function matching the signature provided in the function call.
In other words, same I am working in a particular Python function or class and I realize I need a new function to process some string. In my current function I type processString(myString), which returns an error because the processString function does not currently exist. Is there some way to then click on the processString function call and create a new block in my module:
def processString(myString):
pass
Thanks in advance for your help.
Thank you #Eric Wilson.
If I type the function call processString(myString) then hit 'CTRL+1' the code completion/template window appears offering me the option to create a new class, method, assign to a field, or assign to a variable.
This was exactly what I was looking for.