From d1fc63d62970091a874fcaacaf3f0aadf805b2a9 Mon Sep 17 00:00:00 2001 From: eLBati Date: Wed, 20 Nov 2019 14:33:33 +0100 Subject: [PATCH] ADD account_payment_select_cost_account: The module allows users to specify which account to use in outbound payments. Without this module, you can only use a payable account, not being able to use a cost account. This is useful when you need to track payment status, also attaching files and chatting, for payments not tracked by other documents, like fiscal payments, penalties, etc. --- .../__init__.py | 1 + .../__manifest__.py | 22 ++++++++++++++ .../models/__init__.py | 1 + .../models/account_payment.py | 18 ++++++++++++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/CREDITS.rst | 3 ++ .../readme/DESCRIPTION.rst | 6 ++++ .../readme/USAGE.rst | 2 ++ .../tests/__init__.py | 1 + ...est_account_payment_select_cost_account.py | 29 +++++++++++++++++++ .../views/account_payment_view.xml | 15 ++++++++++ .../account_payment_select_cost_account | 1 + .../setup.py | 6 ++++ 13 files changed, 106 insertions(+) create mode 100644 account_payment_select_cost_account/__init__.py create mode 100644 account_payment_select_cost_account/__manifest__.py create mode 100644 account_payment_select_cost_account/models/__init__.py create mode 100644 account_payment_select_cost_account/models/account_payment.py create mode 100644 account_payment_select_cost_account/readme/CONTRIBUTORS.rst create mode 100644 account_payment_select_cost_account/readme/CREDITS.rst create mode 100644 account_payment_select_cost_account/readme/DESCRIPTION.rst create mode 100644 account_payment_select_cost_account/readme/USAGE.rst create mode 100644 account_payment_select_cost_account/tests/__init__.py create mode 100644 account_payment_select_cost_account/tests/test_account_payment_select_cost_account.py create mode 100644 account_payment_select_cost_account/views/account_payment_view.xml create mode 120000 setup/account_payment_select_cost_account/odoo/addons/account_payment_select_cost_account create mode 100644 setup/account_payment_select_cost_account/setup.py diff --git a/account_payment_select_cost_account/__init__.py b/account_payment_select_cost_account/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/account_payment_select_cost_account/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_payment_select_cost_account/__manifest__.py b/account_payment_select_cost_account/__manifest__.py new file mode 100644 index 00000000000..7ee939625d5 --- /dev/null +++ b/account_payment_select_cost_account/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2019 Lorenzo Battistini +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +{ + "name": "Outbound payments: select account", + "summary": "Allow user to select the account where journal item will be recorded", + "version": "12.0.1.0.0", + "development_status": "Beta", + "category": "Invoicing Management", + "website": "https://github.com/OCA/account-payment", + "author": "TAKOBI, Odoo Community Association (OCA)", + "maintainers": ["eLBati"], + "license": "LGPL-3", + "application": False, + "installable": True, + "depends": [ + "account", + ], + "data": [ + "views/account_payment_view.xml" + ], +} diff --git a/account_payment_select_cost_account/models/__init__.py b/account_payment_select_cost_account/models/__init__.py new file mode 100644 index 00000000000..ab350b87bb1 --- /dev/null +++ b/account_payment_select_cost_account/models/__init__.py @@ -0,0 +1 @@ +from . import account_payment diff --git a/account_payment_select_cost_account/models/account_payment.py b/account_payment_select_cost_account/models/account_payment.py new file mode 100644 index 00000000000..9052e3d4605 --- /dev/null +++ b/account_payment_select_cost_account/models/account_payment.py @@ -0,0 +1,18 @@ +from odoo import models, fields, api + + +class Payment(models.Model): + _inherit = 'account.payment' + force_destination_account_id = fields.Many2one( + 'account.account', string="Cost account") + + @api.onchange("destination_account_id") + def onchange_destination_account_id(self): + if self.destination_account_id: + self.force_destination_account_id = self.destination_account_id.id + + def _get_counterpart_move_line_vals(self, invoice=False): + vals = super(Payment, self)._get_counterpart_move_line_vals(invoice) + if self.force_destination_account_id: + vals['account_id'] = self.force_destination_account_id.id + return vals diff --git a/account_payment_select_cost_account/readme/CONTRIBUTORS.rst b/account_payment_select_cost_account/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..f52b696bb04 --- /dev/null +++ b/account_payment_select_cost_account/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Lorenzo Battistini diff --git a/account_payment_select_cost_account/readme/CREDITS.rst b/account_payment_select_cost_account/readme/CREDITS.rst new file mode 100644 index 00000000000..36a4af1e824 --- /dev/null +++ b/account_payment_select_cost_account/readme/CREDITS.rst @@ -0,0 +1,3 @@ +The development of this module has been financially supported by: + +* TAKOBI https://takobi.online diff --git a/account_payment_select_cost_account/readme/DESCRIPTION.rst b/account_payment_select_cost_account/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..be095a679ee --- /dev/null +++ b/account_payment_select_cost_account/readme/DESCRIPTION.rst @@ -0,0 +1,6 @@ +The module allows users to specify which account to use in outbound payments. + +Without this module, you can only use a payable account, not being able to use a cost account. + +This is useful when you need to track payment status, also attaching files and chatting, for payments not tracked by other documents, like fiscal payments, +penalties, etc. diff --git a/account_payment_select_cost_account/readme/USAGE.rst b/account_payment_select_cost_account/readme/USAGE.rst new file mode 100644 index 00000000000..de6d475824c --- /dev/null +++ b/account_payment_select_cost_account/readme/USAGE.rst @@ -0,0 +1,2 @@ +Just select "Cost account" in vendors payments + diff --git a/account_payment_select_cost_account/tests/__init__.py b/account_payment_select_cost_account/tests/__init__.py new file mode 100644 index 00000000000..146a8c4d7f0 --- /dev/null +++ b/account_payment_select_cost_account/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_payment_select_cost_account diff --git a/account_payment_select_cost_account/tests/test_account_payment_select_cost_account.py b/account_payment_select_cost_account/tests/test_account_payment_select_cost_account.py new file mode 100644 index 00000000000..7a57213c539 --- /dev/null +++ b/account_payment_select_cost_account/tests/test_account_payment_select_cost_account.py @@ -0,0 +1,29 @@ +from odoo.tests.common import TransactionCase + + +class TestPaymentSelectCost(TransactionCase): + + def setUp(self): + super(TestPaymentSelectCost, self).setUp() + self.account_cost = self.env['account.account'].search([ + ('user_type_id', '=', self.env.ref('account.data_account_type_expenses').id) + ], limit=1) + self.bank_journal = self.env['account.journal'].create( + {'name': 'Bank', 'type': 'bank', 'code': 'BNK'}) + + def test_outbound_payment(self): + payment = self.env['account.payment'].create({ + 'payment_type': 'outbound', + 'partner_type': 'supplier', + 'journal_id': self.bank_journal.id, + 'payment_method_id': self.bank_journal.outbound_payment_method_ids[0].id, + 'amount': 100, + }) + payment.onchange_destination_account_id() + payment._convert_to_write(payment._cache) + payment.force_destination_account_id = self.account_cost.id + payment.post() + self.assertEqual(len(payment.move_line_ids), 2) + for line in payment.move_line_ids: + if line.debit: + self.assertEqual(line.account_id.id, self.account_cost.id) diff --git a/account_payment_select_cost_account/views/account_payment_view.xml b/account_payment_select_cost_account/views/account_payment_view.xml new file mode 100644 index 00000000000..ed3df6f7f79 --- /dev/null +++ b/account_payment_select_cost_account/views/account_payment_view.xml @@ -0,0 +1,15 @@ + + + + view_account_payment_form_select_account + account.payment + + + + + + + + + diff --git a/setup/account_payment_select_cost_account/odoo/addons/account_payment_select_cost_account b/setup/account_payment_select_cost_account/odoo/addons/account_payment_select_cost_account new file mode 120000 index 00000000000..fd58c93e9ba --- /dev/null +++ b/setup/account_payment_select_cost_account/odoo/addons/account_payment_select_cost_account @@ -0,0 +1 @@ +../../../../account_payment_select_cost_account \ No newline at end of file diff --git a/setup/account_payment_select_cost_account/setup.py b/setup/account_payment_select_cost_account/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/account_payment_select_cost_account/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)