diff --git a/addons/account_peppol/models/account_journal.py b/addons/account_peppol/models/account_journal.py index 4cd6e988724..b19e7b84ab5 100644 --- a/addons/account_peppol/models/account_journal.py +++ b/addons/account_peppol/models/account_journal.py @@ -1,6 +1,6 @@ # -*- coding:utf-8 -*- -from odoo import fields, models +from odoo import _, fields, models class AccountJournal(models.Model): @@ -22,3 +22,14 @@ class AccountJournal(models.Model): ('company_id', 'in', self.company_id.ids), ]) edi_users._peppol_get_message_status() + + def action_peppol_ready_moves(self): + return { + 'name': _("Peppol Ready invoices"), + 'type': 'ir.actions.act_window', + 'view_mode': 'list', + 'res_model': 'account.move', + 'context': { + 'search_default_peppol_ready': 1, + } + } diff --git a/addons/account_peppol/models/account_move.py b/addons/account_peppol/models/account_move.py index 2e48ec22291..9486942354e 100644 --- a/addons/account_peppol/models/account_move.py +++ b/addons/account_peppol/models/account_move.py @@ -11,15 +11,16 @@ class AccountMove(models.Model): peppol_message_uuid = fields.Char(string='PEPPOL message ID') peppol_move_state = fields.Selection( selection=[ - ('to_send', 'To Send'), - ('processing', 'Processing'), + ('ready', 'Ready to send'), + ('to_send', 'Queued'), + ('processing', 'Pending Reception'), ('canceled', 'Canceled'), ('done', 'Done'), ('error', 'Error'), ], + compute='_compute_peppol_move_state', store=True, string='PEPPOL status', copy=False, - readonly=True, ) peppol_is_demo_uuid = fields.Boolean(compute="_compute_peppol_is_demo_uuid") @@ -29,8 +30,22 @@ class AccountMove(models.Model): if any(move.peppol_move_state in {'processing', 'done'} for move in self): raise UserError(_("Cannot cancel an entry that has already been sent to PEPPOL")) self.peppol_move_state = 'canceled' + self.send_and_print_values = False @api.depends('peppol_message_uuid') def _compute_peppol_is_demo_uuid(self): for move in self: move.peppol_is_demo_uuid = (move.peppol_message_uuid or '').startswith('demo_') + + @api.depends('state') + def _compute_peppol_move_state(self): + for move in self: + if all([ + move.company_id.account_peppol_proxy_state == 'active', + move.partner_id.account_peppol_is_endpoint_valid, + move.state == 'posted', + not move.peppol_move_state, + ]): + move.peppol_move_state = 'ready' + else: + move.peppol_move_state = move.peppol_move_state diff --git a/addons/account_peppol/models/res_company.py b/addons/account_peppol/models/res_company.py index 354c6a03ff8..abf8b05b620 100644 --- a/addons/account_peppol/models/res_company.py +++ b/addons/account_peppol/models/res_company.py @@ -43,6 +43,7 @@ class ResCompany(models.Model): account_peppol_migration_key = fields.Char(string="Migration Key") account_peppol_phone_number = fields.Char( string='Phone number (for validation)', + compute='_compute_account_peppol_phone_number', store=True, readonly=False, help='You will receive a verification code to this phone number', ) account_peppol_proxy_state = fields.Selection( @@ -72,7 +73,7 @@ class ResCompany(models.Model): # HELPER METHODS # ------------------------------------------------------------------------- - def _sanitize_peppol_phone_number(self): + def _sanitize_peppol_phone_number(self, phone_number=None): self.ensure_one() error_message = _( @@ -83,7 +84,10 @@ class ResCompany(models.Model): if not phonenumbers: raise ValidationError(error_message) - phone_number = self.account_peppol_phone_number + phone_number = phone_number or self.account_peppol_phone_number + if not phone_number: + return + if not phone_number.startswith('+'): phone_number = f'+{phone_number}' @@ -164,6 +168,17 @@ class ResCompany(models.Model): if not company.account_peppol_contact_email: company.account_peppol_contact_email = company.email + @api.depends('phone') + def _compute_account_peppol_phone_number(self): + for company in self: + if not company.account_peppol_phone_number: + try: + # precompute only if it's a valid phone number + company._sanitize_peppol_phone_number(company.phone) + company.account_peppol_phone_number = company.phone + except ValidationError: + continue + # ------------------------------------------------------------------------- # LOW-LEVEL METHODS # ------------------------------------------------------------------------- diff --git a/addons/account_peppol/tools/demo_utils.py b/addons/account_peppol/tools/demo_utils.py index 3b405c44c9d..f0a40e3795b 100644 --- a/addons/account_peppol/tools/demo_utils.py +++ b/addons/account_peppol/tools/demo_utils.py @@ -58,7 +58,7 @@ def _mock_make_request(func, self, *args, **kwargs): return { 'messages': [{ 'message_uuid': 'demo_%s' % uuid.uuid4(), - } for i in args[1]], + } for i in args[1]['documents']], } endpoint = args[0].split('/')[-1] diff --git a/addons/account_peppol/views/account_journal_dashboard_views.xml b/addons/account_peppol/views/account_journal_dashboard_views.xml index f76f3ab00e8..cd5b529f162 100644 --- a/addons/account_peppol/views/account_journal_dashboard_views.xml +++ b/addons/account_peppol/views/account_journal_dashboard_views.xml @@ -17,6 +17,9 @@
Fetch Peppol invoice status
+
+ Peppol ready invoices +
diff --git a/addons/account_peppol/views/account_move_views.xml b/addons/account_peppol/views/account_move_views.xml index 3df8b2095c3..7d7676bdc60 100644 --- a/addons/account_peppol/views/account_move_views.xml +++ b/addons/account_peppol/views/account_move_views.xml @@ -72,7 +72,12 @@ - + + + + + + diff --git a/addons/account_peppol/wizard/account_move_send.py b/addons/account_peppol/wizard/account_move_send.py index cc13bd2b1f7..22ca2c77d8a 100644 --- a/addons/account_peppol/wizard/account_move_send.py +++ b/addons/account_peppol/wizard/account_move_send.py @@ -107,6 +107,10 @@ class AccountMoveSend(models.TransientModel): if all([self.checkbox_send_peppol, self.enable_peppol, self.enable_ubl_cii_xml, not self.checkbox_ubl_cii_xml]): self.checkbox_ubl_cii_xml = True + if self.checkbox_send_peppol and self.enable_peppol: + for move in self.move_ids: + if not move.peppol_move_state or move.peppol_move_state == 'ready': + move.peppol_move_state = 'to_send' return super().action_send_and_print(force_synchronous=force_synchronous, allow_fallback_pdf=allow_fallback_pdf, **kwargs)