diff --git a/account_move_partner_bank/README.rst b/account_move_partner_bank/README.rst new file mode 100644 index 00000000..7bbeffa3 --- /dev/null +++ b/account_move_partner_bank/README.rst @@ -0,0 +1,135 @@ +========================= +Account Move Partner Bank +========================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:b0bbc6bb7b42a01fe927641c8dbfcbb8c0209dbd04a2cbf9176a5a4d32e4dcce + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--invoicing-lightgray.png?logo=github + :target: https://github.com/OCA/account-invoicing/tree/18.0/account_move_partner_bank + :alt: OCA/account-invoicing +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-invoicing-18-0/account-invoicing-18-0-account_move_partner_bank + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/account-invoicing&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a bank account field to partners and sets it as the +Recipient Bank on account moves based on the configuration of the +invoice's company. + +The bank source configuration supports multiple source models, allowing +the same logic to be reused for other models (e.g., sale.order) by +calling ``bank_account_source_ids.get_bank_for_record(record)``. + +Note: If you want to add a bank account field to other models related to +account moves, you can extend the ``bank.account.mixin`` in a new module +and simply add the bank account field to the views. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To set up a bank account for a partner: + +- Go to the partner record. +- Under the Invoicing/Accounting tab, set the Recipient Bank field. If + the partner has a company set, you can only select a bank account + linked to that company’s partner. If the partner has no company set, + you can only select a bank account linked to the current company’s + partner. This is a company-dependent field. + +To set up a bank account for a sales team: + +- Go to Sales > Configuration > Sales Teams. +- Select a team and set the Recipient Bank field. You can only choose a + bank account linked to the company's partner (i.e., one of the + company’s own bank accounts). + +To use bank accounts in invoices: + +- Go to Settings → Companies. +- Open a company record. +- In the Bank Account Sources tab, create one or more records. + + - Source Model: Select the model from which the bank field path is + resolved (e.g., Account Move). + - Bank Field Path: Enter the dot-path from the source model to a + bank account (res.partner.bank), for example + partner_id.bank_account_id or team_id.bank_account_id. + +The bank account from the record with the highest priority (lowest +sequence number) will be used first when assigning the bank on invoices. +If no value is found, the system proceeds to the next record, and so on. + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Quartile + +Contributors +------------ + +- ``Quartile ``\ \_\_: + + - Aung Ko Ko Lin + - Yoshi Tashiro + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +.. |maintainer-yostashiro| image:: https://github.com/yostashiro.png?size=40px + :target: https://github.com/yostashiro + :alt: yostashiro +.. |maintainer-aungkokolin1997| image:: https://github.com/aungkokolin1997.png?size=40px + :target: https://github.com/aungkokolin1997 + :alt: aungkokolin1997 + +Current `maintainers `__: + +|maintainer-yostashiro| |maintainer-aungkokolin1997| + +This module is part of the `OCA/account-invoicing `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_move_partner_bank/__init__.py b/account_move_partner_bank/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/account_move_partner_bank/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_move_partner_bank/__manifest__.py b/account_move_partner_bank/__manifest__.py new file mode 100644 index 00000000..1c4a2e08 --- /dev/null +++ b/account_move_partner_bank/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Account Move Partner Bank", + "summary": "Configurable recipient bank account suggestion for invoices", + "version": "18.0.1.0.0", + "author": "Quartile, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/account-invoicing", + "category": "Account", + "license": "AGPL-3", + "depends": ["account"], + "data": [ + "security/ir.model.access.csv", + "views/res_company_views.xml", + "views/res_partner_views.xml", + ], + "maintainers": ["yostashiro", "aungkokolin1997"], + "installable": True, +} diff --git a/account_move_partner_bank/i18n/ja.po b/account_move_partner_bank/i18n/ja.po new file mode 100644 index 00000000..75ab92a3 --- /dev/null +++ b/account_move_partner_bank/i18n/ja.po @@ -0,0 +1,148 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_move_partner_bank +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-12-27 09:37+0000\n" +"PO-Revision-Date: 2025-12-27 09:37+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_move_partner_bank +#: model:ir.model.fields,field_description:account_move_partner_bank.field_bank_account_mixin__bank_account_id_domain +#: model:ir.model.fields,field_description:account_move_partner_bank.field_res_partner__bank_account_id_domain +#: model:ir.model.fields,field_description:account_move_partner_bank.field_res_users__bank_account_id_domain +msgid "Bank Account Id Domain" +msgstr "銀行口座IDドメイン" + +#. module: account_move_partner_bank +#: model:ir.model,name:account_move_partner_bank.model_bank_account_mixin +msgid "Bank Account Mixin" +msgstr "銀行口座Mixin" + +#. module: account_move_partner_bank +#: model:ir.model.fields,field_description:account_move_partner_bank.field_bank_account_source__bank_field_path +msgid "Bank Field Path" +msgstr "銀行フィールドパス" + +#. module: account_move_partner_bank +#: model:ir.model,name:account_move_partner_bank.model_res_company +msgid "Companies" +msgstr "会社" + +#. module: account_move_partner_bank +#: model:ir.model.fields,field_description:account_move_partner_bank.field_bank_account_source__company_id +msgid "Company" +msgstr "会社" + +#. module: account_move_partner_bank +#: model:ir.model,name:account_move_partner_bank.model_res_partner +msgid "Contact" +msgstr "連絡先" + +#. module: account_move_partner_bank +#: model:ir.model.fields,field_description:account_move_partner_bank.field_bank_account_source__create_uid +msgid "Created by" +msgstr "作成者" + +#. module: account_move_partner_bank +#: model:ir.model.fields,field_description:account_move_partner_bank.field_bank_account_source__create_date +msgid "Created on" +msgstr "作成日" + +#. module: account_move_partner_bank +#: model:ir.model.fields,field_description:account_move_partner_bank.field_bank_account_source__display_name +msgid "Display Name" +msgstr "表示名" + +#. module: account_move_partner_bank +#: model:ir.model.fields,help:account_move_partner_bank.field_bank_account_source__bank_field_path +msgid "Field path to res.partner.bank (e.g. partner_id.bank_account_id)." +msgstr "銀行口座へのフィールドパス(例:partner_id.bank_account_id)" + +#. module: account_move_partner_bank +#: model:ir.model.fields,field_description:account_move_partner_bank.field_bank_account_source__id +msgid "ID" +msgstr "ID" + +#. module: account_move_partner_bank +#. odoo-python +#: code:addons/account_move_partner_bank/models/bank_account_source.py:0 +msgid "Invalid bank field path: %s" +msgstr "無効な銀行フィールドパス: %s" + +#. module: account_move_partner_bank +#. odoo-python +#: code:addons/account_move_partner_bank/models/bank_account_source.py:0 +msgid "Invalid path (last field must reference res.partner.bank): %s" +msgstr "無効なパス(最後のフィールドはres.partner.bankを参照する必要があります): %s" + +#. module: account_move_partner_bank +#: model:ir.model,name:account_move_partner_bank.model_account_move +msgid "Journal Entry" +msgstr "仕訳" + +#. module: account_move_partner_bank +#: model:ir.model.fields,field_description:account_move_partner_bank.field_bank_account_source__write_uid +msgid "Last Updated by" +msgstr "最終更新者" + +#. module: account_move_partner_bank +#: model:ir.model.fields,field_description:account_move_partner_bank.field_bank_account_source__write_date +msgid "Last Updated on" +msgstr "最終更新日" + +#. module: account_move_partner_bank +#: model:ir.model,name:account_move_partner_bank.model_bank_account_source +msgid "Bank Account Source" +msgstr "銀行口座提案元" + +#. module: account_move_partner_bank +#: model:ir.model.fields,field_description:account_move_partner_bank.field_res_company__bank_account_source_ids +#: model_terms:ir.ui.view,arch_db:account_move_partner_bank.view_company_form +msgid "Bank Account Sources" +msgstr "銀行口座提案元" + +#. module: account_move_partner_bank +#: model:ir.model.fields,field_description:account_move_partner_bank.field_bank_account_mixin__bank_account_id +#: model:ir.model.fields,field_description:account_move_partner_bank.field_res_partner__bank_account_id +#: model:ir.model.fields,field_description:account_move_partner_bank.field_res_users__bank_account_id +msgid "Recipient Bank" +msgstr "受取銀行口座" + +#. module: account_move_partner_bank +#: model:ir.model.fields,help:account_move_partner_bank.field_res_partner__bank_account_id +#: model:ir.model.fields,help:account_move_partner_bank.field_res_users__bank_account_id +msgid "" +"Select a bank account of the company's partner, or the current company's " +"partner if no company is set." +msgstr "" +"会社の取引先の銀行口座を選択します。会社が設定されていない場合は、現在の会社の" +"取引先の銀行口座を選択します。" + +#. module: account_move_partner_bank +#: model:ir.model.fields,field_description:account_move_partner_bank.field_bank_account_source__sequence +msgid "Sequence" +msgstr "順序" + +#. module: account_move_partner_bank +#: model:ir.model.fields,field_description:account_move_partner_bank.field_bank_account_source__source_model_id +msgid "Source Model" +msgstr "ソースモデル" + +#. module: account_move_partner_bank +#: model:ir.model.fields,help:account_move_partner_bank.field_bank_account_source__source_model_id +msgid "The model from which the bank field path is resolved." +msgstr "銀行フィールドパスの起点となるモデル" + +#. module: account_move_partner_bank +#: model_terms:ir.ui.view,arch_db:account_move_partner_bank.view_company_form +msgid "e.g. partner_id.bank_account_id" +msgstr "例: partner_id.bank_account_id" diff --git a/account_move_partner_bank/models/__init__.py b/account_move_partner_bank/models/__init__.py new file mode 100644 index 00000000..6d490b52 --- /dev/null +++ b/account_move_partner_bank/models/__init__.py @@ -0,0 +1,5 @@ +from . import bank_account_mixin +from . import bank_account_source +from . import res_partner +from . import res_company +from . import account_move diff --git a/account_move_partner_bank/models/account_move.py b/account_move_partner_bank/models/account_move.py new file mode 100644 index 00000000..7c630664 --- /dev/null +++ b/account_move_partner_bank/models/account_move.py @@ -0,0 +1,19 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class AccountMove(models.Model): + _inherit = "account.move" + + @api.depends("bank_partner_id", "partner_id") + def _compute_partner_bank_id(self): + super()._compute_partner_bank_id() + for move in self: + if not move.is_inbound(): + continue + bank = move.company_id.bank_account_source_ids.get_bank_for_record(move) + if bank: + move.partner_bank_id = bank + return diff --git a/account_move_partner_bank/models/bank_account_mixin.py b/account_move_partner_bank/models/bank_account_mixin.py new file mode 100644 index 00000000..9c1bc321 --- /dev/null +++ b/account_move_partner_bank/models/bank_account_mixin.py @@ -0,0 +1,19 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class BankAccountMixin(models.AbstractModel): + _name = "bank.account.mixin" + _description = "Bank Account Mixin" + + bank_account_id = fields.Many2one( + "res.partner.bank", string="Recipient Bank", copy=False + ) + bank_account_id_domain = fields.Binary(compute="_compute_bank_account_id_domain") + + def _compute_bank_account_id_domain(self): + # Override in inheriting models if needed + for record in self: + record.bank_account_id_domain = [] diff --git a/account_move_partner_bank/models/bank_account_source.py b/account_move_partner_bank/models/bank_account_source.py new file mode 100644 index 00000000..2c1fd0f6 --- /dev/null +++ b/account_move_partner_bank/models/bank_account_source.py @@ -0,0 +1,63 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from operator import attrgetter + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class BankAccountSource(models.Model): + _name = "bank.account.source" + _description = "Bank Account Source" + _order = "sequence, id" + + company_id = fields.Many2one( + comodel_name="res.company", + required=True, + ondelete="cascade", + ) + sequence = fields.Integer(default=10) + source_model_id = fields.Many2one( + comodel_name="ir.model", + required=True, + ondelete="cascade", + help="The model from which the bank field path is resolved.", + ) + bank_field_path = fields.Char( + required=True, + help="Field path to res.partner.bank (e.g. partner_id.bank_account_id).", + ) + + @api.constrains("source_model_id", "bank_field_path") + def _check_bank_field_path(self): + for rec in self: + parts = [p.strip() for p in rec.bank_field_path.split(".") if p.strip()] + model = self.env[rec.source_model_id.model] + for attr in parts[:-1]: + field = model._fields.get(attr) + if not field or field.type != "many2one": + raise ValidationError( + _("Invalid bank field path: %s") % rec.bank_field_path + ) + model = self.env[field.comodel_name] + last = model._fields.get(parts[-1]) + if ( + not last + or last.type != "many2one" + or last.comodel_name != "res.partner.bank" + ): + raise ValidationError( + _("Invalid path (last field must reference res.partner.bank): %s") + % rec.bank_field_path + ) + + def get_bank_for_record(self, record): + """Find bank from sources for the given record.""" + record.ensure_one() + sources = self.filtered(lambda s: s.source_model_id.model == record._name) + for source in sources: + bank = attrgetter(source.bank_field_path)(record) or False + if bank: + return bank + return False diff --git a/account_move_partner_bank/models/res_company.py b/account_move_partner_bank/models/res_company.py new file mode 100644 index 00000000..266a6b17 --- /dev/null +++ b/account_move_partner_bank/models/res_company.py @@ -0,0 +1,14 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + bank_account_source_ids = fields.One2many( + "bank.account.source", + "company_id", + string="Bank Account Sources", + ) diff --git a/account_move_partner_bank/models/res_partner.py b/account_move_partner_bank/models/res_partner.py new file mode 100644 index 00000000..0f8f29fc --- /dev/null +++ b/account_move_partner_bank/models/res_partner.py @@ -0,0 +1,28 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ResPartner(models.Model): + _name = "res.partner" + _inherit = ["res.partner", "bank.account.mixin"] + + bank_account_id = fields.Many2one( + company_dependent=True, + help="Select a bank account of the company's partner, or the current company's " + "partner if no company is set.", + ) + + @api.depends_context("company") + @api.depends("company_id") + def _compute_bank_account_id_domain(self): + for partner in self: + if partner.company_id: + partner.bank_account_id_domain = [ + ("partner_id", "=", partner.company_id.partner_id.id) + ] + else: + partner.bank_account_id_domain = [ + ("partner_id", "=", self.env.company.partner_id.id) + ] diff --git a/account_move_partner_bank/pyproject.toml b/account_move_partner_bank/pyproject.toml new file mode 100644 index 00000000..4231d0cc --- /dev/null +++ b/account_move_partner_bank/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_move_partner_bank/readme/CONFIGURE.md b/account_move_partner_bank/readme/CONFIGURE.md new file mode 100644 index 00000000..9a9b3f46 --- /dev/null +++ b/account_move_partner_bank/readme/CONFIGURE.md @@ -0,0 +1,28 @@ +To set up a bank account for a partner: + +- Go to the partner record. +- Under the Invoicing/Accounting tab, set the Recipient Bank field. + If the partner has a company set, you can only select a bank account + linked to that company’s partner. If the partner has no company set, + you can only select a bank account linked to the current company’s + partner. This is a company-dependent field. + +To set up a bank account for a sales team: + +- Go to Sales > Configuration > Sales Teams. +- Select a team and set the Recipient Bank field. You can only choose a bank account + linked to the company's partner (i.e., one of the company’s own bank accounts). + +To use bank accounts in invoices: + +- Go to Settings → Companies. +- Open a company record. +- In the Bank Account Sources tab, create one or more records. + - Source Model: Select the model from which the bank field path is resolved + (e.g., Account Move). + - Bank Field Path: Enter the dot-path from the source model + to a bank account (res.partner.bank), for example + partner_id.bank_account_id or team_id.bank_account_id. + +The bank account from the record with the highest priority (lowest sequence number) will be used first +when assigning the bank on invoices. If no value is found, the system proceeds to the next record, and so on. diff --git a/account_move_partner_bank/readme/CONTRIBUTORS.md b/account_move_partner_bank/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..5c1d25fa --- /dev/null +++ b/account_move_partner_bank/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +* `Quartile `__: + + * Aung Ko Ko Lin + * Yoshi Tashiro diff --git a/account_move_partner_bank/readme/DESCRIPTION.md b/account_move_partner_bank/readme/DESCRIPTION.md new file mode 100644 index 00000000..18f8d837 --- /dev/null +++ b/account_move_partner_bank/readme/DESCRIPTION.md @@ -0,0 +1,11 @@ +This module adds a bank account field to partners and sets it +as the Recipient Bank on account moves based on the configuration of the +invoice's company. + +The bank source configuration supports multiple source models, allowing the +same logic to be reused for other models (e.g., sale.order) by calling +`bank_account_source_ids.get_bank_for_record(record)`. + +Note: If you want to add a bank account field to other models related to account +moves, you can extend the `bank.account.mixin` in a new module and simply add +the bank account field to the views. diff --git a/account_move_partner_bank/security/ir.model.access.csv b/account_move_partner_bank/security/ir.model.access.csv new file mode 100644 index 00000000..d06844bc --- /dev/null +++ b/account_move_partner_bank/security/ir.model.access.csv @@ -0,0 +1,5 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_bank_account_source_public,bank.account.source,model_bank_account_source,base.group_public,1,0,0,0 +access_bank_account_source_portal,bank.account.source,model_bank_account_source,base.group_portal,1,0,0,0 +access_bank_account_source_user,bank.account.source,model_bank_account_source,base.group_user,1,0,0,0 +access_bank_account_source_manager,bank.account.source,model_bank_account_source,base.group_system,1,1,1,1 diff --git a/account_move_partner_bank/static/description/index.html b/account_move_partner_bank/static/description/index.html new file mode 100644 index 00000000..f330f9d0 --- /dev/null +++ b/account_move_partner_bank/static/description/index.html @@ -0,0 +1,470 @@ + + + + + +Account Move Partner Bank + + + +
+

Account Move Partner Bank

+ + +

Beta License: AGPL-3 OCA/account-invoicing Translate me on Weblate Try me on Runboat

+

This module adds a bank account field to partners and sets it as the +Recipient Bank on account moves based on the configuration of the +invoice’s company.

+

The bank source configuration supports multiple source models, allowing +the same logic to be reused for other models (e.g., sale.order) by +calling bank_account_source_ids.get_bank_for_record(record).

+

Note: If you want to add a bank account field to other models related to +account moves, you can extend the bank.account.mixin in a new module +and simply add the bank account field to the views.

+

Table of contents

+ +
+

Configuration

+

To set up a bank account for a partner:

+
    +
  • Go to the partner record.
  • +
  • Under the Invoicing/Accounting tab, set the Recipient Bank field. If +the partner has a company set, you can only select a bank account +linked to that company’s partner. If the partner has no company set, +you can only select a bank account linked to the current company’s +partner. This is a company-dependent field.
  • +
+

To set up a bank account for a sales team:

+
    +
  • Go to Sales > Configuration > Sales Teams.
  • +
  • Select a team and set the Recipient Bank field. You can only choose a +bank account linked to the company’s partner (i.e., one of the +company’s own bank accounts).
  • +
+

To use bank accounts in invoices:

+
    +
  • Go to Settings → Companies.
  • +
  • Open a company record.
  • +
  • In the Bank Account Sources tab, create one or more records.
      +
    • Source Model: Select the model from which the bank field path is +resolved (e.g., Account Move).
    • +
    • Bank Field Path: Enter the dot-path from the source model to a +bank account (res.partner.bank), for example +partner_id.bank_account_id or team_id.bank_account_id.
    • +
    +
  • +
+

The bank account from the record with the highest priority (lowest +sequence number) will be used first when assigning the bank on invoices. +If no value is found, the system proceeds to the next record, and so on.

+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Quartile
  • +
+
+
+

Contributors

+
    +
  • Quartile <https://www.quartile.co>__:
      +
    • Aung Ko Ko Lin
    • +
    • Yoshi Tashiro
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

Current maintainers:

+

yostashiro aungkokolin1997

+

This module is part of the OCA/account-invoicing project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_move_partner_bank/tests/__init__.py b/account_move_partner_bank/tests/__init__.py new file mode 100644 index 00000000..fd85f46a --- /dev/null +++ b/account_move_partner_bank/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_move_partner_bank diff --git a/account_move_partner_bank/tests/test_account_move_partner_bank.py b/account_move_partner_bank/tests/test_account_move_partner_bank.py new file mode 100644 index 00000000..f765a681 --- /dev/null +++ b/account_move_partner_bank/tests/test_account_move_partner_bank.py @@ -0,0 +1,68 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.exceptions import ValidationError +from odoo.tests.common import TransactionCase + + +class TestAccountPartnerBank(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.company = cls.env.ref("base.main_company") + # Remove existing bank accounts from demo data + cls.env["res.partner.bank"].search( + [("partner_id", "=", cls.company.partner_id.id)] + ).unlink() + cls.bank_account_1 = cls.env["res.partner.bank"].create( + { + "acc_number": "11110000", + "partner_id": cls.company.partner_id.id, + "company_id": cls.company.id, + "sequence": 10, + } + ) + cls.bank_account_2 = cls.env["res.partner.bank"].create( + { + "acc_number": "22220000", + "partner_id": cls.company.partner_id.id, + "company_id": cls.company.id, + "sequence": 20, + } + ) + cls.partner = cls.env["res.partner"].create({"name": "Test Partner"}) + account_move_model = cls.env.ref("account.model_account_move") + cls.source = cls.env["bank.account.source"].create( + { + "company_id": cls.company.id, + "sequence": 10, + "source_model_id": account_move_model.id, + "bank_field_path": "partner_id.bank_account_id", + } + ) + + def create_invoice(self, partner): + return self.env["account.move"].create( + {"move_type": "out_invoice", "partner_id": partner.id} + ) + + def test_bank_field_path_constraint(self): + # A random string + with self.assertRaises(ValidationError): + self.source.write({"bank_field_path": "test"}) + # Not a real field + with self.assertRaises(ValidationError): + self.source.write({"bank_field_path": "partner_id.bank_account"}) + # A real field but not many2one to res.partner.bank + with self.assertRaises(ValidationError): + self.source.write({"bank_field_path": "partner_id.country_id"}) + self.source.write({"bank_field_path": "commercial_partner_id.bank_account_id"}) + + def test_account_move_partner_bank(self): + # Odoo's default proposes bank_account_1 (lower sequence) + move = self.create_invoice(self.partner) + self.assertEqual(move.partner_bank_id, self.bank_account_1) + # Assigning bank_account_id to partner supersedes Odoo's default + self.partner.bank_account_id = self.bank_account_2 + move = self.create_invoice(self.partner) + self.assertEqual(move.partner_bank_id, self.bank_account_2) diff --git a/account_move_partner_bank/views/res_company_views.xml b/account_move_partner_bank/views/res_company_views.xml new file mode 100644 index 00000000..4c89f190 --- /dev/null +++ b/account_move_partner_bank/views/res_company_views.xml @@ -0,0 +1,26 @@ + + + + res.company.form + res.company + + + + + + + + + + + + + + + + + + diff --git a/account_move_partner_bank/views/res_partner_views.xml b/account_move_partner_bank/views/res_partner_views.xml new file mode 100644 index 00000000..018d0a17 --- /dev/null +++ b/account_move_partner_bank/views/res_partner_views.xml @@ -0,0 +1,13 @@ + + + + res.partner.property.form.inherit + res.partner + + + + + + + +