-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
base_upflow: add upflow_type and refactor reconcile payload
- Loading branch information
Showing
8 changed files
with
273 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,13 @@ | |
# @author Pierre Verkest <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
import base64 | ||
import logging | ||
|
||
from odoo import _, fields, models | ||
from odoo.exceptions import UserError | ||
from odoo.tools.float_utils import float_compare | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class AccountMove(models.Model): | ||
|
@@ -17,6 +21,81 @@ class AccountMove(models.Model): | |
help="Technical field to get the upflow customer to use on account move", | ||
) | ||
|
||
upflow_type = fields.Selection( | ||
selection=[ | ||
("none", "Not concerned"), | ||
("invoices", "Invoice"), | ||
("payments", "Invoice payment"), | ||
("creditNotes", "Refund"), | ||
("refunds", "Refund payment"), | ||
], | ||
compute="_compute_upflow_type", | ||
help=( | ||
"Technical fields to make sure consistency " | ||
"while sending Journal entry and reconcile " | ||
"payloads. Key values are current payload " | ||
"keys while sending reconcile. While creating " | ||
"malicious entries it can be hard to automatically " | ||
"choose proper type" | ||
), | ||
) | ||
|
||
def _compute_upflow_type(self): | ||
for move in self: | ||
if move.move_type.startswith("in_") or move.state != "posted": | ||
move.upflow_type = "none" | ||
continue | ||
if move.move_type == "out_invoice": | ||
move.upflow_type = "invoices" | ||
elif move.move_type == "out_refund": | ||
move.upflow_type = "creditNotes" | ||
else: | ||
receivables_lines = move.line_ids.filtered( | ||
lambda line: line.account_id.user_type_id.type == "receivable" | ||
) | ||
if not receivables_lines: | ||
move.upflow_type = "none" | ||
continue | ||
debit = sum(receivables_lines.mapped("debit")) | ||
credit = sum(receivables_lines.mapped("credit")) | ||
if ( | ||
float_compare( | ||
debit, | ||
0, | ||
precision_rounding=move.currency_id.rounding, | ||
) | ||
== 0 | ||
and float_compare( | ||
credit, | ||
0, | ||
precision_rounding=move.currency_id.rounding, | ||
) | ||
!= 0 | ||
): | ||
move.upflow_type = "payments" | ||
elif ( | ||
float_compare( | ||
debit, | ||
0, | ||
precision_rounding=move.currency_id.rounding, | ||
) | ||
!= 0 | ||
and float_compare( | ||
credit, | ||
0, | ||
precision_rounding=move.currency_id.rounding, | ||
) | ||
== 0 | ||
): | ||
move.upflow_type = "refunds" | ||
else: | ||
_logger.error( | ||
"Sum of receivable move lines on %s have credit (%d) and debit(%d). " | ||
"Which sounds suspicious and can't set upflow type", | ||
move.name, | ||
) | ||
move.upflow_type = "none" | ||
|
||
def _compute_upflow_commercial_partner_id(self): | ||
# while using OD as counter part or bank statement | ||
# there are chance that partner_id is not set on account.move | ||
|
@@ -56,35 +135,11 @@ def _prepare_upflow_api_payload(self): | |
def get_upflow_api_post_invoice_payload(self): | ||
"""An upflow invoice match with account.move out_invoice odoo type""" | ||
self.ensure_one() | ||
if self.move_type != "out_invoice": | ||
raise UserError( | ||
_( | ||
"You try to get upflow invoice payload " | ||
"on account entry %s with an other type %s " | ||
"(expected out_invoice)" | ||
) | ||
% ( | ||
self.name, | ||
self.move_type, | ||
) | ||
) | ||
return self._prepare_upflow_api_payload() | ||
|
||
def get_upflow_api_post_credit_note_payload(self): | ||
"""An upflow credit note match with account.move out_refund odoo type""" | ||
self.ensure_one() | ||
if self.move_type != "out_refund": | ||
raise UserError( | ||
_( | ||
"You try to get upflow refund payload " | ||
"on account entry %s with an other type %s " | ||
"(expected out_refund)" | ||
) | ||
% ( | ||
self.name, | ||
self.move_type, | ||
) | ||
) | ||
return self._prepare_upflow_api_payload() | ||
|
||
def get_upflow_api_post_payment_payload(self): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.