Compare commits

..

4 commits

9 changed files with 29 additions and 231 deletions

View file

@ -1,4 +1,3 @@
ODOO_VERSION=17.0
COMMAND=-d odoo
PG_VERSION=14.12 #Moved to 14.15 in Odoo 18
ENTERPRISE_PATH=/local/path/to/enterprise/modules

2
.gitignore vendored
View file

@ -1,5 +1,5 @@
.env
odoo
enterprise
modules/*
modules/
.idea/

10
Dockerfile Normal file
View file

@ -0,0 +1,10 @@
FROM odoo:16.0
USER root
RUN apt update
RUN apt install -y locales
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
sed -i -e 's/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales
USER odoo

View file

@ -4,10 +4,18 @@ Odoo local environment boilerplate with Docker/Podman, for development purpose
## Setup
If not enterprise version, remove the enterprise line in compose file
Put your custom modules in `./modules`
Create enterprise directory (Enterprise&Odoo versions must match) - or delete it from compose and odoo.conf files
From env.dist, create an .env file in the project directory root to set up environment variables
```shell
ln -s /path/to/you/enterprise/modules enterprise
```
Create an .env file in the project directory root to set up environment variables :
```file:./.env
ODOO_VERSION=18.0
COMMAND=-d odoo
```
## Start
@ -21,9 +29,9 @@ You can use the COMMAND var to custom the command at launch :
COMMAND="-d odoo -i mymodule" docker-compose up -d
```
## Use
## Links (localhost)
Odoo at [localhost:8089/web](http://localhost:8089/web)
Odoo database manager at [localhost:8089/web/database/manager](http://localhost:8089/web)
Odoo at (http://localhost:8089/web)[https://localhost:8089/web]
Odoo database manager at (http://localhost:8089/web)[https://localhost:8089/web/database/manager]
Mailcatcher at [localhost:1080/](http://localhost:1080/)
Mailcatcher at (http://localhost:1080/)[http://localhost:1080/]

View file

@ -1,6 +1,7 @@
services:
web:
image: "odoo:${ODOO_VERSION}"
build: .
depends_on:
- db
ports:
@ -9,7 +10,7 @@ services:
- odoo-web:/var/lib/odoo
- ./config:/etc/odoo
- ./modules:/mnt/extra-addons
- ${ENTERPRISE_PATH}:/mnt/enterprise
- ./enterprise:/mnt/enterprise
command: "odoo ${COMMAND}"
db:
image: "postgres:${PG_VERSION}"

View file

@ -1,39 +0,0 @@
# Odoo development cheatsheet
## Datetime & Timezones
- All datetime are stored in UTC in database
- `fields.Datetime` are in UTC. They are only _displayed_ in the user's timezone
### Fetching data with specific timezone
This is tricky. If for whatever reason the datetime value cannot be send directly from the UI (and so be automatically converted), the value has to be converted in the code.
```python
import pytz
## Get the timezone first. This is retrieved from context then user, then default. Can be set in another way
timezone = pytz.timezone(self.env.context.get('tz') or self.env.user.tz or 'UTC')
## Create a localized datetime from the date source
date_tz = timezone.localize(fields.Datetime.from_string("1988-05-16 16:55:00"))
## Now get an UTC datetime from the localized one
start = date_tz.astimezone(pytz.timezone('UTC'))
## If needed, set up an end date from the starting one
end = start + relativedelta(years=36)
# Retrieve the data
awesome_guy_ids = self.env['sale.report'].search(['&',
('date', '>=', start),
('date', '<', end),
])
```
### Display date on context timezome
If for whatever reason (reports, typically), the date is displayed in UTC instead of the contaxt timezone, use :
```python
fields.Datetime.context_timestamp(self, date)
```

View file

@ -1,120 +0,0 @@
# Odoo local
## Initialiser les modules enterprise
`odoo -i web_enterprise -d odoo --stop-after-init`
## Commandes Docker utiles
#### accéder à la cli dans un conteneur
(bash peut-être remplacé par shell ou autre)
`docker-compose exec web bash`
entrer une commande odoo-bin (ajouter options si nécessaire)
```shell
docker-compose exec web odoo {command} -d {database} --db_host db --db_password odoo
```
Attention car ça marche pas toujours bien en fait, notamment pour la prise en compte de certaines modifications dans le code des modules. Avant de piquer d'énormes crise de nerf, essayer de redémarrer totalement les services en passant la commande dans le champ `command` du docker-compose.
#### Afficher les logs debug
`odoo {OPTIONS} --log-level debug`
## Trouver le répertoire Odoo dans un volume Docker
Le chemin du répertoire Odoo dans un volume Docker, en assumant qu'il s'agit d'une image docker officielle Debian est:
`/usr/lib/python3/dist-packages/odoo`
Et le chemin pour trouver le volume Docker:
`/var/lib/docker/volumes/{VOLUME}/_data`
## Importer base de prod en local
Récupérer et télécharger un dump via Odoo.sh, s'assurer qu'il est neutralisé (+ sans FS pour plus de légèreté).
Démarrer odoo en local. Le fichier odoo.conf doit avoir les options suivantes:
```odoo.conf
; db_name = ### désactivé
dbfilter = .*
```
Puis se rendre sur `http://localhost:8069/web/database/manager` et importer le dump téléchargé. Attendre que le manager ait fini de charger. Il affichera vraisemblablement une erreur "La DB existe déjà". Redémarrer le serveur et la BDD:
`docker-compose down && docker-compose up -d`
On veut ensuite sans doute suivre les étapes pourchanger le mdp admin.
## Changer mdp admin
memo : hash du mdp "admin" :
```$pbkdf2-sha512$25000$ltIag3AOIWSsNaZ0rpUSog$9rPi2ZoQiulRtZK44PSTaK4YuDw.VDHvXpubCWLljK4Ibmt5vYhH5lDAFnKZKuW8HDttGyd.TxxFHLxIOUEpDA
$pbkdf2-sha512$25000$ltIag3AOIWSsNaZ0rpUSog$9rPi2ZoQiulRtZK44PSTaK4YuDw.VDHvXpubCWLljK4Ibmt5vYhH5lDAFnKZKuW8HDttGyd.TxxFHLxIOUEpDA
```
### Depuis un terminal
```
docker-compose exec db bash
```
```
psql -U {DB_USER} -d {DB_NAME}
```
Depuis un terminal lancé dans l'Onglet "Services"de PyCharm, avec la config "Odoocker"
```shell
psql -h db -U {DB_USER} -d {DB_NAME}
```
Vérifier qui est admin
```sql
SELECT id, login FROM res_users;
```
```sql
UPDATE res_users SET password='$pbkdf2-sha512$25000$ltIag3AOIWSsNaZ0rpUSog$9rPi2ZoQiulRtZK44PSTaK4YuDw.VDHvXpubCWLljK4Ibmt5vYhH5lDAFnKZKuW8HDttGyd.TxxFHLxIOUEpDA' WHERE login = 'admin';
```
Coincé ? `\q` pour quitter psql et `exit` pour quitter le bash :)
### Depuis VSCodium
Avec un module type "Database client JDBC", configurer la connexion, se connecter à la DB et changer directement le mdp dans la table res_users (attention à bien insérer le hash et non le mdp en clair)
## Tests unitaires
### Tester en local
Pour lancer des tests unitaires en local, lancer un bash (`docker-compose exec web bash`)
Puis cibler le test avec test-tags. La syntaxe est `/module` `:Classe` `.fonction`. Ex :
```bash
odoo --db_host db --db_password odoo -d odoo --test-tags /base:TestReports.test_reports
```
Note : le module doit être installé et à jour pour pouvoir lancer des tests dessus. Il est possible de conjuguer `--test-tags` avec `-i` et `-u` (cette dernière option étant particulièrement utile lorsqu'on debug les tests).
## Troubleshooting
### Mes modules custom ne s'affichent pas
Vérifier que les modules sont bien dans le répertoire des modules custom et que celui-ci est ajouté au PATH dans odoo.conf, et au contenaire via docker-compose.yml
Vérifier les permissions de fichiers. Les répertoires doivent être en `drwxr-xr-x` et les fichiers en `rwxr--r--`. Pour réparer les permissions:
```bash
chmod -R 744 {module}/
chmod 755 {module}/
chmod -R 755 {module}/*/
```

View file

@ -1,24 +0,0 @@
# Odoo migration Cheatsheet
## v15 > v18
### (xml) attrs
The field "attr" is not supported since v17. Replace it with :
- invisible : invisible="{PYTHON}"
- readonly : readonly="{PYTHON}"
### (xml) tree
`<tree>` is replaced by `<list>`. This implies :
- You might want to update all your `<xpath>`
- Also replace it in all your custom views
- Also update your action records, the view_mode field
### (py) group_expand
The related function now takes only two arguments after self. The last one (order) has been removed.

View file

@ -1,37 +0,0 @@
# Odoo : Overriding native tests
_Based on information founded [here]( https://www.linkedin.com/pulse/fixing-native-tests-odoo-14-oleh-diatlenko) - Adapted to fit in one file, works in Odoo 15_
## Inheriting the Class
Identify the class with tests to override and declare a class inheriting it, in the `tests` folder of your module
```python
# file : tests/test_to_override.py
# -*- coding: utf-8 -*-
from odoo.addons.module.tests.test_to_override import TestToOverride
from odoo.tests import tagged
@tagged('whatever')
class TestToOverrideInherited(TestToOverride):
def test_function_overriding(self):
#testing
```
## Disable native tests
Even with this system, native tests will still be ran. To disable them, you need to void the functions :
```python
@tagged('whatever')
class TestToOverrideInherited(TestToOverride):
@unittest.skip('Overriden test')
def void(self: TestToOverride):
pass
# disable tests - do not disable a test without writing another one, testing is important!
TestToOverride.test_function_to_override = void
```