From 10bb028540f54e484a999aa987e6442db91e9e7c Mon Sep 17 00:00:00 2001 From: MerlinGuillaume Date: Fri, 4 Nov 2022 15:28:18 +0000 Subject: [PATCH] [FIX] odoo,account: use field attribute exportable Exporting a Binary field with a value of type dict from a record raises an error Steps to reproduce: 1. Install Accounting 2. Open Accounting and go to Vendors > Bills 3. Open any posted bill and register the payment 4. Go back to the list view and export the bill in payment 5. Add field Invoice Payments Widget to the exported fields and export 6. An error is thrown Solution: Make the field attribute `exportable` work (pass it in the field description) Make fields `invoice_outstanding_credits_debits_widget` and `invoice_payments_widget` non-exportable as they contain computed aggregated data for the client's benefit and it doesn't make sense to export them Problem: xlsxwriter's `write` doesn't support type dict opw-3054184 closes odoo/odoo#105972 X-original-commit: c925ecb2a22750524020f0d111888fd76eedb0cb Signed-off-by: Xavier Morel (xmo) --- addons/account/models/account_move.py | 2 ++ addons/account/models/account_move_line.py | 8 +------- odoo/fields.py | 2 ++ 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index f8932204a15..7d6a046b851 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -349,6 +349,7 @@ class AccountMove(models.Model): invoice_outstanding_credits_debits_widget = fields.Binary( groups="account.group_account_invoice,account.group_account_readonly", compute='_compute_payments_widget_to_reconcile_info', + exportable=False, ) invoice_has_outstanding = fields.Boolean( groups="account.group_account_invoice,account.group_account_readonly", @@ -357,6 +358,7 @@ class AccountMove(models.Model): invoice_payments_widget = fields.Binary( groups="account.group_account_invoice,account.group_account_readonly", compute='_compute_payments_widget_reconciled_info', + exportable=False, ) # === Currency fields === # diff --git a/addons/account/models/account_move_line.py b/addons/account/models/account_move_line.py index 68e0784d6bf..706c21d5627 100644 --- a/addons/account/models/account_move_line.py +++ b/addons/account/models/account_move_line.py @@ -110,6 +110,7 @@ class AccountMoveLine(models.Model): string='Cumulated Balance', compute='_compute_cumulated_balance', currency_field='company_currency_id', + exportable=False, help="Cumulated balance depending on the domain and the order chosen in the view.") currency_rate = fields.Float( compute='_compute_currency_rate', @@ -1282,13 +1283,6 @@ class AccountMoveLine(models.Model): ) return super(AccountMoveLine, contextualized).search_read(domain, fields, offset, limit, order) - @api.model - def fields_get(self, allfields=None, attributes=None): - res = super().fields_get(allfields, attributes) - if res.get('cumulated_balance'): - res['cumulated_balance']['exportable'] = False - return res - def init(self): """ change index on partner_id to a multi-column index on (partner_id, ref), the new index will behave in the same way when we search on partner_id, with the addition of being optimal when having a query that will diff --git a/odoo/fields.py b/odoo/fields.py index 81c3ab7f96f..728a7e29678 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -306,6 +306,7 @@ class Field(MetaField('DummyField', (object,), {})): prefetch = True # the prefetch group (False means no group) default_export_compatible = False # whether the field must be exported by default in an import-compatible export + exportable = True def __init__(self, string=Default, **kwargs): kwargs['string'] = string @@ -843,6 +844,7 @@ class Field(MetaField('DummyField', (object,), {})): _description_change_default = property(attrgetter('change_default')) _description_group_operator = property(attrgetter('group_operator')) _description_default_export_compatible = property(attrgetter('default_export_compatible')) + _description_exportable = property(attrgetter('exportable')) def _description_depends(self, env): return env.registry.field_depends[self]