summaryrefslogtreecommitdiff
path: root/addons/account_edi_extended/models
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/account_edi_extended/models
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/account_edi_extended/models')
-rw-r--r--addons/account_edi_extended/models/__init__.py3
-rw-r--r--addons/account_edi_extended/models/account_edi_document.py18
-rw-r--r--addons/account_edi_extended/models/account_move.py81
-rw-r--r--addons/account_edi_extended/models/account_payment.py12
4 files changed, 114 insertions, 0 deletions
diff --git a/addons/account_edi_extended/models/__init__.py b/addons/account_edi_extended/models/__init__.py
new file mode 100644
index 00000000..e8ed2ffb
--- /dev/null
+++ b/addons/account_edi_extended/models/__init__.py
@@ -0,0 +1,3 @@
+from . import account_edi_document
+from . import account_move
+from . import account_payment
diff --git a/addons/account_edi_extended/models/account_edi_document.py b/addons/account_edi_extended/models/account_edi_document.py
new file mode 100644
index 00000000..0894b13e
--- /dev/null
+++ b/addons/account_edi_extended/models/account_edi_document.py
@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+from odoo import models, fields, _
+import logging
+
+_logger = logging.getLogger(__name__)
+DEFAULT_BLOCKING_LEVEL = 'warning' # Keep previous behavior. TODO : when account_edi_extended is merged with account_edi, should be 'error' (document will not be processed again until forced retry or reset to draft)
+
+
+class AccountEdiDocument(models.Model):
+ _inherit = 'account.edi.document'
+
+ blocking_level = fields.Selection(selection=[('info', 'Info'), ('warning', 'Warning'), ('error', 'Error')],
+ help="Blocks the document current operation depending on the error severity :\n"
+ " * Info: the document is not blocked and everything is working as it should.\n"
+ " * Warning : there is an error that doesn't prevent the current Electronic Invoicing operation to succeed.\n"
+ " * Error : there is an error that blocks the current Electronic Invoicing operation.")
+
diff --git a/addons/account_edi_extended/models/account_move.py b/addons/account_edi_extended/models/account_move.py
new file mode 100644
index 00000000..4f81822a
--- /dev/null
+++ b/addons/account_edi_extended/models/account_move.py
@@ -0,0 +1,81 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, models, fields, _
+
+
+class AccountMove(models.Model):
+ _inherit = 'account.move'
+
+ edi_show_abandon_cancel_button = fields.Boolean(
+ compute='_compute_edi_show_abandon_cancel_button')
+ edi_error_message = fields.Html(compute='_compute_edi_error_message')
+ edi_blocking_level = fields.Selection(selection=[('info', 'Info'), ('warning', 'Warning'), ('error', 'Error')], compute='_compute_edi_error_message')
+
+ @api.depends(
+ 'edi_document_ids',
+ 'edi_document_ids.state',
+ 'edi_document_ids.blocking_level',
+ 'edi_document_ids.edi_format_id',
+ 'edi_document_ids.edi_format_id.name')
+ def _compute_edi_web_services_to_process(self):
+ # OVERRIDE to take blocking_level into account
+ for move in self:
+ to_process = move.edi_document_ids.filtered(lambda d: d.state in ['to_send', 'to_cancel'] and d.blocking_level != 'error')
+ format_web_services = to_process.edi_format_id.filtered(lambda f: f._needs_web_services())
+ move.edi_web_services_to_process = ', '.join(f.name for f in format_web_services)
+
+ @api.depends(
+ 'state',
+ 'edi_document_ids.state',
+ 'edi_document_ids.attachment_id')
+ def _compute_edi_show_abandon_cancel_button(self):
+ for move in self:
+ move.edi_show_abandon_cancel_button = any(doc.edi_format_id._needs_web_services()
+ and doc.state == 'to_cancel'
+ and move.is_invoice(include_receipts=True)
+ and doc.edi_format_id._is_required_for_invoice(move)
+ for doc in move.edi_document_ids)
+
+ @api.depends('edi_error_count', 'edi_document_ids.error', 'edi_document_ids.blocking_level')
+ def _compute_edi_error_message(self):
+ for move in self:
+ if move.edi_error_count == 0:
+ move.edi_error_message = None
+ move.edi_blocking_level = None
+ elif move.edi_error_count == 1:
+ error_doc = move.edi_document_ids.filtered(lambda d: d.error)
+ move.edi_error_message = error_doc.error
+ move.edi_blocking_level = error_doc.blocking_level
+ else:
+ error_levels = set([doc.blocking_level for doc in move.edi_document_ids])
+ if 'error' in error_levels:
+ move.edi_error_message = str(move.edi_error_count) + _(" Electronic invoicing error(s)")
+ move.edi_blocking_level = 'error'
+ elif 'warning' in error_levels:
+ move.edi_error_message = str(move.edi_error_count) + _(" Electronic invoicing warning(s)")
+ move.edi_blocking_level = 'warning'
+ else:
+ move.edi_error_message = str(move.edi_error_count) + _(" Electronic invoicing info(s)")
+ move.edi_blocking_level = 'info'
+
+ def action_retry_edi_documents_error(self):
+ self.edi_document_ids.write({'error': False, 'blocking_level': False})
+ self.action_process_edi_web_services()
+
+ def button_abandon_cancel_posted_posted_moves(self):
+ '''Cancel the request for cancellation of the EDI.
+ '''
+ documents = self.env['account.edi.document']
+ for move in self:
+ is_move_marked = False
+ for doc in move.edi_document_ids:
+ if doc.state == 'to_cancel' \
+ and move.is_invoice(include_receipts=True) \
+ and doc.edi_format_id._is_required_for_invoice(move):
+ documents |= doc
+ is_move_marked = True
+ if is_move_marked:
+ move.message_post(body=_("A request for cancellation of the EDI has been called off."))
+
+ documents.write({'state': 'sent'})
diff --git a/addons/account_edi_extended/models/account_payment.py b/addons/account_edi_extended/models/account_payment.py
new file mode 100644
index 00000000..558c4aaa
--- /dev/null
+++ b/addons/account_edi_extended/models/account_payment.py
@@ -0,0 +1,12 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import models
+
+
+class AccountPayment(models.Model):
+ _inherit = 'account.payment'
+
+ def action_retry_edi_documents_error(self):
+ self.ensure_one()
+ return self.move_id.action_retry_edi_documents_error()