Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions account_move_partner_bank/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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
Expand Down Expand Up @@ -55,7 +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.
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:

Expand All @@ -80,6 +85,15 @@ 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.

Bug Tracker
===========

Expand Down
20 changes: 10 additions & 10 deletions account_move_partner_bank/i18n/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions account_move_partner_bank/models/bank_account_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions account_move_partner_bank/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 12 additions & 0 deletions account_move_partner_bank/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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.
29 changes: 23 additions & 6 deletions account_move_partner_bank/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -366,7 +367,7 @@ <h1 class="title">Account Move Partner Bank</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b0bbc6bb7b42a01fe927641c8dbfcbb8c0209dbd04a2cbf9176a5a4d32e4dcce
!! source digest: sha256:1533c70efdef6a414cea12989514e398be6037cea7a1c4fe8ed615f052a1a137
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/account-invoicing/tree/18.0/account_move_partner_bank"><img alt="OCA/account-invoicing" src="https://img.shields.io/badge/github-OCA%2Faccount--invoicing-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-invoicing-18-0/account-invoicing-18-0-account_move_partner_bank"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-invoicing&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds a bank account field to partners and sets it as the
Expand Down Expand Up @@ -400,7 +401,12 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
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.</li>
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.</li>
</ul>
<p>To set up a bank account for a sales team:</p>
<ul class="simple">
Expand All @@ -425,6 +431,15 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>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.</p>
<p>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:</p>
<ul class="simple">
<li>partner_id.bank_account_id, with the lower sequence number.</li>
<li>commercial_partner_id.bank_account_id, with the higher sequence
number.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
Expand Down Expand Up @@ -455,7 +470,9 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
Expand Down
88 changes: 85 additions & 3 deletions account_move_partner_bank/tests/test_account_move_partner_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
)
Expand All @@ -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)
Expand All @@ -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)
2 changes: 1 addition & 1 deletion account_move_partner_bank/views/res_company_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<field name="source_model_id" />
<field
name="bank_field_path"
placeholder="e.g. partner_id.bank_account_id"
placeholder="e.g. partner_id.commercial_partner_id.bank_account_id"
/>
</list>
</field>
Expand Down
12 changes: 12 additions & 0 deletions account_move_partner_bank/views/res_partner_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@
<field name="inherit_id" ref="account.view_partner_property_form" />
<field name="arch" type="xml">
<field name="invoice_sending_method" position="before">
<field name="bank_account_id_domain" invisible="1" />
<field name="bank_account_id" domain="bank_account_id_domain" />
</field>
<!-- A child contact can be given its own bank account, e.g. a branch that
collects on a different account than its head office. -->
<xpath expr="//page[@name='accounting_disabled']" position="inside">
<group name="bank_account" string="Customer Invoices">
<field
name="bank_account_id"
domain="bank_account_id_domain"
placeholder="From the parent company"
/>
</group>
</xpath>
</field>
</record>
</odoo>
Loading