Hide edit button according to status in openerp - odoo

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".

Related

Disable of submit button based on 3 fields(2 input fields and one checkbox) validation

I am trying to enable the submit button if user enters the Password field, the confirm Password field and checks the terms and conditions checkbox, if any of these field is blank, the submit button should get disabled.
For me the button is only getting enabled if user provides all of the above fields, but once it is enabled, the button is not getting disabled if user removes any of the field values and make it blank.
Can someone Please help ?
<div>
<wb-button v-bind:disabled="disableSubmitButton" v-if="showFinalSubmit" v-on:click="validatePassword" type="submit" size="m" variant="primary">
{{ t("submit") }}
</wb-button>
<div>

How to select radio button(contain Javascript) using Robot Framework?

Hope some expert in Robot Framework and Selenium or Selenium2Library could help me figure out how to select this radio button. I've tried many attempts and also search for the solution. The unique thing about this radio button is that it has a javascript in it. Also I'm using IE11 to automate this test.
This is the HTML Codes:
<td>Is turnover figure available?</td>
<td valign="baseline">
<input type="radio" name="turnOverAvailableInd1" value="Y" onclick="javascript:turnOverAvailableToggle(this);" id="turnOverAvailableInd1Yes">YES
<input type="radio" name="turnOverAvailableInd1" value="N" onclick="javascript:turnOverAvailableToggle(this);" id="turnOverAvailableInd1No">NO
</td>
My attempts that pass but does not select on the radio buttons(FAILS) are :
# Click Element xpath=(//input[#name, 'turnOverAvailableInd1'])[2]
# Click Element xpath=//*[contains(#id, 'turnOverAvailableInd1No')]
# Select Radio Button turnOverAvailableInd1 turnOverAvailableInd1No
# Radio Button Should Be Set To turnOverAvailableInd1 No
# Focus xpath=(//input[#name="turnOverAvailableInd1"])
# Press Key xpath=(//input[#id="turnOverAvailableInd1No"]) \\13
#Execute Javascript javascript:turnOverAvailableToggle(this);
Thank you in advance.
I think
Click Element turnOverAvailableInd1No
should work, i've had a similar situation.
You don't have to always use xpaths, the id or the name can be also used as locators.
Radio Button Should Be Set To checks that your radio button is selected (out of a group of radio buttons, only if the group is defined).
In the SeleniumLibrary Documentation for the keyword Select Radio Button
arguments: group_name, value
Sets radio button group group_name to value.
The radio button to be selected is located by two arguments:
group_name is the name of the radio button group.
value is the id or value attribute of the actual radio button.
The Group Name refers to common name that the Radio elements have. The Value refers to the value attribute.
So that would make the right approach:
Select Radio Button turnOverAvailableInd1 N

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.

Selecting the correct "Add" button

I have a field that has a "+" Add button in case you want to add more lines. I want to add 2-3 lines with it, then to click on the "+" button from a newly created line to create 2-3 more. The problem is that all buttons are declared the same:
<button class="ng-scope" ng-if="formData.order_request_status == STATUSES['OPEN']" ng-click="addImportMaterial()" style="margin-left: 3px;" type="button">+</button>
I have written the following xpath:
//button[#ng-click='addImportMaterial()']
but this selects all plus buttons and I want only the third one to be pressed. Any ideas? Thanks!
You should try using xpath with index then as below :-
I want only the third one to be pressed
(//button[#ng-click='addImportMaterial()'])[3]
So, (Assuming your using java) use above xpath to locate third button and click as :-
driver.findElement(By.xpath("(//button[#ng-click='addImportMaterial()'])[3]")).click()
Since you will be getting a List of buttons, to press the third one you just have to do buttons.get(2).click();

How to use a confirmation dialog box in Odoo?

I'd like to get a value in a confirmation dialog bow in odoo.
I have a form with a select. When I choose a value in the select and click the save button, I have a diablog box with a message. In this message I'd like to get the selected value.
Any idea ?
<button string="save"
icon="gtk-ok"
type="object"
name="update_year"
confirm="The selected year is XXXX. Confirm ?"/>