How to set default values in popus form view from parent tree view in odoo 12? - odoo-12

I have this tree view in odoo 12:
When I click in button "Editer liste de prix" of line 1, I get this form view:
How to have values of line 1 in popus view?

you have to define _default_field_name function for every field in you wizard, and you can get the reference to the father searching into the context, is an example:
def _default_a_field(self):
parent_id = self._context.get('active_id', False)
return self.env['parent.model'].search([('id', '=', parent_id)]).a_field_from_parent
a_field = fields.Char(default=_default_a_field)
I hope this answer can be helpful for you.

Related

Accordion dropdown filtering through ion search bar

Hi I just created the ionic accordion dropdowns by following a tutorial blog link which used widgets for creating an accordion dropdowns, Below is the link of that blog.
http://masteringionic.com/blog/2019-01-27-creating-a-simple-accordion-widget-in-ionic-4/
updated: here is the my project demo link https://stackblitz.com/github/dSaif/search-accordion
Everything is working perfect, but i want to add Ion-searchbar at the top of the accordions sothat the dropdowns gets filter by inputing text.
please assist me how can i do that. Thank you.
You are going to have to create a variable in your homepage to store your filtered results. Then you need to have a filter function that will take the input from the search bar and filter your master list. Keep in mind you should not set the new variable to the master list, this could cause issues due to object referencing.
So you should have something like
in your html
<ion-searchbar placeholder="Search a name." [(ngModel)]="searchValue" (ionChange)="filterList()"></ion-searchbar>
In your ts file
searchValue: string = '';
filteredList: Array<{ name: string, description: string, image: string }> = this.technologies;
// function called in the html whenever you change the ion searchbar value
private filterList(){
//Make a variable so as to avoid any flashing on the screen if you set it to an empty array
const localFilteredList = []
this.technologies.forEach(currentItem => {
//here goes your search criteria, in the if statement
if(currentItem.name && currentItem.name.toLowerCase().includes(this.searchValue.toLowerCase())) {
localFilteredList.push(currentItem);
}
});
//finally set the global filter list to your newly filtered list
this.filteredList = localFilteredList;
}
You also need to make sure to reference the filterList variable instead of the current one you are referencing.

Get tab status using pyforms

I'm working with pyforms to create a tab widget and I want to get and set the current active tab. Consider this example:
self.formset = [{
'Person A': ['_firstname', '_lastname'],
'Person B': ['_firstname', '_lastname'] }]
so we get 2 tabs Person A and Person B. If I switch between them I would like to be informed with something similar to PyQt function currentIndex(). So far I havn't been able to find a method in the pyforms documentation, is there a way to accomplish this just using pyforms?
The main issue in getting or setting the current index of your tab widget is to get access to the QTabWidget created by pyforms when the layout is generated. Once you have access to it, you simply call the setCurrentIndex(int)/currentIndex() of the widget.
A (dirty) quick fix to this is to modify the BaseWidget.py located in the pyforms module files which can be <VIRTUALENV_DIR>/lib/python3.6/site-packages/pyforms/gui when using virtualenv.
def generate_tabs(self, formsetdict):
"""
Generate QTabWidget for the module form
#param formset: Tab form configuration
#type formset: dict
"""
tabs = QTabWidget(self)
for key, item in sorted(formsetdict.items()):
ctrl = self.generate_panel(item)
tabs.addTab(ctrl, key[key.find(':') + 1:])
self.tabs = tabs
return tabs
Note the additional :
self.tabs = tabs
Then in the code of your widget/app (subclass of BasicWidget) :
>>> _t = self.tabs
>>> _t.setCurrentIndex(3) # activate the 4th tab
>>> print(_t.currentIndex())
3

Title for Tabbed Panel in wicket

I am working with TabbedPanel in wicket. I have created a TabbedPanel for my search page
My requirement is to create a TabbedPanel with title and three tabs. I am using additional tab (Dummytab in this case) to compensate the title. Please, suggest me how to create a title tab.
First tab is dummy tab and it is active. I want the Search 1 tab to be default tab and Search: tab to be inactive and just represent the title for the TabbedPanel.
Thanks in advance.
I think that you can simply override TabbedPanel's newLink method to replace real link via some container for first tab. It would be something like that:
TabbedPanel tp = new TabbedPanel (...) {
{
#Override
protected WebMarkupContainer newLink(final String linkId, final int index)
{
return (index > 0) ? super.newLink(linkId, index) :
new WebMarkupContainer (linkId);
}
};
tp.setSelectedTab( 1 ); // selecting `Search 1` tab after tp creation;
Also, if you want to prevent selecting first tab programmaticaly - you should play around with overriding setSelectedTab method.
As an alternative: subclass TabbedPanel and provide your own custom markup.

How to get the parent of an element

For example, I am randomly picking a button element from within the rows of a table.
After the button is found, I want to retrieve the table's row which contains a selected button.
Heres is my code snippet:
browser.findElements(by.css('[ng-click*=submit]')).then(function (results) {
var randomNum = Math.floor(Math.random() * results.length);
var row = results[randomNum];
// ^ Here I want to get the parent of my random button
});
As of the most recent Protractor (1.6.1 as of this writing), the syntax changed a bit:
var row = results[randomNum].element(by.xpath('..'));
(use element() instead of findElement()).
Decided to use xpath.
var row = results[randomNum].findElement(by.xpath('ancestor::tr'));
You can now use
var element = element(by.css('.foo')).getWebElement()
var parentElement = element.getDriver() // gets the parent element
to get the parent element. See http://www.protractortest.org/#/api?view=webdriver.WebElement.prototype.getDriver for more info.
Actually, at the moment there is an easier way to select the parent of an element avoiding to use xpath.
From an ElementFinder you can simply access the parent element through parentElementArrayFinder and for example then trigger directly the click method:
myElement.parentElementArrayFinder.click();

Knockout select binding

How to prevent select change event fires when the select biding is initiated? an add button on the page that will add select dynamically to the DOM. when each select box is adding to the DOM, the change event is firing rather than I select the item from the select?
The thing is that KnockoutJS attempts to find which element of your listbox matches the requiredItem observable. There is none in the beginning, which is why it then attempts to set it to the "caption" of the listbox. You did not provide one, so it sets requiredItem to the first element of the listbox.
What you could do is add a caption item to your array:
self.requireditems = ko.observableArray([
{ desc: "Select an option from the list...", key: 0, editable: false } // ... and then all other items]);
and if you really don't want requiredItem to be updated:
self.selectedItem = ko.observable(self.requiredItems()[0]);
Then if you want to know if a valid element has been selected from the list, you could add the following property:
self.isValidSelectedItem = ko.computed(function() {
return self.selectedItem().id;
});