Call a python method in record rule Odoo - odoo

The common syntax of record rules is ['|',('user_id','=',user.id),('user_id','=',False)]]
Is there any possiblilties we can use a python method to get the dynamic ids of user?
For Example
['|',('user_id','=',getuserid()),('user_id','=',False)]

You can try something like,
xml:
['|',('user_id','=', user.env["your.model"].get_userid().id), ('user_id','=',False)]
Py:
def get_userid(self):
domain = []
return self.env["res.user"].search(domain)
Let me know if this works for you.

Related

How to implement conditional When method in Karate

I would like to reuse a feature both for POST-ing and PUT-ing a JSON Object. In order to achieve that I am trying to use a condition in the call:
Given param admin = admin
And request role
When method (role.id == null) ? karate.POST : karate.PUT
The error I get:
no step-definition method match found for: method (role.id == null) ? karate.POST : karate.PUT
I checked the documentation and the examples and search for the solution here, but I did not find an answer to this question.
Thanks in advance for the help.
You can use a variable for the method step:
* def action = 'GET'
* url 'https://httpbin.org/get'
* method action
Other than that I have no suggestions. I strongly advise you to not do this kind of "re-use" as it leads to un-readable and un-maintainable tests. Please read this once: https://stackoverflow.com/a/54126724/143475

Odoo - Call many function with action server

I would like to call many existing functions like action_confirm () from the server action without going through development. It's possible ? Can you help me ?
Thank you !
EDIT :
I managed to do this following method :
if records:
action = records.print_quotation()
for record in records:
record.message_post(body="1")
record.message_post(body=records)
record.message_post(body=record)
#record.print_quotation()
record.message_post(body="Lien bon de commande")
record.action_confirm()
# record.message_post(body="MESSAGE TEST ON LOGGER")
# record.message_post(body=record.action_confirm())
But I don't understand why action_confirm is in a loop and print_quotation is declare via action =. It works but I don't quite understand the logic. If I reverse the roles it doesn't work

How can I access value in sequence type?

There are the following attributes in client_output
weights_delta = attr.ib()
client_weight = attr.ib()
model_output = attr.ib()
client_loss = attr.ib()
After that, I made the client_output in the form of a sequence through
a = tff.federated_collect(client_output) and round_model_delta = tff.federated_map(selecting_fn,a)in here . and I declared
`
#tff.tf_computation() # append
def selecting_fn(a):
#TODO
return round_model_delta
in here. In the process of averaging on the server, I want to average the weights_delta by selecting some of the clients with a small loss value. So I try to access it via a.weights_delta but it doesn't work.
The tff.federated_collect returns a tff.SequenceType placed at tff.SERVER which you can manipulate the same way as for example client dataset is usually handled in a method decorated by tff.tf_computation.
Note that you have to use the tff.federated_collect operator in the scope of a tff.federated_computation. What you probably want to do[*] is pass it into a tff.tf_computation, using the tff.federated_map operator. Once inside the tff.tf_computation, you can think of it as a tf.data.Dataset object and everything in the tf.data module is available.
[*] I am guessing. More detailed explanation of what you would like to achieve would be helpful.

django "use_natural_foreign_keys=True" issue

I currently use the well documented "use_natural_foreign_keys=True" to return the relevant field data required instead of the id:
all_orders = Orders.objects.all()
resp = serializers.serialize('json', all_orders, use_natural_foreign_keys=True)
What I don't know how to do is return both the id AND the field data required as typically returned by the "use of use_natural_foreign_keys=True".
Anyone know of a quick fix to return both?
Many thanks, Alan.
define a "natural_key" method in your model class, whose id and field_name you like to get. e.g
def natural_key(self):
return (self.id, self.field_name)

From within a grails HQL, how would I use a (non-aggregate) Oracle function?

If I were retrieving the data I wanted from a plain sql query, the following would suffice:
select * from stvterm where stvterm_code > TT_STUDENT.STU_GENERAL.F_Get_Current_term()
I have a grails domain set up correctly for this table, and I can run the following code successfully:
def a = SaturnStvterm.findAll("from SaturnStvterm as s where id > 201797") as JSON
a.render(response)
return false
In other words, I can hardcode in the results from the Oracle function and have the HQL run correctly, but it chokes any way that I can figure to try it with the function. I have read through some of the documentation on Hibernate about using procs and functions, but I'm having trouble making much sense of it. Can anyone give me a hint as to the proper way to handle this?
Also, since I think it is probably relevant, there aren't any synonyms in place that would allow the function to be called without qualifying it as schema.package.function(). I'm sure that'll make things more difficult. This is all for Grails 1.3.7, though I could use a later version if needed.
To call a function in HQL, the SQL dialect must be aware of it. You can add your function at runtime in BootStrap.groovy like this:
import org.hibernate.dialect.function.SQLFunctionTemplate
import org.hibernate.Hibernate
def dialect = applicationContext.sessionFactory.dialect
def getCurrentTerm = new SQLFunctionTemplate(Hibernate.INTEGER, "TT_STUDENT.STU_GENERAL.F_Get_Current_term()")
dialect.registerFunction('F_Get_Current_term', getCurrentTerm)
Once registered, you should be able to call the function in your queries:
def a = SaturnStvterm.findAll("from SaturnStvterm as s where id > TT_STUDENT.STU_GENERAL.F_Get_Current_term()")