Odoo Help

0
4 Answers
0
FEDERICO LEONI
3/9/19, 1:46 PM

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):

@api.multi
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'))
pos_obj._update_tree()
</field>
</record>

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.   

1
Avatar

Niyas Raphy

--Niyas Raphy--
14510
| 6 6 9
Calicut, India
--Niyas Raphy--

Odoo Techno Functionalist

Feel free to connect :  niyasraphyk@gmail.com

Twitter:https://twitter.com/niyasraphy
LinkedIn: https://www.linkedin.com/in/niyasraphy/
FB:https://www.facebook.com/niyasraphy123

Happy to help :)

Niyas Raphy
3/8/19, 8:50 PM

Hi,

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.

@api.multi
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
pos_rec.function_name()
return res


Thanks

1 Comment
FEDERICO LEONI
3/9/19, 11:51 AM

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
Writer
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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now