How to get the value of the selection field other than the key in q-web reports odoo 12? - odoo-12

I have a selection field like
field = fields.Selection([('a', 'A'), ('b', 'B')],string='Test')
When i tried fetching the selected element in the selection field the key 'a' is getting printed to the pdf, i needs to print the 'A'
<t t-esc="med['field']"/> #med is one2many line connecting model A to the B,i'm trying to fetch the datas from model B(Notebook),

I don't know about older versions, but atleast in Odoo 13.0 just use t-field instead of t-esc so Odoo will get the right value for you. Simple example:
<span t-field="med.field" />

Related

Laravel Backpack PageManager - Can't add page (Field 'template' doesn't have a default value)

Trying to add a new page in a Laravel BackPack project, using the PageManager addon gives the following error:
SQLSTATE[HY000]: General error: 1364 Field 'template' doesn't have a default value
Expanding the Ignition error message shows the following:
INSERT INTO
`pages` (
`name`,
`title`,
`slug`,
`content`,
`extras`,
`updated_at`,
`created_at`
)
VALUES
(
dghj,
fghj,
fghj,
?,
{ "meta_title": NULL,
"meta_description": NULL,
"meta_keywords": NULL },
2022 -09 -12 16: 19: 59,
2022 -09 -12 16: 19: 59
)
...there's no sign of a template in this query but (I believe) it should be added by the PageManager addon so isn't something I have control of.
None of the frames in Ignition show files I've worked on, they're all illuminate or vendor files, however I've set up a new base app containing Laravel, Backpack and Backpack PageManager only, which works as expected so I don't think this is a bug in a package. I'm at a loss as to what I've done wrong or how to go about finding/resolving the problem.
Further info:
Selecting a template in the CRUD view DOES prompt the JS pop-up 'Are you sure you want to update the page template', confirming DOES update the URL to include the GET parameter e.g. [domain]/admin/page/create?template=standard
PHP Version: 8.1.9
Backpack version: 5.3.12
I also have the MenuCRUD addon installed which is reliant upon PageManager and is working as expected.
I managed to find the issue.
For whatever reason a view had been published to resources\views\vendor\backpack\crud\fields\select_page_template.blade.php
This file included:
<select class="form-control" id="select_template" name="select_template" ... >
Changing the name to 'template' resolved the issue:
<select class="form-control" id="select_template" name="template" ... >
Neither of these variations match what's in the original version of the file here, which doesn't even include a name attribute on the input. I'm not sure why mine does, but is all seems to be working now so I'll let sleeping dogs lie and leave this page up in case it benefits anybody else.

icefaces 1.8.2: update a table with many selectOnemenu depending on a selectOnemenu

I have a ice:selectOneMenu with a list of cars. I need that, when I select a car, an optionals table with many selectOneMenu is updated and default values are automatically selected.
So:
Cars: <select>
Optionals Table
-----------------------
Colors: <select>
Engines: <select>
Seats: <select>
Interior Color: <select>
...
...
The problem is thatI change the Cars value but the table is not updated and its values are not selected
So I want that:
if I select a Ferrari car, in the optionals table: the red color is automatically selected, the 3902CC engine is automatically selected, etc.
if I select a Porche car, the white color is automatically selected, the 616/16 engine is automatically selected,etc.
I'm using icefaces 1.8.2 and probably I can not use an ajax tag.
How can I do?
Thanks!!
I've found a workaround solution. Using:
JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(),javascriptCodeString);
to add Javascript code to the page.
The string javascriptCodeString must contain a Javascript code that use CSS classes to bind a click event to an hidden <ice:commandButton styleClass="updateFieldsCommandButton" ... > that will call an action (for updating fields values):
function updateFields() {
document.getElementsByClassName('updateFieldsCommandButton')[0].click();
}
var listOfFields=document.getElementsByClassName('fieldToBeUpdated');
for(var i=0,len=listOfFields.length;i<len;i++) {
listOfFields[i].addEventListener('change', updateFields);
}
This works with icefaces 1.8.2 without needing an ajax tag.

How can I pull data in a controller and form for one model that is in a different model with out a foreign key relationship?

I am new to rails and haven't really done to much with data outside of the model.
I have a form that references a table controller for files. I want to add an dropdown that will display a list of projects from a project table for the user to assign a the file to a project if they want too. Assigning a project is not a requirement. The file can be unassigned to a project. I do have a project_id column in the file table for those projects assigned but it is allowed to be null and I did not build a relationship because I need to have cases where there are none.
Can someone please tell me how to do this?
When they evaluate the file, the screen posts back with a save or update button depending if it has already been saved in the database.
At the same time as the save and update pop up on the right I want to display a list box of the projects with an assign project button. If new just a list, if update either just a list because not assigned or display the selected value in the list if already assigned, while allowing them to change it from the list if desired.
In the file controller method that posts back to the UI I have this code:
#file_alias_filedata = FileAliasFiledata.all
#projects = Project.all
for update
#projects = Project.find(params[:id])
In the form I have this code:
<p> <label> Select Project to Assign:</label> <br />
<%= select_tag 'projects', (#projects.present? ? options_for_select(#projects, #selected_project) : []) %> </p>
The form runs but I get this in the dropdown box:
#<Project:0x))7ff531ab4518>
Can someone please help me figure out how to accomplish my task and why I see the strange box value?
What am I doing wrong?
Thank you for your help!
Assigning a project is not a requirement. The file can be unassigned
to a project. I do have a project_id column in the file table for
those projects assigned but it is allowed to be null
From the docs:
belongs_to(name, scope = nil, options = {}) public
Specifies a
one-to-one association with another class. This method should only be
used if this class contains the foreign key. If the other class
contains the foreign key, then you should use has_one instead. See
also ActiveRecord::Associations::ClassMethods’s overview on when to
use has_one and when to use belongs_to.
Methods will be added for retrieval and query for a single associated
object, for which this object holds an id:
association(force_reload = false)
Returns the associated object. nil is returned if none is found.
Likewise,
has_many(name, scope = nil, options = {}, &extension) public
Specifies
a one-to-many association. The following methods for retrieval and
query of collections of associated objects will be added:
collection(force_reload = false) Returns an array of all the
associated objects. An empty array is returned if none are found.
But belongs_to() and has_many() are supposed to make things more convenient for you. You certainly do not have to use them.
Next,
and why I see the strange box value? What am I doing wrong?
You see the strange value for the same reason the following two loops display different things:
class Dog
attr_reader :name
def initialize(name)
#name = name
end
end
#dogs = [
Dog.new("Sam"),
Dog.new("Betty"),
Dog.new("Pete"),
]
#dogs.each {|dog| puts dog}
#dog_names = #dogs.map {|dog| dog.name }
#dog_names.each {|dog_name| puts dog_name}
--output:--
#<Dog:0x0000010099a308>
#<Dog:0x0000010099a2b8>
#<Dog:0x0000010099a268>
Sam
Betty
Pete
You will see the same result if you do something like the following in a view:
<div>
<%= select_tag "dog", options_for_select(#dogs) %>
</div>
<div>
<%= select_tag "dog_name", options_for_select(#dog_names) %>
</div>
If you read the docs here:
http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_for_select
...you will see several examples, which should make it clear that options_for_select() takes an argument that is:
An array of Strings.
A Hash where both the keys and values are Strings.
An enumerable that iterates over some Strings.
etc.
Do you see a pattern? It's Strings! options_for_select() needs an argument that consists of Strings. If the argument is not a collection of Strings, e.g. an array of project objects, then options_for_select() tries to convert the objects to strings by calling to_s() on the objects. And the default to_s() method is Object#to_s() which is inherited by all objects and produces a string containing the class name and the object_id.
I am also new to rails, but I think you can try using the options_from_collection_for_select method.
<%= select_tag :search_state, options_from_collection_for_select(State.find(:all, :select => :name), :name, :name) %>
Hope this help. Cause it certainly helped me.

How to select and store ContentElement UID in Flux FlexForm Configuration?

I'm currently building a TYPO3 PageTemplate with Flux and Fluidpages (both GitHub Master-Branch).
I'd like to have the possibility to select a number of ContentElements from the PageTree and store the UIDs in a variable for later rendering.
My first approach combining a Flux TreeField with a RelationField:
<flux:form.sheet name="content" label="content settings">
<flux:field.tree
name="treetest"
label="treetest"
table="pages"
parentField="pid"
foreignLabel="title"
multiple="true"
minItems="0"
maxItems="1000"
size="8"
expandAll="false"
/>
<flux:field.relation
name="relationtest"
label="relationtest"
table="tt_content"
condition="AND tt_content.pid IN ({treetest})"
multiple="true"
size="8"
minItems="0"
maxItems="3"
/>
</flux:form.sheet>
This sadly results in a SQL-Error because the last condition is inserted as:
AND tt_content.pid IN (60|foo)
Where 'foo' is the title of a SysFolder with the UID 60.
Debug-Output in the frontend prints the field 'treetest' as:
treetest => '60' (2 chars)
and the condition for the field 'relationtest' as:
condition => 'AND tt_content.pid IN (60)' (26 chars)
Questions:
As a matter of fact, I'm missing something here and I'd appreciate any hint, where the crux is here?
Is there maybe a different solution to select a ContentElement from the PageTree?
1) It is possible that you have either a default value, an inherited value or somehow disconnected XML which contains the other value. To be 100% sure none of these are your cause, try the same on a completely new page. The expected result of your code and selecting a page UID, is exactly the value 60 - nothing more, nothing less.
2) You may find it easier to use a ###STORAGE_PID### marker in your foreign_table_where and selecting the page(s) allowed for content selection, as values in the Behavior tab when editing your content element or page. This value has the added benefit of being possible to allow only for certain users or usergroups, or admins only.

How to add Count of child table in EntityDataSource

I have an EntityDataSource that works to get row data from tblOrderFile as follows:
<asp:EntityDataSource ID="entityDataSourcePreorder" runat="server"
ConnectionString="name=iDBEntities"
DefaultContainerName="iDBEntities" EnableFlattening="False"
EntitySetName="tblOrderFiles"
Select="it.[pkOrderFileID], it.[fkOrderFileStatusID], it.[Filename], it.[CreateDate], it.[UserId]"
AutoGenerateWhereClause="True" EntityTypeFilter="" Where="">
I would now like to modify it to also return back the number of rows in child table tblOrderFileItem (with Entity Set Name tblOrderFileItems).
I found a way to get the Count to work by adding an Include directive as follows:
<asp:EntityDataSource ID="entityDataSourcePreorder" runat="server"
ConnectionString="name=iDBEntities"
DefaultContainerName="iDBEntities" EnableFlattening="False"
EntitySetName="tblOrderFiles" Include="tblOrderFileItems"
AutoGenerateWhereClause="True" EntityTypeFilter="" Where="" >
</asp:EntityDataSource>
but I believe this is returning the all the columns of all the rows for each Order Item. I only really want the Count and do not want to deliver the rest of the data to the web page.
I also tried simply adding it.tblOrderFileItems.Count to the Select statement but get an error saying
'Count' is not a member of 'Transient.collection[MyDBModel.tblOrderFileItem(Nullable=True,DefaultValue=)]'. To extract a property of a collection element, use a subquery to iterate over the collection.
Select="ANYELEMENT(SELECT VALUE Count(c.ItemId) FROM it.tblOrderFileItems AS c) as ChildCount"