From 026205a637d953e9f3669a2dced019fe0ea20c0f Mon Sep 17 00:00:00 2001 From: Antoine Boonen Date: Fri, 6 Oct 2023 12:25:36 +0200 Subject: [PATCH] [IMP] account_peppol: Add actions on dashboard for peppol operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem --------- User want to verify (when he want) if he has bills on Peppol and the status of his customer invoices. Currently, the only option is wait for a cron that runs twice a day. Objective --------- - Add a button in the Kanban card of the customer invoices that updates the status of invoice send by Peppol.  - Add a button in the Kanban card of the incoming journal that fetches received bills on the Peppol network. Solution --------- This commits does several things in order to achieve the objective: - Seperate the peppol cron function into business action and cron function - Add an interface on the journals so that they can call the peppol business functions - Add an inverse function that resets the journal `is_peppol_journal` to False and sets that field to True on the relevant journal. - Add a related field that checks whether the company has peppol active - Add the buttons on the Kandan Dashboard view that call the relevant cron function thanks to the interface. It edi users on the target companies so that only the target companies are updated when a button is pressed and not all companies. task-3531222 closes odoo/odoo#137840 Signed-off-by: Florian Gilbert (flg) --- addons/account_peppol/__manifest__.py | 1 + addons/account_peppol/models/__init__.py | 1 + .../models/account_edi_proxy_user.py | 27 ++++++++++------- .../account_peppol/models/account_journal.py | 24 +++++++++++++++ addons/account_peppol/models/res_company.py | 12 ++++++++ .../views/account_journal_dashboard_views.xml | 29 +++++++++++++++++++ 6 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 addons/account_peppol/models/account_journal.py create mode 100644 addons/account_peppol/views/account_journal_dashboard_views.xml diff --git a/addons/account_peppol/__manifest__.py b/addons/account_peppol/__manifest__.py index 842ef62eb76..179307d1786 100644 --- a/addons/account_peppol/__manifest__.py +++ b/addons/account_peppol/__manifest__.py @@ -16,6 +16,7 @@ ], 'data': [ 'data/cron.xml', + 'views/account_journal_dashboard_views.xml', 'views/account_move_views.xml', 'views/res_partner_views.xml', 'views/res_config_settings_views.xml', diff --git a/addons/account_peppol/models/__init__.py b/addons/account_peppol/models/__init__.py index d956bf5daa1..0c13f2e665a 100644 --- a/addons/account_peppol/models/__init__.py +++ b/addons/account_peppol/models/__init__.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import account_edi_proxy_user +from . import account_journal from . import account_move from . import res_company from . import res_config_settings diff --git a/addons/account_peppol/models/account_edi_proxy_user.py b/addons/account_peppol/models/account_edi_proxy_user.py index 5fd40b15763..bd2d46f63de 100644 --- a/addons/account_peppol/models/account_edi_proxy_user.py +++ b/addons/account_peppol/models/account_edi_proxy_user.py @@ -63,6 +63,18 @@ class AccountEdiProxyClientUser(models.Model): return super()._get_server_url(proxy_type, edi_mode) + # ------------------------------------------------------------------------- + # CRONS + # ------------------------------------------------------------------------- + + def _cron_peppol_get_new_documents(self): + edi_users = self.search([('company_id.account_peppol_proxy_state', '=', 'active')]) + edi_users._peppol_get_new_documents() + + def _cron_peppol_get_message_status(self): + edi_users = self.search([('company_id.account_peppol_proxy_state', '=', 'active')]) + edi_users._peppol_get_message_status() + # ------------------------------------------------------------------------- # BUSINESS ACTIONS # ------------------------------------------------------------------------- @@ -75,12 +87,8 @@ class AccountEdiProxyClientUser(models.Model): return f'{company.peppol_eas}:{company.peppol_endpoint}' return super()._get_proxy_identification(company, proxy_type) - def _cron_peppol_get_new_documents(self): - # Retrieve all new Peppol documents for every edi user in the database - edi_users = self.env['account_edi_proxy_client.user'].search( - [('company_id.account_peppol_proxy_state', '=', 'active')]) - - for edi_user in edi_users: + def _peppol_get_new_documents(self): + for edi_user in self: proxy_acks = [] try: # request all messages that haven't been acknowledged @@ -186,11 +194,8 @@ class AccountEdiProxyClientUser(models.Model): {'message_uuids': proxy_acks}, ) - def _cron_peppol_get_message_status(self): - edi_users = self.env['account_edi_proxy_client.user'].search( - [('company_id.account_peppol_proxy_state', '=', 'active')]) - - for edi_user in edi_users: + def _peppol_get_message_status(self): + for edi_user in self: edi_user_moves = self.env['account.move'].search([ ('peppol_move_state', '=', 'processing'), ('company_id', '=', edi_user.company_id.id), diff --git a/addons/account_peppol/models/account_journal.py b/addons/account_peppol/models/account_journal.py new file mode 100644 index 00000000000..4cd6e988724 --- /dev/null +++ b/addons/account_peppol/models/account_journal.py @@ -0,0 +1,24 @@ +# -*- coding:utf-8 -*- + +from odoo import fields, models + + +class AccountJournal(models.Model): + _inherit = 'account.journal' + + account_peppol_proxy_state = fields.Selection(related='company_id.account_peppol_proxy_state') + is_peppol_journal = fields.Boolean(string="Account used for Peppol", default=False) + + def peppol_get_new_documents(self): + edi_users = self.env['account_edi_proxy_client.user'].search([ + ('company_id.account_peppol_proxy_state', '=', 'active'), + ('company_id', 'in', self.company_id.ids), + ]) + edi_users._peppol_get_new_documents() + + def peppol_get_message_status(self): + edi_users = self.env['account_edi_proxy_client.user'].search([ + ('company_id.account_peppol_proxy_state', '=', 'active'), + ('company_id', 'in', self.company_id.ids), + ]) + edi_users._peppol_get_message_status() diff --git a/addons/account_peppol/models/res_company.py b/addons/account_peppol/models/res_company.py index 7d4ce931ef6..7f4e20167d0 100644 --- a/addons/account_peppol/models/res_company.py +++ b/addons/account_peppol/models/res_company.py @@ -66,6 +66,7 @@ class ResCompany(models.Model): string='PEPPOL Purchase Journal', domain=[('type', '=', 'purchase')], compute='_compute_peppol_purchase_journal_id', store=True, readonly=False, + inverse='_inverse_peppol_purchase_journal_id', ) # ------------------------------------------------------------------------- @@ -152,6 +153,17 @@ class ResCompany(models.Model): else: company.peppol_purchase_journal_id = False + def _inverse_peppol_purchase_journal_id(self): + for company in self: + # This avoid having 2 or more journals from the same company with + # `is_peppol_journal` set to True (which could occur after changes). + journals_to_reset = self.env['account.journal'].search([ + ('company_id', '=', company.id), + ('is_peppol_journal', '=', True), + ]) + journals_to_reset.is_peppol_journal = False + company.peppol_purchase_journal_id.is_peppol_journal = True + @api.depends('email') def _compute_account_peppol_contact_email(self): for company in self: diff --git a/addons/account_peppol/views/account_journal_dashboard_views.xml b/addons/account_peppol/views/account_journal_dashboard_views.xml new file mode 100644 index 00000000000..726146e7a79 --- /dev/null +++ b/addons/account_peppol/views/account_journal_dashboard_views.xml @@ -0,0 +1,29 @@ + + + + account.journal.dashboard.kanban + account.journal + + + + + + + + + + + + Fetch Peppol invoice status + + + + Fetch from Peppol + + + + + + + +