[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) <xmo@odoo.com>
This commit is contained in:
MerlinGuillaume
2022-11-18 07:46:39 +01:00
parent 00892a3edb
commit 10bb028540
3 changed files with 5 additions and 7 deletions
+2
View File
@@ -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 === #
+1 -7
View File
@@ -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
+2
View File
@@ -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]