Create Radio Button condition in Odoo 9 - radio-button

I'm new learning about odoo.
I have a module with two class, and in my XML, i just wanna make a radio button for part of the class, for example on individual and company radio button, I want to make radio button with a different button which shows different fields from two class.
Thank You.

To do this, You must create a field Selection. In the XML of this field, you specify the widget radio button.
After for each field that is to be displaying in the view, you must add an attribute on the xml field to hide or display the value.
Example :
Python file
type = field.Selection(string='Type',selection=selection=[('val1', 'Val1'), ('val2', 'Val2')])
field1 = fields.Char(string='Field1')
field2 = fields.Char(string='Field2')
Xml file
<field name="type" widget="radio"/>
<field name="field1" attrs="{'invisible': [('type','=', 'val1'))]}"/>
<field name="field2" attrs="{'invisible': [('type','=', 'val2'))]}"/>
In this example, if the radio button has the value "val1" only the field1 is displaying. And if the radio button has the value 'val2' only the field2 is displaying.

Related

how make product name invisible when checkbox is true in other module?

I want to make that when I click true in (other)checkbox in the invoice,the (product) do not dispaly ( be invisible) in the invoice line and when I click false in the checkbox the product display
fields in the picture:
For Hiding based on other module field you can use
** attrs="{'invisible': [('your_other_module_field','condition','value')]}"**
<field name="your_field_to_hide" attrs="{'invisible': [('your_other_module_field','condition','value')]}"/>
But in this case You can not hide column. you have to use invisible="1"

How can I stop Odoo custom button from auto save?

I have created a button inside my view which triggers a method inside the module. However on clicking the button the temporary edited fields are saved and not reverted when clicking the 'Discard' button.
Here is the code for my view:
<form>
<sheet>
<group>
<field name="name" />
</group>
<button name="my_button" string="My Button" type="object" class="oe_edit_only" />
</sheet>
</form>
Once I click my_button the field name is saved in the database and the button Discard has no effect any more.
How can I prevent Odoo from saving the temporary data when clicking my custom button?
(I'm working with Odoo10 but I guess it's the same for older versions of Odoo)
You may be able to change your button into a Boolean field and make your my_button method an onchange.
Python
my_button = fields.Boolean('Label')
#api.multi
#api.onchange('my_button')
def onchange_my_button(self):
for record in self:
# whatever my_button does
If you want it to still display as a button, you can show the label styled as a button and hide the actual checkbox.
XML
<label for="my_button" class="btn btn-sm btn-primary"/>
<field name="my_button" invisible="1"/>
By default in odoo while any of the server side code will render once you trigger any event (Like button click) then record will be saved first anyhow and you will get the record in Self (Invoking object).
So once you click on that button it means that record has been saved in database and there will no effect of Discard after that.
The best example you can see in the Sales Quotation / Order there is one link "Update" which will just return True from the method it performs nothing but once that method will be called then the entire record will be saved and totals (all functional fields will be calculated) and you feel that update link performs calculation (that link is visible in edit mode only).
Generally in new api methods which are called from the button click should be having decorators #api.one or #api.multi.
##Single record will be there in self.
#api.one
def button_click(self):
return False
##list of records (recordset) will be there in self.
#api.multi
def button_click(self):
return False
So when you click that button that record save first and then method will be called.

show/hide fields based on selection in openerp 7

I have a selection field in openerp form
what I want is that when I select any value from this field , another field (which is hidden or invisible ) is shown automatically , based on the selected value.
I know that it is possible to show or hide a field checking or unchecking a boolean field in your view (e.g. needs_moreinfo).
<field name="moreinfo" attrs="{'invisible':['needs_moreinfo','=', false]}" />
I guess you could do the same, based on the IDs of the elements of your selection field. But it has to be hardcoded and you have to know in advance the ids in you DB...

Hide edit button according to status in openerp

I want to hide the edit button from the form in my module.But it should hide after changing the status to 'done'.I have three states for record (new,draft,done).If it is in 'draft' status I want to show the edit button . But if it is on 'done' state need to hide the edit button. I tried this
<form string="Consumption Result" edit="false" version="7.0">
But this cause always hide the edit button . How can I give condition here.
You can provide states="draft" for the button "edit" like below:
<button name="case_edit" string="Edit" type="object" states="draft"/>
with this definition the button is available when the states="draft" and not available at "new" and "done".

How may i increase the size of "Selection Options " of selection filed

i am creating a list of value by selection fields and giving values for user select by selection option property . but when i am doing for three or four item . it is going to good . but when i want to add more items in selection option then i am unable to do this task . selection option property is not giving me more space for adding new value.
so please any one give me solution so i'll add more values .
and other problem is that i've created a button in form . but i want that whenever any user press this button , a another fields should be display . and when again user will click on this button , a 3rd fields should be display.
i've created this 3 fields namely one,two,there.
syntax:-
if click "my" button , a another fields "two" should be display .
thank you
If you have more values in "Selection" field then you should create a class for those selection values and make your selection filed many2one. In your xml file make your field as selection using widget="selection"
For example:
class ur_class(osv.osv):
_columns = {'ur_field_name': fields.many2one('select.type', 'Select')}
ur_class()
class select_type(osv.osv):
_name = 'select.type'
_columns = {'name': fields.char('Type', size=50)}
select_type()
Now in ur xml use widget='selection' like this:
<field name="ur_field_name" widget="selection"/>
Now about your 2nd question to show fields from button click:
If you are changing state in button's method then you can use "attrs" attribute in your xml. You can find examples in addons.
Thank You,