Skip to Content
Menu
This question has been flagged
1 Reply
10024 Views

For Example If i have 3 Fields - Amount 1 , Amount 2 , Amount 3

1. Amount 2 value should be default to Amount 1 value  & can be editable

2. Amount 3 value should be default to Amount 2 value & can be editable

XML View

<?xml version="1.0"?>

<odoo>

<record id="hr_expense_form_view_field" model="ir.ui.view">

<field name="name">hr_expense_additional_field</field>

<field name="model">hr.expense</field>

<field name="inherit_id" ref="hr_expense.hr_expense_form_view"/>

<field name="arch" type="xml">

<xpath expr="//field[@name='amount1']" position="attributes">

<attribute name="string">Amount1</attribute>

</xpath>

<xpath expr="//field[@name='amount1']" position="after">

<field name="amount2" attrs="{'readonly': True}" />

<field name="amount3" attrs="{'readonly': True}"/>

</xpath>

</field>

</record>

.py File

class Expense(models.Model):

_inherit = 'hr.expense'

amount2 = fields.Float(string='Amount2')

amount3 = fields.Float(string='Amount3')

Avatar
Discard
Best Answer

Use onChange as below:

@api.onchange('amount1')
def _onchange_amount1(self):
if self.amount1:
self.amount2 = self.amount1

@api.onchange('amount2')
def _onchange_amount2(self):
if self.amount2:
self.amount3 = self.amount2

Avatar
Discard