Is it possible to show many2many_checkboxes values in multiple Lines in Odoo? - odoo

Just i want to know is there any possibility to show the many2many_checkboxes in multiple lines?
For a field i have given like,
<field name="sports_ids" widget="many2many_checkboxes" options="{'no_create_edit': True}" nolabel="1"/>
Now, how can i show all the check boxes in 3 lines?

You can achieve this by creating new widget for many2many field.
Create static folder with js, css, xml
Add new widget to odoo
instance.web.form.widgets.add('many2many_mycheckboxes',
'instance.web.form.MyCheckBoxes');
And then create widget
Good luck

You can also give CSS style "column-count" for that particular field.

Related

How to loop for each record in One2Many field in form view to create dynamic elements?

I have a customized One2Many field that contains several records for this current data.
I am working on a form view.
I need to construct something like this: (I don't want a tree)
<for every record in one2many_field>
<button something...>
</for>
I only want the result as to create 1 button per record in the one2many_field and be able to get the data in some fields from the model of the one2many_field too.
Is there any way to achieve it? I have searched for some time but found nothing even remotely close to this requirement.
You won't be able to achieve that in a Form View. Views in Odoo are kind of strict but it's mostly to avoid bad stuff to happen.
Anyway, you could think about re-creating the full view by yourself using QWeb View (doc for v14 here)
If you want to keep your Form View, you'll have to use a tree inside the form.
Know that you can totally add buttons in Tree views like adding on a sale.order.line something like <button class="btn btn-primary" type="object" name="product_id_change" string="Force Product Id Change"/> (useless, just for the example)
Check example image here
And play with some attrs to change the visibility of fields...
Hope it helped :)

Odoo 10: Change datetime picker options for a field

This is with Odoo 10 and the default bootstrap-datetimepicker.
I have a field in my view that has a "Start of event" datetime. I'd like the date picker that shows up to work in 5 minute intervals (minuteStepping: 5) and to show the time picker along with the date picker (sideBySide: true).
I've confirmed that this works as I want it to by editing addons/web/static/src/js/widgets/date_picker.js manually.
However, I'd prefer to just give the two options I want to change as a parameter to my <field ..> definition under my <form> tag in the view XML. The source Widget accepts an options parameter in its init method that it extends to end up with the final options object, but I've been unable to insert my configuration options into this object.
I tried giving it as <field ... options="{...}" and as .. t-field-options='..', but I'm guessing the latter won't work since I'm not in a qweb context in my view, and the first one isn't read by widgets.
Is there any way I can do this without creating a new widget? (and hopefully without subclassing or extending the existing widget, but keep it as a pure view configuration option instead)?
You can see a great example in this module. https://github.com/OCA/web/tree/10.0/web_m2x_options
In the file. static/src/js/form.js.
The module has overridden the fields Many2one to add different options can be set in the XML declaration of field.
Example : <field name="partner_id" options="{'search_more':true}" />
In this example. The search more button is visible in all cases.
You can use the logic of this module as a base of your widget extension.
Installation:
In a First time, you must download the Github repository.
https://github.com/jo541/web
Select the branch 10.0.
In the repository, there are a named module "web_widget_datepicker_options". This module gives you the possibility to specify any options as you want for a specific field.
After download and install the module on Odoo. You needing to reload the cache of your browser to be sure.
Modification:
Now you can modify your form view. For an example, I will use the view form sale.order.
In the form view sale.order, you have a field "date_order". If you would like to have the time step 5 by 5.
<field name="date_order" options="{'datepicker':{'minuteStepping': 5}}" attrs="{'invisible': [('state', 'in', ['sale', 'done', 'cancel'])]}"/>
All the options in the dict of the key datepicker will be adding to the option of the bootstrap datepicker.

How to define link text different in Odoo widget=url

I have made read only computed URL-field based on invoice number. It works nicely but I would like to produce text part only itself like 400:
400
Now it's producing whole link as text which is quite ugly
https://external_site_invoice?num=400
My Odoo fields are defined this way...
ext_invoice_number= fields.Integer(string="Ext number")
def _showlink(self):
for rec in self:
if rec.ext_invoice_number:
if rec.ext_invoice_number>0:
rec.ext_link="https://external site/invoice?num=%d" % (rec.ext_invoice_number,)
ext_link = fields.Char(string="Link",compute=_showlink,)
How can I define text part of URL in Odoo to be different than link? This is poorly documented or it's not possible?
you can define the text attribute in widget definition like that:
<field name="field_with_url" widget="url" readonly="1" text="My own text"/>
Regards

OpenERP. Add image into field dynamically in a tree view

I am using v7 and I want to show in a tree view a field with image icons (like a semaphore) depending of other field values in the same row.
Actually, I get the functionality I want with a function field and put the result as string but I really want it as an image. I don't know if is possible to return HTML from the function so I decided to do that with jQuery.
I implemented the jQuery code using the browser console and works but when I put the jQuery code in the view the "data-field" selector does not selected.
Please, can anyone explain me why or tell me another way to get my objective?
Lists
The root element of list views is tree. The list view's root can have the following attributes:
editable, default_order, colors, fonts, create, edit, delete, on_write, string
See more about ListView
You can achieve this by defining child elements button in list view.
I have added icon in product to show whether product is available / hold / sold based on product's status.
button
icon: icon to use to display the button
Xml code to display icon in listview.
<xpath expr="//notebook/page[#string='Order Lines']/field[#name='order_line']/tree[#string='Sales Order Lines']/field[#name='product_id']" position="before">
<field name="product_status" invisible="1" />
<button icon='Hold' readonly="1" attrs="{'invisible':[('product_status', '!=', 'hold')]}"/>
<button icon='Available' readonly="1" attrs="{'invisible':[('product_status', '!=', 'available')]}"/>
<button icon='sold' readonly="1" attrs="{'invisible':[('product_status', '!=', 'sold')]}"/>
</xpath>
NOTE
Remember base field on which you defined button's visibility must be
present on listview, doesn't matter whether it's visible or not but it
must be there, like product_status in above example.
base field must be store=True.
Why store=True ?
Reason: when you set any function field store=True then it will physically created in database, while you give this field name in
domain the odoo framework add this field directly in WHERE clause,
it will not access through browsable object, so if your field is
store=False then it won't be able to find that field and gives you an error.
icons must be present in web/static/src/img/icons.
if you want to keep icons in your custom module then you have to create the same hierarchy for that in side your module folder create /static/src/img/icons and keep all the icons there.
xpath is used to define at which location you want to add/update fields.
See more about xpath

Make a field invisible or readonly dynamically in Odoo 'Websites' (not in Form view)

In odoo 8 the website is generated from Qweb templates. The webpages can also contain fields (say like in the 'Contact Us' form).
In the normal Odoo Form view it is easy to make a field invisible or readonly dynamically based on the user entry in some other field.
How can the similar thing be done in the Website view?
You can use a t-if statement, wrapped around the field you want to hide. Something like:
<div t-if="o.company_id">
<span t-field="o.company_id.partner_id.name">
</div>
In this example, the "name" field will be hidden if "company_id" is not set.
Here's a link to the QWeb reference.
If you want to omit some fields on dynamic basis. You can use "t-if" in your template, When you print it QWEB.