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/base/tests/test_ir_actions.py | |
| 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/base/tests/test_ir_actions.py')
| -rw-r--r-- | odoo/addons/base/tests/test_ir_actions.py | 13 |
1 files changed, 11 insertions, 2 deletions
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) |
