From eca8cccaf7a445a59fdb794ef3b12c7ea2f1f07c Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Fri, 5 Aug 2022 10:26:44 +0200 Subject: [PATCH] [IMP] allow to select wallet when making payment via the wizard --- account_wallet/__manifest__.py | 2 ++ account_wallet/demo/account_journal.xml | 3 +++ account_wallet/hooks.py | 2 +- account_wallet/models/account_move_line.py | 26 ++++++++++++------- account_wallet/views/account_move_line.xml | 6 +++-- account_wallet/views/account_payment.xml | 14 ++++++++++ account_wallet/views/account_wallet.xml | 2 +- account_wallet/wizards/__init__.py | 1 + .../wizards/account_payment_register.py | 21 +++++++++++++++ .../wizards/account_payment_register.xml | 17 ++++++++++++ 10 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 account_wallet/views/account_payment.xml create mode 100644 account_wallet/wizards/account_payment_register.py create mode 100644 account_wallet/wizards/account_payment_register.xml diff --git a/account_wallet/__manifest__.py b/account_wallet/__manifest__.py index e243960..a113bbb 100644 --- a/account_wallet/__manifest__.py +++ b/account_wallet/__manifest__.py @@ -17,8 +17,10 @@ "views/account_wallet_type.xml", "views/account_move_line.xml", "views/account_move.xml", + "views/account_payment.xml", "views/res_partner.xml", "wizards/wizard_account_move_credit_notes_wallet.xml", + "wizards/account_payment_register.xml", "views/wallet_settings.xml", ], "license": "AGPL-3", diff --git a/account_wallet/demo/account_journal.xml b/account_wallet/demo/account_journal.xml index bf7397d..5f79716 100644 --- a/account_wallet/demo/account_journal.xml +++ b/account_wallet/demo/account_journal.xml @@ -8,5 +8,8 @@ Customer Wallet Reserves WAL cash + + + diff --git a/account_wallet/hooks.py b/account_wallet/hooks.py index 3bd7a36..95644f7 100644 --- a/account_wallet/hooks.py +++ b/account_wallet/hooks.py @@ -15,8 +15,8 @@ def load_file(env, module, *args): ) load_file(env, "account_wallet", "demo", "ir_sequence.xml") - load_file(env, "account_wallet", "demo", "account_journal.xml") load_file(env, "account_wallet", "demo", "account_account.xml") + load_file(env, "account_wallet", "demo", "account_journal.xml") load_file(env, "account_wallet", "demo", "product_product.xml") load_file(env, "account_wallet", "demo", "account_wallet_type.xml") diff --git a/account_wallet/models/account_move_line.py b/account_wallet/models/account_move_line.py index 4585dad..d8cc060 100644 --- a/account_wallet/models/account_move_line.py +++ b/account_wallet/models/account_move_line.py @@ -71,12 +71,20 @@ def _prepare_account_wallet_values(self, wallet_type): @api.constrains("account_wallet_id", "account_id") def _check_wallet_account(self): """Account must correspond to wallet account""" - if any( - line.account_wallet_id - and line.account_wallet_id.wallet_type_id.account_id != line.account_id - for line in self - ): - raise ValidationError( - _("The account doesn't correspond to the wallet account") - ) - return True + incorrect_lines = self.filtered( + lambda x: x.account_wallet_id + and x.account_wallet_id.wallet_type_id.account_id != x.account_id + ) + if incorrect_lines: + msg = [] + for line in incorrect_lines: + msg.append( + _( + "The move line account %s doesn't correspond to the wallet account %s" + ) + % ( + line.account_id.display_name, + line.account_wallet_id.wallet_type_id.account_id.display_name, + ) + ) + raise ValidationError("\n".join(msg)) diff --git a/account_wallet/views/account_move_line.xml b/account_wallet/views/account_move_line.xml index d8faacb..31acbd5 100644 --- a/account_wallet/views/account_move_line.xml +++ b/account_wallet/views/account_move_line.xml @@ -1,6 +1,8 @@ - + diff --git a/account_wallet/views/account_payment.xml b/account_wallet/views/account_payment.xml new file mode 100644 index 0000000..9c40847 --- /dev/null +++ b/account_wallet/views/account_payment.xml @@ -0,0 +1,14 @@ + + + + + account.payment + + + + + + + + diff --git a/account_wallet/views/account_wallet.xml b/account_wallet/views/account_wallet.xml index e22e8e2..9af4edb 100644 --- a/account_wallet/views/account_wallet.xml +++ b/account_wallet/views/account_wallet.xml @@ -43,7 +43,7 @@ Journal Items ir.actions.act_window account.move.line - tree + tree,form [('account_wallet_id', '=', active_id)] {"search_default_posted": 1} diff --git a/account_wallet/wizards/__init__.py b/account_wallet/wizards/__init__.py index 65f7aa2..736d9cf 100644 --- a/account_wallet/wizards/__init__.py +++ b/account_wallet/wizards/__init__.py @@ -1 +1,2 @@ +from . import account_payment_register from . import wizard_account_move_credit_notes_wallet diff --git a/account_wallet/wizards/account_payment_register.py b/account_wallet/wizards/account_payment_register.py new file mode 100644 index 0000000..fe7ad2f --- /dev/null +++ b/account_wallet/wizards/account_payment_register.py @@ -0,0 +1,21 @@ +# Copyright (C) 2022-Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class AccountPaymentRegister(models.TransientModel): + + _inherit = "account.payment.register" + + wallet_id = fields.Many2one( + comodel_name="account.wallet", + string="Wallet", + ondelete="cascade", + ) + + def _create_payment_vals_from_wizard(self): + res = super()._create_payment_vals_from_wizard() + res["account_wallet_id"] = self.wallet_id.id + return res diff --git a/account_wallet/wizards/account_payment_register.xml b/account_wallet/wizards/account_payment_register.xml new file mode 100644 index 0000000..c443d70 --- /dev/null +++ b/account_wallet/wizards/account_payment_register.xml @@ -0,0 +1,17 @@ + + + + + + account.payment.register + + + + + + + +