tryton-flask defines an transaction decorator which has a user parameter that can be a user ID or a callable. This callable could use some information from the request to compute the user that initiated it.
may i know how to put the user parameter to transaction decrator during runtime?
example; in flask config TRYTON_USER=0 aka root. then I log in uding user1 with id =2.
how am I put id=2 to the decorator? @tryton.transaction(user=2) --> how to set in runtime?
But flask-tryton is not really the best option to interact with Tryton’s user. It was design with in mind the web_user module.
If you want to make a workflow tailored application, it is probably better to use User Application — trytond 5.3 documentation
Just some update, I have some work around. So to post for help:
Session management which I am using flask-login.
Write the tryton.transaction inside a function.
from flask_login import current_user, login_required
@bp.route('/', methods=['GET', 'POST'])
@bp.route('/index', methods=['GET', 'POST'])
@login_required
def write():
@tryton.transaction(user=current_user.get_id(), readonly=False)
def write_action():
Party = tryton.pool.get('party.party')
party, = Party.search([('id', '=', 2)])
Party.write([party], {'name': 'I am a supplier '})
return user
return write_action()
Hi @ced,
Sorry for reply you late, the solution propose is not working. Because the current_user still in nonetype.
In the end, I used “g” app context for to this purpose.
from flask import g
from flask_login import current_user, login_required
from app.inventory import bp
def get_id():
if 'uid' not in g:
g.uid = current_user.get_id()
return g.uid
@bp.route('/lot_register/<record("stock.move"):move>', methods=['GET', 'POST'])
@login_required
@tryton.transaction(user=get_id)
def lot_register(move):
title = _('Create Lot')
back_url = g.back_url
....