Relation _unknown error in odoo 10? - odoo

field definition:
department_id = fields.Many2one('partner.department',string="Department", compute="_get_product_department",store=True,required=True)
view definition:
<field name="department_id" />
ProgrammingError: relation "_unknown" does not exist
LINE 1: SELECT "_unknown"."id" as "id" FROM "_unknown"

Things which you can check are
1.) put the relation module in depends.
2.) Upgrade the module of which you are trying to add relation.
In my case my issue was resolved when i upgraded the module which was of M2O relation.
Lets say my custom.model is in module named 'my_module'
eg.) dept = fields.Many2one('custom.model', 'Relation Example')
I upgraded my_module and issue was resolved.

i solved this problem, partner.department model is another module so i added that module name into manifest.py file in depend section..

Related

Add permission to group (or find where is the problem)

I have this message:
The requested operation can not be completed due to security
restrictions. Document type: Employee (hr.employee) Operation: read
User: 23 Fields: - contract_id (allowed for groups 'Employees /
Officer')
I would not like to add the user to the mentioned group because I want to restrict his actions, and this group has too many permissions. How can I know what permission is required for that specific field?
UPDATE
Create a module with just these lines. I am trying to overwrite the field by deleting the group but it doesn't work for me. What am I doing something wrong?
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
from odoo.osv import expression
class Employee(models.Model):
_inherit = "hr.employee"
contract_id = fields.Many2one('hr.contract', string='Current Contract',
domain="[('company_id', '=', company_id)]", help='Current contract of the employee')
Odoo is nice for once and is telling you which field on which model is restricted. So in this case you should look into the field definition and will find:
contract_id = fields.Many2one(
'hr.contract', string='Current Contract',
groups="hr.group_hr_user",
domain="[('company_id', '=', company_id), ('employee_id', '=', id)]",
help='Current contract of the employee')
You can see the groups parameter which will lead to a restriction of this field to the following groups. Here it is one: hr.group_hr_user which is created with the hr App and also mentioned in Odoo's Access Error: "Employees / Officer".
So you could change the field definition, but i don't advise to do that. I'm not sure why there is no possibility for an Employee to atleast see some of the current contract information of his own contract.

OneToMany field in Odoo proper way to link two models

raise UserError(_("No inverse field %r found for %r") % (self.inverse_name, self.comodel_name))
odoo.exceptions.UserError: ("No inverse field None found for 'res.sector'", '' )
I'm trying to create a new model and having problems linking it to another model.
You probably declared a One2many field like following:
field_name = fields.One2many('res.sector')
You need to specify the inverse name (mandatory), the name of a Many2one field declared in res.sector that reference the model where you declared the One2many field.
As mentioned above, you need to specify an inverse name on the relation.
For example: (workcenter_id) is the inverse field
equipment_ids = fields.One2many('maintenance.equipment', 'workcenter_id')

Cannot create table in odoo 14

I just created a new module with the following structure:
mainfolder
-models
--__init__.py
`from . import student`
--student.py
```
from odoo import api, fields, models
class SchoolStudent(models.Model):
_name = "school.student"
_description = "School Student Patient"
name = fields.Char(string='Name', required=True)
age = fields.Char(string='Age')
gender = fields.Selection([
('male', 'Male'),
('female', 'Female'),
('other', 'Other'),
], required=True, default='male')
note = fields.Text(string='Description')
```
-__init__.py
`from . import models`
-__manifest__.py
The problem is, when I installed the module, I cannot find the table "School student" in my database, I updated the module several times but the same.
How to fix this issue please?
Thanks
I inform you that I solved the problem just by creating the view and access rights for the module.
Thanks
Odoo15 - For someone who still got this issue:
In my case, i'm missing code in my root __init__.py
My custom module named school and saved inside /var/www/html/odoo_15/addons/school
So the root init file should have path like /var/www/html/odoo_15/addons/school/__init__.py and the content should be
from . import models

How to resolve this error in OpenErp?

I have been trying the following code in openerp and I had been getting this error
The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set
[object with reference: name - name]
In my py file, i had inherited one module
class hr_expense_expense(osv.osv):
_name = "hr.expense.expense"
_inherit = "hr.expense.expense"
_inherits = {'hr.employee':'first_approver'}
You don't give details, but I'm pretty sure the _inherits line should be removed. You probably made a confusion and actually want to add Many2one relation.

Odoo / OpenERP Integrity Error on delete order_line

I use delegation to inherit fields from sale_order in a custom module:
class EXAMPLE(osv.osv):
_name = 'EXAMPLECLASS'
_inherits = {
'sale.order': 'sale_order_id'}
I'm using the standard view for sale_order. Everything works fine, I can add and update order_lines within the sale_order. However, when I try to delete an order_line from the sale_order I get the following error:
Integrity Error
The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set
[object with reference: order_id - order.id]
What am I missing? I think it has something to do with the fact that '_inherits' only inherits fields and not methods.
Any help on this matter would be greatly appreciated.