Sélectionner une révision Git
ecozimut_project_perf.py
account_payment_order.py 3,76 Kio
# Copyright 2020 Le Filament
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
from odoo.exceptions import ValidationError
class AccountPaymentOrder(models.Model):
_inherit = "account.payment.order"
payment_line_amount = fields.Float(
string="Total Opérations", compute="_compute_payment_line_amount"
)
bank_line_amount = fields.Float(
string="Total Lignes de paiement", compute="_compute_bank_line_amount"
)
attachment_ids = fields.One2many(
comodel_name="ir.attachment", compute="_compute_attachment_ids"
)
# ------------------------------------------------------
# Compute fields
# ------------------------------------------------------
def _compute_payment_line_amount(self):
for po in self:
po.payment_line_amount = sum(po.payment_line_ids.mapped("amount_currency"))
def _compute_bank_line_amount(self):
for po in self:
po.bank_line_amount = sum(po.bank_line_ids.mapped("amount_currency"))
def _compute_attachment_ids(self):
Attachment = self.env["ir.attachment"]
for po in self:
po.attachment_ids = Attachment.search(
[
("res_model", "=", "account.payment.order"),
("res_id", "=", po.id),
]
)
# ------------------------------------------------------
# Button function
# ------------------------------------------------------
def view_payment_line(self):
tree_id = self.env.ref("cgscop_cotisation.scop_account_payment_line_tree").id
search_id = self.env.ref(
"cgscop_cotisation.scop_account_payment_line_search"
).id
return {
"type": "ir.actions.act_window",
"name": "Lignes d'opérations",
"res_model": "account.payment.line",
"views": [[tree_id, "tree"]],
"search_view_id": [search_id, "search"],
"domain": [["order_id", "=", self.id]],
}
def view_account_move(self):
tree_id = self.env.ref("cgscop_cotisation.scop_account_move_tree").id
search_id = self.env.ref("cgscop_cotisation.scop_account_move_search").id
return {
"type": "ir.actions.act_window",
"name": "Pièces comptables de l'ordre de prélèvement",
"res_model": "account.move",
"views": [[tree_id, "tree"], [False, "form"]],
"search_view_id": [search_id, "search"],
"domain": [["payment_order_id", "=", self.id]],
}
# ------------------------------------------------------
# Common function
# ------------------------------------------------------
def check_sepa_order(self):
for order in self:
if not order.sepa:
msg = (
"Les comptes bancaires des coopératives "
"suivantes ne sont pas corrects : \n"
)
payment_line_ids = order.payment_line_ids.mapped("partner_bank_id")
account_ids = payment_line_ids.filtered(lambda a: a.acc_type != "iban")
for acc in account_ids:
msg += " - " + acc.partner_id.name + " - " + acc.acc_number + "\n"
msg += (
"\nVeuillez corriger ces comptes bancaires pour "
"pouvoir valider l'ordre de prélèvement."
)
raise ValidationError(msg)
else:
return True
# ------------------------------------------------------
# Override Parent
# ------------------------------------------------------
def open2generated(self):
self.check_sepa_order()
return super(AccountPaymentOrder, self).open2generated()