Odoo disabled edit button depending on state - odoo

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.

Related

How to create a custom button which downloads a pdf report in odoo 13?

I want to create a custom button in the odoo employee model, which creates and downloads a pdf with the working contract of this employee. I tried to reverse engineer the given buttons in odoo, but every approach of mine failed. Does someone have a tip on where to start? Thanks a lot!
I usually return an URL action with the download button, and write a controller for the URL. The result is clicking the button actually downloading a file.
First step is to write your Qweb report. I'll write a sample one here. Note that the report ID is action_report_test_contract which is used later in the controller.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<report string="Test Contract" id="action_report_test_contract" model="hr.contract" name="your_module_folder_name.test_contract_report" file="your_module_folder_name.test_contract_report" report_type="qweb-pdf" print_report_name="'%s - Contract' % (object.name)" />
<template id="test_contract_report">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="doc">
<t t-call="web.internal_layout">
<div class="page">
<h1><t t-esc="doc.name"/></h1>
<h2>Employee: <t t-esc="doc.employee_id.name"/></h2>
<h2>Start Date: <t t-esc="doc.date_start"/></h2>
</div>
</t>
</t>
</t>
</template>
</odoo>
Don't forget to add the report file path to your manufest. Test print the report from a contract, yes the sample works. Now inherit the hr.employee module to add the download method.
class HrEmployee(models.Model):
_inherit = "hr.employee"
def button_download_contract(self):
if not self.contract_id:
return
return {
'type' : 'ir.actions.act_url',
'url': '/web/download/test-contract-report?contract_id=%s'%(self.contract_id.id),
'target': 'self',
}
Also, inherit the view to add the download button:
<button name="button_download_contract" type="object" string="Download Contract" icon="fa-download"/>
Finally, finish the controller:
from odoo import http
from odoo.http import request, content_disposition, route
class testDownload(http.Controller):
#route(['/web/download/test-contract-report'], type='http', auth="user")
def download_pdf(self, contract_id, **kw):
employee_contract = request.env['hr.contract'].sudo().search([('id','=',contract_id)], limit=1)
if not employee_contract:
return None
pdf, _ = request.env.ref('your_module_folder_name.action_report_test_contract').sudo().render_qweb_pdf([int(contract_id)])
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf)),('Content-Disposition', content_disposition('%s - Contract.PDF' % (employee_contract.name)))]
return request.make_response(pdf, headers=pdfhttpheaders)
Note that the method render_qweb_pdf relies on the report object. So action_report_test_contract is used, not test_contract_report.

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>

How to use Chatter in Odoo?

I want to use Chatter for students model, so that, when value of some field is changed then it is logged under student form
To achieve this, I did the following things:
1. Added this div
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread"/>
</div>
in the student form.
It added the chatter, but when i clicked on New Message button, it gave the following error.
This could be because i haven't inherited mail.thread in student model.
Then i inherited this class in student model.
Then it again gave an error as shown below
I search this topic, but couldn't found anything.
It would be appreciated if someone could help me out.
In order to log changes of specific fields you need so set the track_visibility attribute on each field you want to track:
class OpStudent(models.Model):
_name = 'op.student'
_inherits = {
'res.partner': 'partner_id',
}
_inherit = [
'mail.thread',
'ir.needaction_mixin',
]
foo = fields.Char(track_visibility='always')
You may read more about it in the official documentation.
You're using Chatter for keeping the track on student details.
So I'll suggest another module which is working absolutely fine and keeps the track on student or any other model you want as I have personally used it.
I used audit log. It tracks all the CRUD operations. It will create Audit
the menu in setting tab from there you can set the model which you want to track.
For reference you can check this image also.
I had the same problem, but with res.company, I solved it like this:
class ResCompany(models.Model):
_name = 'res.company'
_inherit = ['res.company','mail.thread', 'mail.activity.mixin']
date_end = fields.Date(string="Fin Date",tracking=True)
and in xml:
<xpath expr="//form/sheet" position="after">
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread" />
</div>
</xpath>
I hope, that it serves you.

Bigcommerce Add To Cart Pop-Up

When using bigcommerce before, we were able to choose whether or not to have a pop up or take the user to the cart whenever they clicked the "Add to Cart" button. Does anybody know if this feature has been taken out by BigCommerce or where I can find that setting now? Thank you!
Do you know if you're using the Stencil or Blueprint framework?
If you're using blueprint, you can go to "Store Setup > Store Settings > Display" and choose "Take Them to Their Shopping Cart".
If you're using stencil, that feature is hidden and you have to do customization for it to work. If your products don't have any options, you can follow the instructions on this page: https://support.bigcommerce.com/articles/Public/How-can-I-add-a-product-to-the-cart-with-a-link/#add-to-cart.
However, if you have options, this won't work because it doesn't updated the sku in the url. What i did to get this to work was to edit the product-details.js
First you need to download the theme in order to edit the js file. Then, starting on line 234, you'll see the following code:
// Open preview modal and update content
if (this.previewModal) {
this.previewModal.open();
this.updateCartContent(this.previewModal, response.data.cart_item.hash);
} else {
this.$overlay.show();
// if no modal, redirect to the cart page
this.redirectTo(response.data.cart_item.cart_url || this.context.urls.cart);
}
Directly under the comment, add /* and then go down one line under the closing brace of the else statement (}) and add */ to close the long comment. The code will now look like this:
// Open preview modal and update content
/*
if (this.previewModal) {
this.previewModal.open();
this.updateCartContent(this.previewModal, response.data.cart_item.hash);
} else {
this.$overlay.show();
// if no modal, redirect to the cart page
this.redirectTo(response.data.cart_item.cart_url || this.context.urls.cart);
}
*/
this.redirectTo(response.data.cart_item.cart_url || this.context.urls.cart);
Let me know if this helps!
Just FYI I went through a similar problem and found that the "Ask a Design partner" forum gave me my answer. The answer I used was from this post:
https://support.bigcommerce.com/s/group/0F913000000HLpWCAW/ask-a-design-partner
But to help I will pull out what they said:
"If you want to remove the popup, you will need to edit the theme files, navigate to the templates/components/products/product-view.html file, and comment out (or remove )this code at the bottom of the file:
<div id="previewModal" class="modal modal--large" data-reveal>
<a href="#" class="modal-close" aria-label="{{lang 'common.close'}}" role="button">
<span aria-hidden="true">×</span>
</a>
<div class="modal-content"></div>
<div class="loadingOverlay"></div>
</div>
Hi You need to do this :
1. Login to admin-end then go to store setting
2. From top tabs choose display tab
3. Find the 'Add to Cart' Action choose what you want pop window or redirection to the cart page.
4. hit the save button.
Check image:
Thanks

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)