i have a custom entity defined in entities.xml:
<?xml version="1.0" encoding="utf-8" ?>
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/platform/trunk/src/Core/System/CustomEntity/Xml/entity-1.0.xsd">
<entity name="custom_entity_search">
<fields>
<string name="media_hash" store-api-aware="true" />
<json name="data" store-api-aware="true" />
</fields>
</entity>
</entities>
when i use the admin api to insert a new custom entity i don't get all my fields updated.
request url:
http://localhost/api/custom-entity-search
request body:
{
"name": "custom-entity-search",
"fields": {
"media_hash": "123hashmedia",
"data": {"test": "1234"}
}
}
The entity is created but fields "media_hash" and "data" remain null.
How can i update those fields ?
You need to pass the fields directly in the payload there is no need to specify the entity name in the payload itself, the mapping to the concrete custom entity is done over the REST-API endpoint api/custom-entity-search
so the request body should look like this:
{
"media_hash": "123hashmedia",
"data": {"test": "1234"}
}
Edit (to many relations)
{
"media_hash": "123hashmedia",
"data": {"test": "1234"},
"customer_to_many_field": [
{
"id": "my first customer id",
"firstName": "The new name",
},
{
... // data for second customer if needed
}
]
}
I have a problem and I do not know why. I created a module mrp_custom and I installed it on my laptop and works perfectly. However, when I install on my work computer, it doesn't work and gives an error. Here I show my model, the inherited view and the error.
P.D.: On my laptop it works perfectly and on the other computer it does not.
Model
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class MRPProductsName(models.Model): # FUNCION DEL CAMPO PARA PRODUCTOS SOLO
_inherit = 'mrp.production'
products_name = fields.Char('Producto', related="product_id.product_tmpl_id.name")
Inherited View
<!-- INHERITED VIEW PRODUCTION -->
<record id="view_production_form_inherit" model="ir.ui.view">
<field name="name">view.production.form.inherit</field>
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.mrp_production_tree_view"/>
<field name="arch" type="html">
<xpath expr="//field[#name='product_id']" position="after">
<field name="products_name" optional="show"/>
</xpath>
</field>
</record>
Error
File "C:\Program Files\Odoo 14\server\odoo\models.py", line 4983, in ensure_one
raise ValueError("Expected singleton: %s" % self) Exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Program Files\Odoo
14\server\odoo\http.py", line 639, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception) File "C:\Program Files\Odoo 14\server\odoo\http.py", line 315, in
_handle_exception
raise exception.with_traceback(None) from new_cause ValueError: Expected singleton: product.template(2582, 2657, 2624)
By looking in this error: Expected singleton: product.template(2582, 2657, 2624). There can be multiple product_template related to single product_product. Please make sure there only one product_template related to one product_product!
I am using Odoo 10-e. I want to enable developer mode for a user by default when he logs in and that user is other then admin. Is this possible in odoo 10 ?
You need to just override Web login controller in your module.
Ex:
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import http, _
import odoo
from odoo.http import route
from odoo.http import request
from odoo.addons.web.controllers.main import Home, ensure_db
class DebugMode(Home):
#http.route('/web/login', type='http', auth="none")
def web_login(self, redirect=None, **kw):
ensure_db()
request.params['login_success'] = False
if request.httprequest.method == 'GET' and redirect and request.session.uid:
return http.redirect_with_hash(redirect)
if not request.uid:
request.uid = odoo.SUPERUSER_ID
values = request.params.copy()
try:
values['databases'] = http.db_list()
except odoo.exceptions.AccessDenied:
values['databases'] = None
if request.httprequest.method == 'POST':
old_uid = request.uid
uid = request.session.authenticate(request.session.db, request.params['login'], request.params['password'])
if uid is not False:
request.params['login_success'] = True
if not redirect:
redirect = '/web?debug=1'
return http.redirect_with_hash(redirect)
request.uid = old_uid
values['error'] = _("Wrong login/password")
return request.render('web.login', values)
In above method, we have simply redirect URL in /web?debug=1.
You can do it for specific users as well like just create group Auto Debug Mode.
The only group of this users can auto login with debug mode.
Ex :
<record model="res.groups" id="group_auto_debug_mode">
<field name="name">Auto Debug Mode</field>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
if request.env['res.users'].browse(request.uid).has_group('module_name.group_auto_debug_mode'):
redirect = '/web?debug=1'
else:
redirect = '/web'
You can find Odoo Community module from below link.
https://apps.odoo.com/apps/modules/10.0/admin_auto_debug_mode/
This may help you.
I need to redirect user by pressing a button.
The button code is like that:
from odoo.http import request
...
#api.one
def go_away(self):
return request.redirect('http://example.com/api.jsp?user=1&id=12')
Odoo raises an error:
AttributeError: 'JsonRequest' object has no attribute 'redirect'
When i try this:
werkzeug.utils.redirect(url)
Odoo says:
AttributeError: 'function' object has no attribute 'routing_type'
I can understand what is wrong and how can i redirect user with JSON data in a link.
I found out that i can redirect like this:
#api.multi
def go_away(self)
return {
'type': 'ir.actions.act_url',
'url': url,
'target': 'self',
}
Good Day I've alter the website_hr_recruitment module to add some function to download some file. But an Error has occcured when I try to download the file without user access. The error is
{"message": "Odoo Server Error", "code": 200, "data": {"debug": "Traceback (most recent call last):\n File \"/opt/odoo/odoo-server/addons/web/controllers/main.py\", line 70, in wrap\n return f(*args, **kwargs)\n File \"/opt/odoo/odoo-server/addons/web/controllers/main.py\", line 1092, in saveas\n res = Model.read(cr, uid, [int(id)], fields, context)[0]\n File \"/opt/odoo/odoo-server/openerp/api.py\", line 268, in wrapper\n return old_api(self, *args, **kwargs)\n File \"/opt/odoo/odoo-server/openerp/addons/base/ir/ir_attachment.py\", line 318, in read\n self.check(cr, uid, ids, 'read', context=context)\n File \"/opt/odoo/odoo-server/openerp/api.py\", line 268, in wrapper\n return old_api(self, *args, **kwargs)\n File \"/opt/odoo/odoo-server/openerp/addons/base/ir/ir_attachment.py\", line 260, in check\n raise except_orm(_('Access Denied'), _(\"Sorry, you are not allowed to access this document.\"))\nexcept_orm: (u'Access Denied', u'Sorry, you are not allowed to access this document.')\n", "exception_type": "except_osv", "message": "Access Denied\nSorry, you are not allowed to access this document.", "name": "openerp.exceptions.except_orm", "arguments": ["Access Denied", "Sorry, you are not allowed to access this document."]}}
Heres the Model
#http.route('/jobs/apply/<model("hr.job"):job>', type='http', auth="public", website=True)
def jobs_apply(self, job):
error = {}
default = {}
#Added by SDS 19022016
attachment = http.request.env['ir.attachment'].sudo().search([('name', '=', 'Application-Form-rev2.docx')])
#str_url = 'http://localhost:8069'+'/web/binary/saveas?model=ir.attachment&field=datas&filename_field=name&id='+str(attachment.id)
str_url = request.httprequest.host_url +'web/binary/saveas?model=ir.attachment&field=datas&filename_field=name&id='+str(attachment.id)
if 'website_hr_recruitment_bahia_error' in request.session:
error = request.session.pop('website_hr_recruitment_bahia_error')
default = request.session.pop('website_hr_recruitment_bahia_default')
return request.render("website_hr_recruitment_bahia.apply", {
'job': job,
'error': error,
'default': default,
'url_link': str_url,
})
and heres the Template
<div t-attf-class="form-group #{error.get('first_name') and 'has-error' or ''}">
Click ”<a t-att-href="url_link" >Apply Now</a> ” to download, fill-out and upload below
<label class="col-md-3 col-sm-4 control-label" for="first_name">First Name</label>
<div class="col-md-7 col-sm-8">
<input type="text" t-att-value="default.get('first_name')" class="form-control" name="first_name" required="True"/>
</div>
</div>
I tried to add the sudo access but it has no use can someone help me
Thanks
Please create a security file named - ir.model.access.csv
Add it in __openerp__.py like this -
'data': [
'security/ir.model.access.csv',
'views/your_view.xml',
]
Above security is the folder name and in it the file ir.model.access.csv exist.
And add following lines to your csv file-
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_YOUR_CLASS_NAME,access_YOUR_CLASS_NAME,model_YOUR_CLASS_NAME,,1,1,1,1
This should solve the access problem.
Unfortunately, v8 has a more restrictive policy on ir.attachment object and it only let Employee (base.group_user) group read all document i.e. user have to be logged in to access the document(s). So adding record rule or Access Control List rule will not help you.
The best solution here it's to over-ride the def check method on ir.attachment and make more relax to checking the security of accessing documents publically, or maybe you can just over-ride and do not put any logic and make object security driven by ir.attachment. or you can also let some model document bypass from security check.
Hope this will help you.
Bests