odoo 10 Many2one DropdownView change number of items - odoo

How can I change the number of visible items in the dropdownlist?
model:
category = fields.Many2one('my.category', 'Category', required=True)
view usage inside form:
<field name="category" options="{'no_quick_create':True,'no_create_edit':True}"/>
I just have 9 categories to display & the dropdown list only shows 7 categories + the 'Search more'.
It would be nice to show all categories, if necessary with a scroll bar.
Any help is appreciated. Thanks.

if yout want to change limit in dropdown view, you can find in web->static->src->js->view_from.js. and change the limit values for show many2one list.
create file new_widget.js:
(function() {
var instance = openerp;
var _t = instance.web._t,
_lt = instance.web._lt;
var QWeb = instance.web.qweb;
instance.web.form.CompletionFieldMixin = {
init: function() {
this.limit = 10;
this.orderer = new instance.web.DropMisordered();
},};})();
and write in xml :
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="MyModule assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/MyModule/static/src/js/new_widget.js"></script>
</xpath>
</template>
</data>
</openerp>

Actually this works well for V14: https://apps.odoo.com/apps/modules/14.0/web_m2x_options/

Related

How to add QR code image in Odoo's POS receipt

I'm trying to add a QR image to the POS's receipt. The code I used in a normal invoice that worked was the following one:
<img t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s'%('QR', o.qr_code_string, 150, 150)"/>
For the receipt, I exported for printing my string as receipt.qr_string and added the following line to the receipt's inheriting XML file:
<img t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s'%('QR', receipt.qr_string, 150, 150)"/>
But the image appear like a broken link. How do I achieve this?
I don't know why it is not working for POS receipts but let me tell you that POS is the system that can be run without connection to the server. Everything it executes should always using js i mean always to client side. So, my solution is to use QRrcode.js library as it is easy avaialable here.
Add this library file to the module on path /<your_module/static/src/lib/ folder and also to your pos backend like below and that file needs to added in the manifest as well under the "data" file list.
<odoo>
<data>
<template id="assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/<module_name>/static/src/lib/qrcode.js"></script>
</xpath>
</template>
</data>
</odoo>
Take care of path properly.
Then you can use that library in any POS Receipt Qweb like below to print QRcode.
<div t-attf-id="#{receipt.qr_string}"></div>
<script type="text/javascript">
var lot_name = "<t t-esc="receipt.qr_string"/>";
var qrcode = new QRCode(receipt.qr_string , {
text: "http://jindo.dev.naver.com/collie",
width: 100,
height: 100,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.H
});
qrcode.makeCode(receipt.qr_string);
</script>

active_id and actions in transientModel odoo

I am trying to get some values from (hr.payslip) model. Before that I need to add one more option in Action (dropdown list) where you can delete or export selected payslip. So when I select a payslip from treeView (checkbox in the image below) that new option should show up a wizard showing a table One2many having the selected payslip so I can Print or do some other action.
This is the scenario and i did not start any coding to do that.
I am new to odoo. I hope you can help me with some example.
you have to create new action and new object also
create new object
class NewObject(models.TransientModel):
_name = 'new.object'
_description = 'Description of new object'
#api.multi
def generate_report(self):
payslip_ids = self._.get('active_ids',[])
#payslip_ids this will be your selected payslip ids in list view.
<act_window
name="Your Action string"
res_model="new.object"
src_model="hr.payslip"
view_mode="form"
view_type="form"
target="new"
multi="True"
key2="client_action_multi"
id="id_of_act_window"
view_id="view of new object"
/>
then create view for new object
<record id="id of new view" model="ir.ui.view">
<field name="name">Name of view</field>
<field name="model">model of new view</field>
<field name="arch" type="xml">
<form string="">
<button name="generate_report" string="Generate Report
type="object" class="oe_highlight" />
</form>
</field>
</record>
and here you can add your code you want like.

Odoo disabled edit button depending on state

this question already asked by someone, this in an example question
How to hide the edit button form only when invoice' state is 'paid' Odoo v8?
but i dont get true answer, somebody can help me, i really need to hide or disabled this button.
For your information im using odoo v.10
Thanks in advance
The only way to this is by Javascript you need to add this behavior to your form view
build a custom addon and just add this javascript file to your backend assets template
//file: static/src/js/disable_edit_for_paid_invoice.js
openerp.your_addon_name = function(instance, local) {
var instance = openerp;
var FormView = instance.web.FormView;
// override load_record
FormView.include({
load_record: function(record) {
// disable only for cancel and paid account.invoice
if (record){
if (this.model == 'account.invoice' & _.contains(['paid', 'cancel'], record.state)){
$('button.oe_form_button_edit').hide()
}else {
$('button.oe_form_button_edit').show()
}
}
// call super
return this._super(record);
}
});
}
Add this to backend asset template
<template id="assets_backend" name="disable edit paid invoice assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/your_addon_name/static/src/js/disable_edit_for_paid_invoice.js"></script>
</xpath>
</template>
Don't forget to replace your_addon_name by the real addon name that you create.

Get a database value in QWeb PDF report (Odoo 10)

I would like to retrieve a config parameter from database in a custom QWeb Report.
What shall I do?
Specifically, I want to get the equivalent (in the model):
self.env['ir.config_parameter'].get_param('my_param', '')
Could someone highlight where to start?
As additional information, the report I am trying to use inherits report.minimal_layout:
<?xml version="1.0"?>
<odoo>
<data>
<template id="report_saleorder_css" inherit_id="report.minimal_layout">
<xpath expr="html/head/*[position() = last()]" position="after">
<style>
body {
color: <t t-esc="color"/>;
}
</style>
</xpath>
</template>
</data>
</odoo>
And this is the custom render function I have tried:
class CustomReport(models.AbstractModel):
_name = 'report.mymodule.report_saleorder_css'
#api.model
def render_html(self, data=None):
report_obj = self.env['report']
report = report_obj._get_report_from_name('mymodule.report_saleorder_css')
docargs = {
'doc_ids': self._ids,
'doc_model': report.model,
'docs': self,
'color': 'red'
}
return report_obj.render('mymodule.report_saleorder_css', docargs)
without success
In simple word you want to retrieve a config parameter whenever you print qweb report.
we can not directly use self.env in qweb report, but we can call a function which do that operation and return config parameter value. To do that first create python function in your model.
#api.model
def get_system_para(self):
para_value = self.env['ir.config_parameter'].get_param('web.base.url','')
return para_value
Now call this function in your qweb report
<span t-esc="docs.get_system_para()"/>
You have to retrieve the value beforehand and pass it to your template for usage.
You can do this by defining your own parser for your report, check the documentation.
See under Custom Reports on how you can create your own parser (Python class) and how you can use the docargs. Basically within the render_html method you search for your value, insert it on docargs and then pass it on the render method. Then you can use it from your template like:
<t t-esc="my_param" />

Qweb Report Template Odoo 10

How can I display a field when printing an invoice from sales and hiding it if the report is printed from accounting? Is there any way to access the active module from qweb template? Something similar to the following code:
<template id="report_invoice_document" inherit_id="account.report_invoice_document">
<xpath expr="//div[#class='page']" position="replace">
<div t-if="o.active_module == account" class="page">
<!-- Hide Here -->
</div>
<div t-else="" class="page">
<!-- Show Here -->
</div>
</xpath>
</template>
You can create a custom report or override the existing report with your custom report. Evaluate the active model in the python code and pass an argument to your report for qweb evaluation. You could pass an argument to your qweb just like the one you suggested and then use the exact same logic you used in your suggested code.
import logging
_logger = logging.getLogger(__name__)
class YourReport(models.AbstractModel):
_name = 'report.your_addon.report_template_id'
#api.multi
def render_html(self, data=None):
_logger.info("RUNNING REPORT")
report_obj = self.env['report']
report = report_obj._get_report_from_name('your_addon.report_template_id')
docs = self.env.context.get('active_ids')
docargs = {
'doc_model': report.model,
'active_model': self.env.context.get('active_model'),
'docs': docs,
}
return report_obj.render('your_addon.report_template_id', docargs)