How To Pass Data From One Form To Another In Odoo14
PASSING DATAS FROM ONE FORM TO ANOTHER IN ODOO
- Here we want to pass datas from sale order to our new form name new data passing
- Then you can create one new class in model directory.
eg: class <ClassName>(models.Model):
_name=’your class.name’
field_name=fields.Type(“string”)
- Now you need to give one2many in form
- After that we have to pass data from sale order to our data passing form
- we use onchange method to pass data. first we need to search one field in sale order form and our form then we can mension all field.
eg: class DataPassing(models.Model):
_name = ‘data.passing’
customer_name=fields.Many2one(‘res.partner’,”Partner”)
sale=fields.One2many(‘new.data.passing’,’field’)
@api.onchange(‘parter_id’)
def onchange_customer_name(self):
datas = self.env[‘sale.order’].search(
[(‘partner_id’, ‘=’, self.customer_name)])
print(‘datas’,”datas”)
data = []
for line in datas:
values = (0, 0, {
‘product’: line.product_name.id,
‘quantity’:line.product_uom_qty,
‘unit_price’:line.price_unit
})
data.append(values)
self.sale = None
self.sale = data
class NewDataPassing(models.Model):
_name = ‘new.data.passing’
field=fields.Many2one(‘data.passing’)
product=fields.Many2one(‘product.product’,’Product’)
Quantity=fields.Float(“Qty”)
unit_price=fields.Char(“Unit Price”)
- Then You can create corresponding xml file. like this:
eg: <record id=”data_passing_id” model=”ir.ui.view”>
<field name=”name”>data passing form</field>
<field name=”model”>data.passing</field>
<field name=”arch” type=”xml”>
<form string=”New String”>
<sheet>
<group>
<field name = “customer_name”/>
</group>
<notebook>
<page string=”Sales Data”>
<field name = “sale”>
<tree>
<field name = “product”/>
<field name = “Quantity”/>
<field name = “unit_price”/>
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<record id=”action_record_sales_data” model=”ir.actions.act_window”>
<field name=”name”>Sale Data</field>
<field name=”res_model”>data.passing</field>
<field name=”view_mode”>form</field>
<field name=”context”>{}</field>
<field name=”help” type=”html”>
<p class=”o_view_nocontent_smiling_face”>
No Records !
</p>
</field>
</record>
<menuitem name = “New Data Passingr”
id = “sale_data_passing”
action=”action_record_sales_data”/>
- Then you can add the xml file in __manifest__.py file.
- Run the module