vault backup: 2025-10-14 08:03:44
This commit is contained in:
1059 files changed
+131217
-11710
No files matched your search
+19
-3
@@ -4,6 +4,7 @@ tags:
|
||||
kind: howto
|
||||
section: dev
|
||||
---
|
||||
|
||||
# Odoo Python Scripts
|
||||
|
||||
## Basics
|
||||
@@ -24,11 +25,13 @@ List all products
|
||||
```
|
||||
|
||||
Execute sql quer.
|
||||
|
||||
```python
|
||||
self._cr.execute("SELECT * FROM account_move WHERE id = 16")
|
||||
```
|
||||
|
||||
Generate password.
|
||||
|
||||
```python
|
||||
from passlib.context import CryptContext
|
||||
setpw = CryptContext(schemes=['pbkdf2_sha512'])
|
||||
@@ -37,19 +40,22 @@ setpw.encrypt('odoo')
|
||||
|
||||
## Commands
|
||||
|
||||
Log into Docker Container.
|
||||
Log into Docker Container.
|
||||
|
||||
```bash
|
||||
CONTAINER=odoo04
|
||||
docker exec -it $CONTAINER bin/bash
|
||||
```
|
||||
|
||||
Start Odoo Shell.
|
||||
Start Odoo Shell.
|
||||
|
||||
```bash
|
||||
DATABASE=odoo14
|
||||
odoo shell -d $DATABASE --db_host $HOST -r $USER -w $PASSWORD --no-http
|
||||
```
|
||||
|
||||
Clear assets.
|
||||
Clear assets.
|
||||
|
||||
```python
|
||||
domain = [('res_model', '=', 'ir.ui.view'), ('name', 'like', 'assets_')]
|
||||
env['ir.attachment'].search(domain).unlink()
|
||||
@@ -57,17 +63,20 @@ env.cr.commit()
|
||||
```
|
||||
|
||||
Uninstall app.
|
||||
|
||||
```python
|
||||
env['ir.module.module'].search([('name', '=', 'certificate_planer')]).button_immediate_uninstall()
|
||||
```
|
||||
|
||||
List all users.
|
||||
|
||||
```python
|
||||
users=self.env['res.users'].search([])
|
||||
[print(user.name, user.login) for user in users]
|
||||
```
|
||||
|
||||
List all inactive users.
|
||||
|
||||
```python
|
||||
users=self.env['res.users'].search([('active', '=', False)])
|
||||
for user in users:
|
||||
@@ -75,6 +84,7 @@ for user in users:
|
||||
```
|
||||
|
||||
Enable user.
|
||||
|
||||
```python
|
||||
user = self.env['res.users'].search([('active', '=', False),('login', '=', 'janik.vonrotz@mint-system.ch')])
|
||||
user.active = True
|
||||
@@ -82,6 +92,7 @@ self.env.cr.commit()
|
||||
```
|
||||
|
||||
Reset passwort for user.
|
||||
|
||||
```python
|
||||
user = self.env['res.users'].search([('login', '=', 'admin')], limit=1)
|
||||
user.write({'new_password': 'admin'})
|
||||
@@ -98,6 +109,7 @@ env.cr.commit()
|
||||
```
|
||||
|
||||
List all quality alerts.
|
||||
|
||||
```python
|
||||
alerts=self.env['quality.alert'].search([])
|
||||
for alert in alerts:
|
||||
@@ -105,6 +117,7 @@ for alert in alerts:
|
||||
```
|
||||
|
||||
Set name of alert.
|
||||
|
||||
```python
|
||||
record = env['quality.alert'].browse(57)
|
||||
record.name = "QA0005X"
|
||||
@@ -112,18 +125,21 @@ env.cr.commit()
|
||||
```
|
||||
|
||||
Remove view.
|
||||
|
||||
```python
|
||||
self.env['ir.ui.view'].browse(888).unlink()
|
||||
env.cr.commit()
|
||||
```
|
||||
|
||||
Get sale order info.
|
||||
|
||||
```python
|
||||
sale_order = self.env['sale.order'].browse(60)
|
||||
sale_order.procurement_group_id.stock_move_ids.created_production_id.procurement_group_id.mrp_production_ids
|
||||
```
|
||||
|
||||
List all defaults
|
||||
|
||||
```python
|
||||
defaults = self.env['ir.default'].search([('invoice_cash_rounding_id')], limit=1)
|
||||
[print(default.json_value, default.field_id.name) for default in defaults]
|
||||
|
||||
Reference in new issue
Block a user