diff --git a/account_payment_line_manual_account/__init__.py b/account_payment_line_manual_account/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/account_payment_line_manual_account/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_payment_line_manual_account/__manifest__.py b/account_payment_line_manual_account/__manifest__.py new file mode 100644 index 0000000..be6bd34 --- /dev/null +++ b/account_payment_line_manual_account/__manifest__.py @@ -0,0 +1,25 @@ +# Copyright 2024 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Account Payment Line Manual Account', + 'version': '14.0.1.0.0', + 'category': 'Accounting', + 'license': 'AGPL-3', + 'summary': 'Ability to select the account on payment lines without journal item', + 'description': """ +With this module, when you manually create a payment line that is not linked to a journal item, you can select an account (by default, it is set to the payable/receivable account of the partner) : this account will be used as the counter part of the outbound/inbound payment account configured on the bank journal. It covers special needs of a few companies that use SEPA credit transfer for the same partner in different accounting scenarios. + +This module has been written by Alexis de Lattre from Akretion +. + """, + 'author': 'Akretion', + 'maintainers': ['alexis-via'], + 'website': 'https://github.com/akretion/odoo-usability', + 'depends': ['account_payment_order'], + 'data': [ + "views/account_payment_line.xml", + ], + 'installable': True, +} diff --git a/account_payment_line_manual_account/models/__init__.py b/account_payment_line_manual_account/models/__init__.py new file mode 100644 index 0000000..1dbf225 --- /dev/null +++ b/account_payment_line_manual_account/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_payment_line +from . import account_payment_order diff --git a/account_payment_line_manual_account/models/account_payment_line.py b/account_payment_line_manual_account/models/account_payment_line.py new file mode 100644 index 0000000..5f58592 --- /dev/null +++ b/account_payment_line_manual_account/models/account_payment_line.py @@ -0,0 +1,33 @@ +# Copyright 2024 Akretion France (https://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class AccountPaymentLine(models.Model): + _inherit = "account.payment.line" + + account_id = fields.Many2one( + 'account.account', + compute="_compute_account_id", store=True, readonly=False, check_company=True, + domain="[('company_id', '=', company_id), ('deprecated', '=', False)]") + + @api.depends('move_line_id', 'partner_id') + def _compute_account_id(self): + for line in self: + account_id = False + if not line.move_line_id and line.partner_id: + partner = line.partner_id.with_company(line.order_id.company_id.id) + if line.order_id.payment_type == "inbound": + account_id = partner.property_account_receivable_id.id + else: + account_id = partner.property_account_payable_id.id + line.account_id = account_id + + # take info account account_id for grouping + def payment_line_hashcode(self): + hashcode = super().payment_line_hashcode() + account_str = str(self.account_id.id or False) + hashcode = '-'.join([hashcode, account_str]) + return hashcode diff --git a/account_payment_line_manual_account/models/account_payment_order.py b/account_payment_line_manual_account/models/account_payment_order.py new file mode 100644 index 0000000..d698190 --- /dev/null +++ b/account_payment_line_manual_account/models/account_payment_order.py @@ -0,0 +1,15 @@ +# Copyright 2024 Akretion France (https://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class AccountPaymentOrder(models.Model): + _inherit = "account.payment.order" + + def _prepare_move_line_partner_account(self, bank_line): + vals = super()._prepare_move_line_partner_account(bank_line) + if not bank_line.payment_line_ids[0].move_line_id: + vals['account_id'] = bank_line.payment_line_ids[0].account_id.id + return vals diff --git a/account_payment_line_manual_account/views/account_payment_line.xml b/account_payment_line_manual_account/views/account_payment_line.xml new file mode 100644 index 0000000..a5e150b --- /dev/null +++ b/account_payment_line_manual_account/views/account_payment_line.xml @@ -0,0 +1,33 @@ + + + + + + + + + account.payment.line + + + + + + + + + + account.payment.line + + + + + + + + + +