Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][ADD] account_wallet - NOBUMP #9

Open
wants to merge 60 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
d67507b
[14.0][IMP] account_cagnotte => account_wallet
rousseldenis May 21, 2021
bd1950f
[14.0][IMP] account_wallet: Add partner relation
rousseldenis Jun 14, 2021
464c441
[14.0][IMP] account_wallet: Don't create move with a name
rousseldenis Jun 15, 2021
26f24a5
[14.0][IMP] account_wallet: Fix tests
rousseldenis Jun 15, 2021
e4a042b
[14.0][IMP] account_wallet: Improve form
rousseldenis Jun 15, 2021
ba37c18
[14.0][IMP] account_wallet: Add migration scripts
rousseldenis Jul 28, 2021
17b2ae3
[14.0][IMP] account_wallet: Migrate only if former table exist
rousseldenis Jul 29, 2021
e51c481
[14.0][IMP] account_wallet: Add remark for future migrations
rousseldenis Jul 29, 2021
ae817e5
[14.0][IMP] account_wallet: Remove former methods as models have been…
rousseldenis Jul 29, 2021
166131d
[14.0][IMP] account_wallet: tests improvements, use create multi, cor…
rousseldenis Jul 29, 2021
cd74ba1
[14.0][IMP] account_wallet: Add todo for name_search
rousseldenis Jul 30, 2021
d967906
[14.0][IMP] account_wallet: Improve test, set default account
rousseldenis Aug 19, 2021
15707d8
[14.0][FIX] account_wallet: Prepare good value for move
rousseldenis Aug 24, 2021
7c75cd2
Apply pre-commit
sbidoul Oct 7, 2021
6be4432
[14.0][FIX] account_wallet: Demo files will be loaded by code
rousseldenis Oct 8, 2021
c5271f2
[14.0][FIX] account_wallet*: Rely on openupgradelib
rousseldenis Oct 8, 2021
04270e6
[14.0][IMP] account_wallet*: Remove OCA ref
rousseldenis Oct 8, 2021
e921831
[UPD] README.rst
Oct 8, 2021
50465ed
account_wallet 14.0.1.0.1
Oct 8, 2021
891a134
[14.0][IMP] account_wallet: Don't retrieve too much exisisting wallets
rousseldenis Oct 11, 2021
c2fd17b
account_wallet 14.0.1.0.2
Oct 12, 2021
16def44
[14.0][IMP] account_wallet: Remove partner name from wallet display name
rousseldenis Mar 21, 2022
716a96a
pre-commit: fix manifests website
sbidoul May 18, 2022
f55ba3d
[UPD] Update account_wallet.pot
May 18, 2022
f94cedc
[14.0][IMP] account_wallet: Add wallet on payment side
rousseldenis Nov 16, 2021
e01c0cd
[UPD] Update account_wallet.pot
Jun 8, 2022
a1e0d8b
[14.0][FIX] account_wallet
xavier-bouquiaux Oct 26, 2021
02ee640
account_wallet 14.0.1.1.0
Jun 8, 2022
1ae9f16
[FIX] account_wallet : move-> account_wallet_type_id
xavier-bouquiaux Mar 18, 2022
1e4316c
[ADD] wizard to create a refund as wallet
xavier-bouquiaux May 18, 2022
88efe8e
[UPD] Update account_wallet.pot
Jun 14, 2022
97510bc
account_wallet 14.0.1.2.0
Jun 14, 2022
cb9b25f
[UPD] Update account_wallet.pot
Jul 14, 2022
7c4ab74
[ADD] add documentation + reformat + comment
xavier-bouquiaux Jun 14, 2022
a6ff341
[UPD] Update account_wallet.pot
Jul 14, 2022
d69eff8
[IMP] account_wallet: black, isort, prettier
xavier-bouquiaux Jul 18, 2022
9a1c542
[IMP] make account_wallet OCA compliant
xavier-bouquiaux Jul 18, 2022
23cf1c7
[IMP] account_wallet : add no_anonymous feature to force to have only…
legalsylvain Jul 18, 2022
545d9b2
[FIX] account_wallet : Force account_wallet_type to have product_id d…
legalsylvain Jul 18, 2022
32acd33
[IMP] account_wallet : guess income account based on product accounti…
legalsylvain Jul 18, 2022
7b2e714
Merge pull request #2 from legalsylvain/14.0-IMP-account_wallet-produ…
xavier-bouquiaux Jul 25, 2022
b761cc2
Merge pull request #1 from legalsylvain/14.0-IMP-account_wallet-add-n…
xavier-bouquiaux Jul 25, 2022
9582751
[REF] account_wallet : remove useless comment
legalsylvain Jul 25, 2022
73f2bb4
[IMP] account_wallet : add domain on product_id for account_wallet_ty…
legalsylvain Jul 25, 2022
8100b55
[FIX] rename some 'cagnotte' into 'wallet'
legalsylvain Aug 1, 2022
6de4402
[REF] rename wallet_type.xml to fit with OCA convention
legalsylvain Aug 1, 2022
10acc32
[REF] rename wallet_views.xml to fit with OCA convention
legalsylvain Aug 1, 2022
c94432c
[FIX] remove duplicated account.move.line form view, fix incorrect na…
legalsylvain Aug 1, 2022
b49885a
[FIX] remove duplicated account.move form view
legalsylvain Aug 1, 2022
6f6392d
[FIX] remove unnecessary dependency to openupgradelib python librairy
legalsylvain Aug 2, 2022
2887ce5
[REF] refactor test
legalsylvain Aug 2, 2022
6b8c6d7
[FIX] wallet balance should be updated only when related move lines (…
legalsylvain Aug 2, 2022
0d0e392
[REF] rename account.wallet.type 'no_anonymous' field into 'automatic…
legalsylvain Aug 2, 2022
1c69e03
fixup! [FIX] wallet balance should be updated only when related move …
legalsylvain Aug 2, 2022
e8c4fa3
[IMP] new field only_nominative on account.wallet.type model to preve…
legalsylvain Aug 2, 2022
223e7ef
[IMP] allow to select wallet when making payment via the wizard
legalsylvain Aug 5, 2022
f009d90
[FIX] make payment working with refound
legalsylvain Aug 5, 2022
c23d67b
[FIX] make credit_note_product_id configuration working in multi comp…
legalsylvain Aug 5, 2022
f5de492
[IMP] simplify algorigthm
legalsylvain Oct 10, 2022
d8b866d
[DOC] add legalsylvain as contributors
legalsylvain Oct 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions account_wallet/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ class AccountMove(models.Model):
help="Use this field to give coupon to a customer",
states={"draft": [("readonly", False)]},
)

def action_post(self):
self.mapped("line_ids").create_or_set_wallet()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is linked to the other but it's also a MAJOR change

return super().action_post()
92 changes: 30 additions & 62 deletions account_wallet/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

from odoo import api, fields, models
from odoo.exceptions import ValidationError
from odoo.osv.expression import FALSE_DOMAIN
from odoo.tools import float_compare
from odoo.tools.translate import _


Expand All @@ -31,75 +29,45 @@ def _onchange_account_wallet_id(self):
if partner:
line.partner_id = partner

def _get_wallet_domain(self, values):
account_id = values.get("account_id")
partner_id = values.get("partner_id")
if not account_id or not partner_id:
return FALSE_DOMAIN
domain = [
("wallet_type_id.account_id", "=", values["account_id"]),
("partner_id", "=", values["partner_id"]),
]
return domain
def create_or_set_wallet(self):
AccountWallet = self.env["account.wallet"]
AccountWalletType = self.env["account.wallet.type"]

def _get_account_wallet_type(self, values):
if values.get("account_id"):
wallet_type = self.env["account.wallet.type"].search(
[("account_id", "=", values["account_id"])]
# check if account/partner is linked to a wallet and assign it
# if it the case
for move_line in self.filtered(lambda x: x.partner_id):
wallet_domain = [
("wallet_type_id.account_id", "=", move_line.account_id.id),
("partner_id", "=", move_line.partner_id.id),
]
wallet = AccountWallet.search(wallet_domain)
if wallet:
move_line.write({"account_wallet_id": wallet.id})

# Create new wallet, if the account match with the account if a wallet_type
for move_line in self.filtered(lambda x: not x.account_wallet_id):
wallet_type = AccountWalletType.search(
[("account_id", "=", move_line.account_id.id)]
)
if not wallet_type:
continue
move_line.account_wallet_id = AccountWallet.create(
move_line._prepare_account_wallet_values(wallet_type)
)
return wallet_type

def _prepare_account_wallet_values(self, values):
wallet_type = self._get_account_wallet_type(values)
vals = {}
if wallet_type:
def _prepare_account_wallet_values(self, wallet_type):
self.ensure_one()
vals = {
"wallet_type_id": wallet_type.id,
}
if wallet_type.no_anonymous:
vals.update(
{
"wallet_type_id": wallet_type.id,
"partner_id": self.partner_id.id,
}
)
if wallet_type.no_anonymous:
vals.update(
{
"partner_id": values["partner_id"],
}
)
return vals

def wallet_value(self, vals_list):
"""If used account is on a wallet type,
create a wallet
"""
wallet_obj = self.env["account.wallet"]
for values in vals_list:
if not values.get("account_wallet_id"):
# check if account/partner is linked to a wallet and assign it
# if it the case
wallet = wallet_obj.search(self._get_wallet_domain(values))
if wallet:
values["account_wallet_id"] = wallet.id
else:
# If we try to feed the wallet and none is found, create it
comp = float_compare(
values.get("credit", 0.0), 0.0, precision_digits=2
)
if values.get("account_id") and comp != 0:
wallet_values = self._prepare_account_wallet_values(values)
if wallet_values:
# create wallet
values["account_wallet_id"] = (
self.env["account.wallet"].create(wallet_values).id
)
elif values.get("account_wallet_id"):
wallet = wallet_obj.browse(values["account_wallet_id"])
values["partner_id"] = wallet.partner_id.id or values.get("partner_id")
return vals_list

@api.model_create_multi
def create(self, vals_list):
vals_list = self.wallet_value(vals_list)
return super().create(vals_list)

@api.constrains("account_wallet_id", "account_id")
def _check_wallet_account(self):
"""Account must correspond to wallet account"""
Expand Down
10 changes: 8 additions & 2 deletions account_wallet/models/account_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,19 @@ def name_get(self):

@api.model
def _get_compute_balance_fields(self):
return ["account_move_line_ids.debit", "account_move_line_ids.credit"]
return [
"account_move_line_ids.parent_state",
"account_move_line_ids.debit",
"account_move_line_ids.credit",
]

@api.depends(lambda self: self._get_compute_balance_fields())
def _compute_balance(self):
for wallet in self:
balance = 0
for move_line in wallet.account_move_line_ids:
for move_line in wallet.account_move_line_ids.filtered(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is a HUGE change
i'll have to test

lambda x: x.parent_state == "posted"
):
balance += move_line.credit - move_line.debit
wallet.balance = balance

Expand Down
5 changes: 4 additions & 1 deletion account_wallet/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _create_invoice_credit_wallet(self, credit_amount):
return invoice, wallet

def _create_payment_move_wallet(self, debit_amount, wallet):

old_wallet_balance = wallet.balance
payment_move = self.env["account.move"].create(
{
"journal_id": wallet.wallet_type_id.journal_id.id,
Expand Down Expand Up @@ -106,4 +106,7 @@ def _create_payment_move_wallet(self, debit_amount, wallet):
],
}
)
self.assertEqual(wallet.balance, old_wallet_balance)
payment_move.action_post()
self.assertEqual(wallet.balance, old_wallet_balance - debit_amount)
return payment_move