[IMP] account_edi: Add the possibility to download edi document from
list view In some occasions, we want to be able to download all edi documents so the user can upload them on a governemental platform. From the list view of all the invoice, it is now possible to selected as many invoice as we want, and with a newly added action download them into a zip. task-3122424 closes odoo/odoo#116854 X-original-commit: 5171f607e1fddde06b769ebb78d82548ad4dc84d Signed-off-by: Nicolas Viseur (vin) <vin@odoo.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
from . import models
|
||||
from . import controller
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
from . import main
|
||||
@@ -0,0 +1,18 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from odoo import http
|
||||
from odoo.http import request, content_disposition
|
||||
|
||||
|
||||
class EdiDocumentDownloadController(http.Controller):
|
||||
@http.route('/account_edi/download_edi_documents', type='http', auth='user')
|
||||
def download_edi_documents(self, **args):
|
||||
ids = list(map(int, request.httprequest.args.getlist('ids')))
|
||||
content = request.env['account.move'].browse(ids)._create_zipped()
|
||||
headers = [
|
||||
('Content-Type', 'zip'),
|
||||
('X-Content-Type-Options', 'nosniff'),
|
||||
('Content-Length', len(content)),
|
||||
('Content-Disposition', content_disposition('edi_documents.zip')),
|
||||
]
|
||||
return request.make_response(content, headers)
|
||||
@@ -1,5 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import io
|
||||
import zipfile
|
||||
from werkzeug.urls import url_encode
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
@@ -434,6 +439,27 @@ class AccountMove(models.Model):
|
||||
move_result.setdefault('attachments', []).extend(edi_attachments.get('attachments', []))
|
||||
return result
|
||||
|
||||
####################################################
|
||||
# Export Electronic Document
|
||||
####################################################
|
||||
|
||||
def _action_download_electronic_invoice(self):
|
||||
if not self:
|
||||
return False
|
||||
return {
|
||||
'type': 'ir.actions.act_url',
|
||||
'url': '/account_edi/download_edi_documents?%s' % url_encode({'ids': self.filtered('edi_document_ids').ids}),
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
def _create_zipped(self):
|
||||
buffer = io.BytesIO()
|
||||
with zipfile.ZipFile(buffer, 'w', compression=zipfile.ZIP_DEFLATED) as zipfile_obj:
|
||||
for invoice in self:
|
||||
for document in invoice.edi_document_ids:
|
||||
if document.state in {'sent', 'cancelled'}:
|
||||
zipfile_obj.writestr(document.display_name, document.attachment_id.raw)
|
||||
return buffer.getvalue()
|
||||
|
||||
class AccountMoveLine(models.Model):
|
||||
_inherit = 'account.move.line'
|
||||
|
||||
@@ -90,13 +90,13 @@
|
||||
<div>The invoice will be processed asynchronously by the following E-invoicing service :
|
||||
<field name="edi_web_services_to_process" class="oe_inline"/>
|
||||
</div>
|
||||
<button name="button_process_edi_web_services" type="object" class="oe_link" string="Process now" />
|
||||
<button name="button_process_edi_web_services" type="object" class="oe_link" string="Process now" />
|
||||
</div>
|
||||
<div class="alert alert-danger" role="alert" style="margin-bottom:0px;"
|
||||
attrs="{'invisible': ['|', ('edi_error_count', '=', 0), ('edi_blocking_level', '!=', 'error')]}">
|
||||
<div class="o_row">
|
||||
<field name="edi_error_message" />
|
||||
<button name="%(account_edi.action_open_edi_documents)d" string="⇒ See errors" type="action" class="oe_link" attrs="{'invisible': [('edi_error_count', '=', 1)]}" />
|
||||
<button name="%(account_edi.action_open_edi_documents)d" string="⇒ See errors" type="action" class="oe_link" attrs="{'invisible': [('edi_error_count', '=', 1)]}" />
|
||||
<button name="action_retry_edi_documents_error" type="object" class="oe_link oe_inline" string="Retry" />
|
||||
</div>
|
||||
</div>
|
||||
@@ -104,14 +104,14 @@
|
||||
attrs="{'invisible': ['|', ('edi_error_count', '=', 0), ('edi_blocking_level', '!=', 'warning')]}">
|
||||
<div class="o_row">
|
||||
<field name="edi_error_message" />
|
||||
<button name="%(account_edi.action_open_edi_documents)d" string="⇒ See errors" type="action" class="oe_link" attrs="{'invisible': [('edi_error_count', '=', 1)]}" />
|
||||
<button name="%(account_edi.action_open_edi_documents)d" string="⇒ See errors" type="action" class="oe_link" attrs="{'invisible': [('edi_error_count', '=', 1)]}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="alert alert-info" role="alert" style="margin-bottom:0px;"
|
||||
attrs="{'invisible': ['|', ('edi_error_count', '=', 0), ('edi_blocking_level', '!=', 'info')]}">
|
||||
<div class="o_row">
|
||||
<field name="edi_error_message" />
|
||||
<button name="%(account_edi.action_open_edi_documents)d" string="⇒ See errors" type="action" class="oe_link" attrs="{'invisible': [('edi_error_count', '=', 1)]}" />
|
||||
<button name="%(account_edi.action_open_edi_documents)d" string="⇒ See errors" type="action" class="oe_link" attrs="{'invisible': [('edi_error_count', '=', 1)]}" />
|
||||
</div>
|
||||
</div>
|
||||
</xpath>
|
||||
@@ -142,5 +142,16 @@
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
<record id="model_account_download_electronic_invoice" model="ir.actions.server">
|
||||
<field name="name">Download Electronic Invoices</field>
|
||||
<field name="model_id" ref="model_account_move"/>
|
||||
<field name="binding_model_id" ref="model_account_move"/>
|
||||
<field name="binding_view_types">list</field>
|
||||
<field name="state">code</field>
|
||||
<field name="code">
|
||||
if records:
|
||||
action = records._action_download_electronic_invoice()
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user