External dependencies in odoo
There is some non-obvious issue with external dependency in modules, which I want to say.
Case
Let you need to use some python lib, which is not available in system by default and should be installed manually.
So you just make import:
And maybe you mention required dependence in module's description. Very simple, right? But…
Issue
The case could crash odoo completely.
This is scenario when it could happen:
- User is not going to use your module with external dependency, but
your module available in Local Modules. E.g. if have a lot of
modules in your git repository and user just makes
git clone
and add path to repo toaddons-path
. - User's system doesn't have required dependency
- Your module has
static/
folder, e.g. to place icon.png file.
Then right after restarting server, user would get error:
Suggestion
Whenever you use external dependency, put your import code in try block
and add external_dependencies
to module's manifest:
It will check dependencies before installing and will not raise ImportError if user doesn't use module.
links
Source diving
Odoo is opensource and has module structure. So, for the question
– Is it possible to change /this/ in Odoo?
the only answer is:
– Yes, everything is possible to do in Odoo.
OK, but how to do that? Where to find an instruction of how to implement some particular feature?
Let's take an example. Imagine we need a custom link for product at
website shop. By default link is generated from Name
field, but you
need to make it be generated from new Name SEO
field.
i.e. instead of this link:
/shop/product/ipad-mini-8
there should be this one:
/shop/product/super-seo-link-for-ipad-mini-8
where product has fields:
Name: iPad Mini
Name SEO: Super SEO link for iPad Mini
How to do that? Can we find the answer in documentation? I believe, it doesn't have an answer.
So, let's try to do it ourself. We have Odoo source, so let's try to find a solution there.
In our example we can start from seaching by /shop/product/
:
These lines from addons/website_sale/controllers/main.py
looks interesting:
What about <model("product.template"):product>
? What is it? How it
works? There should be a way for you to find the answer in
source. Maybe you know about werkzeug
library, maybe you know about
slug
function, maybe you know about ir.http
model. So there should
be a keyword to search. At the worst you can search by "model"
keyword OR look through whole website
module.
OK, I found the answer in addons/website/models/ir_http.py
. Function to_url
is what we need.
addons/website/models/website.py
So, that is. To make a custom link, we have to inherit ModelConverter
and modify to_url
function. Something like that:
This is the way I use in odoo development:
- Dive into source
- Figure out how it works
- Create module to make changes you need
Mail relocation
Odoo has a good integration with emails. It allows to have a discussion with a customer attached to some record (task, lead, invoice etc.).
In the main, your customer don't know about this and can send emails
(e.g. about a task) to your personal alias
(e.g. admin@yourcompany). It could not be a problem, if you work on
task alone. But if you need to share mail to colleagues, it's better
to move (attach) mail to task form. I've made module
mail_move_message
to do it.
Technically, the module update fields res_id
and model
of
mail.message
table. It also keeps original values to allow to move
everything back.
A usage guide with screenshots can be found here: https://apps.odoo.com/apps/modules/8.0/mail\_move\_message/
It's not mentioned in module's description, but if you move a message, then all messages in a thread below the message would also be moved to a new location.
Repository: https://github.com/yelizariev/addons-yelizariev/tree/8.0/mail\_move\_message
Uninstalling
Please note, that after uninstalling the module, all infromation about original location of moved messages will be lost.
Skype field in partner form
The module adds skype field to form. When you click on skype address, chat window is opened.
For developers
Example of usage in views:
Repository: https://github.com/yelizariev/addons-yelizariev/tree/8.0/res\_partner\_skype
Templates for user's email signature
If you have a lot of users and you want to control their email
signature, then signature template is what you need. With my module
res_users_signature
you can create signature template and apply one
for your users.
A user can choose his signature template himself at Preference window (which is opened via top right hand menu).
Technically the module make minimal changes at user model. It just put new
value to signature
field at res.users
model.
The module updates signature if there are changes at basic users
models (res.users
, res.partner
, hr.employee
). E.g. if a user
change his phone number, then his signature would be updated. Also,
you can update all signatures manually.
Images
You can use base64-encoded images at signature template:
I've found, that some email clients doesn't show such images. In order
to fix it, the module overwrite build_email
function at
ir.mail_server
model. The module make attachments from base64 images
at email body.
Repository: https://github.com/yelizariev/addons-yelizariev/tree/8.0/res\_users\_signature