Not able to access Odoo custom model with API - python

I am new to odoo. My requirement is to add few custom models to odoo and communicate to those models through odoo api. I want through multiple tutorials for how to create new model in odoo.
Followed link (https://www.odoo.com/documentation/8.0/howtos/backend.html) to create new module and create new model in it. I am able to create module named 'openacademy' as suggested and also I am able to see on the odoo UI.
Following is the model I have created.
from openerp import models, fields
class LessMinimalModel(models.Model):
_name = 'test.model2'
name = fields.Char()
But when I am trying webservice from my Django project with the object name 'test.model2', it is giving error "Object test.model2 doesn't exist".
Am I missing something here? Is there something needs to be configured to access through API ?
Edit:
I have installed the module and model is also getting shown under Database Structure - > Models as shown below.

You need to restart server and update your module.
Before that your py files must be added in __init__.py.
Go to Settings -> Update Module List
Then Settings -> Installed Modules remove filtration and search your module and install it.
Once your module installed your model will be created.

Related

python manage.py inspectdb > models.py dont work in existing mongo database

sample_data is the name of the mongo collection.
At first, I created a model class named sample_data because I thought it will just read what's already existing in my mongodb but the result was... It creates a new collection named {{MyDjangoAppName}}_sample_data so I search on google "Integrating Django with a legacy database", then tried it to generate the model for me but unfortunately it replaces my models with the error message and looks like this...
I added a picture of my terminal with the error message below. Is it about the mongo ObjectId?
How can I exclude the objectId here and generate a new id? Is that possible?
Should I stick on manually creating the models in models.py and rename the collection name of the existing database?
What is the right approach for this?

Which base class to inherit if it's a common class in odoo9

I'm using odoo9 for my project.
In my project, there is a common excel handling class fill in the excel template and output result, and here is my question: which base class should it inherit? models.Model or http.Controller, or nothing?
If you are going to create odoo normal module then you must create models.Model.
If you are going to create odoo module which will handle post or get request from web service then you must use controller.
If you are going to create odoo module for other module, and this module is wizard then you must use transient model and etc.
Also if you need you can make simple class and use in your module but with your question I cant tell you more

Python-Django module import issue

I have JSON data coming through various external API's into my Django project. I have two apps, one called 'products' and other 'extract'. Through product app, have created the database and rendered the views required. Objective of extract app is to parse the JSON data and create/update the fields in the Django database. I have this code saved in extract/views.py as shown below -
import json
import urllib2
from products.models import Product
url = " .........."
.............
for i in data[results]:
Product.objects.get_or_create (...........)
The issue I am having is this code is working well in python shell. It is extracting all the JSON data and updating the database. But, when I run the script on the command line outside of Python shell, it is giving error - 'Import error: No module named products.models'.
Django requires you to run python manage.py shell in order for the product app's models and Django internals to be initialized.
Check out this blog post by Stavros Korokithakis to convert your code into a standalone script.
I believe the error is with the directory set up. Make sure all your migrations are done as well as the initial folder has the paths to your apps. Possible you need to include the paths to each app in the other's settings.

View error Can't find field 'blocked' in the following view parts composing the view of object model

I have migrated my OpenERP 7.0 DB from dev to production and now everytime I try to create a new customder, I get this error:
View error Can't find field 'blocked' in the following view parts composing the view of object model 'res.partner':
res.partner.followup.form.inherit Either you wrongly customized this
view, or some modules bringing those views are not compatible*
Any idea of why I see this error?
I am a magento guy so have no clue whatsoever.
If you have frontend or backend instances. Make sure that:
All code match in both instances
Update your module
check if column exist in your table

Django model proxy in diffrent package

I want to use one model for global scope for app. In future, probably models will be changed. I created backend.py file in root directory of project with model wrapper (I think it's the best solution as I can change declaration of models in one place, and using global model is more transparent than using imports from app).
from project.backend import models as backend_models
class Game(backend_models.Game):
class Meta:
proxy = True
But when I make any relation to model I get following error:
screens.screen: 'game' has a relation with model <class 'energy.backend.Game'>, which has either not been installed or is abstract.
If I import project.package.Game, not backend.Game everything works fine. Of course I have project.backend in installed apps. Only I don't know how to point django that class in backend is installed, and loaded model (from other app).
EDIT
I solved it by in backend.py:
Game = em_models.Game
But there must be same solution with extending model in non-models package.

Categories