[MIG] account_check_deposit to v17

Migration from v16 to v17
Convert read_group to _read_group() for perf improvements
This commit is contained in:
Alexis de Lattre
2024-01-23 16:41:52 +01:00
parent 63f52adae1
commit 45a2d99a65
5 changed files with 86 additions and 105 deletions

View File

@@ -7,7 +7,7 @@
{
"name": "Account Check Deposit",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"category": "Accounting",
"license": "AGPL-3",
"summary": "Manage deposit of checks to the bank",
@@ -19,10 +19,10 @@
"security/ir.model.access.csv",
"security/check_deposit_security.xml",
"data/sequence.xml",
"views/account_check_deposit_view.xml",
"views/account_move_line_view.xml",
"report/report.xml",
"report/report_checkdeposit.xml",
"views/account_check_deposit_view.xml",
"views/account_move_line_view.xml",
],
"installable": True,
}

View File

@@ -18,17 +18,15 @@ class AccountCheckDeposit(models.Model):
_check_company_auto = True
name = fields.Char(
size=64, readonly=True, default=lambda self: _("New"), copy=False
readonly=True, default=lambda self: _("New"), copy=False
)
check_payment_ids = fields.One2many(
comodel_name="account.move.line",
inverse_name="check_deposit_id",
string="Check Payments",
states={"done": [("readonly", "=", True)]},
)
deposit_date = fields.Date(
required=True,
states={"done": [("readonly", "=", True)]},
default=fields.Date.context_today,
tracking=True,
copy=False,
@@ -40,7 +38,6 @@ class AccountCheckDeposit(models.Model):
"('bank_account_id', '=', False)]",
required=True,
check_company=True,
states={"done": [("readonly", "=", True)]},
tracking=True,
)
in_hand_check_account_id = fields.Many2one(
@@ -55,7 +52,6 @@ class AccountCheckDeposit(models.Model):
precompute=True,
readonly=False,
required=True,
states={"done": [("readonly", "=", True)]},
tracking=True,
)
state = fields.Selection(
@@ -78,7 +74,6 @@ class AccountCheckDeposit(models.Model):
domain="[('company_id', '=', company_id), ('type', '=', 'bank'), "
"('bank_account_id', '!=', False)]",
check_company=True,
states={"done": [("readonly", "=", True)]},
tracking=True,
)
line_ids = fields.One2many(
@@ -89,7 +84,6 @@ class AccountCheckDeposit(models.Model):
company_id = fields.Many2one(
comodel_name="res.company",
required=True,
states={"done": [("readonly", "=", True)]},
default=lambda self: self.env.company,
tracking=True,
)
@@ -122,18 +116,18 @@ class AccountCheckDeposit(models.Model):
"move_id.line_ids.reconciled",
)
def _compute_check_deposit(self):
rg_res = self.env["account.move.line"].read_group(
rg_res = self.env["account.move.line"]._read_group(
[("check_deposit_id", "in", self.ids)],
["check_deposit_id", "amount_currency:sum", "debit:sum"],
["check_deposit_id"],
groupby=["check_deposit_id"],
aggregates=["amount_currency:sum", "debit:sum", "id:count"],
)
mapped_data = {
x["check_deposit_id"][0]: {
"debit": x["debit"],
"amount_currency": x["amount_currency"],
"count": x["check_deposit_id_count"],
deposit.id: {
"debit": total_debit,
"amount_currency": total_amount_currency,
"count": line_count,
}
for x in rg_res
for (deposit, total_amount_currency, total_debit, line_count) in rg_res
}
for deposit in self:
@@ -206,20 +200,23 @@ class AccountCheckDeposit(models.Model):
return super().unlink()
def backtodraft(self):
amlo = self.env["account.move.line"]
for deposit in self:
if deposit.move_id:
move = deposit.move_id
counterpart_move_line = move.line_ids.filtered(
lambda x: x.account_id.id != deposit.in_hand_check_account_id.id
)
check_move_lines = amlo
counterpart_move_line = amlo
for move_line in move.line_ids:
if move_line.account_id.id == deposit.in_hand_check_account_id.id:
check_move_lines |= move_line
else:
counterpart_move_line |= move_line
if counterpart_move_line.reconciled:
raise UserError(
_("Deposit '%s' has already been credited on the bank account.")
% deposit.display_name
)
move.line_ids.filtered(
lambda x: x.account_id.id == deposit.in_hand_check_account_id.id
).remove_move_reconcile()
check_move_lines.remove_move_reconcile()
if move.state == "posted":
move.button_cancel()
move.with_context(force_delete=True).unlink()
@@ -305,11 +302,6 @@ class AccountCheckDeposit(models.Model):
lines_to_rec.reconcile()
deposit.write({"state": "done", "move_id": move.id})
def get_report(self):
report = self.env.ref("account_check_deposit.report_account_check_deposit")
action = report.with_context(discard_logo_check=True).report_action(self)
return action
def get_all_checks(self):
self.ensure_one()
if not self.in_hand_check_account_id:

View File

@@ -4,105 +4,83 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests import tagged
from odoo.tests.common import TransactionCase
from odoo import Command
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@tagged("post_install", "-at_install")
class TestPayment(TransactionCase):
def setUp(self):
super().setUp()
self.account_model = self.env["account.account"]
self.partner = self.env["res.partner"].create({"name": "Test partner"})
self.main_company = self.env.company
self.currency = self.main_company.currency_id
self.product = self.env["product.product"].create({"name": "Test product"})
self.account_model.create(
class TestAccountCheckDeposit(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.fr_test_company = cls.setup_company_data(
"Chq deposit test company",
chart_template=chart_template_ref,
country_id=cls.env.ref("base.fr").id,
)
cls.company = cls.fr_test_company["company"]
cls.user.write(
{
"code": "4111ZZ",
"name": "Debtors - (test)",
"reconcile": True,
"account_type": "asset_receivable",
"company_id": self.main_company.id,
"company_ids": [Command.link(cls.company.id)],
"company_id": cls.company.id,
}
)
self.account_model.create(
{
"code": "7071ZZ",
"name": "Product Sales - (test)",
"account_type": "income",
"company_id": self.main_company.id,
}
)
received_check_account = self.account_model.create(
cls.product = cls.env['product.product'].create({'name': 'Test Product'})
cls.account_model = cls.env["account.account"]
cls.partner = cls.env["res.partner"].create({"name": "Test partner"})
cls.currency = cls.company.currency_id
cls.received_check_account = cls.account_model.create(
{
"code": "5112ZZ",
"name": "Received check - (test)",
"reconcile": True,
"account_type": "asset_current",
"company_id": self.main_company.id,
"company_id": cls.company.id,
}
)
self.transfer_account = self.account_model.create(
cls.check_journal = cls.env["account.journal"].create(
{
"code": "5115ZZ",
"name": "Check deposis waiting for credit on bank account - (test)",
"reconcile": True,
"account_type": "asset_current",
"company_id": self.main_company.id,
}
)
self.manual_method_in = self.env.ref("account.account_payment_method_manual_in")
self.check_journal = self._create_journal(
"received check", "bank", "CHK", received_check_account
)
self.bank_journal = self._create_journal(
"Bank Test Chq", "bank", "TEST@@", self.transfer_account
)
self.bank_journal.bank_account_id = self.env["res.partner.bank"].create(
{
"acc_number": "SI56 1910 0000 0123 438 584",
"partner_id": self.main_company.partner_id.id,
}
)
def _create_journal(self, name, journal_type, code, payment_account):
return self.env["account.journal"].create(
{
"name": name,
"type": journal_type,
"code": code,
"company_id": self.main_company.id,
"name": "Received check",
"type": "bank",
"code": "ZZCHK",
"company_id": cls.company.id,
"inbound_payment_method_line_ids": [
(
0,
0,
{
"payment_method_id": self.manual_method_in.id,
"payment_account_id": payment_account.id,
"payment_method_id": cls.env.ref("account.account_payment_method_manual_in").id,
"payment_account_id": cls.received_check_account.id,
},
)
],
}
)
cls.fr_test_company['default_journal_bank'].bank_account_id = cls.env["res.partner.bank"].create(
{
"acc_number": "SI56 1910 0000 0123 438 584",
"partner_id": cls.company.partner_id.id,
}
)
def create_invoice(self, amount=100):
"""Returns an open invoice"""
invoice = self.env["account.move"].create(
{
"company_id": self.main_company.id,
"company_id": self.company.id,
"move_type": "out_invoice",
"partner_id": self.partner.id,
"currency_id": self.currency.id,
"invoice_line_ids": [
(
0,
0,
Command.create(
{
"product_id": self.product.id,
"quantity": 1,
"price_unit": amount,
"tax_ids": [],
},
}
)
],
}
@@ -114,9 +92,9 @@ class TestPayment(TransactionCase):
"""Returns an validated check deposit"""
check_deposit = self.env["account.check.deposit"].create(
{
"company_id": self.main_company.id,
"company_id": self.company.id,
"journal_id": self.check_journal.id,
"bank_journal_id": self.bank_journal.id,
"bank_journal_id": self.fr_test_company['default_journal_bank'].id,
"currency_id": self.currency.id,
}
)
@@ -142,8 +120,9 @@ class TestPayment(TransactionCase):
self.assertAlmostEqual(payment.amount, 300)
self.assertEqual(payment.state, "posted")
check_deposit = self.create_check_deposit()
self.assertEqual(check_deposit.in_hand_check_account_id, self.received_check_account)
liquidity_aml = check_deposit.move_id.line_ids.filtered(
lambda r: r.account_id == self.transfer_account
lambda r: r.account_id != check_deposit.in_hand_check_account_id
)
self.assertAlmostEqual(check_deposit.total_amount, 300)
self.assertAlmostEqual(liquidity_aml.debit, 300)

View File

@@ -14,26 +14,30 @@
<header>
<button
name="get_all_checks"
states="draft"
invisible="state != 'draft'"
type="object"
class="btn-primary"
string="Get All Received Checks"
/>
<button
name="validate_deposit"
states="draft"
invisible="state != 'draft'"
string="Validate"
type="object"
class="btn-primary"
/>
<button
name="backtodraft"
states="done"
invisible="state != 'done'"
string="Back to Draft"
type="object"
confirm="Are you sure you want to go back to draft?"
/>
<button name="get_report" string="Print" type="object" />
<button
name="%(report_account_check_deposit)d"
string="Print"
type="action"
/>
<field
name="state"
widget="statusbar"
@@ -52,16 +56,23 @@
<field
name="deposit_date"
options="{'datepicker': {'warn_future': true}}"
readonly="state == 'done'"
/>
<field
name="journal_id"
options="{'no_create': True}"
readonly="state == 'done'"
/>
<field name="journal_id" options="{'no_create': True}" />
<field
name="currency_id"
groups="base.group_multi_currency"
options="{'no_open': True, 'no_create': True}"
readonly="state == 'done'"
/>
<field
name="bank_journal_id"
options="{'no_create': True}"
readonly="state == 'done'"
/>
<field name="currency_id" invisible="1" />
</group>
@@ -73,6 +84,7 @@
name="company_id"
groups="base.group_multi_company"
options="{'no_open': True, 'no_create': True}"
readonly="state == 'done'"
/>
<field name="move_id" />
<field name="company_id" invisible="1" />
@@ -92,6 +104,7 @@
('company_id', '=', company_id),
('parent_state', '=', 'posted'),
]"
readonly="state == 'done'"
context="{'currency': currency_id,
'journal_id': journal_id}"
>
@@ -165,6 +178,8 @@
name="bank_journal_id"
domain="[('type', '=', 'bank'), ('bank_account_id', '!=', False)]"
/>
<filter string="Deposit Date" name="deposit_date" date="deposit_date" />
<separator />
<filter
name="draft"
string="Draft"
@@ -179,7 +194,7 @@
/>
<filter
name="journal_groupby"
string="Journal"
string="Check Journal"
context="{'group_by': 'journal_id'}"
/>
<filter
@@ -187,11 +202,6 @@
string="Bank Account"
context="{'group_by': 'bank_journal_id'}"
/>
<filter
name="currency_groupby"
string="Currency"
context="{'group_by': 'currency_id'}"
/>
</group>
</search>
</field>

View File

@@ -13,7 +13,7 @@
<field
name="check_deposit_id"
readonly="True"
attrs="{'invisible': [('check_deposit_id', '=', False)]}"
invisible="not check_deposit_id"
/>
</field>
</field>