I am trying to customize a report in Odoo 11. I am modifying an XML file, but I am getting this error:
File "/home/omar/odoo/odoo11/odoo/models.py", line 3094, in write
self._write(old_vals)
File "/home/omar/odoo/odoo11/odoo/models.py", line 3260, in _write
self._validate_fields(vals)
File "/home/omar/odoo/odoo11/odoo/models.py", line 1041, in _validate_fields
raise ValidationError("%s\n\n%s" % (_("Error while validating constraint"), tools.ustr(e)))
odoo.tools.convert.ParseError: "Error while validating constraint
Element '<t t-if="caseacocher">' cannot be located in parent view
Error context:
View `report_quotation_inherit_demo`
[view_id: 714, xml_id: moduletest.report_quotation_inherit_demo, model: n/a, parent_id: 637]
None" while parsing None:14, near
<data inherit_id="sale.report_saleorder_document">
Go Settings, select User Interface, and then Views. Enter in search field the following view: report_saleorder_document. Is a Qweb Type (report).
So, you are trying to inherit from this view and that t-if="caseacocher" can't be located here in parent view (report_saleorder_document). You are missing an xpath.
Where do you want to locate this in parent view? You will need to open this view and find something else from here that you can use in your module instead of that t-if. It must be exist here in parent view!
I suggest you to use xpath to find an expression and then put this condition.
For example, if div has a class named page, then you could use something like:
<xpath expr="//div[#class='page']" position="inside">
<t t-if="caseacocher">
<!--etc what ever you want put here-->
</t>
</xpath>
This is just an example, but you can then use your t-if inside the xpath.
Good luck.
Related
I am trying to add search input in Header Area in Odoo 10 Website. It works when visit /Shop page, but it gives Internal Error 500, on other pages.
My code in Main Layout is,
<t t-call="website_sale.search" />
Screenshot
How can I overcome this problem and make search option available from any page?
Not sure about v10, but in v14 you can remove a line in website_sale.search as a sort of quick workaround.
Comment or remove this line to avoid 500 error:
<t t-set="action" t-value="keep('/shop'+ ('/category/'+slug(category)) if category else None, search=0)"/>
It will probably look something like this in a module:
<template id="name_of_the_id" inherit_id="website_sale.search">
<xpath expr="//t/t/t[1]" position="replace">
</xpath>
</template>
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.
Is it possible with xpath exp in inherit qweb hide below line?
<t t-set="doc" t-value="doc.with_context({'lang':doc.partner_id.lang})" />
You have to use replace and you have to identify the correct node. So identify the node and replace it.
<xpath expr="//t[last()]" position="replace">
<!-- <t t-set="doc" t-value="doc.with_context({'lang':doc.partner_id.lang})" /> -->
</xpath>
I usually like to replace it with a commented out version of itself. Also the above will only work if the t tag is the last in the document.
You may have to capture a parent node and inject all of the existing xml with your desired t element commented out or removed. You may also be able to use these expressions or some variation of them.
expr="//div[#name='div_name']/t"
expr="//div[#name='div_name']/t[first()]"
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
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