diff --git a/account_check_deposit/README.rst b/account_check_deposit/README.rst index 12fb31dca..fc0afa5b3 100644 --- a/account_check_deposit/README.rst +++ b/account_check_deposit/README.rst @@ -52,6 +52,7 @@ Contributors * Benoît GUILLOT * Chafique DELLI * Alexis de Lattre +* Mourad EL HADJ MIMOUNE Maintainer ---------- diff --git a/account_check_deposit/__openerp__.py b/account_check_deposit/__manifest__.py similarity index 63% rename from account_check_deposit/__openerp__.py rename to account_check_deposit/__manifest__.py index e4fff91d2..854713d08 100644 --- a/account_check_deposit/__openerp__.py +++ b/account_check_deposit/__manifest__.py @@ -7,18 +7,7 @@ # @author: Chafique DELLI # @author: Alexis de Lattre # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # ############################################################################### @@ -32,7 +21,6 @@ 'website': 'http://www.akretion.com/', 'depends': [ 'account_accountant', - 'report_webkit', ], 'data': [ 'views/account_deposit_view.xml', diff --git a/account_check_deposit/data/account_deposit_sequence.xml b/account_check_deposit/data/account_deposit_sequence.xml index 07c4c13bd..4206b28cc 100644 --- a/account_check_deposit/data/account_deposit_sequence.xml +++ b/account_check_deposit/data/account_deposit_sequence.xml @@ -9,12 +9,6 @@ - - - Account Check Deposit - account.check.deposit - - Account Check Deposit account.check.deposit diff --git a/account_check_deposit/models/account_deposit.py b/account_check_deposit/models/account_deposit.py index 980a61b0c..076775c4d 100644 --- a/account_check_deposit/models/account_deposit.py +++ b/account_check_deposit/models/account_deposit.py @@ -2,23 +2,13 @@ ############################################################################### # # account_check_deposit for Odoo -# Copyright (C) 2012-2015 Akretion (http://www.akretion.com/) +# 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 # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # ############################################################################### @@ -37,7 +27,7 @@ class AccountCheckDeposit(models.Model): @api.depends( 'company_id', 'currency_id', 'check_payment_ids.debit', 'check_payment_ids.amount_currency', - 'move_id.line_id.reconcile_id') + 'move_id.line_ids.reconciled') def _compute_check_deposit(self): for deposit in self: total = 0.0 @@ -53,8 +43,8 @@ class AccountCheckDeposit(models.Model): else: total += line.debit if deposit.move_id: - for line in deposit.move_id.line_id: - if line.debit > 0 and line.reconcile_id: + for line in deposit.move_id.line_ids: + if line.debit > 0 and line.reconciled: reconcile = True deposit.total_amount = total deposit.is_reconcile = reconcile @@ -82,9 +72,10 @@ class AccountCheckDeposit(models.Model): currency_none_same_company_id = fields.Many2one( 'res.currency', compute='_compute_check_deposit', string='Currency (False if same as company)') - state = fields.Selection([ - ('draft', 'Draft'), - ('done', 'Done'), + state = fields.Selection( + [ + ('draft', 'Draft'), + ('done', 'Done'), ], string='Status', default='draft', readonly=True) move_id = fields.Many2one( 'account.move', string='Journal Entry', readonly=True) @@ -93,7 +84,7 @@ class AccountCheckDeposit(models.Model): domain="[('company_id', '=', company_id)]", states={'done': [('readonly', '=', True)]}) line_ids = fields.One2many( - 'account.move.line', related='move_id.line_id', + 'account.move.line', related='move_id.line_ids', string='Lines', readonly=True) company_id = fields.Many2one( 'res.company', string='Company', required=True, @@ -154,8 +145,8 @@ class AccountCheckDeposit(models.Model): # It will raise here if journal_id.update_posted = False deposit.move_id.button_cancel() for line in deposit.check_payment_ids: - if line.reconcile_id: - line.reconcile_id.unlink() + if line.reconciled: + line.remove_move_reconcile() deposit.move_id.unlink() deposit.write({'state': 'draft'}) return True @@ -170,16 +161,12 @@ class AccountCheckDeposit(models.Model): @api.model def _prepare_account_move_vals(self, deposit): date = deposit.deposit_date - period_obj = self.env['account.period'] - period_ids = period_obj.find(dt=date) - # period_ids will always have a value, cf the code of find() move_vals = { 'journal_id': deposit.journal_id.id, 'date': date, - 'period_id': period_ids[0].id, 'name': _('Check Deposit %s') % deposit.name, 'ref': deposit.name, - } + } return move_vals @api.model @@ -193,7 +180,7 @@ class AccountCheckDeposit(models.Model): 'partner_id': line.partner_id.id, 'currency_id': line.currency_id.id or False, 'amount_currency': line.amount_currency * -1, - } + } @api.model def _prepare_counterpart_move_lines_vals( @@ -206,25 +193,24 @@ class AccountCheckDeposit(models.Model): 'partner_id': False, 'currency_id': deposit.currency_none_same_company_id.id or False, 'amount_currency': total_amount_currency, - } + } @api.multi def validate_deposit(self): am_obj = self.env['account.move'] - aml_obj = self.env['account.move.line'] for deposit in self: move_vals = self._prepare_account_move_vals(deposit) - move = am_obj.create(move_vals) total_debit = 0.0 total_amount_currency = 0.0 to_reconcile_lines = [] + mv_lines_vals = [] for line in deposit.check_payment_ids: total_debit += line.debit total_amount_currency += line.amount_currency line_vals = self._prepare_move_line_vals(line) - line_vals['move_id'] = move.id - move_line = aml_obj.create(line_vals) - to_reconcile_lines.append(line + move_line) + mv_lines_vals.append((0, 0, line_vals)) + + to_reconcile_lines.append(line) # Create counter-part if not deposit.company_id.check_deposit_account_id: @@ -234,8 +220,10 @@ class AccountCheckDeposit(models.Model): counter_vals = self._prepare_counterpart_move_lines_vals( deposit, total_debit, total_amount_currency) - counter_vals['move_id'] = move.id - aml_obj.create(counter_vals) + mv_lines_vals.append((0, 0, counter_vals)) + move_vals['line_ids'] = mv_lines_vals + move = am_obj.create(move_vals) + to_reconcile_lines.extend(move.line_ids) move.post() deposit.write({'state': 'done', 'move_id': move.id}) @@ -257,8 +245,8 @@ class AccountCheckDeposit(models.Model): @api.onchange('journal_id') def onchange_journal_id(self): if self.journal_id: - if self.journal_id.currency: - self.currency_id = self.journal_id.currency + if self.journal_id.currency_id: + self.currency_id = self.journal_id.currency_id else: self.currency_id = self.journal_id.company_id.currency_id @@ -275,7 +263,4 @@ class ResCompany(models.Model): check_deposit_account_id = fields.Many2one( 'account.account', string='Account for Check Deposits', copy=False, - domain=[ - ('type', '<>', 'view'), - ('type', '<>', 'closed'), - ('reconcile', '=', True)]) + domain=[('reconcile', '=', True)]) diff --git a/account_check_deposit/tests/__init__.py b/account_check_deposit/tests/__init__.py new file mode 100644 index 000000000..841522611 --- /dev/null +++ b/account_check_deposit/tests/__init__.py @@ -0,0 +1,2 @@ + +from . import test_check_deposit diff --git a/account_check_deposit/tests/test_check_deposit.py b/account_check_deposit/tests/test_check_deposit.py new file mode 100644 index 000000000..477dd8e3e --- /dev/null +++ b/account_check_deposit/tests/test_check_deposit.py @@ -0,0 +1,189 @@ +# -*- coding: utf-8 -*- +# © 2014-2016 Akretion (http://www.akretion.com) +# @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\ + import AccountingTestCase +import time + + +class TestPayment(AccountingTestCase): + + def setUp(self): + super(TestPayment, self).setUp() + self.register_payments_model = self.env['account.register.payments'] + self.payment_model = self.env['account.payment'] + self.journal_model = self.env['account.journal'] + self.account_account_model = self.env['account.account'] + self.invoice_model = self.env['account.invoice'] + self.invoice_line_model = self.env['account.invoice.line'] + self.acc_bank_stmt_model = self.env['account.bank.statement'] + self.acc_bank_stmt_line_model = self.env['account.bank.statement.line'] + self.res_partner_bank_model = self.env['res.partner.bank'] + self.check_deposit_model = self.env['account.check.deposit'] + + self.partner_agrolait = self.env.ref("base.res_partner_2") + self.currency_eur_id = self.env.ref("base.EUR").id + self.main_company = self.env.ref('base.main_company') + self.main_company.write({'currency_id': self.currency_eur_id}) + self.product = self.env.ref("product.product_product_4") + self.payment_method_manual_in = self.env.ref( + "account.account_payment_method_manual_in") + self.payment_method_manual_out = self.env.ref( + "account.account_payment_method_manual_out") + # check if those accounts exist otherwise create them + self.account_receivable = self.account_account_model.search( + [('code', '=', '411100')], limit=1) + + if not self.account_receivable: + self.account_receivable = self.account_account_model.create( + {"code": '411100', + "name": "Debtors - (test)", + "reconcile": True, + "user_type_id": + self.ref('account.data_account_type_receivable') + }) + + self.account_revenue = self.account_account_model.search( + [('code', '=', '707100')], limit=1) + if not self.account_revenue: + self.account_revenue = self.account_account_model.create( + {"code": '707100', + "name": "Product Sales - (test)", + "user_type_id": + self.ref('account.data_account_type_revenue') + }) + + self.recived_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( + {"code": '511200', + "name": "Recived check - (test)", + "reconcile": True, + "user_type_id": + self.ref('account.data_account_type_liquidity') + }) + self.main_company.check_deposit_account_id = \ + self.account_account_model.search( + [('code', '=', '511201')], limit=1) + if not self.main_company.check_deposit_account_id: + self.main_company.check_deposit_account_id = \ + self.account_account_model.create( + {"code": '511201', + "name": "Check deposited in bank - (test)", + "reconcile": True, + "user_type_id": + self.ref('account.data_account_type_liquidity') + }) + self.bank_account_id = self.account_account_model.search( + [('code', '=', '512001')], limit=1) + if not self.bank_account_id: + self.bank_account_id = self.account_account_model.create( + {"code": '512001', + "name": "Bank - (test)", + "reconcile": True, + "user_type_id": + self.ref('account.data_account_type_liquidity') + }) + + self.check_journal = self.journal_model.search( + [('code', '=', 'CHK')], limit=1) + if not self.check_journal: + self.check_journal = self.journal_model.create( + {'name': 'Recived check', 'type': 'bank', 'code': 'CHK'}) + self.check_journal.default_debit_account_id = \ + self.recived_check_account_id + self.check_journal.default_credit_account_id = \ + self.recived_check_account_id + self.bank_journal = self.journal_model.search( + [('code', '=', 'BNK1')], limit=1) + if not self.bank_journal: + self.bank_journal = self.journal_model.create( + {'name': 'Bank', 'type': 'bank', 'code': 'BNK1'}) + self.bank_journal.default_debit_account_id = self.bank_account_id + self.bank_journal.default_credit_account_id = self.bank_account_id + self.partner_bank_id = self.res_partner_bank_model.search( + [('partner_id', '=', self.main_company.partner_id.id)], limit=1) + if not self.partner_bank_id: + self.partner_bank_id = self.res_partner_bank_model.create( + {"acc_number": 'SI56 1910 0000 0123 438 584', + "partner_id": self.main_company.partner_id.id, + }) + + def create_invoice(self, amount=100, type='out_invoice', currency_id=None): + """ Returns an open invoice """ + invoice = self.invoice_model.create({ + 'partner_id': self.partner_agrolait.id, + 'reference_type': 'none', + 'currency_id': currency_id, + 'name': type == 'out_invoice' and + 'invoice to client' or 'invoice to supplier', + 'account_id': self.account_receivable.id, + 'type': type, + 'date_invoice': time.strftime('%Y-%m-%d'), + }) + self.invoice_line_model.create({ + 'product_id': self.product.id, + 'quantity': 1, + 'price_unit': amount, + 'invoice_id': invoice.id, + 'name': 'something', + 'account_id': self.account_revenue.id, + }) + invoice.signal_workflow('invoice_open') + return invoice + + def create_check_deposit( + self, move_lines): + """ 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, + 'deposit_date': time.strftime('%Y-%m-%d'), + 'currency_id': self.currency_eur_id, + }) + for move_line in move_lines: + move_line.check_deposit_id = check_deposit + check_deposit.validate_deposit() + return check_deposit + + def test_full_payment_process(self): + """ 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) + + ctx = { + 'active_model': 'account.invoice', + 'active_ids': [ + inv_1.id, + inv_2.id]} + register_payments = self.register_payments_model.with_context( + ctx).create({ + 'payment_date': time.strftime('%Y-%m-%d'), + 'journal_id': self.check_journal.id, + 'payment_method_id': self.payment_method_manual_in.id, + }) + register_payments.create_payment() + payment = self.payment_model.search([], order="id desc", limit=1) + + self.assertAlmostEquals(payment.amount, 300) + self.assertEqual(payment.state, 'posted') + self.assertEqual(inv_1.state, 'paid') + self.assertEqual(inv_2.state, 'paid') + + check_aml = payment.move_line_ids.filtered( + lambda r: r.account_id == self.recived_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) + + self.assertEqual(check_deposit.total_amount, 300) + self.assertEqual(liquidity_aml.debit, 300) + self.assertEqual(check_deposit.move_id.state, 'posted') + self.assertEqual(check_deposit.state, 'done') diff --git a/account_check_deposit/views/account_deposit_view.xml b/account_check_deposit/views/account_deposit_view.xml index fd58b77f9..f09700ef8 100644 --- a/account_check_deposit/views/account_deposit_view.xml +++ b/account_check_deposit/views/account_deposit_view.xml @@ -55,7 +55,7 @@ ', 0), ('check_deposit_id', '=', False), ('currency_id', '=', currency_none_same_company_id), @@ -119,7 +119,7 @@