diff --git a/sale_analytic/README.rst b/sale_analytic/README.rst new file mode 100644 index 0000000000..40f06207df --- /dev/null +++ b/sale_analytic/README.rst @@ -0,0 +1,106 @@ +============= +Sale Analytic +============= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:95d633c8841b121283e33b43805969ea3564c8980b15ebf731ea9c651bf97c3d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Faccount--analytic-lightgray.png?logo=github + :target: https://github.com/OCA/account-analytic/tree/18.0/sale_analytic + :alt: OCA/account-analytic +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-analytic-18-0/account-analytic-18-0-sale_analytic + :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/account-analytic&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +The goal of this module is to ease analytic distribution management on +sale order. This module add analytic distribution on sale order. + +If all lines of the sale order have the same analytic distribution, the +analytic distribution on the sale order is automatically set with this +value. If a analytic distribution is set on the sale order, all lines of +the sale will take this value. + +**Table of contents** + +.. contents:: + :local: + +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 +------- + +* Exo Software +* Acsone SA/NV + +Contributors +------------ + +- Laetitia Gangloff +- Cédric Pigeon +- Pimolnat Suntian +- `Jarsa `__ + + - Alan Ramos + +- Lois Rilo +- `Quartile `__: + + - Aung Ko Ko Lin + +- `Exo Software `__: + + - André Leite + - Fábio Paiva + +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. + +.. |maintainer-andrel-exo| image:: https://github.com/andrel-exo.png?size=40px + :target: https://github.com/andrel-exo + :alt: andrel-exo + +Current `maintainer `__: + +|maintainer-andrel-exo| + +This module is part of the `OCA/account-analytic `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_analytic/__init__.py b/sale_analytic/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/sale_analytic/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_analytic/__manifest__.py b/sale_analytic/__manifest__.py new file mode 100644 index 0000000000..a835236098 --- /dev/null +++ b/sale_analytic/__manifest__.py @@ -0,0 +1,16 @@ +# © 2016 Laetitia Gangloff, Acsone SA/NV (http://www.acsone.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Sale Analytic", + "version": "18.0.1.0.0", + "author": "Exo Software, Acsone SA/NV, Odoo Community Association (OCA)", + "category": "Sale Management", + "website": "https://github.com/OCA/account-analytic", + "depends": ["sale", "base_view_inheritance_extension"], + "data": ["views/sale_order_views.xml"], + "license": "AGPL-3", + "installable": True, + "application": False, + "maintainers": ["andrel-exo"], +} diff --git a/sale_analytic/i18n/sale_analytic.pot b/sale_analytic/i18n/sale_analytic.pot new file mode 100644 index 0000000000..f7cc555b02 --- /dev/null +++ b/sale_analytic/i18n/sale_analytic.pot @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_analytic +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-08-29 08:21+0000\n" +"PO-Revision-Date: 2025-08-29 08:21+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: sale_analytic +#: model:ir.model.fields,field_description:sale_analytic.field_sale_order__analytic_distribution +msgid "Analytic Distribution" +msgstr "" + +#. module: sale_analytic +#: model:ir.model.fields,field_description:sale_analytic.field_sale_order__analytic_precision +msgid "Analytic Precision" +msgstr "" + +#. module: sale_analytic +#: model:ir.model.fields,field_description:sale_analytic.field_sale_order__distribution_analytic_account_ids +msgid "Distribution Analytic Account" +msgstr "" + +#. module: sale_analytic +#: model:ir.model,name:sale_analytic.model_sale_order +msgid "Sales Order" +msgstr "" diff --git a/sale_analytic/models/__init__.py b/sale_analytic/models/__init__.py new file mode 100644 index 0000000000..6aacb75313 --- /dev/null +++ b/sale_analytic/models/__init__.py @@ -0,0 +1 @@ +from . import sale_order diff --git a/sale_analytic/models/sale_order.py b/sale_analytic/models/sale_order.py new file mode 100644 index 0000000000..f80fc07eba --- /dev/null +++ b/sale_analytic/models/sale_order.py @@ -0,0 +1,37 @@ +from odoo import api, fields, models + + +class SaleOrder(models.Model): + _name = "sale.order" + _inherit = ["sale.order", "analytic.mixin"] + + analytic_distribution = fields.Json(inverse="_inverse_analytic_distribution") + + @api.depends("order_line.analytic_distribution") + def _compute_analytic_distribution(self): + """If all lines have the same analytic distribution, set it on the order. + + If no lines exist, respect the value given by the user. + """ + for so in self: + if so.order_line: + al = so.order_line[0].analytic_distribution or False + for ol in so.order_line: + if ol.analytic_distribution != al: + al = False + break + so.analytic_distribution = al + + def _inverse_analytic_distribution(self): + """When setting the analytic distribution`, apply it to all order lines.""" + for so in self: + if so.analytic_distribution: + so.order_line.write({"analytic_distribution": so.analytic_distribution}) + + @api.onchange("analytic_distribution") + def _onchange_analytic_distribution(self): + """When changing the analytic distribution, apply it to all order lines.""" + if self.analytic_distribution: + self.order_line.update( + {"analytic_distribution": self.analytic_distribution} + ) diff --git a/sale_analytic/pyproject.toml b/sale_analytic/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/sale_analytic/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_analytic/readme/CONTRIBUTORS.md b/sale_analytic/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..41ae6bf4cc --- /dev/null +++ b/sale_analytic/readme/CONTRIBUTORS.md @@ -0,0 +1,11 @@ +- Laetitia Gangloff \<\> +- Cédric Pigeon \<\> +- Pimolnat Suntian \<\> +- [Jarsa](https://www.jarsa.com) + - Alan Ramos +- Lois Rilo \<\> +- [Quartile](https://www.quartile.co): + - Aung Ko Ko Lin +- [Exo Software](https://www.exosoftware.pt): + - André Leite \<\> + - Fábio Paiva \<\> diff --git a/sale_analytic/readme/DESCRIPTION.md b/sale_analytic/readme/DESCRIPTION.md new file mode 100644 index 0000000000..262f15eed6 --- /dev/null +++ b/sale_analytic/readme/DESCRIPTION.md @@ -0,0 +1,7 @@ +The goal of this module is to ease analytic distribution management on +sale order. This module add analytic distribution on sale order. + +If all lines of the sale order have the same analytic distribution, +the analytic distribution on the sale order is automatically set +with this value. If a analytic distribution is set on the sale +order, all lines of the sale will take this value. diff --git a/sale_analytic/static/description/icon.png b/sale_analytic/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/sale_analytic/static/description/icon.png differ diff --git a/sale_analytic/static/description/index.html b/sale_analytic/static/description/index.html new file mode 100644 index 0000000000..f8bfab7f8d --- /dev/null +++ b/sale_analytic/static/description/index.html @@ -0,0 +1,447 @@ + + + + + +Sale Analytic + + + +
+

Sale Analytic

+ + +

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

+

The goal of this module is to ease analytic distribution management on +sale order. This module add analytic distribution on sale order.

+

If all lines of the sale order have the same analytic distribution, the +analytic distribution on the sale order is automatically set with this +value. If a analytic distribution is set on the sale order, all lines of +the sale will take this value.

+

Table of contents

+ +
+

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

+
    +
  • Exo Software
  • +
  • Acsone SA/NV
  • +
+
+
+

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.

+

Current maintainer:

+

andrel-exo

+

This module is part of the OCA/account-analytic project on GitHub.

+

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

+
+
+
+ + diff --git a/sale_analytic/tests/__init__.py b/sale_analytic/tests/__init__.py new file mode 100644 index 0000000000..a245d61dd9 --- /dev/null +++ b/sale_analytic/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_analytic diff --git a/sale_analytic/tests/test_sale_analytic.py b/sale_analytic/tests/test_sale_analytic.py new file mode 100644 index 0000000000..44d622a082 --- /dev/null +++ b/sale_analytic/tests/test_sale_analytic.py @@ -0,0 +1,95 @@ +# © 2016 Laetitia Gangloff, Acsone SA/NV (http://www.acsone.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +from odoo import Command +from odoo.tests import Form, TransactionCase + + +class TestSaleAnalytic(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env.user.groups_id |= cls.env.ref("analytic.group_analytic_accounting") + cls.partner = cls.env.ref("base.res_partner_12") + cls.product = cls.env.ref("product.product_product_9") + cls.uom = cls.env.ref("uom.product_uom_unit") + analytic_plan = cls.env["account.analytic.plan"].create({"name": "Plan Test"}) + analytic_account_manual = cls.env["account.analytic.account"].create( + {"name": "manual", "plan_id": analytic_plan.id} + ) + cls.analytic_distribution_manual = {str(analytic_account_manual.id): 100} + cls.analytic_distribution_manual2 = {str(analytic_account_manual.id): 50} + + def add_so_line(self, order, product=None): + if not product: + product = self.product + order.order_line = [ + Command.create( + { + "product_id": product.id, + } + ) + ] + + def test_analytic_distribution_with_create(self): + """Create a sale order (create) + Set analytic distribution on sale + Check analytic distribution and line is set + """ + so = self.env["sale.order"].create({"partner_id": self.partner.id}) + + # Test setting analytic distribution without order lines + so.analytic_distribution = self.analytic_distribution_manual + self.assertEqual(so.analytic_distribution, self.analytic_distribution_manual) + + # Test setting analytic distribution with an order line + self.add_so_line(so) + so.analytic_distribution = self.analytic_distribution_manual2 + self.assertEqual(so.analytic_distribution, self.analytic_distribution_manual2) + self.assertEqual( + so.order_line.analytic_distribution, self.analytic_distribution_manual2 + ) + + # Test clearing analytic distribution with an order line + so.analytic_distribution = False + self.assertEqual( + so.order_line.analytic_distribution, self.analytic_distribution_manual2 + ) + + def test_analytic_distribution_with_form(self): + """Create a sale order (form) + Set analytic distribution on sale + Check analytic distribution and line is set + """ + order = Form( + self.env["sale.order"].with_context(default_partner_id=self.partner.id) + ) + + # Test setting analytic distribution without order lines + order.analytic_distribution = self.analytic_distribution_manual + self.assertEqual(order.analytic_distribution, self.analytic_distribution_manual) + + # Test setting analytic distribution with an order line + order = order.save() + self.add_so_line(order) + with Form(order) as so: + so.analytic_distribution = self.analytic_distribution_manual2 + self.assertEqual( + so.analytic_distribution, self.analytic_distribution_manual2 + ) + self.assertEqual( + so.order_line._field_value.get_vals(order.order_line.id)[ + "analytic_distribution" + ], + self.analytic_distribution_manual2, + ) + + # Test clearing analytic distribution with an order line + so.analytic_distribution = False + self.assertEqual( + so.order_line._field_value.get_vals(order.order_line.id)[ + "analytic_distribution" + ], + self.analytic_distribution_manual2, + ) diff --git a/sale_analytic/views/sale_order_views.xml b/sale_analytic/views/sale_order_views.xml new file mode 100644 index 0000000000..cc6cfd3d89 --- /dev/null +++ b/sale_analytic/views/sale_order_views.xml @@ -0,0 +1,25 @@ + + + + sale.order.form (sale_analytic) + sale.order + + + + + + + + { + "default_analytic_distribution": analytic_distribution, + } + + + + +