I want to create a button that opens a popup that takes over some form fields. These fields can be modified / filled in. When closing the fields concerned are updated. without saving or creating the record before I click on the save button. I don't see how to get there knowing that there are no relational fields. Should I create a widget, a wizard, both .... Help me please.
Here is my current code :
test_scale.py :
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class TestScale(models.Model):
_name = 'test.scale'
name = fields.Char(required=True)
weighing = fields.Integer('weighing', default=0)
test_scale.xml :
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="test_scale_tree_view" model="ir.ui.view">
<field name="name">test.scale.tree</field>
<field name="model">test.scale</field>
<field name="arch" type="xml">
<tree string="Test scale">
<field name="name"></field>
<field name="weighing"></field>
</tree>
</field>
</record>
<record id="test_scale_form_view" model="ir.ui.view">
<field name="name">test.scale.form</field>
<field name="model">test.scale</field>
<field name="arch" type="xml">
<form string="Test scale">
<sheet>
<group name="main_info">
<field name="name"></field>
<field name="weighing"></field>
<button name="%(test_scale_configurator_action)d"
type="action"
string="Weighing"
class="oe_highlight"
context="{'weighing': weighing}"></button>
</group>
</sheet>
</form>
</field>
</record>
<record id="saisie_menu_action" model="ir.actions.act_window">
<field name="name">Test_scale</field>
<field name="res_model">test.scale</field>
<field name="type">ir.actions.act_window</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Aucun enregistrement
</p>
</field>
</record>
<menuitem id="test_scale_menu"
name="Test_scale"/>
<menuitem id="test_scale_saisie_menu"
parent="test_scale_menu"
name="Saisie"
action="saisie_menu_action"/>
</odoo>
test_scale_configurator.xml :
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="test_scale_configurator_view_form" model="ir.ui.view">
<field name="name">test.scale.configurator.view.form</field>
<field name="model">test.scale.configurator</field>
<field name="arch" type="xml">
<form>
<field name="weighing"/>
<footer>
<button type="object"
name="button_save"
string="Save"
/>
<button special="cancel"
string="Cancel"
class="btn-secondary"/>
</footer>
</form>
</field>
</record>
<record id="test_scale_configurator_action" model="ir.actions.act_window">
<field name="name">Test Scale</field>
<field name="res_model">test.scale.configurator</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="view_id" ref="test_scale_configurator_view_form"/>
</record>
</odoo>
test_scale_configurator.py :
# -*- coding: utf-8 -*-
from odoo import models, fields
class TestScaleConfigurator(models.TransientModel):
_name = 'test.scale.configurator'
weighing = fields.Integer(string='weighing')
def button_save(self):
self.ensure_one()
return True
This thing is done by relational fields of odoo , For EX:-
In your
test.scale
model your field isweighing
,First you need to configure your current model
test.scale
's id in wizard so you can reference it, like this you can add the field in wizard.After that add
context
in you main model's xml file where is the button which one opens the wizard like this.After that this field needs to be invisible in your wizard's form in order to save data in wizard so you can refernce it later.
and in your wizard weighing field is stayed like this.
Note: This process , making field is one time process.
after that you can use any field which is in your main model and you want to use in wizard you can get those fields by
test_scale_id.any_of_your_field
.