Skip to content

Instantly share code, notes, and snippets.

View odony's full-sized avatar

Olivier Dony odony

View GitHub Profile

Rotating your Odoo API key programmatically

Odoo lets you rotate your own API keys over RPC, without touching the web UI. This is useful for portal users and service integrations that need to roll credentials on a schedule.

The examples below use the modern /json/2 HTTP endpoint (Odoo 19+). The older /xmlrpc/2 and /jsonrpc endpoints are deprecated and will be removed in a future version, so new integrations should target /json/2.

@odony
odony / l10n_uk.totp.patch
Created March 29, 2023 10:07
l10n_uk.totp.patch
diff --git l10n_uk_reports/models/hmrc_service.py l10n_uk_reports/models/hmrc_service.py
index c1927802e68..e5fe7db0a97 100644
--- l10n_uk_reports/models/hmrc_service.py
+++ l10n_uk_reports/models/hmrc_service.py
@@ -129,7 +129,7 @@ class HmrcService(models.AbstractModel):
if remote_needed: #no need when on a private network
gov_dict['Gov-Client-Public-IP'] = urls.url_quote(remote_address)
gov_dict['Gov-Client-Public-Port'] = urls.url_quote(str(environ.get('REMOTE_PORT')))
- if self.env.user.totp_enabled:
+ if 'totp_enabled' in self.env.user._fields and self.env.user.totp_enabled:
@odony
odony / find_indexes.sql
Last active March 10, 2023 09:15
Determine useful indexes for DELETE in res_users
WITH fk_actions ( code, action ) AS (
VALUES ( 'a', 'error' ),
( 'r', 'restrict' ),
( 'c', 'cascade' ),
( 'n', 'set null' ),
( 'd', 'set default' )),
fk_list AS (
SELECT pg_constraint.oid as fkoid, conrelid, confrelid as parentid,
conname, relname, nspname,
fk_actions_update.action as update_action,
@odony
odony / editable_cart.patch
Created July 16, 2021 08:04
14.0 Prevent cart changes when a transaction has been started
diff --git addons/website_sale/controllers/main.py addons/website_sale/controllers/main.py
index b5bdc26c9a3..e24977212c4 100644
--- addons/website_sale/controllers/main.py
+++ addons/website_sale/controllers/main.py
@@ -384,7 +384,7 @@ class WebsiteSale(http.Controller):
revive: Revival method when abandoned cart. Can be 'merge' or 'squash'
"""
order = request.website.sale_get_order()
- if order and order.state != 'draft':
+ if order and not order.is_cart_editable:
@odony
odony / curl_to_ab.py
Last active May 15, 2022 16:19 — forked from ctolsen/curl_to_ab.py
"Copy to cURL" in Chrome to Apache Bench command
#!/usr/bin/env python
import sys
import tempfile
import os
def curl_to_ab(curl_cmd, num=200, cur=4):
"""
Translate a cURL command created by Chrome's developer tools into a
command for ``ab``, the ApacheBench HTTP benchmarking tool.
@odony
odony / registry.patch
Created January 29, 2021 17:56
registry: avoid phantom cache signaling
diff --git odoo/modules/registry.py odoo/modules/registry.py
index 907e13ef4ae5..c3c317b77f0d 100644
--- odoo/modules/registry.py
+++ odoo/modules/registry.py
@@ -616,7 +616,6 @@ class Registry(Mapping):
if self.cache_sequence != c:
_logger.info("Invalidating all model caches after database signaling.")
self._clear_cache()
- self.cache_invalidated = False
if self.cache_longterm_sequence != cl:
@odony
odony / shell_commands.py
Created October 5, 2020 20:30
fix_v14_db_uninstall_account
# Run this in an odoo shell command, assuming you can still start a shell on the broken database
# repair the ir.action* table structure
env.registry.init_models(env.cr, ['ir.actions.actions', 'ir.actions.act_window',
'ir.actions.server', 'ir.actions.act_url',
'ir.actions.client', 'ir.actions.report'], {})
# re-allow name constraint
env.cr.execute("update ir_actions set name = 'action ' || id where name is null");
# repair constraint again
env.registry.init_models(env.cr, ['ir.actions.actions', 'ir.actions.act_window',
@odony
odony / test.py
Last active August 27, 2019 14:05
multi-company check
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, api, _
from odoo.exceptions import UserError
class StockPutawayRule(models.Model):
_name = 'stock.putaway.rule'
_order = 'sequence,product_id'
_description = 'Putaway Rule'
@odony
odony / decimal_precision.patch
Last active June 19, 2019 12:14
Decimal Precision compatibility patch
diff --git odoo/addons/base/models/decimal_precision.py odoo/addons/base/models/decimal_precision.py
index c1d00611d43..1bd34a804ce 100644
--- odoo/addons/base/models/decimal_precision.py
+++ odoo/addons/base/models/decimal_precision.py
@@ -2,8 +2,10 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, tools
+import odoo.addons
@odony
odony / 1912199.patch
Created February 15, 2019 10:02
patch signature activity task 1912199
diff --git sign/controllers/main.py sign/controllers/main.py
index c535bff..217e888 100644
--- sign/controllers/main.py
+++ sign/controllers/main.py
@@ -258,8 +258,10 @@ class Sign(http.Controller):
return False
# mark signature as done in next activity
- user_id = http.request.env['res.users'].search([('partner_id', '=', request_item.partner_id.id)]).id
- request_item.sign_request_id.activity_feedback(['mail.mail_activity_data_todo'], user_id=user_id)