default values on a related model - odoo-14

From my model I have a many2one relationship to res.partner
Such relationship "feeds" a dropdown field (menu)
Such dropdown field contains a list of partners and the last item is "Start writing", to create a new partner (see this picture; "Inizia a scrivere is the Italian for "Start writing")
I'd like the new partner being created to have some fields automatically assigned with some default values
I've been suggested to use an action with a context but in this case I'm not starting the creation of a new partner from a menu or button and I'm not sure how to call my action from the last item of the dropdown menu

you can apply a context attribute on a related field in a view
Like this
<field name="some_related_field_id"
context="{'default_field_to_be_set_on_the_related_model': 'some_value'}"/>
Please notice that the name of the field to be set is not
default_field_to_be_set_on_the_related_model
it is
field_to_be_set_on_the_related_model
The initial default_ is a convention to set default values
That's required, if you don't prefix the name of your field with default_ the thing won't work

Related

How to obtain the record ID of the selected item in a dropdown list in google app-maker

Summary
Obtaining the record ID of the selected item in a drop-down list or radio-button UI appears to be a common question, but I have not found the answer for Google AppMaker despite months of searching.
The example use case: is I wish to edit a product that belongs to a family:
Product - (N:1) --> Family
Product - (M:N) --> FeatureValues
Example
The product belongs to the family Credit Card.
The credit-card family has the following features: |Contactles
|Near field
|Rates
|Chip & Pin|
In the edit form if I change the family the product belongs to then the list of features will change and new values for the features will need to be entered. (Dynamic form)
Hierarchy table
The family, features and permitted values are held in a single hierarchy table:
Family
|
Features
|
Values
newValue._key appears to only work for text-box UI items.
Dropdown list:
widget.datasource.item.Id or _key
provides the Product ID of the parent data source, ProductById (because I am editing a single product)
widget.datasource.selectKey(newValue._key); returns undefined
Sample code
Drop-down-list
OnValueChange event:
//update the features drop-down based on the taxonomy family selected
app.datasources.TaxonomyChildren.query.parameters.parent_fk = app.datasources.TaxonomyFamilies.item.Id;
app.datasources.TaxonomyChildren.load();
If I can pick up the record ID for the selected family in the dropdown list I can set a query.filter.parameter to show the features and values for the newly selected family.
Note: if it is a case you cannot create 'dynamic' forms in Google app-maker, then I'll stop as this has exhausted a lot of time.
Markus wrote:
So leave the options and value settings but in the onValueEdit run your query against TaxonomyChildren by passing in newValue.id to the query
Great Markus, that worked. On the drop-down ValueEdit event I call the function loadTaxonomyChildById(newValue.Id); passing it the Id of the selected TaxonomyFamily, changing the features displayed.

The method getKids() is undefined for the type PDField

https://issues.apache.org/jira/browse/PDFBOX-2148
When there are multiple copies with the same field name, the getFullyQualifiedName for each kid in the list of PDField objects returns the name of the parent, followed by .null. So if the parent field is called Button2 and it has 4 instances the result of printing out all the names will be:
Button2.null
Button2.null
Button2.null
Button2.null
According to the comments to the question, the OP refers to PDFBox 2.0.x versions, in particular 2.0.6.
getKids()
The method getKids() is undefined for the type PDField
In PDFBox 2.0.6 there are two immediate sub-classes of PDField. Different variants of the former (1.8.x) getKids() method are implemented in there:
PDNonTerminalField - the method retrieving the kids in this class is getChildren() and returns a List<PDField>, a list of form fields.
PDTerminalField - the method retrieving the kids in this class is getWidgets and returns a List<PDAnnotationWidget>, a list of widget annotations.
name of the parent, followed by .null
When there are multiple copies with the same field name, the getFullyQualifiedName for each kid in the list of PDField objects returns the name of the parent, followed by .null
This is not the case in PDFBox 2.0.x.
In the sample document attached to the PDFBox issue PDFBOX-2148 PDFBox now correctly finds only a single field which appropriately is named "Button2". This field is a PDTerminalField and has 4 widget annotations. The class of the latter, PDAnnotationWidget, has no getFullyQualifiedName method, so there are no ".null" names.
Thus, this problem is gone.
FQN of duplicate fields
(from the OP's comment responding to "What exactly is your question?")
how to get Fully Qualified Name of duplicate fields in pdfbox
There are no duplicate fields in (valid) PDFs, for a given name there is at most a single field which may have multiple widgets. Widgets do not have individual FQNs.
Thus, what you call "duplicate fields" in your example document actually is a single field with multiple widgets; the name of that field is "Button2" and can be retrieved using getFullyQualifiedName().
which page which form field
(from the OP's comments to this answer)
but how to get current page no in pdfbox.. for example there are 3 page and in page 2 there is a form field so how can i get which page which form field ?
All PDAnnotation classes, among them PDAnnotationWidget, have a getPage() method returning a PDPage instance.
BUT: As specified in ISO 32000-1, annotations (in particular form field widgets) are not required to have a link to the page on which they are drawn (except for screen annotations associated with rendition actions).
Thus, the above mentioned method getPage() may return null (probably more often than not).
So to determine the respective pages of your widgets, you have to approach the problem the other way around: Iterate over all pages and look for the annotation widgets in the respective annotation array.
For PDFBox 1.8.x you can find example code in this stackoverflow answer. With the information given in the previous parts of this answer it should be easy to port the code to PDFBox 2.0.x.
checkbox and radio button
(also from the OP's comments to this answer)
one more issue if i am using checkbox and radio button both then field.getFieldType() output is Btn for both. how to identify it?
You can identify them by inspecting the field flags which you retrieve via fields.getFieldFlags():
If the Pushbutton flag is set (PDButton.FLAG_PUSHBUTTON), the field is a regular push button.
Otherwise, if the Radio flag is set (FLAG_RADIO), the field is a radio button.
Otherwise, the field is a check box.
Alternatively you can check the class of the field object which for Btn may be PDPushButton, PDRadioButton, or PDCheckBox.
Beware: If a check box field has multiple widgets with differently named on states, this check box field and its widgets act like a radio button group! And not only in theory, I've seen PDFs with such check box fields in the wild.
To really be sure concerning the behavior of the fields, you therefore also should compare the names of the on states of all the widgets of a given check box.

MVC Complex ViewModel

I need to build a sample MVC UI app using Kendo UI.
I have 2 multiselect widgets for airline names and airport names respectively and below I have a grid with airline airport data.
Now when I select airlines or airports in the multiselect, upon clicking a Fetch button, the grid should refresh.
I created a ViewModel named AirlineAirportViewModel for containing List<Airlines>, List<Airports> and List<AirlineAirports>.
I instantiate the List<AirlineAirports> in the Get action method of the controller and fill the other two lists getting distinct airline and airport values from the List<AirlineAirports>.
While posting on filter button click, I am able to get action parameters as 2 List<string> types which contain only the selected multiselect items
Instead of that, I want this action parameter of type AirlineAirportViewModel so that in future, I will be able to add more filter widgets and the number of parameters stay one only.
Now, am I approaching this in the right way ? If I need the ViewModel as action parameter, where should I store the selected items from the multiselects ?

How to add one2many field of custom model to the tree view in Openerp?

I want to add a selection field to the form view and show the selection in tree view.
I first tried adding a custom selection field to the model but since I have many values to add to the selection field I bumped to the char(128) limit of the selection field of ir.model model.
Second I created a new custom model named x_newmodel with 3 fiedls with names x_name, x_code, x_description
added a one2many field x_newfield connecting to the x_newmodel solved the problem with the form view.
However when I try to add the new field x_newfield to the tree view I cannot get to show the data on the view.
My question is how can I add the field one2many relationship of the custom field to the tree view?
AFAIK, it is not supported.
What you could do is add a function field on your model which would compute
','.join(elem.name for elem in obj.x_newfield)
and use this in your tree display.
If you need to add a filter, you can implement the search function for your function field.

Automatic filling of NAME_1 when entered a valid KUNNR - SM30

I've made a table with three fields: KUNNR, NAME_1 and Z_CLASS. KUNNR has KUNNR as data element, NAME_1 has NAME1_GP and Z_CLASS has a data element that I made with 3 values (1, 2 or 3). I've made the table maintenance generator and put some data in with SM30. Now, I need to make the name of the client show automatically (NAME_1) when I enter a client number (KUNNR) and press enter; and need to make sure that the Z_CLASS is filled and not leaved in blank. I don't really know how to search for the solution because I'm new to SAP. Thank you.
PROCESS BEFORE OUTPUT.
MODULE LISTE_INITIALISIEREN.
LOOP AT EXTRACT WITH CONTROL
TCTRL_Z10FICLASSFICA CURSOR NEXTLINE.
MODULE LISTE_SHOW_LISTE.
ENDLOOP.
*
PROCESS AFTER INPUT.
MODULE LISTE_EXIT_COMMAND AT EXIT-COMMAND.
MODULE LISTE_BEFORE_LOOP.
LOOP AT EXTRACT.
MODULE LISTE_INIT_WORKAREA.
CHAIN.
FIELD Z10FICLASSFICA-KUNNR .
FIELD Z10FICLASSFICA-NAME1 .
FIELD Z10FICLASSFICA-Z_CLASS .
MODULE SET_UPDATE_FLAG ON CHAIN-REQUEST.
ENDCHAIN.
FIELD VIM_MARKED MODULE LISTE_MARK_CHECKBOX.
CHAIN.
FIELD Z10FICLASSFICA-KUNNR .
MODULE LISTE_UPDATE_LISTE.
ENDCHAIN.
ENDLOOP.
MODULE LISTE_AFTER_LOOP.
As for the name, do not keep it as a reundant field. Define a foreign key relationship and then use a maintenance view to display the name that corresponds to the customer number.
For the mandatory field check, edit the generated screen and add a module that checks whether the required fields are filled out. It should also be possible to set the field to mandatory in the screen field options, but I wouldn't recommend this because then the field will be displayed as mandatory even for empty lines.
I've found the answer for both problems. For automatic filling the name of the client I used a form routine with the event "Filling hidden fields" (no. 21). In the generated include I used this code:
FORM fill_hidden.
DATA: lc_name1 TYPE kna1-name1.
Data: lc_kunnr TYPE kna1-kunnr.
lc_kunnr = z10ficlassfica-kunnr.
SELECT SINGLE name1 INTO lc_name1 FROM kna1 WHERE kunnr = lc_kunnr.
z10ficlassfica-name1 = lc_name1.
endform.
For the mandatory field I went to Maintenance Screens, Element List tab, Special Attributes tab and choose mandatory from the drop down menu in the Entry column.
Worked like a charm. Thanks for all your answers :)