From 9f33f9770352206c63a6f98859448d278f810f80 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 6 Dec 2016 08:52:08 +0100 Subject: [PATCH] Port account_check_deposit to v10 Add option to have the counter-part of the deposit move directly to the bank account Use account.config.settings page --- account_check_deposit/README.rst | 27 ++++--- account_check_deposit/__manifest__.py | 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 +- .../views/account_config_settings.xml | 28 +++++++ .../views/account_deposit_view.xml | 4 +- account_check_deposit/views/company_view.xml | 25 ------ 10 files changed, 130 insertions(+), 95 deletions(-) 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..4b05315ef 100644 --- a/account_check_deposit/README.rst +++ b/account_check_deposit/README.rst @@ -18,30 +18,29 @@ 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. -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. +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 +56,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 +66,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..19df0157e 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', @@ -26,7 +20,7 @@ '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', 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/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 - - - - - - - - - - -