Progressbar second sum field - odoo

I added a second sum field to the kanban progress bar view and it looks like the following.
Now I want to give the same format to the second view, instead of 24000, that shows 24k.
I’m using this code:
<templates>
<t t-inherit="web.KanbanView.ColumnProgressBar" t-inherit-mode="extension">
<xpath expr="//div[hasclass('o_kanban_counter_side')]" position="after">
<![CDATA[ ]]>
<string name = "Bs"> Bs</string>
<t t-set="total" t-value="0"/>
<t t-foreach="widget.columnState.data" t-as="data_record">
<t t-set="total" t-value="total + data_record.data.expected_revenue_1"/>
</t>
<b class="mt-0">
<t t-esc="total"/>
</b>
</xpath>
</t>
</templates>
I tried using widget: ‘monetary’, also I read the odoo cookbook but can’t find anything that helps me

Related

Generate html and render in qweb

Is it possible generate html in .py file and render in qweb?
<openerp>
<data>
<record id="paperformat_time" model="report.paperformat">
<field name="name">Time</field>
<field name="font_size">10</field>
</record>
<report id="time_qweb" model="hr_timesheet_sheet.sheet" string="Time"
report_type="qweb-pdf" name="time.report_time" file="time.report_time" />
<record id="time_qweb" model="ir.actions.report.xml">
<field name="paperformat_id" ref="time.paperformat_time" />
</record>
</data>
</openerp>
qweb
<template id="report_time">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="t">
<span t-esc="t.__compute_html()" />
<div class="page">
<span t-field="t.html_text " />
</div>
</t>
</t>
</template>
.py file
class Time(models.Model):
_inherit = 'hr_timesheet_sheet.sheet'
html_text = fields.Html(string = 'Html')
#api.one
def _compute_html(self):
html_value = "<h1>TEST</h1>"
html_value += "<h1>TEST 2</h1>"
self.html_text = html_value
eg.
html_value = "<h1> + employee_id.name + "</h1>"
html_value += "<h1> + employee_id.phone + "</h1>"
now I need html_value render in qweb in put in <div class="page"> put here html_value </div>
Now I save text in database, any better solution?................................
Yes you can if you have a variable that have html code if you use t-esc or t-field odoo will print it as text.
If you want to render it use. t-raw
<div t-raw="doc.some_attribute" > </div>
Or
<t t-raw="doc.some_attribute" > </t>
You can try this
<span t-raw="my_html_field"/>
Here my_html_field is your html formated data
Since Odoo version 15, t-raw is deprecated. You need to render the HTML in a safe way using Python, then parse that into XML. Reference
import markupsafe
...
class YourController(http.Controller):
...
#http.route(...)
def your_rendering_method(self):
...
return request.render("YOUR_TEMPLATE", {"YOUR_FIELD": markupsafe.Markup("<a href='https://www.stackoverflow.com'>Stack Overflow</a>")})
<t t-esc="YOUR_FIELD" />

How to extend a qweb template in Odoo?

Im trying to extend the point of sale, template to modify the web ticket and the printed version also.... I want to put a codebar with the id numbe. But reading and testing my code doesn't work.... For testing purpuse I put a text in several parts of the template to watch if it is modify... but it's not.
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-extend="XmlReceipt">
<t t-jquery=".receipt-change" t-operation="inner">
<div><span>hello world</span></div>
</t>
</t>
<t t-extend="PosTicket">
<t t-jquery=".receipt-orderlines .product_line" t-operation="inner">
<div><span>hello world</span></div>
</t>
</t>
<t t-extend="PaymentScreenWidget">
<t t-jquery="div.pos-payment-container" t-operation="inner">
<div>
Payment Screen Modified
</div>
</t>
</t>
</templates>
This code is in a file name pos.xml and I append it from openerp.py like this:
'qweb': ['static/src/xml/pos.xml'],
Why the XmlReceipt or the PosTicket or the payment template are not extending????
Then when I sucessfully extend the template, Im gonna try to replace the hello world with
<barcode encoding="CODE128"><t t-esc="o.id"/></barcode>
Thanks!
[EDIT]
Ok, now I'm extending the template, but I cant generate the barcode from the order.sequence_number
I'm trying like this:
<img class="img-responsive" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('Code128', order.sequence_number, 500, 100)" style="width:250px;height:50px;"/>
The barcode its not generate like this... but if I do it like this it is
<img t-att-src="'/report/barcode/Code128/*mycode*'" style="width:250px;height:50px;"/>
So I think the error is in the string rendering.....
This is how I extends the mail chatter in odoo-10 and it's working fine for me.
Take a look, may be its help if still needed.
<templates>
<!--
Chatter composer
-->
<t t-extend="mail.chatter.ChatComposer">
<!-- Insert information before the composer -->
<t t-jquery=".o_composer_suggested_partners" t-operation="replace">
<!-- List of followers -->
<div class="o_composer_suggested_partners">
<t t-foreach='widget.suggested_partners' t-as='recipient'>
<div t-attf-title="Add as recipient and follower (reason: #{recipient.reason})">
<input type="checkbox" t-att-data-fullname="recipient.full_name"/>
<t t-esc="recipient.name"/>
<t t-if="recipient.email_address">(<t t-esc="recipient.email_address"/>)</t>
</div>
</t>
</div>
</t>
</t>
</templates>

Odoo - Change create button text

I am using Odoo 10e. In tree view or in form view for my particular model, i want to change the create button text to Add New User. How can we achieve this?
I tried to use Xpath for this, but as far as i know Xpath is use to inherit from a view and add something in the view not to change the item in the parent view
Create one xml file and write this below code in it.
For listview and formview it will change the name of create button as per your custom string.
Add this xml file path to qweb section in manifest file.
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="ListView.buttons">
<t t-jquery=".o_list_button_add" t-operation="replace">
<button type="button" class="btn btn-primary btn-sm o_list_button_add" accesskey="c">
<t t-if="widget.model === 'sale.order'">
Your String
</t>
<t t-if="widget.model !== 'sale.order'">
<t t-esc="widget.options.addable"/>
</t>
</button>
</t>
</t>
<t t-extend="FormView.buttons">
<t t-jquery=".o_form_button_create" t-operation="replace">
<button t-if="widget.is_action_enabled('create')" type="button"
class="btn btn-default btn-sm o_form_button_create" accesskey="c">
<t t-if="widget.model === 'sale.order'">
Your String
</t>
<t t-if="widget.model !== 'sale.order'">
Create
</t>
</button>
</t>
</t>
</templates>
I hope this answer will help you.
Simply just xpath to that button.
Then give position replace and change the string to Add New User from Create.
Try the code like this.
But remember the name of the button will be as it is.
Thanks
<xpath expr="//button[#name='action_set_create']" position="replace">
<button name="action_set_create" string="Add New User"/>
</xpath>

Conditionally extend template with Odoo QWeb

I added a boolean field to my stock.picking.type model called x_is_dropship_aggregate_picking_type. This field is False for all picking types in my database except for one.
I am trying to make some changes to the Kanban card for the picking type that has x_is_dropship_aggregate_picking_type == true, but I can't seem to get it to work.
Here's my template created through the Odoo V10 UI. It inherits from the stock.picking.type.kanban view:
<?xml version="1.0"?>
<data>
<xpath expr="//field[#name='count_picking_backorders']" position="after">
<field name="x_is_dropship_aggregate_picking_type"/>
</xpath>
<templates>
<t t-extend="kanban-box">
<t t-if="record.x_is_dropship_aggregate_picking_type.raw_value" t-jquery="button" t-operation="replace">
<button class="btn btn-primary">
<span>100 To Receive</span>
</button>
</t>
</t>
</templates>
</data>
As you can see on this line:
<t t-if="record.x_is_dropship_aggregate_picking_type.raw_value" t-jquery="button" t-operation="replace">
I am attempting to only alter the parent template if the value of this field is true. Unfortunately, every Kanban card within the view is getting changed, not just the one I want. It seems that t-if and t-jquery do not working together in that way.
Is there any way to conditionally alter this view and leave it unchanged otherwise?

QWebException: "'NoneType' object has no attribute 'with_context'" while evaluating "doc.with_context({'lang':doc.partner_id.lang})"

I am new to odoo, I created a module by inheriting sales_order to create a custom report. I am getting the above error when I am printing the report. Need help please?
Here is the code snippets:
test/my_module.py:
class sale_order(models.Model):
_name = 'sale.order'
_description = 'Inheritance'
_inherit = 'sale.order'
test/views/report_template_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="test_report">
<t t-call="report.html_container">
<t t-call="report.internal_layout">
<t t-set="doc" t-value="doc.with_context({'lang':doc.partner_id.lang})"/>
<div class="page">
<div class="oe_structure"/>
<div> <strong><left>User</left></strong>
<p t-field="doc.user_id"/>
</div>
</div>
</t>
</t>
</template>
</data>
How can I access records in custom_report_template?
i know i'm late but the name of the variable containing the recordSet passed to the template is docs not doc.
and you are trying to get value from a variable that don't have anything.
doc.with_context({'lang':doc.partner_id.lang})
i think you need to do docs not doc because doc is None
This why all template in loop docs :
<t t-foreach="docs" t-as="o">