diff --git a/CHANGELOG b/CHANGELOG index 8fb51a45f8..d2f55d0edc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add resources method to ModelStorage * Validate selection format in Dict schema * Allow to extend Field's string and help * Add console diff --git a/doc/ref/models/models.rst b/doc/ref/models/models.rst index 10157e3bb7..690c6d6253 100644 --- a/doc/ref/models/models.rst +++ b/doc/ref/models/models.rst @@ -328,6 +328,11 @@ Dual methods: Instance methods: +.. method:: ModelStorage.resources() + + Return a dictionary with the number of attachments (`attachment_count`), + notes (`note_count`) and unread note (`note_unread`). + .. method:: ModelStorage.get_rec_name(name) Getter for the :class:`trytond.model.fields.Function` field diff --git a/trytond/model/modelstorage.py b/trytond/model/modelstorage.py index 650142bd67..1e8772408f 100644 --- a/trytond/model/modelstorage.py +++ b/trytond/model/modelstorage.py @@ -114,6 +114,7 @@ class ModelStorage(Model): 'search': RPC(result=lambda r: list(map(int, r))), 'search_count': RPC(), 'search_read': RPC(), + 'resources': RPC(instantiate=0, unique=False), 'export_data': RPC(instantiate=0, unique=False), 'import_data': RPC(readonly=False), }) @@ -525,6 +526,24 @@ class ModelStorage(Model): return domain return process(domain) + def resources(self): + pool = Pool() + Attachment = pool.get('ir.attachment') + Note = pool.get('ir.note') + + return { + 'attachment_count': Attachment.search_count([ + ('resource', '=', str(self)), + ]), + 'note_count': Note.search_count([ + ('resource', '=', str(self)), + ]), + 'note_unread': Note.search_count([ + ('resource', '=', str(self)), + ('unread', '=', True), + ]), + } + def get_rec_name(self, name): ''' Return the rec_name of the instance.