From d289db5c0edd6b4c0ac72f0160c525cf5f1769de Mon Sep 17 00:00:00 2001 From: nobuQuartile Date: Fri, 31 Jul 2026 06:52:25 +0000 Subject: [PATCH 1/2] [7070][IMP] account_move_partner_bank --- account_move_partner_bank/README.rst | 25 +++++- account_move_partner_bank/i18n/ja.po | 20 ++--- .../models/bank_account_source.py | 4 + .../models/res_partner.py | 6 +- account_move_partner_bank/readme/CONFIGURE.md | 12 +++ .../static/description/index.html | 62 ++++++++----- .../tests/test_account_move_partner_bank.py | 88 ++++++++++++++++++- .../views/res_company_views.xml | 2 +- .../views/res_partner_views.xml | 12 +++ 9 files changed, 185 insertions(+), 46 deletions(-) diff --git a/account_move_partner_bank/README.rst b/account_move_partner_bank/README.rst index 7bbeffa3..ef1e458c 100644 --- a/account_move_partner_bank/README.rst +++ b/account_move_partner_bank/README.rst @@ -1,3 +1,7 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + ========================= Account Move Partner Bank ========================= @@ -7,13 +11,13 @@ Account Move Partner Bank !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:b0bbc6bb7b42a01fe927641c8dbfcbb8c0209dbd04a2cbf9176a5a4d32e4dcce + !! source digest: sha256:1533c70efdef6a414cea12989514e398be6037cea7a1c4fe8ed615f052a1a137 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |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 +.. |badge2| image:: https://img.shields.io/badge/license-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 @@ -55,7 +59,13 @@ To set up a bank account for a partner: 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. + partner. This is a company-dependent field. As with the other partner + accounting settings, the field is normally set on the commercial + entity, and it applies to all of its child contacts. A child contact + can still be given its own bank account (e.g. a branch that collects + on a different account than its head office): set the field on the + contact itself, and leave it empty to keep using the bank account of + the commercial entity. To set up a bank account for a sales team: @@ -74,12 +84,19 @@ To use bank accounts in invoices: 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. + commercial_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. +Use commercial_partner_id.bank_account_id (instead of +partner_id.bank_account_id) to resolve the partner's bank account from +its commercial entity, so that the invoices of the child contacts of a +company also get the bank account set on that company. To let a child +contact take precedence with its own bank account, add +partner_id.bank_account_id as a source with a lower sequence number. + Bug Tracker =========== diff --git a/account_move_partner_bank/i18n/ja.po b/account_move_partner_bank/i18n/ja.po index 75ab92a3..afe17e73 100644 --- a/account_move_partner_bank/i18n/ja.po +++ b/account_move_partner_bank/i18n/ja.po @@ -57,6 +57,11 @@ msgstr "作成者" msgid "Created on" msgstr "作成日" +#. module: account_move_partner_bank +#: model_terms:ir.ui.view,arch_db:account_move_partner_bank.view_partner_property_form +msgid "Customer Invoices" +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" @@ -67,6 +72,11 @@ msgstr "表示名" 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_terms:ir.ui.view,arch_db:account_move_partner_bank.view_partner_property_form +msgid "From the parent company" +msgstr "親会社から取得" + #. module: account_move_partner_bank #: model:ir.model.fields,field_description:account_move_partner_bank.field_bank_account_source__id msgid "ID" @@ -117,16 +127,6 @@ msgstr "銀行口座提案元" 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" diff --git a/account_move_partner_bank/models/bank_account_source.py b/account_move_partner_bank/models/bank_account_source.py index 2c1fd0f6..a166057b 100644 --- a/account_move_partner_bank/models/bank_account_source.py +++ b/account_move_partner_bank/models/bank_account_source.py @@ -55,6 +55,10 @@ def _check_bank_field_path(self): def get_bank_for_record(self, record): """Find bank from sources for the given record.""" record.ensure_one() + if "company_id" in record._fields and record.company_id: + # The bank account fields in the path may be company-dependent (as on + # res.partner), so resolve them in the company of the record. + record = record.with_company(record.company_id) 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 diff --git a/account_move_partner_bank/models/res_partner.py b/account_move_partner_bank/models/res_partner.py index 0f8f29fc..ee226817 100644 --- a/account_move_partner_bank/models/res_partner.py +++ b/account_move_partner_bank/models/res_partner.py @@ -8,11 +8,7 @@ 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.", - ) + bank_account_id = fields.Many2one(company_dependent=True) @api.depends_context("company") @api.depends("company_id") diff --git a/account_move_partner_bank/readme/CONFIGURE.md b/account_move_partner_bank/readme/CONFIGURE.md index 9a9b3f46..1503159e 100644 --- a/account_move_partner_bank/readme/CONFIGURE.md +++ b/account_move_partner_bank/readme/CONFIGURE.md @@ -6,6 +6,11 @@ To set up a bank account for a partner: 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. + The field can be set on a child contact as well, so that a contact can be + invoiced with a bank account of its own (e.g. a branch that collects on a + different account than its head office). Whether the bank account of the parent + company applies to its child contacts depends on the bank account sources + configured below. To set up a bank account for a sales team: @@ -26,3 +31,10 @@ To use bank accounts in invoices: 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. + +Sources can therefore be combined to let the bank account of a company apply to the +invoices of its child contacts, while a contact that has its own bank account still +takes precedence. To do so, configure the following two sources on Account Move: + +- partner_id.bank_account_id, with the lower sequence number. +- commercial_partner_id.bank_account_id, with the higher sequence number. diff --git a/account_move_partner_bank/static/description/index.html b/account_move_partner_bank/static/description/index.html index f330f9d0..fcb4db66 100644 --- a/account_move_partner_bank/static/description/index.html +++ b/account_move_partner_bank/static/description/index.html @@ -2,18 +2,18 @@ - -Account Move Partner Bank + +README.rst -
-

Account Move Partner Bank

+
+ +Odoo Community Association +
+

Account Move Partner Bank

-

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

+

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.

@@ -381,18 +384,18 @@

Account Move Partner Bank

Table of contents

-

Configuration

+

Configuration

To set up a bank account for a partner:

  • Go to the partner record.
  • @@ -400,7 +403,13 @@

    Configuration

    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. +partner. This is a company-dependent field. As with the other partner +accounting settings, the field is normally set on the commercial +entity, and it applies to all of its child contacts. A child contact +can still be given its own bank account (e.g. a branch that collects +on a different account than its head office): set the field on the +contact itself, and leave it empty to keep using the bank account of +the commercial entity.

To set up a bank account for a sales team:

    @@ -418,16 +427,22 @@

    Configuration

    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.
  • +commercial_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.

+

Use commercial_partner_id.bank_account_id (instead of +partner_id.bank_account_id) to resolve the partner’s bank account from +its commercial entity, so that the invoices of the child contacts of a +company also get the bank account set on that company. To let a child +contact take precedence with its own bank account, add +partner_id.bank_account_id as a source with a lower sequence number.

-

Bug Tracker

+

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 @@ -435,15 +450,15 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

  • Quartile
-

Contributors

+

Contributors

  • Quartile <https://www.quartile.co>__:
-

Maintainers

+

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

+

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/test_account_move_partner_bank.py b/account_move_partner_bank/tests/test_account_move_partner_bank.py index f765a681..ff3f0dcb 100644 --- a/account_move_partner_bank/tests/test_account_move_partner_bank.py +++ b/account_move_partner_bank/tests/test_account_move_partner_bank.py @@ -30,13 +30,32 @@ def setUpClass(cls): "sequence": 20, } ) + cls.bank_account_3 = cls.env["res.partner.bank"].create( + { + "acc_number": "33330000", + "partner_id": cls.company.partner_id.id, + "company_id": cls.company.id, + "sequence": 30, + } + ) cls.partner = cls.env["res.partner"].create({"name": "Test Partner"}) - account_move_model = cls.env.ref("account.model_account_move") + cls.account_move_model = cls.env.ref("account.model_account_move") cls.source = cls.env["bank.account.source"].create( { "company_id": cls.company.id, + "sequence": 20, + "source_model_id": cls.account_move_model.id, + "bank_field_path": "commercial_partner_id.bank_account_id", + } + ) + + def create_contact_source(self): + """Let the contact's own bank account take precedence.""" + return self.env["bank.account.source"].create( + { + "company_id": self.company.id, "sequence": 10, - "source_model_id": account_move_model.id, + "source_model_id": self.account_move_model.id, "bank_field_path": "partner_id.bank_account_id", } ) @@ -56,7 +75,7 @@ def test_bank_field_path_constraint(self): # 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"}) + self.source.write({"bank_field_path": "partner_id.bank_account_id"}) def test_account_move_partner_bank(self): # Odoo's default proposes bank_account_1 (lower sequence) @@ -66,3 +85,66 @@ def test_account_move_partner_bank(self): 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) + + def test_bank_account_from_commercial_entity(self): + # The bank account of the commercial entity applies to its contacts, without + # being copied to them + self.partner.bank_account_id = self.bank_account_2 + contact = self.env["res.partner"].create( + {"name": "Test Contact", "parent_id": self.partner.id} + ) + self.assertFalse(contact.bank_account_id) + move = self.create_invoice(contact) + self.assertEqual(move.partner_bank_id, self.bank_account_2) + # An update on the commercial entity applies to the contacts as well + self.partner.bank_account_id = self.bank_account_1 + move = self.create_invoice(contact) + self.assertEqual(move.partner_bank_id, self.bank_account_1) + + def test_bank_account_contact_override(self): + # A contact can collect on its own bank account (e.g. a branch), while the + # other contacts of the company keep using the one of the commercial entity + self.create_contact_source() + self.partner.bank_account_id = self.bank_account_2 + branch, other_contact = self.env["res.partner"].create( + [ + { + "name": "Test Branch", + "parent_id": self.partner.id, + "bank_account_id": self.bank_account_1.id, + }, + {"name": "Test Contact", "parent_id": self.partner.id}, + ] + ) + move = self.create_invoice(branch) + self.assertEqual(move.partner_bank_id, self.bank_account_1) + move = self.create_invoice(other_contact) + self.assertEqual(move.partner_bank_id, self.bank_account_2) + # An update on the commercial entity does not overwrite the branch + self.partner.bank_account_id = self.bank_account_3 + self.assertEqual(branch.bank_account_id, self.bank_account_1) + move = self.create_invoice(other_contact) + self.assertEqual(move.partner_bank_id, self.bank_account_3) + + def test_bank_account_child_company(self): + # A child company is its own commercial entity, so it keeps its bank account + self.partner.bank_account_id = self.bank_account_2 + child_company = self.env["res.partner"].create( + { + "name": "Test Child Company", + "parent_id": self.partner.id, + "is_company": True, + "bank_account_id": self.bank_account_1.id, + } + ) + move = self.create_invoice(child_company) + self.assertEqual(move.partner_bank_id, self.bank_account_1) + + def test_bank_account_company_dependent(self): + # The bank account is resolved in the company of the record, not in the one + # of the environment + other_company = self.env["res.company"].create({"name": "Test Company 2"}) + self.partner.bank_account_id = self.bank_account_2 + move = self.create_invoice(self.partner) + bank = self.source.get_bank_for_record(move.with_company(other_company)) + self.assertEqual(bank, 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 index 4c89f190..953fc16e 100644 --- a/account_move_partner_bank/views/res_company_views.xml +++ b/account_move_partner_bank/views/res_company_views.xml @@ -14,7 +14,7 @@ diff --git a/account_move_partner_bank/views/res_partner_views.xml b/account_move_partner_bank/views/res_partner_views.xml index 018d0a17..698b52e1 100644 --- a/account_move_partner_bank/views/res_partner_views.xml +++ b/account_move_partner_bank/views/res_partner_views.xml @@ -6,8 +6,20 @@ + + + + + + + From 232fa586eae87c67a5b83df4f8c285e88ca4800c Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Mon, 3 Aug 2026 06:56:51 +0000 Subject: [PATCH 2/2] upd readme --- account_move_partner_bank/README.rst | 35 ++++---- .../static/description/index.html | 83 ++++++++++--------- 2 files changed, 58 insertions(+), 60 deletions(-) diff --git a/account_move_partner_bank/README.rst b/account_move_partner_bank/README.rst index ef1e458c..e1e7d8e3 100644 --- a/account_move_partner_bank/README.rst +++ b/account_move_partner_bank/README.rst @@ -1,7 +1,3 @@ -.. image:: https://odoo-community.org/readme-banner-image - :target: https://odoo-community.org/get-involved?utm_source=readme - :alt: Odoo Community Association - ========================= Account Move Partner Bank ========================= @@ -17,7 +13,7 @@ Account Move Partner Bank .. |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/license-AGPL--3-blue.png +.. |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 @@ -59,13 +55,12 @@ To set up a bank account for a partner: 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. As with the other partner - accounting settings, the field is normally set on the commercial - entity, and it applies to all of its child contacts. A child contact - can still be given its own bank account (e.g. a branch that collects - on a different account than its head office): set the field on the - contact itself, and leave it empty to keep using the bank account of - the commercial entity. + partner. This is a company-dependent field. The field can be set on a + child contact as well, so that a contact can be invoiced with a bank + account of its own (e.g. a branch that collects on a different + account than its head office). Whether the bank account of the parent + company applies to its child contacts depends on the bank account + sources configured below. To set up a bank account for a sales team: @@ -84,18 +79,20 @@ To use bank accounts in invoices: 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 - commercial_partner_id.bank_account_id or team_id.bank_account_id. + 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. -Use commercial_partner_id.bank_account_id (instead of -partner_id.bank_account_id) to resolve the partner's bank account from -its commercial entity, so that the invoices of the child contacts of a -company also get the bank account set on that company. To let a child -contact take precedence with its own bank account, add -partner_id.bank_account_id as a source with a lower sequence number. +Sources can therefore be combined to let the bank account of a company +apply to the invoices of its child contacts, while a contact that has +its own bank account still takes precedence. To do so, configure the +following two sources on Account Move: + +- partner_id.bank_account_id, with the lower sequence number. +- commercial_partner_id.bank_account_id, with the higher sequence + number. Bug Tracker =========== diff --git a/account_move_partner_bank/static/description/index.html b/account_move_partner_bank/static/description/index.html index fcb4db66..dc9c4556 100644 --- a/account_move_partner_bank/static/description/index.html +++ b/account_move_partner_bank/static/description/index.html @@ -2,18 +2,19 @@ - -README.rst + +Account Move Partner Bank -
+
+

Account Move Partner Bank

- -Odoo Community Association -
-

Account Move Partner Bank

-

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

+

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.

@@ -384,18 +382,18 @@

Account Move Partner Bank

Table of contents

-

Configuration

+

Configuration

To set up a bank account for a partner:

  • Go to the partner record.
  • @@ -403,13 +401,12 @@

    Configuration

    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. As with the other partner -accounting settings, the field is normally set on the commercial -entity, and it applies to all of its child contacts. A child contact -can still be given its own bank account (e.g. a branch that collects -on a different account than its head office): set the field on the -contact itself, and leave it empty to keep using the bank account of -the commercial entity. +partner. This is a company-dependent field. The field can be set on a +child contact as well, so that a contact can be invoiced with a bank +account of its own (e.g. a branch that collects on a different +account than its head office). Whether the bank account of the parent +company applies to its child contacts depends on the bank account +sources configured below.

To set up a bank account for a sales team:

    @@ -427,22 +424,25 @@

    Configuration

    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 -commercial_partner_id.bank_account_id or team_id.bank_account_id.
  • +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.

-

Use commercial_partner_id.bank_account_id (instead of -partner_id.bank_account_id) to resolve the partner’s bank account from -its commercial entity, so that the invoices of the child contacts of a -company also get the bank account set on that company. To let a child -contact take precedence with its own bank account, add -partner_id.bank_account_id as a source with a lower sequence number.

+

Sources can therefore be combined to let the bank account of a company +apply to the invoices of its child contacts, while a contact that has +its own bank account still takes precedence. To do so, configure the +following two sources on Account Move:

+
    +
  • partner_id.bank_account_id, with the lower sequence number.
  • +
  • commercial_partner_id.bank_account_id, with the higher sequence +number.
  • +
-

Bug Tracker

+

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 @@ -450,15 +450,15 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

  • Quartile
-

Contributors

+

Contributors

  • Quartile <https://www.quartile.co>__:
-

Maintainers

+

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +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

+

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.

-