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
Related
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.
I am new to Django. I am to create some sort of todo app. I am having trouble setting IntegerField as optional field. As far as I can see the problem is when I try to save to save the object to the database. I get error: NOT NULL constraint failed: lista_row.quantity. I have made (and migrated) migrations. Here is my models.py:
from django.db import models
from django.contrib import admin
class Row(models.Model):
name = models.CharField(max_length=200)
quantity = models.IntegerField(null=False, blank=True)
If you want to make it optional, use this instead:
quantity = models.IntegerField(blank=True, null=True)
I am new to the django framework. I currently started learning from an online video tutorial and I came across some errors. I have an app called groups which has two separate view files namely company and family. Due to that I have my groups/url file as this:
from django.urls import path, include, re_path
from . views import company
from . views import family
app_name = 'groups'
company_patterns = [
path('create/', company.Create.as_view(), name='create'),
re_path(r'^edit/(?P<slug>\w+)/$', company.Update.as_view(), name='update'),
path('<str:slug>/', company.Details.as_view(), name='detail'),
]
family_patterns = [
path('create/', family.Create.as_view(), name='create'),
path('edit/<str:slug>/', family.Update.as_view(), name='update'),
path('<str:slug>/', family.Details.as_view(), name='detail'),
]
urlpatterns = [
path('companies/', include(company_patterns, namespace='companies')),
path('families/', include(family_patterns, namespace='families')),
]
But anytime I run the application from my dashboard template. I get this error:
'Specifying a namespace in include() without providing an app_name '
django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.
Please, can anyone assist me with further explanation and solution? thank you
define app_name in another urls.py file
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..
I need to create a model, to have backward compatibility with older field names.
This way,
I can develop modules that could read the "new" fields, but migrating the old ones is not necessary for this to work.
This works only for reading or presenting the fields, but not for writing them.
So I thought it would be good to create an alias for each field, and made this:
from openerp import models, fields, api
class backward_compatibility(models.Model):
_description = 'Backward compatibility'
_inherit = 'account.invoice'
new_document_class_id = fields.Integer(
compute='_comp_new_doc_class', string='Tipo')
new_document_number = fields.Char(
compute='_comp_new_doc_number', string='Folio')
#api.multi
def _comp_new_doc_class(self):
for record in self:
try:
record.new_document_class_id = record.old_document_class_id
except:
pass
#api.multi
def _comp_new_doc_number(self):
for record in self:
try:
record.new_document_number = record.old_document_number
except:
pass
This approach works for the Char field, but it doesn't for the Integer (Many2one).
What ideas do you have to make this work? Should I replicate the relationship in the new field?
oldname: the previous name of this field, so that ORM can rename it automatically at migration
Try to use "oldname". I saw this in the core modules. Never used personally.
_inherit = 'res.partner'
_columns = {
'barcode' : fields.char('Barcode', help="BarCode", oldname='ean13'),
}
Also dummy fields are user to help with backward compatibility.
'pricelist_id': fields.dummy(string='Pricelist', relation='product.pricelist', type='many2one'),