diff --git a/sale_stock_analytic/README.rst b/sale_stock_analytic/README.rst new file mode 100644 index 0000000000..0c8d068f7b --- /dev/null +++ b/sale_stock_analytic/README.rst @@ -0,0 +1,63 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +=================== +Sale Stock Analytic +=================== + +Copies the analytic account of the sale order and the analytic tags of the sale order line to the stock move + +Usage +===== + +To use this module, you need to: + +#. Go to your sale order +#. Set values for analytic tags on your sale order lines +#. Set value for analytic account on your sale order +#. Confirm sale order +#. ... and you should have your analytic account and analytic tags on your stock moves + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/87/13.0 + +.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt +.. branch is "8.0" for example + +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 smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Benoit Aimont + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/sale_stock_analytic/__init__.py b/sale_stock_analytic/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/sale_stock_analytic/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_stock_analytic/__manifest__.py b/sale_stock_analytic/__manifest__.py new file mode 100644 index 0000000000..38e38b5f0a --- /dev/null +++ b/sale_stock_analytic/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Sale Stock Analytic", + "summary": """ + Copies the analytic account of the sale order and the analytic tags + of the sale order line to the stock move""", + "version": "13.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/account-analytic", + "depends": ["sale", "stock_analytic"], +} diff --git a/sale_stock_analytic/models/__init__.py b/sale_stock_analytic/models/__init__.py new file mode 100644 index 0000000000..55eae1720e --- /dev/null +++ b/sale_stock_analytic/models/__init__.py @@ -0,0 +1 @@ +from . import stock_rule diff --git a/sale_stock_analytic/models/stock_rule.py b/sale_stock_analytic/models/stock_rule.py new file mode 100644 index 0000000000..9f560dbc90 --- /dev/null +++ b/sale_stock_analytic/models/stock_rule.py @@ -0,0 +1,42 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class StockRule(models.Model): + + _inherit = "stock.rule" + + def _get_stock_move_values( + self, + product_id, + product_qty, + product_uom, + location_id, + name, + origin, + company_id, + values, + ): + move_values = super(StockRule, self)._get_stock_move_values( + product_id, + product_qty, + product_uom, + location_id, + name, + origin, + company_id, + values, + ) + sol_id = move_values.get("sale_line_id", False) + if sol_id: + sol_model = self.env["sale.order.line"] + sol = sol_model.browse(sol_id) + analytic_tags = sol.analytic_tag_ids + analytic_account = sol.order_id.analytic_account_id + if analytic_tags: + move_values.update({"analytic_tag_ids": [(6, 0, analytic_tags.ids)]}) + if analytic_account: + move_values.update({"analytic_account_id": analytic_account.id}) + return move_values diff --git a/sale_stock_analytic/static/description/icon.png b/sale_stock_analytic/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/sale_stock_analytic/static/description/icon.png differ diff --git a/sale_stock_analytic/tests/__init__.py b/sale_stock_analytic/tests/__init__.py new file mode 100644 index 0000000000..68f033e5f1 --- /dev/null +++ b/sale_stock_analytic/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_stock_analytic diff --git a/sale_stock_analytic/tests/test_sale_stock_analytic.py b/sale_stock_analytic/tests/test_sale_stock_analytic.py new file mode 100644 index 0000000000..83ad67ecb8 --- /dev/null +++ b/sale_stock_analytic/tests/test_sale_stock_analytic.py @@ -0,0 +1,47 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import SavepointCase + + +class TestSaleStockAnalytic(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.sale_order_model = cls.env["sale.order"] + cls.sale_order_line_model = cls.env["sale.order.line"] + cls.analytic_tag_model = cls.env["account.analytic.tag"] + cls.product_model = cls.env["product.product"] + cls.res_partner_model = cls.env["res.partner"] + + cls.analytic_tag_1 = cls.analytic_tag_model.create({"name": "Tag test 1"}) + cls.analytic_tag_2 = cls.analytic_tag_model.create({"name": "Tag test 2"}) + cls.partner = cls.res_partner_model.create({"name": "Partner test"}) + cls.product = cls.product_model.create({"name": "Product test"}) + cls.analytic_account = cls.env.ref("analytic.analytic_agrolait") + + cls.sale_order = cls.sale_order_model.create( + { + "partner_id": cls.partner.id, + "analytic_account_id": cls.analytic_account.id, + } + ) + cls.sale_order_line = cls.sale_order_line_model.create( + { + "name": "sale order line test", + "order_id": cls.sale_order.id, + "product_id": cls.product.id, + "analytic_tag_ids": [ + (6, 0, [cls.analytic_tag_1.id, cls.analytic_tag_2.id]) + ], + } + ) + + def test_sale_stock_analytic(self): + self.sale_order.action_confirm() + self.move = self.sale_order.picking_ids.move_ids_without_package + self.assertEqual(self.move.analytic_account_id, self.analytic_account) + self.assertEqual( + self.move.analytic_tag_ids.ids, + [self.analytic_tag_1.id, self.analytic_tag_2.id], + ) diff --git a/setup/sale_stock_analytic/.eggs/README.txt b/setup/sale_stock_analytic/.eggs/README.txt new file mode 100644 index 0000000000..5d01668824 --- /dev/null +++ b/setup/sale_stock_analytic/.eggs/README.txt @@ -0,0 +1,6 @@ +This directory contains eggs that were downloaded by setuptools to build, test, and run plug-ins. + +This directory caches those eggs to prevent repeated downloads. + +However, it is safe to delete this directory. + diff --git a/setup/sale_stock_analytic/odoo/addons/sale_stock_analytic b/setup/sale_stock_analytic/odoo/addons/sale_stock_analytic new file mode 120000 index 0000000000..8779d6c330 --- /dev/null +++ b/setup/sale_stock_analytic/odoo/addons/sale_stock_analytic @@ -0,0 +1 @@ +../../../../sale_stock_analytic \ No newline at end of file diff --git a/setup/sale_stock_analytic/setup.py b/setup/sale_stock_analytic/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/sale_stock_analytic/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)