diff --git a/account_payment_return/README.rst b/account_payment_return/README.rst index bb8bc9996e12..9993550cd0ac 100644 --- a/account_payment_return/README.rst +++ b/account_payment_return/README.rst @@ -24,20 +24,19 @@ Another option to fill info is setting references and click match button to find matches with invoices, move lines or moves. This functionality is extended by other modules as *account_payment_return_import_sepa_pain* +It's possible to add a commission amount on each line. + Next, press button "Confirm" to create a new move line that removes the balance from the bank journal and reconcile items together to show payment history through it. +After confirmation you can access from the payment form view to the move +created. + .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot :target: https://runbot.odoo-community.org/runbot/96/10.0 -Known issues / Roadmap -====================== - -* Add a button to see the created move. -* Allow to add a commission amount on each line. - Bug Tracker =========== @@ -58,6 +57,7 @@ Contributors * Sergio Teruel * Carlos Dauden * David Vidal +* Luis M. Ontalba Maintainer ---------- diff --git a/account_payment_return/__manifest__.py b/account_payment_return/__manifest__.py index 80185c6923a7..1554ba9333b0 100644 --- a/account_payment_return/__manifest__.py +++ b/account_payment_return/__manifest__.py @@ -11,7 +11,7 @@ { "name": "Account Payment Returns", - "version": "10.0.1.0.0", + "version": "10.0.1.1.0", "summary": "Manage the return of your payments", 'license': 'AGPL-3', "depends": [ @@ -27,6 +27,7 @@ 'security/ir.model.access.csv', 'security/account_payment_return_security.xml', 'views/payment_return_view.xml', + 'views/account_journal_view.xml', 'data/ir_sequence_data.xml', 'views/account_invoice_view.xml', ], diff --git a/account_payment_return/models/__init__.py b/account_payment_return/models/__init__.py index 82b2fff59ab5..29328c91ac91 100644 --- a/account_payment_return/models/__init__.py +++ b/account_payment_return/models/__init__.py @@ -5,3 +5,4 @@ from . import account_invoice from . import payment_return_reason from . import account_move +from . import account_journal diff --git a/account_payment_return/models/account_journal.py b/account_payment_return/models/account_journal.py new file mode 100644 index 000000000000..ed9acd6a1a86 --- /dev/null +++ b/account_payment_return/models/account_journal.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 luis M. Ontalba +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class AccountJournal(models.Model): + _inherit = "account.journal" + + default_expense_account_id = fields.Many2one( + comodel_name='account.account', string='Default Expense Account', + help='Default account for commission expenses') + default_expense_partner_id = fields.Many2one( + comodel_name="res.partner", string="Default Expense Partner", + domain=[('supplier', '=', True)], help='Default partner for ' + 'commission expenses') diff --git a/account_payment_return/models/payment_return.py b/account_payment_return/models/payment_return.py index 0c1481384c88..f1c25db43e3e 100644 --- a/account_payment_return/models/payment_return.py +++ b/account_payment_return/models/payment_return.py @@ -4,6 +4,7 @@ # Copyright 2013 Pedro M. Baeza # Copyright 2014 Markus Schneider # Copyright 2016 Carlos Dauden +# Copyright 2017 Luis M. Ontalba # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, api, fields, models @@ -157,6 +158,28 @@ def action_confirm(self): (move_line | move_line2).reconcile() return_line.move_line_ids.mapped('matched_debit_ids').write( {'origin_returned_move_ids': [(6, 0, returned_moves.ids)]}) + if return_line.expense_amount: + expense_lines_vals = [] + expense_lines_vals.append({ + 'name': move.ref, + 'move_id': move.id, + 'debit': 0.0, + 'credit': return_line.expense_amount, + 'partner_id': return_line.expense_partner_id.id, + 'account_id': (return_line.return_id.journal_id. + default_credit_account_id.id), + }) + expense_lines_vals.append({ + 'move_id': move.id, + 'debit': return_line.expense_amount, + 'name': move.ref, + 'credit': 0.0, + 'partner_id': return_line.expense_partner_id.id, + 'account_id': return_line.expense_account.id, + }) + for expense_line_vals in expense_lines_vals: + move_line_obj.with_context( + check_move_validity=False).create(expense_line_vals) extra_lines_vals = return_line._prepare_extra_move_lines(move) for extra_line_vals in extra_lines_vals: move_line_obj.create(extra_line_vals) @@ -231,6 +254,13 @@ class PaymentReturnLine(models.Model): string='Amount', help="Returned amount. Can be different from the move amount", digits=dp.get_precision('Account')) + expense_account = fields.Many2one( + comodel_name='account.account', string='Expense Account') + expense_amount = fields.Float(string='Expense amount') + expense_partner_id = fields.Many2one( + comodel_name="res.partner", string="Expense partner", + domain=[('supplier', '=', True)], + ) @api.multi def _compute_amount(self): @@ -251,6 +281,13 @@ def _get_partner_from_move(self): def _onchange_move_line(self): self._compute_amount() + @api.onchange('expense_amount') + def _onchange_expense_amount(self): + if self.expense_amount: + journal = self.return_id.journal_id + self.expense_account = journal.default_expense_account_id + self.expense_partner_id = journal.default_expense_partner_id + @api.multi def match_invoice(self): for line in self: diff --git a/account_payment_return/tests/test_payment_return.py b/account_payment_return/tests/test_payment_return.py index 001d28c34cf3..edef0f2db34f 100644 --- a/account_payment_return/tests/test_payment_return.py +++ b/account_payment_return/tests/test_payment_return.py @@ -2,6 +2,7 @@ # Copyright 2015 Pedro M. Baeza # Copyright 2016 Carlos Dauden # Copyright 2017 David Vidal +# Copyright 2017 Luis M. Ontalba # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html import json @@ -20,12 +21,6 @@ def setUpClass(cls): 'type': 'sale', 'update_posted': True, }) - cls.bank_journal = cls.env['account.journal'].create({ - 'name': 'Test Bank Journal', - 'code': 'BANK', - 'type': 'bank', - 'update_posted': True, - }) cls.account_type = cls.env['account.account.type'].create({ 'name': 'Test', 'type': 'receivable', @@ -36,6 +31,15 @@ def setUpClass(cls): 'user_type_id': cls.account_type.id, 'reconcile': True, }) + cls.partner_expense = cls.env['res.partner'].create({'name': 'PE'}) + cls.bank_journal = cls.env['account.journal'].create({ + 'name': 'Test Bank Journal', + 'code': 'BANK', + 'type': 'bank', + 'update_posted': True, + 'default_expense_account_id': cls.account.id, + 'default_expense_partner_id': cls.partner_expense.id, + }) cls.account_income = cls.env['account.account'].create({ 'name': 'Test income account', 'code': 'INCOME', @@ -80,7 +84,10 @@ def setUpClass(cls): 'line_ids': [ (0, 0, {'partner_id': cls.partner.id, 'move_line_ids': [(6, 0, cls.payment_line.ids)], - 'amount': cls.payment_line.credit})]}) + 'amount': cls.payment_line.credit, + 'expense_account': cls.account.id, + 'expense_amount': 10.0, + 'expense_partner_id': cls.partner.id})]}) def test_confirm_error(self): self.payment_return.line_ids[0].move_line_ids = False @@ -100,11 +107,18 @@ def test_payment_return(self): self.assertEqual(self.payment_return.state, 'cancelled') self.payment_return.action_draft() self.assertEqual(self.payment_return.state, 'draft') + self.payment_return.line_ids[0].expense_amount = 20.0 + self.payment_return.line_ids[0]._onchange_expense_amount() self.payment_return.action_confirm() self.assertEqual(self.payment_return.state, 'done') self.assertEqual(self.invoice.state, 'open') self.assertEqual(self.invoice.residual, self.receivable_line.debit) self.assertFalse(self.receivable_line.reconciled) + self.assertEqual(self.payment_return.line_ids[0].expense_account, + self.bank_journal.default_expense_account_id) + self.assertEqual(self.payment_return.line_ids[0].expense_partner_id, + self.bank_journal.default_expense_partner_id) + self.assertEqual(len(self.payment_return.move_id.line_ids), 4) with self.assertRaises(UserError): self.payment_return.unlink() self.payment_return.action_cancel() diff --git a/account_payment_return/views/account_journal_view.xml b/account_payment_return/views/account_journal_view.xml new file mode 100644 index 000000000000..7a515954f4e3 --- /dev/null +++ b/account_payment_return/views/account_journal_view.xml @@ -0,0 +1,19 @@ + + + + + + + account.journal.form + account.journal + + + + + + + + + + diff --git a/account_payment_return/views/payment_return_view.xml b/account_payment_return/views/payment_return_view.xml index 82e0087d3687..c35643bb2c54 100644 --- a/account_payment_return/views/payment_return_view.xml +++ b/account_payment_return/views/payment_return_view.xml @@ -23,6 +23,7 @@ + @@ -42,6 +43,11 @@ ('reconciled', '=', True)]" /> + + +