Odoo Help

Welcome!

This community 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.

0

How to update the value of field of from view when update the field of tree view?

By
Thu Ra
on 10/23/15, 3:04 AM 599 views

How to update the value of field of from view when update the field of tree view?

I want to change the value of "total_location_qty" when I update the value of "location_qty".

This is my obj

class Demo(models.TransientModel):
    _name = 'demo.parent'
    demo_lines_ids = fields.One2many('demo.lines', 'demo_id', 'demo Items')
    total_location_qty = fields.Float(string='Total of location qty')

class DemoLines(models.TransientModel):
    _name = "demo.lines"
demo_id = fields.Many2one('demo.parent', 'Demo')
location_id = fields.Many2one('stock.location', 'Stock Location', readonly=True)
location_qty = fields.Float(string='Location Qty')

@api.onchange('location_qty')
def on_change_location_qty(self):
self.demo_id.total_location_qty = self.location_qty


This is my view

<record id="view_demo_wizard" model="ir.ui.view">
<field name="name">Demo</field>
<field name="model">demo.parent</field>
<field name="arch" type="xml">
<form string="Demo Parent">
<group string="Demo">
<group colspan="4">
<field name="total_location_qty" readonly="1"/>
</group>
<field name="demo_lines_ids" nolabel="1" >
<tree string="Demo Lines" editable="bottom" create="false" delete="false" >
<field name="location_qty"/>
</tree>
</field>
</group>
</form>
</field>
</record>

Hi did you try the answer?

Akhil P Sivan
on 10/25/15, 12:57 AM
0

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 10/24/15, 11:20 AM

Hi,

Try like this:

class Demo(models.TransientModel):
_name = 'demo.parent'
demo_lines_ids = fields.One2many('demo.lines', 'demo_id', 'demo Items')
total_location_qty = fields.Float(compute='_get_total_qty', string='Total of location qty')

@api.one
@api.depends('demo_lines_ids.location_qty')
def _get_total_qty(self):
s=0
for rec in self.demo_lines_ids:
s = s + rec.location_qty
self.total_location_qty = s


class DemoLines(models.TransientModel):
_name = "demo.lines"
demo_id = fields.Many2one('demo.parent', 'Demo')
location_id = fields.Many2one('stock.location', 'Stock Location', readonly=True)
location_qty = fields.Float(string='Location Qty')
0

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 10/24/15, 5:41 AM

You define method  @api.onchange('demo_lines_ids') in the model demo.parent instead of @api.onchange('location_qty')

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/23/15, 3:04 AM
Seen: 599 times
Last updated: 10/25/15, 12:57 AM