From 65c685ad2418f4a65914eda0d1ed5ba31bab0ba2 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 12 Oct 2016 12:30:42 +0200 Subject: [PATCH] [FIX] context mutations (#10368) when extending these methods with the new api, the context is a frozendict so we need to copy before mutating. this patch was made by searching for key addition to context and calls to the update() method on the 8.0 addons, and checking if a copy was made before in the method. --- addons/account/account.py | 3 +-- addons/account/account_move_line.py | 6 ++---- addons/account/wizard/account_report_general_ledger.py | 3 +-- addons/document/document.py | 3 +-- addons/l10n_be/wizard/l10n_be_partner_vat_listing.py | 1 + addons/point_of_sale/point_of_sale.py | 6 ++---- 6 files changed, 8 insertions(+), 14 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 0c32aea78f5..2bae5c5c7e4 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -2303,8 +2303,7 @@ class account_model(osv.osv): pt_obj = self.pool.get('account.payment.term') period_obj = self.pool.get('account.period') - if context is None: - context = {} + context = dict(context or {}) if data.get('date', False): context = dict(context) diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 84778dc0928..143c8ff5468 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -674,8 +674,7 @@ class account_move_line(osv.osv): #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id def onchange_currency(self, cr, uid, ids, account_id, amount, currency_id, date=False, journal=False, context=None): - if context is None: - context = {} + context = dict(context or {}) account_obj = self.pool.get('account.account') journal_obj = self.pool.get('account.journal') currency_obj = self.pool.get('res.currency') @@ -1090,8 +1089,7 @@ class account_move_line(osv.osv): return r_id def view_header_get(self, cr, user, view_id, view_type, context=None): - if context is None: - context = {} + context = dict(context or {}) context = self.convert_to_period(cr, user, context=context) if context.get('account_id', False): cr.execute('SELECT code FROM account_account WHERE id = %s', (context['account_id'], )) diff --git a/addons/account/wizard/account_report_general_ledger.py b/addons/account/wizard/account_report_general_ledger.py index cd242e79657..f15f65a6de4 100644 --- a/addons/account/wizard/account_report_general_ledger.py +++ b/addons/account/wizard/account_report_general_ledger.py @@ -49,8 +49,7 @@ class account_report_general_ledger(osv.osv_memory): return res def _print_report(self, cr, uid, ids, data, context=None): - if context is None: - context = {} + context = dict(context or {}) data = self.pre_print_report(cr, uid, ids, data, context=context) data['form'].update(self.read(cr, uid, ids, ['landscape', 'initial_balance', 'amount_currency', 'sortby'])[0]) if not data['form']['fiscalyear_id']:# GTK client problem onchange does not consider in save record diff --git a/addons/document/document.py b/addons/document/document.py index a30099df905..244cde2d7b2 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -620,9 +620,8 @@ class node_context(object): def __init__(self, cr, uid, context=None): self.dbname = cr.dbname self.uid = uid + context = dict(context or {}) self.context = context - if context is None: - context = {} context['uid'] = uid self._dirobj = openerp.registry(cr.dbname).get('document.directory') self.node_file_class = node_file diff --git a/addons/l10n_be/wizard/l10n_be_partner_vat_listing.py b/addons/l10n_be/wizard/l10n_be_partner_vat_listing.py index 8fa11545dee..b692966bb4f 100644 --- a/addons/l10n_be/wizard/l10n_be_partner_vat_listing.py +++ b/addons/l10n_be/wizard/l10n_be_partner_vat_listing.py @@ -45,6 +45,7 @@ class partner_vat(osv.osv_memory): _name = "partner.vat" def get_partner(self, cr, uid, ids, context=None): + context = dict(context or {}) obj_period = self.pool.get('account.period') obj_partner = self.pool.get('res.partner') obj_vat_lclient = self.pool.get('vat.listing.clients') diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index b4476a9505e..47e1c7895d0 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -443,8 +443,7 @@ class pos_session(osv.osv): """ call the Point Of Sale interface and set the pos.session to 'opened' (in progress) """ - if context is None: - context = dict() + context = dict(context or {}) if isinstance(ids, (int, long)): ids = [ids] @@ -537,8 +536,7 @@ class pos_session(osv.osv): return True def open_frontend_cb(self, cr, uid, ids, context=None): - if not context: - context = {} + context = dict(context or {}) if not ids: return {} for session in self.browse(cr, uid, ids, context=context):