|
| 1 | +========================== |
| 2 | +Attachment Zipped Download |
| 3 | +========================== |
| 4 | + |
| 5 | +.. |
| 6 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 7 | + !! This file is generated by oca-gen-addon-readme !! |
| 8 | + !! changes will be overwritten. !! |
| 9 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 10 | + !! source digest: sha256:4163544eb16787f39f46edcd97305586594a6f708c1e489908d344467c82483e |
| 11 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 12 | +
|
| 13 | +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png |
| 14 | + :target: https://odoo-community.org/page/development-status |
| 15 | + :alt: Beta |
| 16 | +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png |
| 17 | + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html |
| 18 | + :alt: License: AGPL-3 |
| 19 | +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github |
| 20 | + :target: https://github.com/OCA/knowledge/tree/17.0/attachment_zipped_download |
| 21 | + :alt: OCA/knowledge |
| 22 | +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png |
| 23 | + :target: https://translation.odoo-community.org/projects/knowledge-17-0/knowledge-17-0-attachment_zipped_download |
| 24 | + :alt: Translate me on Weblate |
| 25 | +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png |
| 26 | + :target: https://runboat.odoo-community.org/builds?repo=OCA/knowledge&target_branch=17.0 |
| 27 | + :alt: Try me on Runboat |
| 28 | + |
| 29 | +|badge1| |badge2| |badge3| |badge4| |badge5| |
| 30 | + |
| 31 | +This module allows downloading multiple attachments as a zip file. |
| 32 | + |
| 33 | +This also provide a helper class IrAttachmentActionDownloadMixin to be |
| 34 | +used by developer to add action method on models. |
| 35 | + |
| 36 | +**Table of contents** |
| 37 | + |
| 38 | +.. contents:: |
| 39 | + :local: |
| 40 | + |
| 41 | +Usage |
| 42 | +===== |
| 43 | + |
| 44 | +1. Go to *Settings > Technical > Database Structure > Attachments* and |
| 45 | + select some files. |
| 46 | +2. Go to *Actions > Download* and a zip file containing the selected |
| 47 | + files will be downloaded. |
| 48 | + |
| 49 | +## For developer |
| 50 | + |
| 51 | +You can reuse the IrAttachmentActionDownloadMixin on your favorite |
| 52 | +models: |
| 53 | + |
| 54 | +:: |
| 55 | + |
| 56 | + from odoo import models |
| 57 | + |
| 58 | + |
| 59 | + class StockPicking(models.Model): |
| 60 | + _name = "stock.picking" |
| 61 | + _inherit = ["stock.picking", "ir.attachment.action_download"] |
| 62 | + |
| 63 | +Then you can add an action button on list view line or on the action |
| 64 | +button (when multiple lines are selected) to download all files: |
| 65 | + |
| 66 | +:: |
| 67 | + |
| 68 | + <odoo> |
| 69 | + <!-- |
| 70 | + add a button on list view to download all attachement present |
| 71 | + on the given transfert |
| 72 | + --> |
| 73 | + <record id="vpicktree" model="ir.ui.view"> |
| 74 | + <field name="inherit_id" ref="stock.vpicktree"/> |
| 75 | + <field name="name">stock.picking.tree download attachments</field> |
| 76 | + <field name="model">stock.picking</field> |
| 77 | + <field name="arch" type="xml"> |
| 78 | + <field name="json_popover" position="after"> |
| 79 | + <button name="action_download_attachments" |
| 80 | + type="object" |
| 81 | + icon="fa-download" |
| 82 | + string="Download attachment(s)" |
| 83 | + aria-label="Download Proof documents" |
| 84 | + class="float-right"/> |
| 85 | + </field> |
| 86 | + </field> |
| 87 | + </record> |
| 88 | + |
| 89 | + <!-- |
| 90 | + Add "Download attachments" item in the Action menu when |
| 91 | + multiple records are selected |
| 92 | + --> |
| 93 | + <record id="action_download_picking_attachements" model="ir.actions.server"> |
| 94 | + <field name="name">Download attachments</field> |
| 95 | + <field name="model_id" ref="stock.model_stock_picking"/> |
| 96 | + <field name="binding_model_id" ref="stock.model_stock_picking"/> |
| 97 | + <field name="binding_view_types">list</field> |
| 98 | + <field name="state">code</field> |
| 99 | + <field name="code"> |
| 100 | + action = records.action_download_attachments() |
| 101 | + </field> |
| 102 | + </record> |
| 103 | + </odoo> |
| 104 | + |
| 105 | +.. note:: |
| 106 | + |
| 107 | + Even you will be able to generate a zip file with multiple document |
| 108 | + with the same name it's advice to overwrite \_compute_zip_file_name |
| 109 | + to improve the name. When a slash (/) is present in the path it will |
| 110 | + create a directory. This example will create a directory per |
| 111 | + stock.picking using its name: |
| 112 | + |
| 113 | + :: |
| 114 | + |
| 115 | + class IrAttachment(models.Model): |
| 116 | + _inherit = "ir.attachment" |
| 117 | + |
| 118 | + def _compute_zip_file_name(self): |
| 119 | + self.ensure_one() |
| 120 | + if self.res_model and self.res_model == "stock.picking": |
| 121 | + return ( |
| 122 | + self.env[self.res_model] |
| 123 | + .browse(self.res_id) |
| 124 | + .display_name.replace("/", "-") |
| 125 | + + "/" |
| 126 | + + self.name |
| 127 | + ) |
| 128 | + return super()._compute_zip_file_name() |
| 129 | + |
| 130 | +Bug Tracker |
| 131 | +=========== |
| 132 | + |
| 133 | +Bugs are tracked on `GitHub Issues <https://github.com/OCA/knowledge/issues>`_. |
| 134 | +In case of trouble, please check there if your issue has already been reported. |
| 135 | +If you spotted it first, help us to smash it by providing a detailed and welcomed |
| 136 | +`feedback <https://github.com/OCA/knowledge/issues/new?body=module:%20attachment_zipped_download%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
| 137 | + |
| 138 | +Do not contact contributors directly about support or help with technical issues. |
| 139 | + |
| 140 | +Credits |
| 141 | +======= |
| 142 | + |
| 143 | +Authors |
| 144 | +------- |
| 145 | + |
| 146 | +* Tecnativa |
| 147 | + |
| 148 | +Contributors |
| 149 | +------------ |
| 150 | + |
| 151 | +- César Fernández Domínguez <cesfernandez@outlook.com> |
| 152 | +- `Tecnativa <https://www.tecnativa.com>`__: |
| 153 | + |
| 154 | + - Víctor Martínez |
| 155 | + - Pedro M. Baeza |
| 156 | + |
| 157 | +- Pierre Verkest <pierreverkest@gmail.com> |
| 158 | + |
| 159 | +Maintainers |
| 160 | +----------- |
| 161 | + |
| 162 | +This module is maintained by the OCA. |
| 163 | + |
| 164 | +.. image:: https://odoo-community.org/logo.png |
| 165 | + :alt: Odoo Community Association |
| 166 | + :target: https://odoo-community.org |
| 167 | + |
| 168 | +OCA, or the Odoo Community Association, is a nonprofit organization whose |
| 169 | +mission is to support the collaborative development of Odoo features and |
| 170 | +promote its widespread use. |
| 171 | + |
| 172 | +This module is part of the `OCA/knowledge <https://github.com/OCA/knowledge/tree/17.0/attachment_zipped_download>`_ project on GitHub. |
| 173 | + |
| 174 | +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
0 commit comments