[MIG] account_check_deposit from v13 to v14

This commit is contained in:
Alexis de Lattre
2020-11-14 00:32:18 +01:00
committed by Víctor Martínez
parent 2246128fb0
commit 42b8b9b415
16 changed files with 141 additions and 146 deletions

View File

@@ -1,13 +1,13 @@
# Copyright 2012-2016 Akretion (http://www.akretion.com/)
# Copyright 2012-2020 Akretion France (http://www.akretion.com/)
# @author: Benoît GUILLOT <benoit.guillot@akretion.com>
# @author: Chafique DELLI <chafique.delli@akretion.com>
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# Copyright 2018 Tecnativa - Pedro M. Baeza
# Copyright 2018-2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Account Check Deposit",
"version": "13.0.1.0.0",
"version": "14.0.1.0.0",
"category": "Accounting",
"license": "AGPL-3",
"summary": "Manage deposit of checks to the bank",
@@ -19,7 +19,7 @@
"security/ir.model.access.csv",
"security/check_deposit_security.xml",
"data/sequence.xml",
"views/account_deposit_view.xml",
"views/account_check_deposit_view.xml",
"views/account_move_line_view.xml",
"views/res_config_settings_views.xml",
"report/report.xml",

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
© 2012-2019 Akretion (http://www.akretion.com/)
Copyright 2012-2020 Akretion France (http://www.akretion.com/)
@author: Benoît GUILLOT <benoit.guillot@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->

View File

@@ -1,4 +1,4 @@
from . import account_deposit
from . import account_check_deposit
from . import account_move_line
from . import res_company
from . import res_config_settings

View File

@@ -1,4 +1,4 @@
# Copyright 2012-2016 Akretion (http://www.akretion.com/)
# Copyright 2012-2020 Akretion (http://www.akretion.com/)
# @author: Benoît GUILLOT <benoit.guillot@akretion.com>
# @author: Chafique DELLI <chafique.delli@akretion.com>
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
@@ -14,6 +14,7 @@ class AccountCheckDeposit(models.Model):
_name = "account.check.deposit"
_description = "Account Check Deposit"
_order = "deposit_date desc"
_check_company_auto = True
@api.depends(
"company_id",
@@ -23,26 +24,36 @@ class AccountCheckDeposit(models.Model):
"move_id.line_ids.reconciled",
)
def _compute_check_deposit(self):
rg_res = self.env["account.move.line"].read_group(
[("check_deposit_id", "in", self.ids)],
["check_deposit_id", "debit", "amount_currency"],
["check_deposit_id"],
)
mapped_data = {
x["check_deposit_id"][0]: {
"debit": x["debit"],
"amount_currency": x["amount_currency"],
"count": x["check_deposit_id_count"],
}
for x in rg_res
}
for deposit in self:
total = 0.0
count = 0
reconcile = False
currency_none_same_company_id = False
if deposit.company_id.currency_id != deposit.currency_id:
currency_none_same_company_id = deposit.currency_id.id
for line in deposit.check_payment_ids:
count += 1
if currency_none_same_company_id:
total += line.amount_currency
else:
total += line.debit
company_cur = deposit.company_id.currency_id
if company_cur != deposit.currency_id:
total = mapped_data.get(deposit.id, {"amount_currency": 0.0})[
"amount_currency"
]
else:
total = mapped_data.get(deposit.id, {"debit": 0.0})["debit"]
count = mapped_data.get(deposit.id, {"count": 0})["count"]
if deposit.move_id:
for line in deposit.move_id.line_ids:
if line.debit > 0 and line.reconciled:
if not company_cur.is_zero(line.debit) and line.reconciled:
reconcile = True
deposit.total_amount = total
deposit.is_reconcile = reconcile
deposit.currency_none_same_company_id = currency_none_same_company_id
deposit.check_count = count
name = fields.Char(string="Name", size=64, readonly=True, default="/")
@@ -63,12 +74,13 @@ class AccountCheckDeposit(models.Model):
string="Journal",
domain=[("type", "=", "bank"), ("bank_account_id", "=", False)],
required=True,
check_company=True,
states={"done": [("readonly", "=", True)]},
)
journal_default_account_id = fields.Many2one(
comodel_name="account.account",
related="journal_id.default_debit_account_id",
string="Default Debit Account of the Journal",
related="journal_id.payment_debit_account_id",
string="Outstanding Receipts Account",
)
currency_id = fields.Many2one(
comodel_name="res.currency",
@@ -76,12 +88,6 @@ class AccountCheckDeposit(models.Model):
required=True,
states={"done": [("readonly", "=", True)]},
)
currency_none_same_company_id = fields.Many2one(
comodel_name="res.currency",
compute="_compute_check_deposit",
store=True,
string="Currency (False if same as company)",
)
state = fields.Selection(
selection=[("draft", "Draft"), ("done", "Done")],
string="Status",
@@ -89,7 +95,10 @@ class AccountCheckDeposit(models.Model):
readonly=True,
)
move_id = fields.Many2one(
comodel_name="account.move", string="Journal Entry", readonly=True
comodel_name="account.move",
string="Journal Entry",
readonly=True,
check_company=True,
)
bank_journal_id = fields.Many2one(
comodel_name="account.journal",
@@ -97,13 +106,13 @@ class AccountCheckDeposit(models.Model):
required=True,
domain="[('company_id', '=', company_id), ('type', '=', 'bank'), "
"('bank_account_id', '!=', False)]",
check_company=True,
states={"done": [("readonly", "=", True)]},
)
line_ids = fields.One2many(
comodel_name="account.move.line",
related="move_id.line_ids",
string="Lines",
readonly=True,
)
company_id = fields.Many2one(
comodel_name="res.company",
@@ -112,59 +121,40 @@ class AccountCheckDeposit(models.Model):
states={"done": [("readonly", "=", True)]},
default=lambda self: self.env.company,
)
total_amount = fields.Float(
total_amount = fields.Monetary(
compute="_compute_check_deposit",
string="Total Amount",
readonly=True,
store=True,
digits="Account",
currency_field="currency_id",
)
check_count = fields.Integer(
compute="_compute_check_deposit",
readonly=True,
store=True,
string="Number of Checks",
)
is_reconcile = fields.Boolean(
compute="_compute_check_deposit", readonly=True, store=True, string="Reconcile"
compute="_compute_check_deposit", store=True, string="Reconcile"
)
@api.constrains("currency_id", "check_payment_ids", "company_id")
def _check_deposit(self):
for deposit in self:
deposit_currency = deposit.currency_id
if deposit_currency == deposit.company_id.currency_id:
for line in deposit.check_payment_ids:
if line.currency_id:
raise ValidationError(
_(
"The check with amount %s and reference '%s' "
"is in currency %s but the deposit is in "
"currency %s."
)
% (
line.debit,
line.ref or "",
line.currency_id.name,
deposit_currency.name,
)
for line in deposit.check_payment_ids:
if line.currency_id != deposit_currency:
raise ValidationError(
_(
"The check with amount %s and reference '%s' "
"is in currency %s but the deposit is in "
"currency %s."
)
else:
for line in deposit.check_payment_ids:
if line.currency_id != deposit_currency:
raise ValidationError(
_(
"The check with amount %s and reference '%s' "
"is in currency %s but the deposit is in "
"currency %s."
)
% (
line.debit,
line.ref or "",
line.currency_id.name,
deposit_currency.name,
)
% (
line.debit,
line.ref or "",
line.currency_id.name,
deposit_currency.name,
)
)
def unlink(self):
for deposit in self:
@@ -176,40 +166,42 @@ class AccountCheckDeposit(models.Model):
)
% deposit.name
)
return super(AccountCheckDeposit, self).unlink()
return super().unlink()
def backtodraft(self):
for deposit in self:
if deposit.move_id:
move = deposit.move_id
# It will raise here if journal_id.update_posted = False
deposit.move_id.button_cancel()
if move.state == "posted":
move.button_draft()
for line in deposit.check_payment_ids:
if line.reconciled:
line.remove_move_reconcile()
deposit.move_id.unlink()
move.unlink()
deposit.write({"state": "draft"})
return True
@api.model
def create(self, vals):
if "company_id" in vals:
self = self.with_company(vals["company_id"])
if vals.get("name", "/") == "/":
vals["name"] = (
self.env["ir.sequence"]
.with_context(ir_sequence_date=vals.get("deposit_date"))
.next_by_code("account.check.deposit")
vals["name"] = self.env["ir.sequence"].next_by_code(
"account.check.deposit", vals.get("deposit_date")
)
return super(AccountCheckDeposit, self).create(vals)
return super().create(vals)
@api.model
def _prepare_account_move_vals(self, deposit):
if deposit.company_id.check_deposit_offsetting_account == "bank_account":
journal_id = deposit.bank_journal_id.id
def _prepare_account_move_vals(self):
self.ensure_one()
if self.company_id.check_deposit_offsetting_account == "bank_account":
journal_id = self.bank_journal_id.id
else:
journal_id = deposit.journal_id.id
journal_id = self.journal_id.id
move_vals = {
"journal_id": journal_id,
"date": deposit.deposit_date,
"ref": _("Check Deposit %s") % deposit.name,
"date": self.deposit_date,
"ref": _("Check Deposit %s") % self.name,
}
return move_vals
@@ -226,11 +218,9 @@ class AccountCheckDeposit(models.Model):
"amount_currency": line.amount_currency * -1,
}
@api.model
def _prepare_counterpart_move_lines_vals(
self, deposit, total_debit, total_amount_currency
):
company = deposit.company_id
def _prepare_counterpart_move_lines_vals(self, total_debit, total_amount_currency):
self.ensure_one()
company = self.company_id
if not company.check_deposit_offsetting_account:
raise UserError(
_(
@@ -239,12 +229,12 @@ class AccountCheckDeposit(models.Model):
)
)
if company.check_deposit_offsetting_account == "bank_account":
if not deposit.bank_journal_id.default_debit_account_id:
if not self.bank_journal_id.default_account_id:
raise UserError(
_("Missing 'Default Debit Account' on bank journal '%s'")
% deposit.bank_journal_id.name
% self.bank_journal_id.name
)
account_id = deposit.bank_journal_id.default_debit_account_id.id
account_id = self.bank_journal_id.default_account_id.id
elif company.check_deposit_offsetting_account == "transfer_account":
if not company.check_deposit_transfer_account_id:
raise UserError(
@@ -256,12 +246,12 @@ class AccountCheckDeposit(models.Model):
)
account_id = company.check_deposit_transfer_account_id.id
return {
"name": _("Check Deposit %s") % deposit.name,
"name": _("Check Deposit %s") % self.name,
"debit": total_debit,
"credit": 0.0,
"account_id": account_id,
"partner_id": False,
"currency_id": deposit.currency_none_same_company_id.id or False,
"currency_id": self.currency_id.id or False,
"amount_currency": total_amount_currency,
}
@@ -269,7 +259,7 @@ class AccountCheckDeposit(models.Model):
am_obj = self.env["account.move"]
move_line_obj = self.env["account.move.line"]
for deposit in self:
move_vals = self._prepare_account_move_vals(deposit)
move_vals = deposit._prepare_account_move_vals()
move = am_obj.create(move_vals)
total_debit = 0.0
total_amount_currency = 0.0
@@ -285,13 +275,13 @@ class AccountCheckDeposit(models.Model):
to_reconcile_lines.append(line + move_line)
# Create counter-part
counter_vals = self._prepare_counterpart_move_lines_vals(
deposit, total_debit, total_amount_currency
counter_vals = deposit._prepare_counterpart_move_lines_vals(
total_debit, total_amount_currency
)
counter_vals["move_id"] = move.id
move_line_obj.create(counter_vals)
if deposit.company_id.check_deposit_post_move:
move.post()
move.action_post()
deposit.write({"state": "done", "move_id": move.id})
for reconcile_lines in to_reconcile_lines:

View File

@@ -1,9 +1,9 @@
# Copyright 2012-2016 Akretion (http://www.akretion.com/)
# Copyright 2012-2020 Akretion France (http://www.akretion.com/)
# @author: Benoît GUILLOT <benoit.guillot@akretion.com>
# @author: Chafique DELLI <chafique.delli@akretion.com>
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# @author: Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
# Copyright 2018 Tecnativa - Pedro M. Baeza
# Copyright 2018-2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
@@ -13,5 +13,8 @@ class AccountMoveLine(models.Model):
_inherit = "account.move.line"
check_deposit_id = fields.Many2one(
comodel_name="account.check.deposit", string="Check Deposit", copy=False,
comodel_name="account.check.deposit",
string="Check Deposit",
copy=False,
check_company=True,
)

View File

@@ -1,4 +1,4 @@
# © 2012-2016 Akretion (http://www.akretion.com/)
# Copyright 2012-2020 Akretion France (http://www.akretion.com/)
# @author: Benoît GUILLOT <benoit.guillot@akretion.com>
# @author: Chafique DELLI <chafique.delli@akretion.com>
# @author: Alexis de Lattre <alexis.delattre@akretion.com>

View File

@@ -1,5 +1,6 @@
# Copyright 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# Copyright 2018 Tecnativa - Pedro M. Baeza
# Copyright 2016-2020 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# Copyright 2018-2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models

View File

@@ -4,11 +4,10 @@ journal:
* Name: Checks Received
* Type: Bank
* Short Code: CHK (or any code you want)
* Default Debit Account: select an account for checks received
* Default Credit Account: idem
* Outstanding Receipts Account: select an account for checks received
This bank journal will be available as a payment method in Odoo. The account
you configured as *Default Debit Account* and *Defaut Credit Account* is the
you configured as *Outstanding Receipts Account* is the
account via which the amounts of checks will transit between the reception of a
check from a customer and the validation of the check deposit in Odoo.
@@ -16,7 +15,7 @@ On the Settings page of the Accounting, you should configure the
*Check Deposit Offsetting Account*:
* if you select *Bank Account*, the counter-part of the account move related to
the check deposit will be the default debit account of the bank account
the check deposit will be the default account of the bank account
selected on the check deposit.
* if you select *Transfer Account*, you will have to select a specific account
that will be used as transfer account for check deposits.

View File

@@ -1,4 +1,4 @@
This module allows you to easily manage check deposits : you can select all
This module allows you to easily manage check deposits: you can select all
the checks you received and create a global deposit for the selected checks.
This module supports multi-currency ; each deposit has a currency and all the
checks of the deposit must have the same currency (so, if you have checks in

View File

@@ -1,9 +1,9 @@
When you receive a check that pays a customer invoice, you can go to that
invoice and click on the button *Register Payment* and select the
*Check Received* journal as *Payment Journal*.
*Check Received* journal as *Journal*.
When you want to deposit checks to the bank, go to the menu
*Invoicing > Accounting > Check Deposit*, create a new check deposit and set the
*Invoicing > Accounting > Miscellaneous > Check Deposit*, create a new check deposit and set the
journal *Checks Received* and select the bank account on which you want to
credit the checks. Then click on *Add a line* to select the checks you want to
deposit at the bank. Eventually, validate the deposit and print the report

View File

@@ -1,17 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright (C) 2014-2019 Akretion (http://www.akretion.com/)
Copyright (C) 2014-2020 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __manifest__.py
-->
<odoo>
<report
id="report_account_check_deposit"
model="account.check.deposit"
string="Check Deposit"
report_type="qweb-pdf"
name="account_check_deposit.report_checkdeposit"
file="account_check_deposit.report_checkdeposit"
print_report_name="'check_deposit-%s%s' % (object.name, object.state == 'draft' and '-draft' or '')"
/>
<record id="report_account_check_deposit" model="ir.actions.report">
<field name="name">Check Deposit</field>
<field name="model">account.check.deposit</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">account_check_deposit.report_checkdeposit</field>
<field name="report_file">account_check_deposit.report_checkdeposit</field>
<field
name="print_report_name"
>'check_deposit-%s%s' % (object.name, object.state == 'draft' and '-draft' or '')</field>
<field name="binding_model_id" ref="model_account_check_deposit" />
<field name="binding_type">report</field>
</record>
</odoo>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright (C) 2014-2019 Akretion (http://www.akretion.com/)
Copyright (C) 2014-2020 Akretion France (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __manifest__.py
-->
@@ -9,7 +9,7 @@
<field name="name">Check Deposit multi-company</field>
<field name="model_id" ref="model_account_check_deposit" />
<field name="domain_force">
['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])]
['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]
</field>
</record>
</odoo>

View File

@@ -167,8 +167,8 @@ class TestPayment(AccountingTestCase):
return check_deposit
def test_full_payment_process(self):
""" Create a payment for on invoice by check,
post it and create check deposit"""
"""Create a payment for on invoice by check,
post it and create check deposit"""
inv_1 = self.create_invoice(amount=100, currency_id=self.currency_eur_id)
inv_2 = self.create_invoice(amount=200, currency_id=self.currency_eur_id)

View File

@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright (C) 2012-2015 Akretion (http://www.akretion.com/)
Copyright (C) 2012-2020 Akretion France (http://www.akretion.com/)
@author: Benoît GUILLOT <benoit.guillot@akretion.com>
@author: Chafique DELLI <chafique.delli@akretion.com>
@author: Alexis de Lattre <alexis.delattre@akretion.com>
Copyright 2018 Tecnativa - Pedro M. Baeza
Copyright 2018-2020 Tecnativa - Pedro M. Baeza
-->
<odoo>
<record id="account_check_deposit_view_form" model="ir.ui.view">
@@ -17,7 +17,7 @@
states="draft"
string="Validate"
type="object"
class="oe_highlight"
class="btn-primary"
/>
<button
name="backtodraft"
@@ -43,7 +43,6 @@
<group name="left">
<field name="deposit_date" />
<field name="journal_id" widget="selection" />
<field name="journal_default_account_id" invisible="1" />
<field
name="currency_id"
groups="base.group_multi_currency"
@@ -51,17 +50,13 @@
<field name="bank_journal_id" widget="selection" />
</group>
<group name="right">
<field name="check_count" />
<field name="total_amount" />
<field name="journal_default_account_id" />
<field
name="company_id"
groups="base.group_multi_company"
/>
<field name="currency_none_same_company_id" invisible="1" />
<field name="check_count" />
<field
name="total_amount"
widget="monetary"
options="{'currency_field': 'currency_id'}"
/>
<field name="move_id" />
</group>
</group>
@@ -73,7 +68,7 @@
domain="[('reconciled', '=', False),
('debit', '>', 0),
('check_deposit_id', '=', False),
('currency_id', '=', currency_none_same_company_id),
('currency_id', '=', currency_id),
('account_id', '=', journal_default_account_id)]"
context="{'currency': currency_id,
'journal_id': journal_id}"
@@ -81,20 +76,20 @@
<tree>
<field name="date" />
<field name="date_maturity" />
<field name="move_id" />
<field name="journal_id" />
<field name="name" />
<field name="move_id" />
<field name="ref" />
<field name="partner_id" />
<field name="account_id" />
<field name="debit" sum="Total Debit" />
<field name="credit" sum="Total Credit" />
<field name="name" />
<field name="debit" sum="1" />
<field name="credit" sum="1" />
<field
name="amount_currency"
readonly="True"
groups="base.group_multi_currency"
sum="1"
/>
<field name="currency_id" invisible="1" />
<field name="company_currency_id" invisible="1" />
<field name="full_reconcile_id" />
</tree>
</field>
@@ -166,7 +161,7 @@
<menuitem
action="action_check_deposit_tree"
id="menu_check_deposit_tree"
parent="account.menu_finance_entries"
sequence="20"
parent="account.menu_finance_entries_accounting_miscellaneous"
sequence="30"
/>
</odoo>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2015 Akretion - Alexis de Lattre
Copyright 2018 Tecnativa - Pedro M. Baeza
Copyright 2015-2020 Akretion France - Alexis de Lattre
Copyright 2018-2020 Tecnativa - Pedro M. Baeza
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
@@ -10,7 +10,11 @@
<field name="inherit_id" ref="account.view_move_line_form" />
<field name="arch" type="xml">
<field name="statement_id" position="after">
<field name="check_deposit_id" />
<field
name="check_deposit_id"
readonly="True"
attrs="{'invisible': [('check_deposit_id', '=', False)]}"
/>
</field>
</field>
</record>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2015 Akretion - Alexis de Lattre
Copyright 2018 Tecnativa - Pedro M. Baeza
Copyright 2015-2020 Akretion - Alexis de Lattre
Copyright 2018-2020 Tecnativa - Pedro M. Baeza
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>