Skip to content

Commit

Permalink
[IMP] allow to select wallet when making payment via the wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Aug 5, 2022
1 parent e8c4fa3 commit eca8ccc
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 13 deletions.
2 changes: 2 additions & 0 deletions account_wallet/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions account_wallet/demo/account_journal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
<field name="name">Customer Wallet Reserves</field>
<field name="code">WAL</field>
<field name="type">cash</field>
<field name="default_account_id" ref="account_wallet_type_customer" />
<field name="payment_debit_account_id" ref="account_wallet_type_customer" />
<field name="payment_credit_account_id" ref="account_wallet_type_customer" />
</record>
</odoo>
2 changes: 1 addition & 1 deletion account_wallet/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
26 changes: 17 additions & 9 deletions account_wallet/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
6 changes: 4 additions & 2 deletions account_wallet/views/account_move_line.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2021 ACSONE SA/NV
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<!--
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). -->
<odoo>

<record id="account_move_line_view_form" model="ir.ui.view">
Expand Down
14 changes: 14 additions & 0 deletions account_wallet/views/account_payment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2021 ACSONE SA/NV
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="view_account_payment_form" model="ir.ui.view">
<field name="model">account.payment</field>
<field name="inherit_id" ref="account.view_account_payment_form" />
<field name="arch" type="xml">
<field name="journal_id" position="after">
<field name="account_wallet_id" />
</field>
</field>
</record>
</odoo>
2 changes: 1 addition & 1 deletion account_wallet/views/account_wallet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<field name="name">Journal Items</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">account.move.line</field>
<field name="view_mode">tree</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('account_wallet_id', '=', active_id)]</field>
<field name="context">{"search_default_posted": 1}</field>
</record>
Expand Down
1 change: 1 addition & 0 deletions account_wallet/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import account_payment_register
from . import wizard_account_move_credit_notes_wallet
21 changes: 21 additions & 0 deletions account_wallet/wizards/account_payment_register.py
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions account_wallet/wizards/account_payment_register.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
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). -->
<odoo>

<record id="view_account_payment_register_form" model="ir.ui.view">
<field name="model">account.payment.register</field>
<field name="inherit_id" ref="account.view_account_payment_register_form" />
<field name="arch" type="xml">
<field name="journal_id" position="after">
<field name="wallet_id" />
</field>
</field>
</record>
</odoo>

0 comments on commit eca8ccc

Please sign in to comment.