Odoo Help


4 Answers
09/03/19 13.46

Solved, even if  with a not so elegant, pythonic way.

On pos.adm I created a new def since is quite easy search for the correct one (pos_session.name =is equal to pos_adm.pos_ref):

def _update_tree(self):

pse = self.env['pos.session'].search([('name', '=', self.pos_ref)])
pse.write({'order_paid': pse.order_paid + 1})

Since order_paid field is just an index used to trigger function is not a problem use it to force a db check.

After that I simply wrote some lines of xml for a function called by a button.

    <record id = "update" model = "ir.actions.server">
<field name = "sequence" eval = "5"/>
<field name = "name">update_session</field>
<field name = "model_id" ref = "model_pos_adm"/>
<field name = "condition">True</field>
<field name = "type">ir.actions.server</field>
<field name = "state">code</field>
<field name = "code">
pos_obj = env['pos.adm'].browse(context.get('active_id'))

The button call:

<button name="%(update)d" string="Up" type="action"
class="oe_highlight" attrs = "{'invisible':[('state','!=','opened')]}"/>

Now I have a quicker real time update on my tree view.   


Niyas Raphy

--Niyas Raphy--
| 7 7 11
Wayanad, India
--Niyas Raphy--

Odoo Techno Functionalist

Feel free to connect :  niyasraphyk@gmail.com

LinkedIn: https://www.linkedin.com/in/niyasraphy/

Happy to help :)

Niyas Raphy
08/03/19 20.50


Inside the write function you can achieve this, check whether Vals contains order_paid value, if so you can execute your action. First of all what is the relation between pos.session and pos.admin ? You have to get it, then if you need to execute a function in the pos.admin model, you can search the records of pos.admin model and iterate over the loop and call the function.

def _write(self, vals):
res = super(divina_session, self)._write(vals)
if vals.get('order_paid'):
# if there is any search filters you can give it
pos_admin_rec = self.env['pos.admin'].search([])
for pos_rec in POs_admin_rec:
#here call the function in pos.admin model
return res


1 Comment
09/03/19 11.51

Niyas, thanks for your reply.

When an order is marked as paid, vals is reached two times (don't know exactly why) with tho different values. THe first time gets 'sequence_number' and the second one gets 'order_paid':

vals {'sequence_number': 17}

vals {'order_paid': 2}

Then I can intercept vals and make my call.

There is not a direct relation (nor related field) between pos.session and pos.adm.

The function on pos.session will create the basic data on pos.adm, and then the record will be populated from another function on pos.adm.

I know how to reach a function on another model (thanks anyway!) but the problem is calling by a button. I have update the thread title because was not clear.

Ask a Question
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Odoo Training Center

Access to our eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now