XML Parsing Error while Upgrading Custom Module - odoo

I'm new in Odoo. Created a simple custom module. It was working fine till when I've splitted xml file into two. Its giving below error while trying to upgrade my custom module:
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\Odoo\Odoo_15\odoo\odoo\http.py", line 643, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "D:\Odoo\Odoo_15\odoo\odoo\http.py", line 301, in _handle_exception
raise exception.with_traceback(None) from new_cause
odoo.tools.convert.ParseError: while parsing file:/d:/odoo/odoo_15/custom_addons/om_hospital/views/menu.xml:17, somewhere inside
<menuitem id="menu_patient" name="Patient" action="action_hospital_patient" parent="menu_patient_master" sequence="0"/>
Here are codes:
manifest.py:
{
'name': 'Custom Hospital Management by Milon',
'version': '1.0.0',
'category': 'Hospital Maanagement',
'author': 'Milon Sarker',
'summary': 'Its a custom system',
'description': 'Its a custom system bro',
'depends': [],
'data': [
'views/menu.xml',
'views/patient_view.xml',
],
'installable': True,
'auto_install': False,
'application': True,
'sequence': -100
}
model : patient.py:
from odoo import api, fields, models
class hospitalPatient(models.Model):
_name = 'hospital.patient'
_description = 'Hospital Patient'
name = fields.Char(string = 'Name')
age = fields.Integer(string = "Age")
gender = fields.Selection([('male','Male'), ('female', 'Female')], string = "Gender")
menu.xml:
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<menuitem id = "menu_hospital_root"
name = "Hospital"
sequence = "0"
/>
<menuitem id = "menu_patient_master"
name = "Patient Details"
parent = "menu_hospital_root"
sequence = "0"
/>
<menuitem id="menu_patient"
name="Patient"
action="action_hospital_patient"
parent="menu_patient_master"
sequence="0"
/>
</odoo>
patient_view.xml:
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id = "action_hospital_patient" model = "ir.actions.act_window">
<field name="name">Patients</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">hospital.patient</field>
<field name="view_mode">tree,form,</field>
<field name="context">{}</field>
<field name="help" type = "html">
<p class = "o_view_nocontent_smiling_face">
Create your first patient!
</p>
</field>
</record>
</odoo>

From menuitem documentation:
actionif specified, the action attribute should be the external id of an action to execute when the menu is open.
Use the external id in the last menu item for the action:
om_hospital.action_hospital_patient
When loading the menu item, odoo will try to get the action database id if the action is set and valid.
You should load the menu.xml after the patient_view.xml, update the data entry in the manifest file to the following:
'data': [
'views/patient_view.xml',
'views/menu.xml',
],

Related

Shopware 6 custom entity fields are not updated via admin api

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 install a module in my personal computer and it works however when I install it in my work computer it does not. (Odoo 14)

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!

Odoo- Enable developer mode by default for a user

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.

Odoo redirect with JSON

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',
}

Odoo 8 Error Downloading a file in the Website Module

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