diff --git a/sale_invoice_disable_salesperson_autosubscribe/README.rst b/sale_invoice_disable_salesperson_autosubscribe/README.rst new file mode 100644 index 000000000000..93d3f8be848d --- /dev/null +++ b/sale_invoice_disable_salesperson_autosubscribe/README.rst @@ -0,0 +1,89 @@ +============================================== +Sale Invoice Disable Salesperson Autosubscribe +============================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:81dc1a25d85f4d98c4657553af4d3a606cb37afdc2daa19a336a8fac6f281f23 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/17.0/sale_invoice_disable_salesperson_autosubscribe + :alt: OCA/sale-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-workflow-17-0/sale-workflow-17-0-sale_invoice_disable_salesperson_autosubscribe + :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/sale-workflow&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module disables salesperson autosubscription when creating +invoices. + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +Just install + +Usage +===== + +Just install + +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 +------- + +* Sygel + +Contributors +------------ + +- Harald Panten +- Valentín Vinagre +- Roger Sans + +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. + +This module is part of the `OCA/sale-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_invoice_disable_salesperson_autosubscribe/__init__.py b/sale_invoice_disable_salesperson_autosubscribe/__init__.py new file mode 100644 index 000000000000..fabb87f218c2 --- /dev/null +++ b/sale_invoice_disable_salesperson_autosubscribe/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 Roger Sans +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/sale_invoice_disable_salesperson_autosubscribe/__manifest__.py b/sale_invoice_disable_salesperson_autosubscribe/__manifest__.py new file mode 100644 index 000000000000..c861e59a6bb5 --- /dev/null +++ b/sale_invoice_disable_salesperson_autosubscribe/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2024 Roger Sans +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Sale Invoice Disable Salesperson Autosubscribe", + "version": "17.0.1.0.0", + "author": "Sygel, Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Sales", + "summary": "This module disables salesperson autosubscription " + "when creating invoices.", + "website": "https://github.com/OCA/sale-workflow", + "depends": [ + "sale", + ], + "data": [], +} diff --git a/sale_invoice_disable_salesperson_autosubscribe/models/__init__.py b/sale_invoice_disable_salesperson_autosubscribe/models/__init__.py new file mode 100644 index 000000000000..8c76c4ea1cd8 --- /dev/null +++ b/sale_invoice_disable_salesperson_autosubscribe/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 Roger Sans +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import account_move diff --git a/sale_invoice_disable_salesperson_autosubscribe/models/account_move.py b/sale_invoice_disable_salesperson_autosubscribe/models/account_move.py new file mode 100644 index 000000000000..8f4114015db5 --- /dev/null +++ b/sale_invoice_disable_salesperson_autosubscribe/models/account_move.py @@ -0,0 +1,18 @@ +# Copyright 2024 Roger Sans +# 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.model_create_multi + def create(self, vals): + res = super().create(vals) + if self._context.get("active_model") == "sale.order" or not self._context.get( + "active_model" + ): + if res.user_id: + res.message_unsubscribe([res.user_id.partner_id.id]) + return res diff --git a/sale_invoice_disable_salesperson_autosubscribe/pyproject.toml b/sale_invoice_disable_salesperson_autosubscribe/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/sale_invoice_disable_salesperson_autosubscribe/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_invoice_disable_salesperson_autosubscribe/readme/CONTRIBUTORS.md b/sale_invoice_disable_salesperson_autosubscribe/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..26869bf09593 --- /dev/null +++ b/sale_invoice_disable_salesperson_autosubscribe/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- Harald Panten \<\> +- Valentín Vinagre \<\> +- Roger Sans \<\> diff --git a/sale_invoice_disable_salesperson_autosubscribe/readme/DESCRIPTION.md b/sale_invoice_disable_salesperson_autosubscribe/readme/DESCRIPTION.md new file mode 100644 index 000000000000..f3ea932005d0 --- /dev/null +++ b/sale_invoice_disable_salesperson_autosubscribe/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module disables salesperson autosubscription when creating invoices. diff --git a/sale_invoice_disable_salesperson_autosubscribe/readme/INSTALL.md b/sale_invoice_disable_salesperson_autosubscribe/readme/INSTALL.md new file mode 100644 index 000000000000..2bbf78d53e98 --- /dev/null +++ b/sale_invoice_disable_salesperson_autosubscribe/readme/INSTALL.md @@ -0,0 +1 @@ +Just install diff --git a/sale_invoice_disable_salesperson_autosubscribe/readme/USAGE.md b/sale_invoice_disable_salesperson_autosubscribe/readme/USAGE.md new file mode 100644 index 000000000000..2bbf78d53e98 --- /dev/null +++ b/sale_invoice_disable_salesperson_autosubscribe/readme/USAGE.md @@ -0,0 +1 @@ +Just install diff --git a/sale_invoice_disable_salesperson_autosubscribe/static/description/icon.png b/sale_invoice_disable_salesperson_autosubscribe/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/sale_invoice_disable_salesperson_autosubscribe/static/description/icon.png differ diff --git a/sale_invoice_disable_salesperson_autosubscribe/static/description/index.html b/sale_invoice_disable_salesperson_autosubscribe/static/description/index.html new file mode 100644 index 000000000000..c3b71ff769d0 --- /dev/null +++ b/sale_invoice_disable_salesperson_autosubscribe/static/description/index.html @@ -0,0 +1,436 @@ + + + + + +Sale Invoice Disable Salesperson Autosubscribe + + + +
+

Sale Invoice Disable Salesperson Autosubscribe

+ + +

Beta License: AGPL-3 OCA/sale-workflow Translate me on Weblate Try me on Runboat

+

This module disables salesperson autosubscription when creating +invoices.

+

Table of contents

+ +
+

Installation

+

Just install

+
+
+

Usage

+

Just install

+
+
+

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

+
    +
  • Sygel
  • +
+
+
+

Contributors

+ +
+
+

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.

+

This module is part of the OCA/sale-workflow project on GitHub.

+

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

+
+
+
+ + diff --git a/sale_invoice_disable_salesperson_autosubscribe/tests/__init__.py b/sale_invoice_disable_salesperson_autosubscribe/tests/__init__.py new file mode 100644 index 000000000000..6463f60fb5a1 --- /dev/null +++ b/sale_invoice_disable_salesperson_autosubscribe/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 Roger Sans +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_disable_autosubscribe diff --git a/sale_invoice_disable_salesperson_autosubscribe/tests/test_disable_autosubscribe.py b/sale_invoice_disable_salesperson_autosubscribe/tests/test_disable_autosubscribe.py new file mode 100644 index 000000000000..b3d3bd0fceab --- /dev/null +++ b/sale_invoice_disable_salesperson_autosubscribe/tests/test_disable_autosubscribe.py @@ -0,0 +1,98 @@ +# Copyright 2024 Roger Sans +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import logging + +from odoo import fields +from odoo.fields import Command +from odoo.tests import tagged + +from odoo.addons.sale.tests.common import TestSaleCommon + +_logger = logging.getLogger(__name__) + + +@tagged("-at_install", "post_install") +class TestDisableAutosubscribe(TestSaleCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.test_user = cls.env.ref("base.user_demo") + cls.test_company = cls.test_user.company_id + cls.test_partner = cls.env.ref("base.res_partner_1") + cls.test_product = cls.env.ref("product.consu_delivery_01") + + @classmethod + def _get_taxes(cls, descs): + taxes = cls.env["account.tax"] + for desc in descs.split(","): + parts = desc.split(".") + xml_id = parts[1] if len(parts) > 1 else parts[0] + if xml_id.lower() != xml_id and len(parts) == 1: + # shortcut for not changing existing tests with old codes + xml_id = "account_tax_template_" + xml_id.lower() + tax_id = cls.company._get_tax_id_from_xmlid(xml_id) + taxes |= cls.env["account.tax"].browse(tax_id) + if not tax_id: + _logger.error(f"Tax not found: {desc}") + return taxes + + def test_subscribed(self): + sale_order = self.env["sale.order"].create( + { + "partner_id": self.test_partner.id, + "user_id": self.test_user.id, + "order_line": [ + Command.create( + { + "product_id": self.test_product.id, + "product_uom_qty": 2, + "price_unit": 223.4, + } + ) + ], + } + ) + + context = { + "active_model": "sale.order", + "active_ids": [sale_order.id], + "active_id": sale_order.id, + "default_journal_id": self.company_data["default_journal_sale"].id, + "default_invoice_user_id": self.test_user.id, + } + + sale_order.action_confirm() + payment = ( + self.env["sale.advance.payment.inv"].with_context(**context).create({}) + ) + payment.create_invoices() + invoice = sale_order.invoice_ids[0] + actual_followers = invoice.message_follower_ids.ids + self.assertFalse(invoice.invoice_user_id.id in actual_followers) + + direct_invoice = self.env["account.move"].create( + [ + { + "move_type": "out_invoice", + "partner_id": self.test_partner.id, + "invoice_date": fields.Date.from_string("2016-01-01"), + "currency_id": self.currency_data["currency"].id, + "invoice_user_id": self.test_user.id, + "invoice_line_ids": [ + ( + 0, + None, + { + "product_id": self.test_product.id, + "quantity": 3, + "price_unit": 750, + }, + ), + ], + } + ] + ) + + direct_followers = invoice.message_follower_ids.ids + self.assertFalse(direct_invoice.invoice_user_id.id in direct_followers)