diff --git a/account_invoice_section_sale_order/__manifest__.py b/account_invoice_section_sale_order/__manifest__.py index beb125bd37c..4e8d2e9829c 100644 --- a/account_invoice_section_sale_order/__manifest__.py +++ b/account_invoice_section_sale_order/__manifest__.py @@ -10,4 +10,7 @@ "license": "AGPL-3", "category": "Accounting & Finance", "depends": ["account", "sale"], + "data": [ + "views/res_config_settings.xml" + ], } diff --git a/account_invoice_section_sale_order/models/__init__.py b/account_invoice_section_sale_order/models/__init__.py index 6aacb753131..9359829439e 100644 --- a/account_invoice_section_sale_order/models/__init__.py +++ b/account_invoice_section_sale_order/models/__init__.py @@ -1 +1,3 @@ from . import sale_order +from . import res_config_settings +from . import res_company diff --git a/account_invoice_section_sale_order/models/res_company.py b/account_invoice_section_sale_order/models/res_company.py new file mode 100644 index 00000000000..9076350b022 --- /dev/null +++ b/account_invoice_section_sale_order/models/res_company.py @@ -0,0 +1,12 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + always_create_invoice_section = fields.Boolean( + help="Defines when to create sections", + default=False, + ) diff --git a/account_invoice_section_sale_order/models/res_config_settings.py b/account_invoice_section_sale_order/models/res_config_settings.py new file mode 100644 index 00000000000..36f393d676d --- /dev/null +++ b/account_invoice_section_sale_order/models/res_config_settings.py @@ -0,0 +1,12 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + always_create_invoice_section = fields.Boolean( + related="company_id.always_create_invoice_section", + readonly=False, + ) diff --git a/account_invoice_section_sale_order/models/sale_order.py b/account_invoice_section_sale_order/models/sale_order.py index fdf55d0bc01..1a78fa8834d 100644 --- a/account_invoice_section_sale_order/models/sale_order.py +++ b/account_invoice_section_sale_order/models/sale_order.py @@ -16,7 +16,13 @@ def _create_invoices(self, grouped=False, final=False, date=None): """ invoice_ids = super()._create_invoices(grouped=grouped, final=final) for invoice in invoice_ids: - if len(invoice.line_ids.mapped("sale_line_ids.order_id.id")) == 1: + if ( + not invoice.company_id.always_create_invoice_section + and len( + invoice.line_ids.mapped(invoice.line_ids._get_section_grouping()) + ) + == 1 + ): continue so = None sequence = 10 diff --git a/account_invoice_section_sale_order/views/res_config_settings.xml b/account_invoice_section_sale_order/views/res_config_settings.xml new file mode 100644 index 00000000000..6f8bc50c5d9 --- /dev/null +++ b/account_invoice_section_sale_order/views/res_config_settings.xml @@ -0,0 +1,27 @@ + + + + res.config.settings.view.form.inherit.account + res.config.settings + + + + + +
+
+
+
+
+
+