Skip to content

Commit 0d7c7b8

Browse files
authored
[5614][ADD] account_move_order_partner (#80)
[5614][ADD] account_move_order_partner (#80)
1 parent 4e3b264 commit 0d7c7b8

22 files changed

Lines changed: 975 additions & 0 deletions
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
==========================
2+
Account Move Order Partner
3+
==========================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:4c8bc67b9ae34cc79ec93ccac1970fe0244fee5a288405a3f4cc964b08dd0c7e
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--invoicing-lightgray.png?logo=github
20+
:target: https://github.com/OCA/account-invoicing/tree/16.0/account_move_order_partner
21+
:alt: OCA/account-invoicing
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/account-invoicing-16-0/account-invoicing-16-0-account_move_order_partner
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-invoicing&target_branch=16.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
Adds the order partner (sold-to partner) to invoices and prints it on
32+
the report. If multiple partners are involved, the sale partner defaults
33+
to the invoice partner.
34+
35+
**Table of contents**
36+
37+
.. contents::
38+
:local:
39+
40+
Configuration
41+
=============
42+
43+
To make sure each invoice is linked to a single order partner:
44+
45+
1. Navigate to Sales ▸ Configuration ▸ Settings.
46+
2. Enable the option Group invoices by order partner.
47+
48+
When enabled, invoices will only be grouped if the order partner is the
49+
same across all sale orders. Even if the invoice partner is the same,
50+
sale orders with different order partners will result in separate
51+
invoices.
52+
53+
If you'd like to control the grouping behavior per invoice partner,
54+
consider disabling this configuration and installing the
55+
sale_order_invoicing_grouping_criteria module.
56+
57+
Bug Tracker
58+
===========
59+
60+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-invoicing/issues>`_.
61+
In case of trouble, please check there if your issue has already been reported.
62+
If you spotted it first, help us to smash it by providing a detailed and welcomed
63+
`feedback <https://github.com/OCA/account-invoicing/issues/new?body=module:%20account_move_order_partner%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
64+
65+
Do not contact contributors directly about support or help with technical issues.
66+
67+
Credits
68+
=======
69+
70+
Authors
71+
-------
72+
73+
* Quartile
74+
75+
Contributors
76+
------------
77+
78+
- Quartile <https://www.quartile.co>
79+
80+
- Aung Ko Ko Lin
81+
82+
Maintainers
83+
-----------
84+
85+
This module is maintained by the OCA.
86+
87+
.. image:: https://odoo-community.org/logo.png
88+
:alt: Odoo Community Association
89+
:target: https://odoo-community.org
90+
91+
OCA, or the Odoo Community Association, is a nonprofit organization whose
92+
mission is to support the collaborative development of Odoo features and
93+
promote its widespread use.
94+
95+
.. |maintainer-yostashiro| image:: https://github.com/yostashiro.png?size=40px
96+
:target: https://github.com/yostashiro
97+
:alt: yostashiro
98+
.. |maintainer-aungkokolin1997| image:: https://github.com/aungkokolin1997.png?size=40px
99+
:target: https://github.com/aungkokolin1997
100+
:alt: aungkokolin1997
101+
102+
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
103+
104+
|maintainer-yostashiro| |maintainer-aungkokolin1997|
105+
106+
This module is part of the `OCA/account-invoicing <https://github.com/OCA/account-invoicing/tree/16.0/account_move_order_partner>`_ project on GitHub.
107+
108+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import models
2+
from .hooks import pre_init_hook
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2025 Quartile (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
{
4+
"name": "Account Move Order Partner",
5+
"category": "Invoice",
6+
"version": "16.0.1.0.0",
7+
"author": "Quartile, Odoo Community Association (OCA)",
8+
"website": "https://github.com/OCA/account-invoicing",
9+
"license": "AGPL-3",
10+
"depends": ["sale"],
11+
"data": [
12+
"reports/report_invoice_document.xml",
13+
"views/account_move_views.xml",
14+
"views/res_config_settings_views.xml",
15+
],
16+
"pre_init_hook": "pre_init_hook",
17+
"maintainers": ["yostashiro", "aungkokolin1997"],
18+
"installable": True,
19+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2025 Quartile (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo.tools.sql import column_exists
5+
6+
7+
def pre_init_hook(cr):
8+
if not column_exists(cr, "account_move", "order_partner_id"):
9+
cr.execute(
10+
"""
11+
ALTER TABLE account_move
12+
ADD COLUMN order_partner_id INTEGER
13+
REFERENCES res_partner(id)
14+
ON DELETE SET NULL;
15+
"""
16+
)
17+
cr.execute(
18+
"""
19+
WITH spc AS (
20+
SELECT
21+
am.id AS move_id,
22+
COUNT(DISTINCT sol.order_partner_id) AS cnt,
23+
MIN(sol.order_partner_id) AS single_partner_id
24+
FROM account_move am
25+
LEFT JOIN account_move_line aml
26+
ON aml.move_id = am.id
27+
LEFT JOIN sale_order_line_invoice_rel rel
28+
ON rel.invoice_line_id = aml.id
29+
LEFT JOIN sale_order_line sol
30+
ON sol.id = rel.order_line_id
31+
WHERE am.move_type IN ('out_invoice', 'out_refund')
32+
GROUP BY am.id
33+
)
34+
UPDATE account_move am
35+
SET order_partner_id = CASE
36+
WHEN spc.cnt = 1 AND spc.single_partner_id IS NOT NULL
37+
THEN spc.single_partner_id
38+
ELSE am.partner_id
39+
END
40+
FROM spc
41+
WHERE am.id = spc.move_id
42+
AND am.move_type IN ('out_invoice', 'out_refund')
43+
AND am.order_partner_id IS NULL;
44+
"""
45+
)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * account_move_order_partner
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 16.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"POT-Creation-Date: 2026-01-16 06:59+0000\n"
10+
"PO-Revision-Date: 2026-01-16 06:59+0000\n"
11+
"Last-Translator: \n"
12+
"Language-Team: \n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: \n"
17+
18+
#. module: account_move_order_partner
19+
#: model_terms:ir.ui.view,arch_db:account_move_order_partner.report_invoice_order_partner
20+
msgid "<strong>Sold-to and Shipping Address:</strong>"
21+
msgstr "<strong>お取引先とお届け先:</strong>"
22+
23+
#. module: account_move_order_partner
24+
#: model_terms:ir.ui.view,arch_db:account_move_order_partner.report_invoice_order_partner
25+
msgid "<strong>Sold-to:</strong>"
26+
msgstr "<strong>お取引先:</strong>"
27+
28+
#. module: account_move_order_partner
29+
#: model:ir.model,name:account_move_order_partner.model_res_company
30+
msgid "Companies"
31+
msgstr "会社"
32+
33+
#. module: account_move_order_partner
34+
#: model:ir.model,name:account_move_order_partner.model_res_config_settings
35+
msgid "Config Settings"
36+
msgstr "コンフィグ設定"
37+
38+
#. module: account_move_order_partner
39+
#: model_terms:ir.ui.view,arch_db:account_move_order_partner.view_stock_config_settings
40+
msgid ""
41+
"Group invoices by order partner\n"
42+
" If enabled, invoices created from multiple sale orders will be grouped only\n"
43+
" when the sale partner is the same. Even if the invoice partner is the same,\n"
44+
" sale orders with different sale partners will generate separate invoices."
45+
msgstr ""
46+
"オーダ顧客ごとに請求書をグループ化\n"
47+
" 有効にすると、複数の販売オーダから作成される請求書は、販売連絡先が同一の場合のみグループ化されます。\n"
48+
" 請求連絡先が同一であっても、販売連絡先が異なる販売オーダは別々の請求書として作成されます。"
49+
50+
#. module: account_move_order_partner
51+
#: model:ir.model.fields,field_description:account_move_order_partner.field_res_company__invoice_group_by_order_partner
52+
#: model:ir.model.fields,field_description:account_move_order_partner.field_res_config_settings__invoice_group_by_order_partner
53+
msgid "Invoice Group By Order Partner"
54+
msgstr "オーダ顧客ごとに請求書をグループ化"
55+
56+
#. module: account_move_order_partner
57+
#: model:ir.model,name:account_move_order_partner.model_account_move
58+
msgid "Journal Entry"
59+
msgstr "仕訳"
60+
61+
#. module: account_move_order_partner
62+
#: model:ir.model,name:account_move_order_partner.model_sale_order
63+
msgid "Sales Order"
64+
msgstr "販売オーダ"
65+
66+
#. module: account_move_order_partner
67+
#: model_terms:ir.ui.view,arch_db:account_move_order_partner.view_account_invoice_filter_inherit
68+
#: model_terms:ir.ui.view,arch_db:account_move_order_partner.view_move_form_inherit
69+
msgid "Sold-to"
70+
msgstr "お取引先"
71+
72+
#. module: account_move_order_partner
73+
#: model:ir.model.fields,field_description:account_move_order_partner.field_account_bank_statement_line__order_partner_id
74+
#: model:ir.model.fields,field_description:account_move_order_partner.field_account_move__order_partner_id
75+
#: model:ir.model.fields,field_description:account_move_order_partner.field_account_payment__order_partner_id
76+
msgid "Sold-to Partner"
77+
msgstr "お取引先連絡先"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from . import account_move
2+
from . import res_company
3+
from . import res_config_settings
4+
from . import sale_order
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2025 Quartile (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, fields, models
5+
6+
7+
class AccountMove(models.Model):
8+
_inherit = "account.move"
9+
10+
order_partner_id = fields.Many2one(
11+
"res.partner",
12+
string="Sold-to Partner",
13+
compute="_compute_order_partner_id",
14+
store=True,
15+
)
16+
17+
@api.depends(
18+
"move_type", "partner_id", "invoice_line_ids.sale_line_ids.order_partner_id"
19+
)
20+
def _compute_order_partner_id(self):
21+
for move in self:
22+
move.order_partner_id = move.partner_id
23+
sale_partners = move.move_type in [
24+
"out_invoice",
25+
"out_refund",
26+
] and move.invoice_line_ids.mapped("sale_line_ids.order_partner_id")
27+
if sale_partners and len(sale_partners) == 1:
28+
move.order_partner_id = sale_partners.id
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2025 Quartile (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResCompany(models.Model):
8+
_inherit = "res.company"
9+
10+
invoice_group_by_order_partner = fields.Boolean()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2025 Quartile (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResConfigSettings(models.TransientModel):
8+
_inherit = "res.config.settings"
9+
10+
invoice_group_by_order_partner = fields.Boolean(
11+
related="company_id.invoice_group_by_order_partner", readonly=False
12+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2025 Quartile (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import models
5+
6+
7+
class SaleOrder(models.Model):
8+
_inherit = "sale.order"
9+
10+
def _prepare_invoice(self):
11+
vals = super()._prepare_invoice()
12+
# Set for use in _get_invoice_grouping_keys
13+
vals["order_partner_id"] = self.partner_id.id
14+
return vals
15+
16+
def _get_invoice_grouping_keys(self):
17+
keys = super()._get_invoice_grouping_keys()
18+
if self.env.company.invoice_group_by_order_partner:
19+
keys.append("order_partner_id")
20+
return keys

0 commit comments

Comments
 (0)