From 8dbff2d03e5846229ca9f7410b82b7a055dcb6a8 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 6 Dec 2016 08:52:08 +0100 Subject: [PATCH] [MIG] account_check_deposit: Migration to v10 * Add option to have the counter-part of the deposit move directly to the bank account Use account.config.settings page * Remove data that create a bank journal because it blocks the loading of the chart of accounts when the module is installed at the same time as the chart of account (via dependencies) --- account_check_deposit/README.rst | 37 +++++---- account_check_deposit/__manifest__.py | 21 ++--- account_check_deposit/data/account_data.xml | 22 ------ .../data/account_deposit_sequence.xml | 21 ----- account_check_deposit/data/sequence.xml | 18 +++++ account_check_deposit/models/__init__.py | 2 + .../models/account_config_settings.py | 14 ++++ .../models/account_deposit.py | 77 ++++++++++--------- account_check_deposit/models/company.py | 22 ++++++ .../report/report_checkdeposit.xml | 8 +- .../tests/test_check_deposit.py | 28 ++++--- .../views/account_config_settings.xml | 28 +++++++ .../views/account_deposit_view.xml | 4 +- account_check_deposit/views/company_view.xml | 25 ------ 14 files changed, 174 insertions(+), 153 deletions(-) delete mode 100644 account_check_deposit/data/account_data.xml delete mode 100644 account_check_deposit/data/account_deposit_sequence.xml create mode 100644 account_check_deposit/data/sequence.xml create mode 100644 account_check_deposit/models/account_config_settings.py create mode 100644 account_check_deposit/models/company.py create mode 100644 account_check_deposit/views/account_config_settings.xml delete mode 100644 account_check_deposit/views/company_view.xml diff --git a/account_check_deposit/README.rst b/account_check_deposit/README.rst index fc0afa5b3..9a5e28e99 100644 --- a/account_check_deposit/README.rst +++ b/account_check_deposit/README.rst @@ -16,32 +16,39 @@ one in EUR and one in USD). Configuration ============= -A journal named *Check Received* is automatically created. It will be available as a payment method in Odoo. On this journal, you must configure the *Default Debit Account* and *Defaut Credit Account* ; this 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. +In the menu *Accounting > Configuration > Accounting > Journals*, create a new journal: -On the company form view, you should configure the *Account for Check Deposits* ; this is the account via which the amounts of checks will transit between the validation of the check deposit in Odoo and the credit on the bank account. +* 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 + +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 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. + +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 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. Usage ===== 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 Method*. -When you want to deposit checks to the bank, go to the menu *Accounting > Bank and Cash > 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 an item* to select the checks you want to deposit at the bank. Eventually, validate the deposit and print the report (you probably want to customize this report). +When you want to deposit checks to the bank, go to the menu *Accounting > Adviser > 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 an item* to select the checks you want to deposit at the bank. Eventually, validate the deposit and print the report (you probably want to customize this report). .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/92/8.0 - -For further information, please visit: - - * https://www.odoo.com/forum/help-1 + :target: https://runbot.odoo-community.org/runbot/92/10.0 Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. -In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed feedback -`here `_. +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. Credits ======= @@ -57,9 +64,9 @@ Contributors Maintainer ---------- -.. image:: http://odoo-community.org/logo.png +.. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association - :target: http://odoo-community.org + :target: https://odoo-community.org This module is maintained by the OCA. @@ -67,4 +74,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit http://odoo-community.org. +To contribute to this module, please visit https://odoo-community.org. diff --git a/account_check_deposit/__manifest__.py b/account_check_deposit/__manifest__.py index 854713d08..79d13f9f5 100644 --- a/account_check_deposit/__manifest__.py +++ b/account_check_deposit/__manifest__.py @@ -1,19 +1,13 @@ # -*- coding: utf-8 -*- -############################################################################### -# -# account_check_deposit for Odoo -# Copyright (C) 2012-2015 Akretion (http://www.akretion.com/) -# @author: Benoît GUILLOT -# @author: Chafique DELLI -# @author: Alexis de Lattre -# +# © 2012-2015 Akretion (http://www.akretion.com/) +# @author: Benoît GUILLOT +# @author: Chafique DELLI +# @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -# -############################################################################### { 'name': 'Account Check Deposit', - 'version': '8.0.0.1.0', + 'version': '10.0.1.0.0', 'category': 'Accounting & Finance', 'license': 'AGPL-3', 'summary': 'Manage deposit of checks to the bank', @@ -23,13 +17,12 @@ 'account_accountant', ], 'data': [ + 'data/sequence.xml', 'views/account_deposit_view.xml', 'views/account_move_line_view.xml', - 'data/account_deposit_sequence.xml', - 'views/company_view.xml', + 'views/account_config_settings.xml', 'security/ir.model.access.csv', 'security/check_deposit_security.xml', - 'data/account_data.xml', 'report/report.xml', 'report/report_checkdeposit.xml', ], diff --git a/account_check_deposit/data/account_data.xml b/account_check_deposit/data/account_data.xml deleted file mode 100644 index a2c525ec6..000000000 --- a/account_check_deposit/data/account_data.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - Check Received - CHK - bank - - - - - - diff --git a/account_check_deposit/data/account_deposit_sequence.xml b/account_check_deposit/data/account_deposit_sequence.xml deleted file mode 100644 index 4206b28cc..000000000 --- a/account_check_deposit/data/account_deposit_sequence.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - Account Check Deposit - account.check.deposit - DEP - 3 - - - - - diff --git a/account_check_deposit/data/sequence.xml b/account_check_deposit/data/sequence.xml new file mode 100644 index 000000000..d299ca661 --- /dev/null +++ b/account_check_deposit/data/sequence.xml @@ -0,0 +1,18 @@ + + + + + + + Account Check Deposit + account.check.deposit + DEP + 3 + + + + diff --git a/account_check_deposit/models/__init__.py b/account_check_deposit/models/__init__.py index a98c879ff..2bec86b0c 100644 --- a/account_check_deposit/models/__init__.py +++ b/account_check_deposit/models/__init__.py @@ -1,3 +1,5 @@ # -*- coding: utf-8 -*- +from . import company +from . import account_config_settings from . import account_deposit diff --git a/account_check_deposit/models/account_config_settings.py b/account_check_deposit/models/account_config_settings.py new file mode 100644 index 000000000..51f3423fa --- /dev/null +++ b/account_check_deposit/models/account_config_settings.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models, fields + + +class AccountConfigSettings(models.TransientModel): + _inherit = 'account.config.settings' + + check_deposit_offsetting_account = fields.Selection( + related='company_id.check_deposit_offsetting_account') + check_deposit_transfer_account_id = fields.Many2one( + related='company_id.check_deposit_transfer_account_id') diff --git a/account_check_deposit/models/account_deposit.py b/account_check_deposit/models/account_deposit.py index 38f37feda..c3ad7628d 100644 --- a/account_check_deposit/models/account_deposit.py +++ b/account_check_deposit/models/account_deposit.py @@ -1,21 +1,14 @@ # -*- coding: utf-8 -*- -############################################################################### -# -# account_check_deposit for Odoo -# Copyright (C) 2012-2016 Akretion (http://www.akretion.com/) -# @author: Benoît GUILLOT -# @author: Chafique DELLI -# @author: Alexis de Lattre -# @author: Mourad EL HADJ MIMOUNE -# +# © 2012-2016 Akretion (http://www.akretion.com/) +# @author: Benoît GUILLOT +# @author: Chafique DELLI +# @author: Alexis de Lattre +# @author: Mourad EL HADJ MIMOUNE # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -# -############################################################################### -from openerp import models, fields, api, _ -import openerp.addons.decimal_precision as dp -from openerp.exceptions import ValidationError -from openerp.exceptions import Warning as UserError +from odoo import models, fields, api, _ +import odoo.addons.decimal_precision as dp +from odoo.exceptions import ValidationError, UserError class AccountCheckDeposit(models.Model): @@ -61,7 +54,8 @@ class AccountCheckDeposit(models.Model): states={'done': [('readonly', '=', True)]}, default=fields.Date.context_today) journal_id = fields.Many2one( - 'account.journal', string='Journal', domain=[('type', '=', 'bank')], + 'account.journal', string='Journal', + domain=[('type', '=', 'bank'), ('bank_account_id', '=', False)], required=True, states={'done': [('readonly', '=', True)]}) journal_default_account_id = fields.Many2one( 'account.account', related='journal_id.default_debit_account_id', @@ -79,9 +73,10 @@ class AccountCheckDeposit(models.Model): ], string='Status', default='draft', readonly=True) move_id = fields.Many2one( 'account.move', string='Journal Entry', readonly=True) - partner_bank_id = fields.Many2one( - 'res.partner.bank', string='Bank Account', required=True, - domain="[('company_id', '=', company_id)]", + bank_journal_id = fields.Many2one( + 'account.journal', string='Bank Account', required=True, + domain="[('company_id', '=', company_id), ('type', '=', 'bank'), " + "('bank_account_id', '!=', False)]", states={'done': [('readonly', '=', True)]}) line_ids = fields.One2many( 'account.move.line', related='move_id.line_ids', @@ -185,11 +180,28 @@ class AccountCheckDeposit(models.Model): @api.model def _prepare_counterpart_move_lines_vals( self, deposit, total_debit, total_amount_currency): + company = deposit.company_id + if not company.check_deposit_offsetting_account: + raise UserError(_( + "You must configure the 'Check Deposit Offsetting Account' " + "on the Accounting Settings page")) + if company.check_deposit_offsetting_account == 'bank_account': + if not deposit.bank_journal_id.default_debit_account_id: + raise UserError(_( + "Missing 'Default Debit Account' on bank journal '%s'") + % deposit.bank_journal_id.name) + account_id = deposit.bank_journal_id.default_debit_account_id.id + elif company.check_deposit_offsetting_account == 'transfer_account': + if not company.check_deposit_transfer_account_id: + raise UserError(_( + "Missing 'Account for Check Deposits' on the " + "company '%s'.") % company.name) + account_id = company.check_deposit_transfer_account_id.id return { 'name': _('Check Deposit %s') % deposit.name, 'debit': total_debit, 'credit': 0.0, - 'account_id': deposit.company_id.check_deposit_account_id.id, + 'account_id': account_id, 'partner_id': False, 'currency_id': deposit.currency_none_same_company_id.id or False, 'amount_currency': total_amount_currency, @@ -215,11 +227,6 @@ class AccountCheckDeposit(models.Model): to_reconcile_lines.append(line + move_line) # Create counter-part - if not deposit.company_id.check_deposit_account_id: - raise UserError( - _("Missing Account for Check Deposits on the " - "company '%s'.") % deposit.company_id.name) - counter_vals = self._prepare_counterpart_move_lines_vals( deposit, total_debit, total_amount_currency) counter_vals['move_id'] = move.id @@ -235,12 +242,14 @@ class AccountCheckDeposit(models.Model): @api.onchange('company_id') def onchange_company_id(self): if self.company_id: - partner_banks = self.env['res.partner.bank'].search( - [('company_id', '=', self.company_id.id)]) - if len(partner_banks) == 1: - self.partner_bank_id = partner_banks[0] + bank_journals = self.env['account.journal'].search([ + ('company_id', '=', self.company_id.id), + ('type', '=', 'bank'), + ('bank_account_id', '!=', False)]) + if len(bank_journals) == 1: + self.bank_journal_id = bank_journals[0] else: - self.partner_bank_id = False + self.bank_journal_id = False @api.onchange('journal_id') def onchange_journal_id(self): @@ -256,11 +265,3 @@ class AccountMoveLine(models.Model): check_deposit_id = fields.Many2one( 'account.check.deposit', string='Check Deposit', copy=False) - - -class ResCompany(models.Model): - _inherit = 'res.company' - - check_deposit_account_id = fields.Many2one( - 'account.account', string='Account for Check Deposits', copy=False, - domain=[('reconcile', '=', True)]) diff --git a/account_check_deposit/models/company.py b/account_check_deposit/models/company.py new file mode 100644 index 000000000..f83c1ac7d --- /dev/null +++ b/account_check_deposit/models/company.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# © 2012-2016 Akretion (http://www.akretion.com/) +# @author: Benoît GUILLOT +# @author: Chafique DELLI +# @author: Alexis de Lattre +# @author: Mourad EL HADJ MIMOUNE +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models, fields + + +class ResCompany(models.Model): + _inherit = 'res.company' + + check_deposit_offsetting_account = fields.Selection([ + ('bank_account', 'Bank Account'), + ('transfer_account', 'Transfer Account'), + ], string='Check Deposit Offsetting Account', default='bank_account') + check_deposit_transfer_account_id = fields.Many2one( + 'account.account', string='Transfer Account for Check Deposits', + ondelete='restrict', copy=False, + domain=[('reconcile', '=', True), ('deprecated', '=', False)]) diff --git a/account_check_deposit/report/report_checkdeposit.xml b/account_check_deposit/report/report_checkdeposit.xml index 0ec70ed2b..68809535d 100644 --- a/account_check_deposit/report/report_checkdeposit.xml +++ b/account_check_deposit/report/report_checkdeposit.xml @@ -20,15 +20,15 @@

Check Deposit n°

Bank:

-


-
-

+


+
+

Beneficiary:

-

Bank Account Number to Credit:

+

Bank Account Number to Credit:

Check Currency:

diff --git a/account_check_deposit/tests/test_check_deposit.py b/account_check_deposit/tests/test_check_deposit.py index 477dd8e3e..351152c07 100644 --- a/account_check_deposit/tests/test_check_deposit.py +++ b/account_check_deposit/tests/test_check_deposit.py @@ -3,7 +3,7 @@ # @author Mourad EL HADJ MIMOUNE # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp.addons.account.tests.account_test_classes\ +from odoo.addons.account.tests.account_test_classes\ import AccountingTestCase import time @@ -55,12 +55,15 @@ class TestPayment(AccountingTestCase): self.ref('account.data_account_type_revenue') }) - self.recived_check_account_id = self.account_account_model.search( + self.received_check_account_id = self.account_account_model.search( [('code', '=', '511200')], limit=1) - if not self.recived_check_account_id: - self.recived_check_account_id = self.account_account_model.create( + if self.received_check_account_id: + if not self.received_check_account_id.reconcile: + self.received_check_account_id.reconcile = True + else: + self.received_check_account_id = self.account_account_model.create( {"code": '511200', - "name": "Recived check - (test)", + "name": "Received check - (test)", "reconcile": True, "user_type_id": self.ref('account.data_account_type_liquidity') @@ -92,11 +95,11 @@ class TestPayment(AccountingTestCase): [('code', '=', 'CHK')], limit=1) if not self.check_journal: self.check_journal = self.journal_model.create( - {'name': 'Recived check', 'type': 'bank', 'code': 'CHK'}) + {'name': 'received check', 'type': 'bank', 'code': 'CHK'}) self.check_journal.default_debit_account_id = \ - self.recived_check_account_id + self.received_check_account_id self.check_journal.default_credit_account_id = \ - self.recived_check_account_id + self.received_check_account_id self.bank_journal = self.journal_model.search( [('code', '=', 'BNK1')], limit=1) if not self.bank_journal: @@ -111,6 +114,7 @@ class TestPayment(AccountingTestCase): {"acc_number": 'SI56 1910 0000 0123 438 584', "partner_id": self.main_company.partner_id.id, }) + self.bank_journal.bank_account_id = self.partner_bank_id.id def create_invoice(self, amount=100, type='out_invoice', currency_id=None): """ Returns an open invoice """ @@ -132,7 +136,7 @@ class TestPayment(AccountingTestCase): 'name': 'something', 'account_id': self.account_revenue.id, }) - invoice.signal_workflow('invoice_open') + invoice.action_invoice_open() return invoice def create_check_deposit( @@ -140,7 +144,7 @@ class TestPayment(AccountingTestCase): """ Returns an validated check deposit """ check_deposit = self.check_deposit_model.create({ 'journal_id': self.bank_journal.id, - 'partner_bank_id': self.partner_bank_id.id, + 'bank_journal_id': self.bank_journal.id, 'deposit_date': time.strftime('%Y-%m-%d'), 'currency_id': self.currency_eur_id, }) @@ -177,11 +181,11 @@ class TestPayment(AccountingTestCase): self.assertEqual(inv_2.state, 'paid') check_aml = payment.move_line_ids.filtered( - lambda r: r.account_id == self.recived_check_account_id) + lambda r: r.account_id == self.received_check_account_id) check_deposit = self.create_check_deposit([check_aml]) liquidity_aml = check_deposit.move_id.line_ids.filtered( - lambda r: r.account_id != self.recived_check_account_id) + lambda r: r.account_id != self.received_check_account_id) self.assertEqual(check_deposit.total_amount, 300) self.assertEqual(liquidity_aml.debit, 300) diff --git a/account_check_deposit/views/account_config_settings.xml b/account_check_deposit/views/account_config_settings.xml new file mode 100644 index 000000000..995e10a7f --- /dev/null +++ b/account_check_deposit/views/account_config_settings.xml @@ -0,0 +1,28 @@ + + + + + + currency_rate_update.account_config_settings.form + account.config.settings + + +
+
+
+
+
+
+
+
+ +
diff --git a/account_check_deposit/views/account_deposit_view.xml b/account_check_deposit/views/account_deposit_view.xml index 7d178d400..9e7ed8e9b 100644 --- a/account_check_deposit/views/account_deposit_view.xml +++ b/account_check_deposit/views/account_deposit_view.xml @@ -39,7 +39,7 @@ invisible="1"/> - + - + diff --git a/account_check_deposit/views/company_view.xml b/account_check_deposit/views/company_view.xml deleted file mode 100644 index 06329163a..000000000 --- a/account_check_deposit/views/company_view.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - check.deposit.company.form - res.company - - - - - - - - - - -