diff --git a/purchase_stock_analytic/README.rst b/purchase_stock_analytic/README.rst new file mode 100644 index 0000000000..263a2692b8 --- /dev/null +++ b/purchase_stock_analytic/README.rst @@ -0,0 +1,62 @@ +.. 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 + +======================= +Purchase Stock Analytic +======================= + +Copies the analytic account of the purchase order item to the stock move + +Usage +===== + +To use this module, you need to: + +#. Create a purchase order +#. Set an analytic account and analytic tags on purchase order lines +#. Confirm purchase 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/purchase_stock_analytic/__init__.py b/purchase_stock_analytic/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/purchase_stock_analytic/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/purchase_stock_analytic/__manifest__.py b/purchase_stock_analytic/__manifest__.py new file mode 100644 index 0000000000..03c95a955f --- /dev/null +++ b/purchase_stock_analytic/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Purchase Stock Analytic", + "summary": """ + Copies the analytic account of the purchase order item to the stock move""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/account-analytic", + "depends": ["purchase_stock", "stock_analytic"], +} diff --git a/purchase_stock_analytic/i18n/purchase_stock_analytic.pot b/purchase_stock_analytic/i18n/purchase_stock_analytic.pot new file mode 100644 index 0000000000..dd4013e3f4 --- /dev/null +++ b/purchase_stock_analytic/i18n/purchase_stock_analytic.pot @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_stock_analytic +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \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: purchase_stock_analytic +#: model:ir.model.fields,field_description:purchase_stock_analytic.field_purchase_order_line__display_name +msgid "Display Name" +msgstr "" + +#. module: purchase_stock_analytic +#: model:ir.model.fields,field_description:purchase_stock_analytic.field_purchase_order_line__id +msgid "ID" +msgstr "" + +#. module: purchase_stock_analytic +#: model:ir.model.fields,field_description:purchase_stock_analytic.field_purchase_order_line____last_update +msgid "Last Modified on" +msgstr "" + +#. module: purchase_stock_analytic +#: model:ir.model,name:purchase_stock_analytic.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "" diff --git a/purchase_stock_analytic/models/__init__.py b/purchase_stock_analytic/models/__init__.py new file mode 100644 index 0000000000..fa6c0e40fd --- /dev/null +++ b/purchase_stock_analytic/models/__init__.py @@ -0,0 +1 @@ +from . import purchase_order_line diff --git a/purchase_stock_analytic/models/purchase_order_line.py b/purchase_stock_analytic/models/purchase_order_line.py new file mode 100644 index 0000000000..9be96d5d23 --- /dev/null +++ b/purchase_stock_analytic/models/purchase_order_line.py @@ -0,0 +1,17 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class PurchaseOrderLine(models.Model): + + _inherit = "purchase.order.line" + + def _prepare_stock_moves(self, picking): + res = super(PurchaseOrderLine, self)._prepare_stock_moves(picking) + for line in res: + analytic_distribution = self.analytic_distribution + if analytic_distribution: + line.update({"analytic_distribution": analytic_distribution}) + return res diff --git a/purchase_stock_analytic/static/description/icon.png b/purchase_stock_analytic/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/purchase_stock_analytic/static/description/icon.png differ diff --git a/purchase_stock_analytic/tests/__init__.py b/purchase_stock_analytic/tests/__init__.py new file mode 100644 index 0000000000..76a2c027dd --- /dev/null +++ b/purchase_stock_analytic/tests/__init__.py @@ -0,0 +1 @@ +from . import test_purchase_stock_analytic diff --git a/purchase_stock_analytic/tests/test_purchase_stock_analytic.py b/purchase_stock_analytic/tests/test_purchase_stock_analytic.py new file mode 100644 index 0000000000..efd33c1137 --- /dev/null +++ b/purchase_stock_analytic/tests/test_purchase_stock_analytic.py @@ -0,0 +1,43 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields +from odoo.tests.common import SavepointCase + + +class TestPurchaseStockAnalytic(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.purchase_order_model = cls.env["purchase.order"] + cls.purchase_order_line_model = cls.env["purchase.order.line"] + cls.product_model = cls.env["product.product"] + cls.res_partner_model = cls.env["res.partner"] + + cls.partner = cls.res_partner_model.create({"name": "Partner test"}) + cls.product = cls.product_model.create({"name": "Product test"}) + cls.analytic_distribution = dict( + {str(cls.env.ref("analytic.analytic_agrolait").id): 100.0} + ) + + cls.purchase_order = cls.purchase_order_model.create( + {"partner_id": cls.partner.id} + ) + cls.purchase_order_line = cls.purchase_order_line_model.create( + { + "name": "purchase order line test", + "product_qty": 3, + "order_id": cls.purchase_order.id, + "price_unit": 20, + "product_id": cls.product.id, + "analytic_distribution": cls.analytic_distribution, + "date_planned": fields.Datetime.today(), + "product_uom": cls.product.uom_po_id.id, + } + ) + + def test_purchase_stock_analytic(self): + self.purchase_order.button_confirm() + self.move = self.purchase_order.picking_ids.move_ids_without_package + self.assertEqual(self.move.analytic_distribution, self.analytic_distribution) diff --git a/setup/purchase_stock_analytic/odoo/addons/purchase_stock_analytic b/setup/purchase_stock_analytic/odoo/addons/purchase_stock_analytic new file mode 120000 index 0000000000..a8db341fa2 --- /dev/null +++ b/setup/purchase_stock_analytic/odoo/addons/purchase_stock_analytic @@ -0,0 +1 @@ +../../../../purchase_stock_analytic \ No newline at end of file diff --git a/setup/purchase_stock_analytic/setup.py b/setup/purchase_stock_analytic/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/purchase_stock_analytic/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)