From 42b8b9b415e28d305afaa97efb49feb8545ae7fc Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Sat, 14 Nov 2020 00:32:18 +0100 Subject: [PATCH] [MIG] account_check_deposit from v13 to v14 --- account_check_deposit/__manifest__.py | 8 +- account_check_deposit/data/sequence.xml | 2 +- account_check_deposit/models/__init__.py | 2 +- ...nt_deposit.py => account_check_deposit.py} | 166 ++++++++---------- .../models/account_move_line.py | 9 +- account_check_deposit/models/res_company.py | 2 +- .../models/res_config_settings.py | 5 +- account_check_deposit/readme/CONFIGURE.rst | 7 +- account_check_deposit/readme/DESCRIPTION.rst | 2 +- account_check_deposit/readme/USAGE.rst | 4 +- account_check_deposit/report/report.xml | 23 +-- .../security/check_deposit_security.xml | 4 +- .../tests/test_check_deposit.py | 4 +- ...iew.xml => account_check_deposit_view.xml} | 35 ++-- .../views/account_move_line_view.xml | 10 +- .../views/res_config_settings_views.xml | 4 +- 16 files changed, 141 insertions(+), 146 deletions(-) rename account_check_deposit/models/{account_deposit.py => account_check_deposit.py} (67%) rename account_check_deposit/views/{account_deposit_view.xml => account_check_deposit_view.xml} (88%) diff --git a/account_check_deposit/__manifest__.py b/account_check_deposit/__manifest__.py index 96664ef33..68f56835b 100644 --- a/account_check_deposit/__manifest__.py +++ b/account_check_deposit/__manifest__.py @@ -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 # @author: Chafique DELLI # @author: Alexis de Lattre -# 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", diff --git a/account_check_deposit/data/sequence.xml b/account_check_deposit/data/sequence.xml index 19fda568c..f8cec9449 100644 --- a/account_check_deposit/data/sequence.xml +++ b/account_check_deposit/data/sequence.xml @@ -1,6 +1,6 @@ diff --git a/account_check_deposit/models/__init__.py b/account_check_deposit/models/__init__.py index 91bc35f52..1af2c065a 100644 --- a/account_check_deposit/models/__init__.py +++ b/account_check_deposit/models/__init__.py @@ -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 diff --git a/account_check_deposit/models/account_deposit.py b/account_check_deposit/models/account_check_deposit.py similarity index 67% rename from account_check_deposit/models/account_deposit.py rename to account_check_deposit/models/account_check_deposit.py index aabc0ef17..4394811b9 100644 --- a/account_check_deposit/models/account_deposit.py +++ b/account_check_deposit/models/account_check_deposit.py @@ -1,4 +1,4 @@ -# Copyright 2012-2016 Akretion (http://www.akretion.com/) +# Copyright 2012-2020 Akretion (http://www.akretion.com/) # @author: Benoît GUILLOT # @author: Chafique DELLI # @author: Alexis de Lattre @@ -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: diff --git a/account_check_deposit/models/account_move_line.py b/account_check_deposit/models/account_move_line.py index 16e4d6def..f5155f713 100644 --- a/account_check_deposit/models/account_move_line.py +++ b/account_check_deposit/models/account_move_line.py @@ -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 # @author: Chafique DELLI # @author: Alexis de Lattre # @author: Mourad EL HADJ MIMOUNE -# 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, ) diff --git a/account_check_deposit/models/res_company.py b/account_check_deposit/models/res_company.py index 6a657cfa6..21b74bb71 100644 --- a/account_check_deposit/models/res_company.py +++ b/account_check_deposit/models/res_company.py @@ -1,4 +1,4 @@ -# © 2012-2016 Akretion (http://www.akretion.com/) +# Copyright 2012-2020 Akretion France (http://www.akretion.com/) # @author: Benoît GUILLOT # @author: Chafique DELLI # @author: Alexis de Lattre diff --git a/account_check_deposit/models/res_config_settings.py b/account_check_deposit/models/res_config_settings.py index 4049988c3..aad69d50b 100644 --- a/account_check_deposit/models/res_config_settings.py +++ b/account_check_deposit/models/res_config_settings.py @@ -1,5 +1,6 @@ -# Copyright 2016 Akretion (Alexis de Lattre ) -# Copyright 2018 Tecnativa - Pedro M. Baeza +# Copyright 2016-2020 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre +# 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 diff --git a/account_check_deposit/readme/CONFIGURE.rst b/account_check_deposit/readme/CONFIGURE.rst index 478b663ae..a9e38033a 100644 --- a/account_check_deposit/readme/CONFIGURE.rst +++ b/account_check_deposit/readme/CONFIGURE.rst @@ -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. diff --git a/account_check_deposit/readme/DESCRIPTION.rst b/account_check_deposit/readme/DESCRIPTION.rst index 7702051c2..0f325e30f 100644 --- a/account_check_deposit/readme/DESCRIPTION.rst +++ b/account_check_deposit/readme/DESCRIPTION.rst @@ -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 diff --git a/account_check_deposit/readme/USAGE.rst b/account_check_deposit/readme/USAGE.rst index afbe8897c..9298b04d0 100644 --- a/account_check_deposit/readme/USAGE.rst +++ b/account_check_deposit/readme/USAGE.rst @@ -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 diff --git a/account_check_deposit/report/report.xml b/account_check_deposit/report/report.xml index b6120242d..a2e84594d 100644 --- a/account_check_deposit/report/report.xml +++ b/account_check_deposit/report/report.xml @@ -1,17 +1,20 @@ - + + Check Deposit + account.check.deposit + qweb-pdf + account_check_deposit.report_checkdeposit + account_check_deposit.report_checkdeposit + 'check_deposit-%s%s' % (object.name, object.state == 'draft' and '-draft' or '') + + report + diff --git a/account_check_deposit/security/check_deposit_security.xml b/account_check_deposit/security/check_deposit_security.xml index 1051eb453..29e54f5ff 100644 --- a/account_check_deposit/security/check_deposit_security.xml +++ b/account_check_deposit/security/check_deposit_security.xml @@ -1,6 +1,6 @@ @@ -9,7 +9,7 @@ Check Deposit multi-company - ['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])] + ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)] diff --git a/account_check_deposit/tests/test_check_deposit.py b/account_check_deposit/tests/test_check_deposit.py index d75a5cf7d..e217fc2f9 100644 --- a/account_check_deposit/tests/test_check_deposit.py +++ b/account_check_deposit/tests/test_check_deposit.py @@ -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) diff --git a/account_check_deposit/views/account_deposit_view.xml b/account_check_deposit/views/account_check_deposit_view.xml similarity index 88% rename from account_check_deposit/views/account_deposit_view.xml rename to account_check_deposit/views/account_check_deposit_view.xml index 05ac80972..4053609d8 100644 --- a/account_check_deposit/views/account_deposit_view.xml +++ b/account_check_deposit/views/account_check_deposit_view.xml @@ -1,10 +1,10 @@ @@ -17,7 +17,7 @@ states="draft" string="Validate" type="object" - class="oe_highlight" + class="btn-primary" />