How can I format date in Odoo 10 QWeb report? - qweb

t-field-option is not working.
I have tried
<span t-field="o.date_invoice" t-field-options='{"format": "MM/dd/yyyy"}'/>

Instead of using
<span t-field="o.date_invoice" t-field-options='{"format": "MM/dd/yyyy"}'/>
use
<span t-field="o.date_invoice" t-options='{"format": "MM/dd/yyyy"}'/>
Hope that helps!

For those who arrive here from search engines, you can control display of date in form fields using widgets.
<field name="date_planned" widget="date"/>
or,
<field name="date_planned" widget="datetime"/>
In v12, the date/datetime fields are python date/datetime objects and not string representations. The following python formatting will work in v12 reports:
<span t-esc="o.date_invoice.strftime('%m/%d/%Y')"/>
https://www.odoo.com/groups/technical-62/technical-56392463

To display localized date strings. Try the following:
<span t-field="o.date_invoice" t-options="{"widget": "date"}" />

To delete the time section:
<span t-field="o.date_invoice" t-field-options='{"widget": "date"}'/>
Use t-field-options instead of t-options
Do not change the position of the quotes in t-field-options
This code respects the format date according to lang/country.

Try this.
<span t-esc="datetime.datetime.strptime(o.sale_id.confirmation_date, '%Y-%m-%d %H:%M:%S').strftime('%B %d,%Y')"/>
My Output is: May 28,2018

According to my experience, you have used the correct way to format Qweb date, but sometimes there is problem in other thing and odoo gives error somewhere else. Hope trying this code may be helpful.
<span t-field="o.date_order" t-field-options='{"format": "d MMMM y"}'/>
also use this code
<span t-field="o.date_order" t-field-options="{'format': 'yyyy-MM-dd'}" />
You can also do one thing as formatting the date variable in the model itself and then show it on your QWeb report.

Related

selenium xpath to fetch the value of element which has no id associated to it

I wanted to fetch the value 606 from the following code for selenium
<div class="price pad-15 per-person budget-pp marg-left-10 ">
<span>From</span>
<h2 class="size-28 dis-inblock">
<span class="size-22">£</span>
606
</h2>
<span>Per person</span>
</div>
Can anyone please help me with identifying xpath for the value 606. Thanks in advance.
XPath for element that contains 606 is:
//h2[span[text()="£"]]
You can fetch value with appropriate method in your programming language (like .get_attribute("text") or .text in Python')
Let me know in case of any issues
//div/h2/text() here is enough.
//text()[. = '606'] would be too (but I doubt it's what you require here!)
You can use below cssSelector as well :-
div.price.per-person > h2
(Assuming you're using Java) Now you can use WebElement#getText() to fetching the desired text after locating element using above selector, this would fetch text as £606, you can use some programming stuff to omit £ and get actual value which you want.

How to define current date with yaml in OpenERP?

I want to create the demo data on my module and use yaml to do this
and my problem is i want to create the current date on my demo
in xml
<field name="date_invoice" eval="time.strftime('%Y')+'-06-23'"/>
and my question is if i want to put in yaml what can i do ?
Some one please help me and thank you for you time to rend my word (sorry about my language :'|)
You can use
field_date: !eval time.strftime('%Y-%m-%d')
or if you want defined day code like this
field_date: !eval time.strftime('%Y-%m-24')

Output correct "datetime" <time> attribute (Umbraco/Razor)

I'm looking to output a timestamp of when content was published within Umbraco, in the correct format required by the HTML5 <time> element.
For example:
<time datetime="2012-02-28T20:00+00:00" pubdate>February 28, 2012</time>
Is there a way to achieve this within Umbraco or with Razor? I know with PHP there's a particular "W3C" way of outputting timestamps: http://goo.gl/sEFsh.
More info on correct formatting of this element can be found here: http://html5doctor.com/the-time-element/
How about this in razor:
#DateTime.Now.ToString("yyyy-MM-ddTHH:mmzzz")
This does not generate any output for seconds and milliseconds as in your example.
I think the format string you may be looking for is "o", like this (in razor):
#{
var now = DateTime.Now;
}
<time datetime="#now.ToString("o")" pubdate>#now.ToLongDateString()</time>
Produces this for me:
<time datetime="2012-02-28T11:41:50.3697628-05:00" pubdate>Tuesday, February 28, 2012</time>
It looks like the best option for this might be to use the global "UpdateDate" like this:
<time datetime="#Model.UpdateDate.ToString("yyyy-MM-ddTH:mmzzz")" pubdate>
#Model.UpdateDate.ToLongDateString()
</time>
Seems to output the desired format and the date published rather than the current date. Can anyone see any issues with this solution?
Use .ToString("s")
<time datetime="#Model.UpdateDate.ToString("s")">...</time>
The output will generate: "2013-02-15T21:15:07" and pass html validation
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx
I usually just use this code in cshtml
#yourDate.Date.ToString("yyyy-MM-dd")T00:00+00:00

How to preserve spaces in hyperlinks when converting restructured text to html?

I'm using python docutils and the rst2html.py script to convert restructured text to html.
I want to convert a line like this:
Test1 `(link1) <C:/path with spaces/file.html>`_
Into something like this:
<p>Test1 <a class="reference external" href="C:/path with spaces/file.html">(link1)</a>
But instead I get this (spaces in path are dropped):
<p>Test1 <a class="reference external" href="C:/pathwithspaces/file.html">(link1)</a>
How do I preserve the whitespace in links?
I don't know how you are grabbing the line from the file (or stdin), but you should convert the link related string to HTML entities. You can find more information in the following link Escaping HTML - Python Wiki.
Hope this help you.

HTML:Server Tag Not well Formed

Hi all I get the Server Tag Not Well Formed error on the following line of code.
<a class="button"><span><input id="btnEmbedCodes" type="button"
value="Click for Embed Codes" onclick='javascript:window.open("%=ExternalLink%>","ExternalFeeds","height=575,width=675,
scrollbars=yes,overflow-x:hidden")'; Style="width:165px" /></span></a>
Please help me out. Thanks
window.open("%=ExternalLink%>"
In this starting "<" is missing. Seems like that is the problem.
It looks like you missed a < in the first argument of your javascript function
You are missing the opening bracket before ExternalLink
You have missed less than sign (<) before ExternalLink and also surround it with single quotes rather than double quotes.
Thanks.

Resources