diff options
| author | Xavier Morel <xmo@odoo.com> | 2018-12-06 10:46:57 +0000 |
|---|---|---|
| committer | Xavier Morel <xmo@odoo.com> | 2018-12-07 13:37:34 +0000 |
| commit | 66f0e26f6f3f2155fcfcc55e84f2e76cbfdb2c1d (patch) | |
| tree | 7dbd4cbc827e8455eb4d8bd4013003b8069fc448 /odoo/addons | |
| parent | 299f9f1eb06f9df950df1dc02e368caa9b3a9871 (diff) | |
[CHG] *: make binary fields default to attachment=True
Check that it makes custom binary fields into attachment as that's the
main reason for the change: when users create binary fields via Studio,
they're necessarily db-stored (as the interface doesn't allow altering
the attachment attribute and it's unclear how we'd handle users
switching it on/off every time), which significantly bloats their
database (and burns storage & backup space), especially as the primary
use case for binary fields is adding images and documents to records.
* check that binary fields are properly created as attachment=True
* add attachment=False on fields where that seems relevant (most but not
all of the fields previously using the default)
* remove occurrences of attachment=True
closes odoo/odoo#29308
Diffstat (limited to 'odoo/addons')
| -rw-r--r-- | odoo/addons/base/models/ir_actions.py | 2 | ||||
| -rw-r--r-- | odoo/addons/base/models/ir_attachment.py | 2 | ||||
| -rw-r--r-- | odoo/addons/base/models/ir_property.py | 2 | ||||
| -rw-r--r-- | odoo/addons/base/models/res_company.py | 2 | ||||
| -rw-r--r-- | odoo/addons/base/models/res_partner.py | 6 | ||||
| -rw-r--r-- | odoo/addons/base/tests/test_ir_actions.py | 13 | ||||
| -rw-r--r-- | odoo/addons/base/wizard/base_export_language.py | 2 | ||||
| -rw-r--r-- | odoo/addons/base/wizard/base_import_language.py | 2 | ||||
| -rw-r--r-- | odoo/addons/test_converter/models.py | 2 |
9 files changed, 21 insertions, 12 deletions
diff --git a/odoo/addons/base/models/ir_actions.py b/odoo/addons/base/models/ir_actions.py index 2b9f88104f1..814973aedc9 100644 --- a/odoo/addons/base/models/ir_actions.py +++ b/odoo/addons/base/models/ir_actions.py @@ -772,7 +772,7 @@ class IrActionsActClient(models.Model): params = fields.Binary(compute='_compute_params', inverse='_inverse_params', string='Supplementary arguments', help="Arguments sent to the client along with " "the view tag") - params_store = fields.Binary(string='Params storage', readonly=True) + params_store = fields.Binary(string='Params storage', readonly=True, attachment=False) @api.depends('params_store') def _compute_params(self): diff --git a/odoo/addons/base/models/ir_attachment.py b/odoo/addons/base/models/ir_attachment.py index 967f93a33e2..942c5c906b2 100644 --- a/odoo/addons/base/models/ir_attachment.py +++ b/odoo/addons/base/models/ir_attachment.py @@ -294,7 +294,7 @@ class IrAttachment(models.Model): # the field 'datas' is computed and may use the other fields below datas = fields.Binary(string='File Content', compute='_compute_datas', inverse='_inverse_datas') - db_datas = fields.Binary('Database Data') + db_datas = fields.Binary('Database Data', attachment=False) store_fname = fields.Char('Stored Filename') file_size = fields.Integer('File Size', readonly=True) checksum = fields.Char("Checksum/SHA1", size=40, index=True, readonly=True) diff --git a/odoo/addons/base/models/ir_property.py b/odoo/addons/base/models/ir_property.py index 3360693d70d..0690080670f 100644 --- a/odoo/addons/base/models/ir_property.py +++ b/odoo/addons/base/models/ir_property.py @@ -42,7 +42,7 @@ class Property(models.Model): value_float = fields.Float() value_integer = fields.Integer() value_text = fields.Text() # will contain (char, text) - value_binary = fields.Binary() + value_binary = fields.Binary(attachment=False) value_reference = fields.Char() value_datetime = fields.Datetime() type = fields.Selection([('char', 'Char'), diff --git a/odoo/addons/base/models/res_company.py b/odoo/addons/base/models/res_company.py index 64fb3ee6fb2..958b7a4edba 100644 --- a/odoo/addons/base/models/res_company.py +++ b/odoo/addons/base/models/res_company.py @@ -39,7 +39,7 @@ class Company(models.Model): logo = fields.Binary(related='partner_id.image', default=_get_logo, string="Company Logo", readonly=False) # logo_web: do not store in attachments, since the image is retrieved in SQL for # performance reasons (see addons/web/controllers/main.py, Binary.company_logo) - logo_web = fields.Binary(compute='_compute_logo_web', store=True) + logo_web = fields.Binary(compute='_compute_logo_web', store=True, attachment=False) currency_id = fields.Many2one('res.currency', string='Currency', required=True, default=lambda self: self._get_user_currency()) user_ids = fields.Many2many('res.users', 'res_company_users_rel', 'cid', 'user_id', string='Accepted Users') account_no = fields.Char(string='Account No.') diff --git a/odoo/addons/base/models/res_partner.py b/odoo/addons/base/models/res_partner.py index f61dbbced38..5868209f38d 100644 --- a/odoo/addons/base/models/res_partner.py +++ b/odoo/addons/base/models/res_partner.py @@ -222,13 +222,13 @@ class Partner(models.Model): company_name = fields.Char('Company Name') # image: all image fields are base64 encoded and PIL-supported - image = fields.Binary("Image", attachment=True, + image = fields.Binary("Image", help="This field holds the image used as avatar for this contact, limited to 1024x1024px",) - image_medium = fields.Binary("Medium-sized image", attachment=True, + image_medium = fields.Binary("Medium-sized image", help="Medium-sized image of this contact. It is automatically "\ "resized as a 128x128px image, with aspect ratio preserved. "\ "Use this field in form views or some kanban views.") - image_small = fields.Binary("Small-sized image", attachment=True, + image_small = fields.Binary("Small-sized image", help="Small-sized image of this contact. It is automatically "\ "resized as a 64x64px image, with aspect ratio preserved. "\ "Use this field anywhere a small image is required.") diff --git a/odoo/addons/base/tests/test_ir_actions.py b/odoo/addons/base/tests/test_ir_actions.py index 865cca5e43a..9eb47d569da 100644 --- a/odoo/addons/base/tests/test_ir_actions.py +++ b/odoo/addons/base/tests/test_ir_actions.py @@ -246,14 +246,14 @@ class TestCustomFields(common.TransactionCase): self.registry.enter_test_mode(self.cr) self.addCleanup(self.registry.leave_test_mode) - def create_field(self, name): + def create_field(self, name, *, field_type='char'): """ create a custom field and return it """ model = self.env['ir.model'].search([('model', '=', self.MODEL)]) field = self.env['ir.model.fields'].create({ 'model_id': model.id, 'name': name, 'field_description': name, - 'ttype': 'char', + 'ttype': field_type, }) self.assertIn(name, self.env[self.MODEL]._fields) return field @@ -385,3 +385,12 @@ class TestCustomFields(common.TransactionCase): # uninstall mode: unlink dependant fields field.with_context(_force_unlink=True).unlink() self.assertFalse(dependant.exists()) + + def test_create_binary(self): + """ binary custom fields should be created as attachment=True to avoid + bloating the DB when creating e.g. image fields via studio + """ + self.create_field('x_image', field_type='binary') + custom_binary = self.env[self.MODEL]._fields['x_image'] + + self.assertTrue(custom_binary.attachment) diff --git a/odoo/addons/base/wizard/base_export_language.py b/odoo/addons/base/wizard/base_export_language.py index 4695c250603..e8147c8954e 100644 --- a/odoo/addons/base/wizard/base_export_language.py +++ b/odoo/addons/base/wizard/base_export_language.py @@ -25,7 +25,7 @@ class BaseLanguageExport(models.TransientModel): string='File Format', required=True, default='csv') modules = fields.Many2many('ir.module.module', 'rel_modules_langexport', 'wiz_id', 'module_id', string='Apps To Export', domain=[('state','=','installed')]) - data = fields.Binary('File', readonly=True) + data = fields.Binary('File', readonly=True, attachment=False) state = fields.Selection([('choose', 'choose'), ('get', 'get')], # choose language or get the file default='choose') diff --git a/odoo/addons/base/wizard/base_import_language.py b/odoo/addons/base/wizard/base_import_language.py index aea906b8dc9..1017806119e 100644 --- a/odoo/addons/base/wizard/base_import_language.py +++ b/odoo/addons/base/wizard/base_import_language.py @@ -19,7 +19,7 @@ class BaseLanguageImport(models.TransientModel): name = fields.Char('Language Name', required=True) code = fields.Char('ISO Code', size=5, required=True, help="ISO Language and Country code, e.g. en_US") - data = fields.Binary('File', required=True) + data = fields.Binary('File', required=True, attachment=False) filename = fields.Char('File Name', required=True) overwrite = fields.Boolean('Overwrite Existing Terms', help="If you enable this option, existing translations (including custom ones) " diff --git a/odoo/addons/test_converter/models.py b/odoo/addons/test_converter/models.py index 49fc86cbb07..29a8bcefebf 100644 --- a/odoo/addons/test_converter/models.py +++ b/odoo/addons/test_converter/models.py @@ -12,7 +12,7 @@ class test_model(models.Model): float = fields.Float() numeric = fields.Float(digits=(16, 2)) many2one = fields.Many2one('test_converter.test_model.sub', group_expand='_gbf_m2o') - binary = fields.Binary() + binary = fields.Binary(attachment=False) date = fields.Date() datetime = fields.Datetime() selection = fields.Selection([ |
