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..7ca12649c --- /dev/null +++ b/stock_request_analytic/README.rst @@ -0,0 +1,92 @@ +====================== +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-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%2Fstock--logistics--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/14.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-14-0/stock-logistics-warehouse-14-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/14.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 +* Alan Ramos +* Denis Roussel +* `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..3bd333be8 --- /dev/null +++ b/stock_request_analytic/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2017-2020 ForgeFlow, S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Stock Request Analytic", + "summary": "Internal request for stock", + "version": "15.0.1.0.0", + "license": "AGPL-3", + "website": "https://github.com/OCA/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..2911c0eac --- /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: 2022-02-01 20:33+0000\n" +"Last-Translator: Rodrigo Macedo \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 4.3.2\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 "Etiquetas Analíticas" + +#. 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..bd3bfa0ea --- /dev/null +++ b/stock_request_analytic/i18n/stock_request_analytic.pot @@ -0,0 +1,104 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_request_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: 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_order__analytic_tag_count +msgid "Analytic Tag 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 +#: model_terms:ir.ui.view,arch_db:stock_request_analytic.stock_request_order_form +msgid "Analytic Tags" +msgstr "" + +#. module: stock_request_analytic +#: code:addons/stock_request_analytic/models/stock_request_order.py:0 +#, python-format +msgid "Analytic type (analytic_type) not present in the context" +msgstr "" + +#. module: stock_request_analytic +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request_order__default_analytic_account_id +msgid "Default Analytic Account" +msgstr "" + +#. module: stock_request_analytic +#: model:ir.model.fields,field_description:stock_request_analytic.field_account_analytic_account__display_name +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request__display_name +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request_order__display_name +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_rule__display_name +msgid "Display Name" +msgstr "" + +#. module: stock_request_analytic +#: model:ir.model.fields,field_description:stock_request_analytic.field_account_analytic_account__id +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request__id +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request_order__id +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_rule__id +msgid "ID" +msgstr "" + +#. module: stock_request_analytic +#: model:ir.model.fields,field_description:stock_request_analytic.field_account_analytic_account____last_update +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request____last_update +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_request_order____last_update +#: model:ir.model.fields,field_description:stock_request_analytic.field_stock_rule____last_update +msgid "Last Modified on" +msgstr "" + +#. module: stock_request_analytic +#: model:ir.model.fields,help:stock_request_analytic.field_stock_request_order__default_analytic_account_id +msgid "Set this if you want to define a default analytic account on requests" +msgstr "" + +#. module: stock_request_analytic +#: model:ir.model,name:stock_request_analytic.model_stock_request +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 +#: model_terms:ir.ui.view,arch_db:stock_request_analytic.view_account_analytic_account_form +msgid "Stock Requests" +msgstr "" + +#. module: stock_request_analytic +#: model:ir.model,name:stock_request_analytic.model_stock_rule +msgid "Stock Rule" +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..a3d4bc2da --- /dev/null +++ b/stock_request_analytic/models/analytic.py @@ -0,0 +1,29 @@ +# Copyright 2017-2020 ForgeFlow, S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.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() + xmlid = "stock_request.action_stock_request_form" + action = self.env["ir.actions.act_window"]._for_xml_id(xmlid) + 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..6d9b94bce --- /dev/null +++ b/stock_request_analytic/models/stock_request.py @@ -0,0 +1,43 @@ +# Copyright 2017-2020 ForgeFlow, S.L. (https://www.forgeflow.com) +# Copyright 2021 Tecnativa - João Marques +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class StockRequest(models.Model): + _inherit = "stock.request" + _check_company_auto = True + + analytic_account_id = fields.Many2one( + comodel_name="account.analytic.account", + string="Analytic Account", + compute="_compute_analytic_id", + store=True, + readonly=False, + check_company=True, + compute_sudo=True, + ) + analytic_tag_ids = fields.Many2many( + comodel_name="account.analytic.tag", + string="Analytic Tags", + check_company=True, + ) + + @api.depends("order_id") + def _compute_analytic_id(self): + """ + Set default analytic account on lines from order if defined. + """ + for req in self: + if req.order_id and req.order_id.default_analytic_account_id: + req.analytic_account_id = req.order_id.default_analytic_account_id + + def _prepare_procurement_values(self, group_id=False): + """ + Add analytic account to procurement values + """ + res = super()._prepare_procurement_values(group_id=group_id) + if self.analytic_account_id: + res.update({"analytic_account_id": self.analytic_account_id.id}) + return res 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..9605503c3 --- /dev/null +++ b/stock_request_analytic/models/stock_request_order.py @@ -0,0 +1,81 @@ +# Copyright 2018 Creu Blanca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.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, + compute_sudo=True, + ) + analytic_tag_count = fields.Integer( + compute="_compute_analytic_ids", + readonly=True, + compute_sudo=True, + ) + analytic_account_ids = fields.One2many( + comodel_name="account.analytic.account", + compute="_compute_analytic_ids", + string="Analytic Accounts", + readonly=True, + compute_sudo=True, + ) + analytic_tag_ids = fields.One2many( + comodel_name="account.analytic.tag", + compute="_compute_analytic_ids", + string="Analytic Tags", + readonly=True, + compute_sudo=True, + ) + default_analytic_account_id = fields.Many2one( + comodel_name="account.analytic.account", + string="Default Analytic Account", + help="Set this if you want to define a default analytic account on requests", + ) + + @api.depends("stock_request_ids") + def _compute_analytic_ids(self): + for req in self: + 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") + ) + xmlid = MAP_ACTIONS[analytic_type] + action = self.env["ir.actions.act_window"]._for_xml_id(xmlid) + 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..9f7d30a92 --- /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 AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.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()._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..0e00ac65b --- /dev/null +++ b/stock_request_analytic/readme/CONTRIBUTORS.rst @@ -0,0 +1,8 @@ +* Aaron Henriquez +* Lois Rilo +* Pimolnat Suntian +* Alan Ramos +* Denis Roussel +* `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..d4f6a65ac 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..ba2f449f6 --- /dev/null +++ b/stock_request_analytic/static/description/index.html @@ -0,0 +1,441 @@ + + + + + + +Stock Request Analytic + + + +
+

Stock Request Analytic

+ + +

Beta License: AGPL-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..cc33ad877 --- /dev/null +++ b/stock_request_analytic/tests/test_stock_request_analytic.py @@ -0,0 +1,198 @@ +# Copyright 2017-2020 ForgeFlow, S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import fields +from odoo.exceptions import UserError +from odoo.tests import Form +from odoo.tests.common import TransactionCase + + +class TestStockRequestAnalytic(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + # Model + cls.AccountAnalyticAccount = cls.env["account.analytic.account"] + cls.AccountAnalyticTag = cls.env["account.analytic.tag"] + cls.ProductProduct = cls.env["product.product"] + cls.ResUsers = cls.env["res.users"] + cls.StockRequest = cls.env["stock.request"] + cls.StockRequestOrder = cls.env["stock.request.order"] + cls.StockLocation = cls.env["stock.location"] + cls.StockLocationRoute = cls.env["stock.location.route"] + cls.StockRule = cls.env["stock.rule"] + + # Data + cls.expected_date = fields.Datetime.now() + cls.main_company = cls.env.ref("base.main_company") + cls.company_2 = cls.env.ref("stock.res_company_1") + cls.warehouse = cls.env.ref("stock.warehouse0") + cls.stock_request_user_group = cls.env.ref( + "stock_request.group_stock_request_user" + ) + cls.stock_request_manager_group = cls.env.ref( + "stock_request.group_stock_request_manager" + ) + cls.analytic1 = cls.AccountAnalyticAccount.create({"name": "Analytic"}) + cls.analytic2 = cls.AccountAnalyticAccount.create( + {"name": "Analytic", "company_id": cls.company_2.id} + ) + cls.analytic3 = cls.AccountAnalyticAccount.create({"name": "Analytic 3"}) + cls.demand_loc = cls.StockLocation.create( + { + "name": "demand_loc", + "location_id": cls.warehouse.lot_stock_id.id, + "usage": "internal", + } + ) + cls.demand_route = cls.StockLocationRoute.create( + { + "name": "Transfer", + "product_categ_selectable": False, + "product_selectable": True, + "company_id": cls.main_company.id, + "sequence": 10, + } + ) + cls.demand_rule = cls.StockRule.create( + { + "name": "Transfer", + "route_id": cls.demand_route.id, + "location_src_id": cls.warehouse.lot_stock_id.id, + "location_id": cls.demand_loc.id, + "action": "pull", + "picking_type_id": cls.warehouse.int_type_id.id, + "procure_method": "make_to_stock", + "warehouse_id": cls.warehouse.id, + "company_id": cls.main_company.id, + } + ) + cls.product = cls.ProductProduct.create( + { + "name": "Test Product", + "type": "product", + "route_ids": [(6, 0, cls.demand_route.ids)], + } + ) + + def prepare_order_request_analytic(self, analytic, company, analytic_tags=None): + analytic_tags = analytic_tags or self.AccountAnalyticTag + vals = { + "company_id": company.id, + "warehouse_id": self.warehouse.id, + "location_id": self.demand_loc.id, + "expected_date": self.expected_date, + "stock_request_ids": [ + ( + 0, + 0, + { + "product_id": self.product.id, + "product_uom_id": self.product.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": self.expected_date, + }, + ) + ], + } + return vals + + def prepare_order_request_multi_analytic(self, analytic1, analytic2, company): + vals = { + "company_id": company.id, + "warehouse_id": self.warehouse.id, + "location_id": self.demand_loc.id, + "expected_date": self.expected_date, + "stock_request_ids": [ + ( + 0, + 0, + { + "product_id": self.product.id, + "product_uom_id": self.product.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": self.expected_date, + }, + ), + ( + 0, + 0, + { + "product_id": self.product.id, + "product_uom_id": self.product.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": self.expected_date, + }, + ), + ], + } + return vals + + def test_stock_analytic(self): + analytic_tag = self.env.ref("analytic.tag_contract") + vals = self.prepare_order_request_analytic( + self.analytic1, self.main_company, analytic_tags=analytic_tag + ) + order = self.StockRequestOrder.create(vals) + req = order.stock_request_ids + order.action_confirm() + self.assertEqual(req.move_ids.mapped("analytic_account_id"), self.analytic1) + 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.analytic1.id) + action2 = self.analytic1.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.analytic1, self.analytic3, self.main_company + ) + order = self.StockRequestOrder.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.StockRequestOrder.create(vals) + + def test_default_analytic(self): + """ + Create request order with a default analytic + """ + vals = self.prepare_order_request_analytic( + self.AccountAnalyticAccount.browse(), self.main_company + ) + vals.update( + { + "default_analytic_account_id": self.analytic1.id, + } + ) + order = self.StockRequestOrder.create(vals) + with Form(order) as order_form: + with order_form.stock_request_ids.new() as line_form: + line_form.product_id = self.product + line_form.product_uom_qty = 5.0 + self.assertEqual( + order.default_analytic_account_id, + order.stock_request_ids.mapped("analytic_account_id"), + ) diff --git a/stock_request_analytic/views/analytic_views.xml b/stock_request_analytic/views/analytic_views.xml new file mode 100644 index 000000000..1f77af7a2 --- /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..4e3b124f2 --- /dev/null +++ b/stock_request_analytic/views/stock_request_views.xml @@ -0,0 +1,23 @@ + + + + + stock.request.form + stock.request + + + + + + + + +