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 + + + + + + + +