field inheritance in POS (Odoo) - odoo-10

I've added the field 'limit' in 'res.partner' model in 'Sales'. Now, I want to inherit the same in my POS module during the Customer Creation.
I've included all my files(xml and js) in manifest.py with proper syntax.
My '.js' file is working completely fine. The problem shows in 'static/src/xml/pos.xml' file.
Here's my code of pos.xml file. No syntax error, still cant get 'limit' field in POS.
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template_test" xml:space="preserve">
<t t-extend="ClientDetailsEdit">
<t t-jquery=".client-details-right" t-operation="append">
<div class='client-detail'>
<span class='label'>Limit</span>
<input class='detail limit' name='limit' value="5000" readonly="True" t-att-value='partner.limit || ""'></input>
</div>
</t>
</t>
</templates>
Please, tell me if anything is wrong or missing!

Related

Odoo xpath expression rule

I'm developing a Qweb report in Odoo and I need to use xpath expressions for replacing some content.
This is the main template where is needed to make the replace of the content:
<template id="report_saleorder2_template">
<t t-name="report_saleorder2_template">
<t t-call="web.external_layout">
<div class="page">
<div class="oe_structure" />
<div class="row" id="report_data_0">
<h1>Annual voluntary contribution to Fecoas - Alcaste school</h1>
//more code
This is the other template where I'm tying to use the xpath expression for replacing the content:
<template id="report_saleorder3_template">
<t t-name="report_saleorder3_template">
<t t-call="custom_v12_reports.report_saleorder2_template" t-lang="doc.partner_id.lang" />
<xpath expr="//div[#id='report_data_0']/h1[1]" position="replace">
<h1>Annual AMPA's member fee Alcaste school</h1>
</xpath>
</t>
</t>
</template>
This is not working. Someone knows why?
Thanks for reading!
You have to inherit the origin template with inherit_id. Then you're able to use XPath expressions to change or add new code.
<template id="report_saleorder3_template"
inherit_id="module_name.report_saleorder2_template">
<xpath expr="//div[#id='report_data_0']/h1[1]" position="replace">
<h1>Annual AMPA's member fee Alcaste school</h1>
</xpath>
<!-- and other XPath expressions -->
</template>

How to set font size or bold on description record row on Qweb sale report?

<?xml version="1.0" encoding="utf-8"?><odoo> <data>
<template id="id_document" inherit_id="sale.report_saleorder_document">
<xpath expr="//tbody[#class='sale_tbody']//tr//td[1]" position="replace">
<t t-esc="layout_category['name']" style="font-weight: bold;"/>
</xpath>
</template> </data></odoo>
the following code doesn't work for me,please any suggestion thanks
Got a solution
<xpath expr="//div[hasclass('row','mt32','mb32')]/div[#t-if='doc.user_id.name']/p" position="attributes">
<attribute name="style">font-weight: bold;color:red;</attribute>
</xpath>
You can not use style attribute in <t t-esc> tag.
If you want to use style attribute then you must need to use any HTML tag like div, p, span
Here is an example.
<span style="font-weight: bold;"><t t-esc="layout_category['name']"/></span>
Try to use above code. Hope it will work fine. Upvote if the suggestion is working.

Odoo 10 :Adding field in templates by inheritance

I want to add "default_code" field in addons/point_of_sale/static/src/xml by inheriting it in my custom_module.
But getting these erros when Installing/Upgrading my custom module.
Here is my code :
<?xml version="1.0" encoding="UTF-8"?>
<templates id="pos_inh" xml:space="preserve">
<t t-name="ProductRef" t-extends="Product">
<t t-jquery='.product-name' t-operation='inside'>
<span t-esc="product.default_code"/>
</t>
</t>
</templates>
And here is the code where I want to add the default_code field :
<t t-name="Product">
<span class='product' t-att-data-product-id="product.id">
<div class="product-img">
<img t-att-src='image_url' />
<t t-if="!product.to_weight">
<span class="price-tag">
<t t-esc="widget.format_currency(product.price,'Product Price')"/>
</span>
</t>
<t t-if="product.to_weight">
<span class="price-tag">
<t t-esc="widget.format_currency(product.price,'Product Price')+'/'+widget.pos.units_by_id[product.uom_id[0]].name"/>
</span>
</t>
</div>
<div class="product-name">
<t t-esc="product.display_name"/>
</div>
</span>
</t>
Can you help me? Thank you very much
Please use the below code:
<?xml version="1.0" encoding="UTF-8"?>
<templates id="pos_inh" xml:space="preserve">
<t t-name="ProductRef" t-extend="Product">
<t t-jquery='.product-name' t-operation='replace'>
<div class="product-name">
<t t-esc="product.display_name"/>
<span t-esc="product.default_code"/>
</div>
</t>
</t>
</templates>
use the below also in js file
var models = require('point_of_sale.models');
models.load_fields("product.product", ['default_code']);
After some digging on odoo/Apps, I find a module that do something similare, so I just copy, paste and modify the code to do what I need. So, here is the code :
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="Product" name="ProductStockWidget">
<t t-jquery="div.product-name" t-operation="append">
<t t-if="product.default_code">
<br/>
[<t t-esc="product.default_code"/>]
</t>
</t>
</t>
</templates>
And the jquery code is :
odoo.define('pos_ref_articles', function (require) {
"use strict";
var module = require('point_of_sale.models');
var models = module.PosModel.prototype.models;
for (var i = 0; i < models.length; i++) {
var model = models[i];
if (model.model === 'product.product') {
model.fields.push('default_code');
}
}
});

internal reference of the product did not add to the invoice report in odoo 10

I add internal reference of product to the sale form and I want it in the invoice report also
the sale code is :
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
_name = 'sale.order.line'
x_field = fields.Float('Unit cost')
internal_ref=fields.Char(related='product_id.default_code',string='Internal
reference product',store=True,default=100)
partner_name=fields.Many2one('res.partner','partner_id.name')
this is my code but did not work
the python code:
class invoiceLineField(models.Model):
_inherit='account.invoice.line'
internal_ref=fields.Char(related='product_id.default_code',string='Internal
reference product',store=True)
and this is xml report:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="report_invoice_document_itemnumber"
inherit_id="account.report_invoice_document">
<xpath expr="//div[contains(#class, 'page')]/table[1]/thead/tr/th[1]"
position="before">
<th>Internal reference</th>
</xpath>
<xpath expr="//div[contains(#class, 'page')]/table[1]/tbody/tr/td[1]"
position="before">
<td>
<span t-field="l.internal_ref"/>
</td>
</xpath>
</template>
</data>
</odoo>
no error but the internal reference of product did not appear in the result
If you want the 'default_code' field just to print in report then you can achieve it by 'product_id.default_code'.
<span t-field="l.product_id.default_code"/>

How can I create a view without a model in Odoo 10

I just need a basic page to show some static information in a <p> tag. How can I create a form that has no model?
For this you can create a QWeb Report wich are standard web pages.
openacademy/views/report.xml
<template id='template_id'>
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="report.external_layout">
<div class="page">
<h2>Report title</h2>
<p> report text </p>
</div>
</t>
</t>
</t>
</template>
Place the report in the manifest file
openacademy/manifest.py
# always loaded
'data': [
'views/openacademy.xml',
'views/report.xml',
],
Documentation on QWeb Report
The best way to solve this is with simple Odoo MVC. Just create a controller that will render a view; define the view to be rendered and register the view. I found a tutorial here: https://www.odoo.yenthevg.com/creating-webpages-controllers-odoo10/
Note that (as of the time of this posting) the tutorial has an error in the view's XML -- line 16 and 17 need to be swapped so that the XML is nested properly.

Resources