Skip to content
Extraits de code Groupes Projets
Valider 030fb417 rédigé par Benjamin - Le Filament's avatar Benjamin - Le Filament
Parcourir les fichiers

[UPD] add remove mandate functions

parent d2d037a3
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -44,7 +44,7 @@ class AccountBankingMandate(models.Model):
)
return invoice_ids
def _change_invoice_mandate(self, invoice):
def _change_invoice_mandate(self, invoice_ids):
"""
Affecte le mandat courant pur la facture passée en paramètre
:param invoice : objet account.move
......@@ -54,6 +54,8 @@ class AccountBankingMandate(models.Model):
)
if not payment_mode:
raise UserError(_("Aucun mode de prélèvement SEPA configuré."))
for invoice in invoice_ids:
invoice.update(
{
"payment_mode_id": payment_mode.id,
......@@ -61,3 +63,23 @@ class AccountBankingMandate(models.Model):
"mandate_id": self.id,
}
)
def _remove_invoice_mandate(self, invoice_ids):
"""
Supprime le mandat courant pur la facture passée en paramètre
:param invoice : objet account.move
"""
payment_mode = self.env["account.payment.mode"].search(
[("name", "ilike", "Virement")]
)
if not payment_mode:
raise UserError(_("Aucun mode de paiement 'Virement' configuré."))
for invoice in invoice_ids:
invoice.update(
{
"payment_mode_id": payment_mode.id,
"partner_bank_id": False,
"mandate_id": False,
}
)
self.partner_id.customer_payment_mode_id = payment_mode
......@@ -26,8 +26,18 @@
class="btn-outline-info"
style="margin-left: 15px;"
string="Affecter ce mandat aux factures ouvertes"
context="{'action_type': 'update_mandate'}"
attrs="{'invisible': [('state', '!=', 'valid')]}"
/>
<button
name="set_invoice_mandate"
type="object"
class="btn-outline-danger"
style="margin-left: 15px;"
string="Affecter 'Virement' aux factures et cotisations ouvertes"
context="{'action_type': 'remove_mandate'}"
attrs="{'invisible': [('state', 'not in', ['expired', 'cancel'])]}"
/>
</div>
</xpath>
</field>
......
......@@ -4,3 +4,4 @@
from . import account_banking_mandate_change_wizard
from . import account_move_reversal
from . import account_payment_line_create
from . import scop_deces_wizard
......@@ -35,5 +35,8 @@ class AccountBankingMandateChange(models.TransientModel):
)
def change_mandate(self):
for invoice in self.invoice_ids:
self.mandate_id._change_invoice_mandate(invoice)
if self.env.context.get("action_type") == "update_mandate":
self.mandate_id._change_invoice_mandate(self.invoice_ids)
elif self.env.context.get("action_type") == "remove_mandate":
self.mandate_id._remove_invoice_mandate(self.invoice_ids)
......@@ -32,6 +32,8 @@
string="Partenaire"
/>
<field name="invoice_date_due" />
<field name="payment_mode_id" optional="show" />
<field name="mandate_id" optional="show" />
<field name="amount_untaxed_signed" string="Total HT" />
<field
name="amount_total_signed"
......@@ -63,6 +65,15 @@
string="Affecter le mandat"
class="btn-primary"
confirm="Valider le changement de mandat ?"
invisible="context.get('action_type') != 'update_mandate'"
/>
<button
name="change_mandate"
type="object"
string="Supprimer le mandat"
class="btn-danger"
confirm="Valider la suppression des mandats et le passage en virement ?"
invisible="context.get('action_type') != 'remove_mandate'"
/>
<button special="cancel" string="Cancel" />
</footer>
......
# © 2020 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models
class ScopDecesWizard(models.TransientModel):
_inherit = "scop.deces.wizard"
def deces_action(self):
super().deces_action()
partner_id = self.env["res.partner"].browse(self.partner_id)
mandate_ids = self.env["account.banking.mandate"].search(
[
("partner_id", "=", partner_id.id),
("state", "=", "valid"),
("company_id", "=", self.env.company.id),
]
)
if mandate_ids:
for mandate in mandate_ids:
mandate.update({"state": "expired"})
invoice_ids = self.env["account.move"].search([
("mandate_id", "=", mandate.id),
("move_type", "in", ("out_invoice", "out_refund")),
("state", "in", ("draft", "posted")),
("payment_state", "in", ("draft", "not_paid", "partial")),
])
mandate._remove_invoice_mandate(invoice_ids)
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter