diff --git a/oca_dependencies.txt b/oca_dependencies.txt index b468c811f..56779b7ed 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1,3 +1,4 @@ +account-analytic product-attribute server-env server-ux diff --git a/setup/stock_request_analytic/odoo/addons/stock_request_analytic b/setup/stock_request_analytic/odoo/addons/stock_request_analytic new file mode 120000 index 000000000..f4f495d18 --- /dev/null +++ b/setup/stock_request_analytic/odoo/addons/stock_request_analytic @@ -0,0 +1 @@ +../../../../stock_request_analytic \ No newline at end of file diff --git a/setup/stock_request_analytic/setup.py b/setup/stock_request_analytic/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_request_analytic/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_request_analytic/README.rst b/stock_request_analytic/README.rst new file mode 100644 index 000000000..d04c52d0d --- /dev/null +++ b/stock_request_analytic/README.rst @@ -0,0 +1,90 @@ +====================== +Stock Request Analytic +====================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_request_analytic + :alt: OCA/stock-logistics-warehouse +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-13-0/stock-logistics-warehouse-13-0-stock_request_analytic + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/153/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows for users to be able to display and assign analytic +accounts to stock requests. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Assign the analytic account to the stock request. + +Known issues / Roadmap +====================== + +* Integrate this module with stock_request_purchase to pass the analytic + account to the purchase order + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* Aaron Henriquez +* Lois Rilo +* Pimolnat Suntian +* `Tecnativa `__: + + * João Marques + +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/stock-logistics-warehouse `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_request_analytic/__init__.py b/stock_request_analytic/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/stock_request_analytic/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_request_analytic/__manifest__.py b/stock_request_analytic/__manifest__.py new file mode 100644 index 000000000..82cbd0f9a --- /dev/null +++ b/stock_request_analytic/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2017-2020 ForgeFlow, S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Stock Request Analytic", + "summary": "Internal request for stock", + "version": "13.0.1.0.0", + "license": "LGPL-3", + "website": "https://github.com/stock-logistics-warehouse", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "category": "Analytic", + "depends": ["stock_request", "stock_analytic"], + "data": [ + "security/ir.model.access.csv", + "views/stock_request_views.xml", + "views/stock_request_order_views.xml", + "views/analytic_views.xml", + ], + "installable": True, +} diff --git a/stock_request_analytic/i18n/pt_BR.po b/stock_request_analytic/i18n/pt_BR.po new file mode 100644 index 000000000..e64161f73 --- /dev/null +++ b/stock_request_analytic/i18n/pt_BR.po @@ -0,0 +1,71 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_request_analytic +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-03-24 18:22+0000\n" +"Last-Translator: Marcel Savegnago \n" +"Language-Team: none\n" +"Language: pt_BR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 3.10\n" + +#. module: stock_request_analytic +#: model:ir.model,name:stock_request_analytic.model_account_analytic_account +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request__analytic_account_id +msgid "Analytic Account" +msgstr "Conta Analítica" + +#. module: stock_request_analytic +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request_order__analytic_account_ids +#: model_terms:ir.ui.view,arch_db:stock_request_analytic.stock_request_order_form +msgid "Analytic Accounts" +msgstr "Contas Analíticas" + +#. module: stock_request_analytic +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request_order__analytic_count +msgid "Analytic Count" +msgstr "Contagem Analítica" + +#. module: stock_request_analytic +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request__analytic_tag_ids +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request_order__analytic_tag_ids +msgid "Analytic Tags" +msgstr "" + +#. module: stock_request_analytic +#: model:ir.model,name:stock_request_analytic.model_stock_request +#: model_terms:ir.ui.view,arch_db:stock_request_analytic.view_account_analytic_account_form +msgid "Stock Request" +msgstr "Requisição de Estoque" + +#. module: stock_request_analytic +#: model:ir.model,name:stock_request_analytic.model_stock_request_order +msgid "Stock Request Order" +msgstr "Ordens de Requisição de Estoque" + +#. module: stock_request_analytic +#: model:ir.model.fields,field_description:stock_request_analytic.field_account_analytic_account__stock_request_ids +msgid "Stock Requests" +msgstr "Requisições de Estoque" + +#. module: stock_request_analytic +#: model:ir.model,name:stock_request_analytic.model_stock_rule +msgid "Stock Rule" +msgstr "Regras de Estoque" + +#. module: stock_request_analytic +#: code:addons/stock_request_analytic/models/stock_request.py:21 +#, python-format +msgid "" +"You cannot link a analytic account to a stock request that belongs to " +"another company." +msgstr "" +"Você não pode vincular uma conta analítica a uma requisição de estoque que " +"pertence a outra empresa." diff --git a/stock_request_analytic/i18n/stock_request_analytic.pot b/stock_request_analytic/i18n/stock_request_analytic.pot new file mode 100644 index 000000000..7b86097a1 --- /dev/null +++ b/stock_request_analytic/i18n/stock_request_analytic.pot @@ -0,0 +1,65 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_request_analytic +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.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: stock_request_analytic +#: model:ir.model,name:stock_request_analytic.model_account_analytic_account +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request__analytic_account_id +msgid "Analytic Account" +msgstr "" + +#. module: stock_request_analytic +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request_order__analytic_account_ids +#: model_terms:ir.ui.view,arch_db:stock_request_analytic.stock_request_order_form +msgid "Analytic Accounts" +msgstr "" + +#. module: stock_request_analytic +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request_order__analytic_count +msgid "Analytic Count" +msgstr "" + +#. module: stock_request_analytic +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request__analytic_tag_ids +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request_order__analytic_tag_ids +msgid "Analytic Tags" +msgstr "" + +#. module: stock_request_analytic +#: model:ir.model,name:stock_request_analytic.model_stock_request +#: model_terms:ir.ui.view,arch_db:stock_request_analytic.view_account_analytic_account_form +msgid "Stock Request" +msgstr "" + +#. module: stock_request_analytic +#: model:ir.model,name:stock_request_analytic.model_stock_request_order +msgid "Stock Request Order" +msgstr "" + +#. module: stock_request_analytic +#: model:ir.model.fields,field_description:stock_request_analytic.field_account_analytic_account__stock_request_ids +msgid "Stock Requests" +msgstr "" + +#. module: stock_request_analytic +#: model:ir.model,name:stock_request_analytic.model_stock_rule +msgid "Stock Rule" +msgstr "" + +#. module: stock_request_analytic +#: code:addons/stock_request_analytic/models/stock_request.py:21 +#, python-format +msgid "You cannot link a analytic account to a stock request that belongs to another company." +msgstr "" + diff --git a/stock_request_analytic/i18n/zh_CN.po b/stock_request_analytic/i18n/zh_CN.po new file mode 100644 index 000000000..9e92c2160 --- /dev/null +++ b/stock_request_analytic/i18n/zh_CN.po @@ -0,0 +1,69 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_request_analytic +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2019-10-16 15:58+0000\n" +"Last-Translator: 黎伟杰 <674416404@qq.com>\n" +"Language-Team: none\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Weblate 3.8\n" + +#. module: stock_request_analytic +#: model:ir.model,name:stock_request_analytic.model_account_analytic_account +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request__analytic_account_id +msgid "Analytic Account" +msgstr "分析账户" + +#. module: stock_request_analytic +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request_order__analytic_account_ids +#: model_terms:ir.ui.view,arch_db:stock_request_analytic.stock_request_order_form +msgid "Analytic Accounts" +msgstr "分析账户" + +#. module: stock_request_analytic +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request_order__analytic_count +msgid "Analytic Count" +msgstr "分析数量" + +#. module: stock_request_analytic +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request__analytic_tag_ids +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request_order__analytic_tag_ids +msgid "Analytic Tags" +msgstr "" + +#. module: stock_request_analytic +#: model:ir.model,name:stock_request_analytic.model_stock_request +#: model_terms:ir.ui.view,arch_db:stock_request_analytic.view_account_analytic_account_form +msgid "Stock Request" +msgstr "库存请求" + +#. module: stock_request_analytic +#: model:ir.model,name:stock_request_analytic.model_stock_request_order +msgid "Stock Request Order" +msgstr "库存请求单" + +#. module: stock_request_analytic +#: model:ir.model.fields,field_description:stock_request_analytic.field_account_analytic_account__stock_request_ids +msgid "Stock Requests" +msgstr "库存请求" + +#. module: stock_request_analytic +#: model:ir.model,name:stock_request_analytic.model_stock_rule +msgid "Stock Rule" +msgstr "库存规则" + +#. module: stock_request_analytic +#: code:addons/stock_request_analytic/models/stock_request.py:21 +#, python-format +msgid "" +"You cannot link a analytic account to a stock request that belongs to " +"another company." +msgstr "您无法将分析帐户链接到属于另一家公司的库存请求。" diff --git a/stock_request_analytic/models/__init__.py b/stock_request_analytic/models/__init__.py new file mode 100644 index 000000000..4a24765c7 --- /dev/null +++ b/stock_request_analytic/models/__init__.py @@ -0,0 +1,4 @@ +from . import analytic +from . import stock_rule +from . import stock_request +from . import stock_request_order diff --git a/stock_request_analytic/models/analytic.py b/stock_request_analytic/models/analytic.py new file mode 100644 index 000000000..b0203d0f9 --- /dev/null +++ b/stock_request_analytic/models/analytic.py @@ -0,0 +1,28 @@ +# Copyright 2017-2020 ForgeFlow, S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import fields, models + + +class AccountAnalyticAccount(models.Model): + _inherit = "account.analytic.account" + + stock_request_ids = fields.One2many( + comodel_name="stock.request", + inverse_name="analytic_account_id", + string="Stock Requests", + copy=False, + ) + + def action_view_stock_request(self): + self.ensure_one() + action = self.env.ref("stock_request.action_stock_request_form").read()[0] + requests = self.mapped("stock_request_ids") + if len(requests) > 1: + action["domain"] = [("id", "in", requests.ids)] + elif requests: + action["views"] = [ + (self.env.ref("stock_request.view_stock_request_form").id, "form") + ] + action["res_id"] = requests.id + return action diff --git a/stock_request_analytic/models/stock_request.py b/stock_request_analytic/models/stock_request.py new file mode 100644 index 000000000..038a16276 --- /dev/null +++ b/stock_request_analytic/models/stock_request.py @@ -0,0 +1,17 @@ +# Copyright 2017-2020 ForgeFlow, S.L. (https://www.forgeflow.com) +# Copyright 2021 Tecnativa - João Marques +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import fields, models + + +class StockRequest(models.Model): + _inherit = "stock.request" + _check_company_auto = True + + analytic_account_id = fields.Many2one( + "account.analytic.account", string="Analytic Account", check_company=True, + ) + analytic_tag_ids = fields.Many2many( + "account.analytic.tag", string="Analytic Tags", check_company=True, + ) diff --git a/stock_request_analytic/models/stock_request_order.py b/stock_request_analytic/models/stock_request_order.py new file mode 100644 index 000000000..eed38a1ae --- /dev/null +++ b/stock_request_analytic/models/stock_request_order.py @@ -0,0 +1,65 @@ +# Copyright 2018 Creu Blanca +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + +MAP_ACTIONS = { + "analytic_account": "analytic.action_account_analytic_account_form", + "analytic_tag": "analytic.account_analytic_tag_action", +} +MAP_FIELDS = { + "analytic_account": "analytic_account_ids", + "analytic_tag": "analytic_tag_ids", +} +MAP_VIEWS = { + "analytic_account": "analytic.view_account_analytic_account_form", + "analytic_tag": "analytic.account_analytic_tag_form_view", +} + + +class StockRequestOrder(models.Model): + _inherit = "stock.request.order" + + analytic_count = fields.Integer(compute="_compute_analytic_ids", readonly=True) + analytic_tag_count = fields.Integer(compute="_compute_analytic_ids", readonly=True) + analytic_account_ids = fields.One2many( + comodel_name="account.analytic.account", + compute="_compute_analytic_ids", + string="Analytic Accounts", + readonly=True, + ) + analytic_tag_ids = fields.One2many( + comodel_name="account.analytic.tag", + compute="_compute_analytic_ids", + string="Analytic Tags", + readonly=True, + ) + + @api.depends("stock_request_ids") + def _compute_analytic_ids(self): + for req in self.sudo(): + req.analytic_account_ids = req.stock_request_ids.mapped( + "analytic_account_id" + ) + req.analytic_tag_ids = req.stock_request_ids.mapped("analytic_tag_ids") + req.analytic_count = len(req.analytic_account_ids) + req.analytic_tag_count = len(req.analytic_tag_ids) + + def action_view_analytic(self): + self.ensure_one() + analytic_type = self.env.context.get("analytic_type") + if not analytic_type: + raise ValidationError( + _("Analytic type (analytic_type) not present in the context") + ) + action = self.env.ref(MAP_ACTIONS[analytic_type]).read()[0] + records = self.mapped(MAP_FIELDS[analytic_type]) + if len(records) > 1: + action["domain"] = [("id", "in", records.ids)] + elif records: + action["views"] = [ + (self.env.ref(MAP_VIEWS[self._context["analytic_type"]]).id, "form") + ] + action["res_id"] = records.id + return action diff --git a/stock_request_analytic/models/stock_rule.py b/stock_request_analytic/models/stock_rule.py new file mode 100644 index 000000000..8ce90f47c --- /dev/null +++ b/stock_request_analytic/models/stock_rule.py @@ -0,0 +1,39 @@ +# Copyright 2017-2020 ForgeFlow, S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import models + + +class ProcurementRule(models.Model): + _inherit = "stock.rule" + + def _get_stock_move_values( + self, + product_id, + product_qty, + product_uom, + location_id, + name, + origin, + company_id, + values, + ): + res = super(ProcurementRule, self)._get_stock_move_values( + product_id, + product_qty, + product_uom, + location_id, + name, + origin, + company_id, + values, + ) + if values.get("stock_request_id"): + stock_request = self.env["stock.request"].browse(values["stock_request_id"]) + analytic_account = stock_request.analytic_account_id + analytic_tags = stock_request.analytic_tag_ids + res.update( + analytic_account_id=analytic_account.id, + analytic_tag_ids=[(4, tag.id) for tag in analytic_tags], + ) + return res diff --git a/stock_request_analytic/readme/CONTRIBUTORS.rst b/stock_request_analytic/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..decc3d3ea --- /dev/null +++ b/stock_request_analytic/readme/CONTRIBUTORS.rst @@ -0,0 +1,6 @@ +* Aaron Henriquez +* Lois Rilo +* Pimolnat Suntian +* `Tecnativa `__: + + * João Marques diff --git a/stock_request_analytic/readme/DESCRIPTION.rst b/stock_request_analytic/readme/DESCRIPTION.rst new file mode 100644 index 000000000..259f4ba9c --- /dev/null +++ b/stock_request_analytic/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module allows for users to be able to display and assign analytic +accounts to stock requests. diff --git a/stock_request_analytic/readme/ROADMAP.rst b/stock_request_analytic/readme/ROADMAP.rst new file mode 100644 index 000000000..fe59d5a8d --- /dev/null +++ b/stock_request_analytic/readme/ROADMAP.rst @@ -0,0 +1,2 @@ +* Integrate this module with stock_request_purchase to pass the analytic + account to the purchase order diff --git a/stock_request_analytic/readme/USAGE.rst b/stock_request_analytic/readme/USAGE.rst new file mode 100644 index 000000000..e9c6ebb47 --- /dev/null +++ b/stock_request_analytic/readme/USAGE.rst @@ -0,0 +1 @@ +Assign the analytic account to the stock request. diff --git a/stock_request_analytic/security/ir.model.access.csv b/stock_request_analytic/security/ir.model.access.csv new file mode 100644 index 000000000..43a1348f0 --- /dev/null +++ b/stock_request_analytic/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_stock_request_analytic_user,stock.request analytic user,stock_request.model_stock_request,analytic.group_analytic_accounting,1,0,0,0 diff --git a/stock_request_analytic/static/description/icon.png b/stock_request_analytic/static/description/icon.png new file mode 100644 index 000000000..c31ecfd9f Binary files /dev/null and b/stock_request_analytic/static/description/icon.png differ diff --git a/stock_request_analytic/static/description/index.html b/stock_request_analytic/static/description/index.html new file mode 100644 index 000000000..39ffa27e2 --- /dev/null +++ b/stock_request_analytic/static/description/index.html @@ -0,0 +1,439 @@ + + + + + + +Stock Request Analytic + + + +
+

Stock Request Analytic

+ + +

Beta License: LGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runbot

+

This module allows for users to be able to display and assign analytic +accounts to stock requests.

+

Table of contents

+ +
+

Usage

+

Assign the analytic account to the stock request.

+
+
+

Known issues / Roadmap

+
    +
  • Integrate this module with stock_request_purchase to pass the analytic +account to the purchase order
  • +
+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow
  • +
+
+
+

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/stock-logistics-warehouse project on GitHub.

+

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

+
+
+
+ + diff --git a/stock_request_analytic/tests/__init__.py b/stock_request_analytic/tests/__init__.py new file mode 100644 index 000000000..fd35f0ff6 --- /dev/null +++ b/stock_request_analytic/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_request_analytic diff --git a/stock_request_analytic/tests/test_stock_request_analytic.py b/stock_request_analytic/tests/test_stock_request_analytic.py new file mode 100644 index 000000000..c6b343b03 --- /dev/null +++ b/stock_request_analytic/tests/test_stock_request_analytic.py @@ -0,0 +1,150 @@ +# Copyright 2017-2020 ForgeFlow, S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0). + +from odoo import fields +from odoo.exceptions import UserError + +from odoo.addons.stock_request.tests import test_stock_request + + +class TestStockRequestAnalytic(test_stock_request.TestStockRequest): + def setUp(self): + super(TestStockRequestAnalytic, self).setUp() + self.analytic_model = self.env["account.analytic.account"] + self.analytic = self.analytic_model.create({"name": "Pizza"}) + self.analytic2 = self.analytic_model.create( + {"name": "Pizza", "company_id": self.company_2.id} + ) + self.analytic3 = self.analytic_model.create({"name": "Hamburger"}) + self.demand_loc = self.env["stock.location"].create( + { + "name": "demand_loc", + "location_id": self.warehouse.lot_stock_id.id, + "usage": "internal", + } + ) + self.demand_route = self.env["stock.location.route"].create( + { + "name": "Transfer", + "product_categ_selectable": False, + "product_selectable": True, + "company_id": self.main_company.id, + "sequence": 10, + } + ) + self.pizza = self._create_product("PZ", "Pizza", False) + self.demand_rule = self.env["stock.rule"].create( + { + "name": "Transfer", + "route_id": self.demand_route.id, + "location_src_id": self.warehouse.lot_stock_id.id, + "location_id": self.demand_loc.id, + "action": "pull", + "picking_type_id": self.warehouse.int_type_id.id, + "procure_method": "make_to_stock", + "warehouse_id": self.warehouse.id, + "company_id": self.main_company.id, + } + ) + self.pizza.route_ids = [(6, 0, self.demand_route.ids)] + + def prepare_order_request_analytic(self, analytic, company, analytic_tags=None): + expected_date = fields.Datetime.now() + analytic_tags = analytic_tags or self.env["account.analytic.tag"] + vals = { + "company_id": company.id, + "warehouse_id": self.warehouse.id, + "location_id": self.demand_loc.id, + "expected_date": expected_date, + "stock_request_ids": [ + ( + 0, + 0, + { + "product_id": self.pizza.id, + "product_uom_id": self.pizza.uom_id.id, + "product_uom_qty": 5.0, + "analytic_account_id": analytic.id, + "analytic_tag_ids": [(4, tag.id) for tag in analytic_tags], + "company_id": company.id, + "warehouse_id": self.warehouse.id, + "location_id": self.demand_loc.id, + "expected_date": expected_date, + }, + ) + ], + } + return vals + + def prepare_order_request_multi_analytic(self, analytic1, analytic2, company): + expected_date = fields.Datetime.now() + vals = { + "company_id": company.id, + "warehouse_id": self.warehouse.id, + "location_id": self.demand_loc.id, + "expected_date": expected_date, + "stock_request_ids": [ + ( + 0, + 0, + { + "product_id": self.pizza.id, + "product_uom_id": self.pizza.uom_id.id, + "product_uom_qty": 5.0, + "analytic_account_id": analytic1.id, + "company_id": company.id, + "warehouse_id": self.warehouse.id, + "location_id": self.demand_loc.id, + "expected_date": expected_date, + }, + ), + ( + 0, + 0, + { + "product_id": self.pizza.id, + "product_uom_id": self.pizza.uom_id.id, + "product_uom_qty": 5.0, + "analytic_account_id": analytic2.id, + "company_id": company.id, + "warehouse_id": self.warehouse.id, + "location_id": self.demand_loc.id, + "expected_date": expected_date, + }, + ), + ], + } + return vals + + def test_stock_analytic(self): + analytic_tag = self.env.ref("analytic.tag_contract") + vals = self.prepare_order_request_analytic( + self.analytic, self.main_company, analytic_tags=analytic_tag + ) + order = self.env["stock.request.order"].create(vals) + req = order.stock_request_ids + order.action_confirm() + self.assertEqual(req.move_ids.mapped("analytic_account_id"), self.analytic) + self.assertEqual(req.move_ids.mapped("analytic_tag_ids"), analytic_tag) + self.assertEqual(order.analytic_count, 1) + action = order.with_context( + analytic_type="analytic_account" + ).action_view_analytic() + self.assertTrue(action["res_id"], self.analytic.id) + action2 = self.analytic.action_view_stock_request() + self.assertTrue(action2["res_id"], order.id) + + def test_stock_multi_analytic(self): + vals = self.prepare_order_request_multi_analytic( + self.analytic, self.analytic3, self.main_company + ) + order = self.env["stock.request.order"].create(vals) + order.action_confirm() + self.assertEqual(order.analytic_count, 2) + + def test_company(self): + with self.assertRaises(UserError): + vals = self.prepare_order_request_analytic( + self.analytic2, self.main_company + ) + self.env["stock.request.order"].create(vals) diff --git a/stock_request_analytic/views/analytic_views.xml b/stock_request_analytic/views/analytic_views.xml new file mode 100644 index 000000000..8c0807452 --- /dev/null +++ b/stock_request_analytic/views/analytic_views.xml @@ -0,0 +1,24 @@ + + + + + analytic.order.form + account.analytic.account + + + + + + + + + + + + + + diff --git a/stock_request_analytic/views/stock_request_views.xml b/stock_request_analytic/views/stock_request_views.xml new file mode 100644 index 000000000..e39f74bda --- /dev/null +++ b/stock_request_analytic/views/stock_request_views.xml @@ -0,0 +1,23 @@ + + + + + stock.request.form + stock.request + + + + + + + + +