From b1bf079650698511d71aa46b697776193047aeee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Fri, 4 Nov 2022 13:07:15 +0100 Subject: [PATCH] [MIG] project_stock: Migration to 15.0 TT40363 --- project_stock/README.rst | 12 +- project_stock/__manifest__.py | 3 +- .../migrations/15.0.1.0.0/pre-migration.py | 16 +++ project_stock/models/project_task.py | 7 +- project_stock/models/stock_move.py | 12 +- project_stock/readme/CONFIGURE.rst | 2 +- .../security/project_stock_security.xml | 12 ++ project_stock/static/description/index.html | 10 +- project_stock/tests/common.py | 10 +- project_stock/tests/test_project_stock.py | 135 +++++++++++++++--- project_stock/views/project_task_view.xml | 2 +- 11 files changed, 175 insertions(+), 46 deletions(-) create mode 100644 project_stock/migrations/15.0.1.0.0/pre-migration.py create mode 100644 project_stock/security/project_stock_security.xml diff --git a/project_stock/README.rst b/project_stock/README.rst index 1ff3c452f7..0b2bdf5db3 100644 --- a/project_stock/README.rst +++ b/project_stock/README.rst @@ -14,13 +14,13 @@ Project Stock :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github - :target: https://github.com/OCA/project/tree/14.0/project_stock + :target: https://github.com/OCA/project/tree/15.0/project_stock :alt: OCA/project .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/project-14-0/project-14-0-project_stock + :target: https://translation.odoo-community.org/projects/project-15-0/project-15-0-project_stock :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/140/14.0 + :target: https://runbot.odoo-community.org/runbot/140/15.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -49,7 +49,7 @@ To configure this module, you need to: #. Create a new project with the following options: * `Name`: Task material * `Operation type`: Task material -#. Go to *Project -> Configuration -> Stages* and edit some records. +#. Go to *Project -> Configuration -> Task Stages* and edit some records. * `In progress`: Check Use Stock Moves option and add the created project. * `Done`: Check Use Stock Moves option + Lock Stock Moves and add the created project. @@ -74,7 +74,7 @@ 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -115,6 +115,6 @@ Current `maintainer `__: |maintainer-victoralmau| -This module is part of the `OCA/project `_ project on GitHub. +This module is part of the `OCA/project `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/project_stock/__manifest__.py b/project_stock/__manifest__.py index 6e2aa4ca4a..aa8f549390 100644 --- a/project_stock/__manifest__.py +++ b/project_stock/__manifest__.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { "name": "Project Stock", - "version": "14.0.1.1.1", + "version": "15.0.1.0.0", "category": "Project Management", "website": "https://github.com/OCA/project", "author": "Tecnativa, Odoo Community Association (OCA)", @@ -10,6 +10,7 @@ "depends": ["project", "stock"], "installable": True, "data": [ + "security/project_stock_security.xml", "views/project_project_view.xml", "views/project_task_type_view.xml", "views/stock_move_view.xml", diff --git a/project_stock/migrations/15.0.1.0.0/pre-migration.py b/project_stock/migrations/15.0.1.0.0/pre-migration.py new file mode 100644 index 0000000000..df72e18301 --- /dev/null +++ b/project_stock/migrations/15.0.1.0.0/pre-migration.py @@ -0,0 +1,16 @@ +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openupgradelib import openupgrade + +_table_renamed = [ + ( + "account_analytic_tag_project_task_rel", + "account_analytic_tag_project_task_stock_rel", + ), +] + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.rename_tables(env.cr, _table_renamed) diff --git a/project_stock/models/project_task.py b/project_stock/models/project_task.py index 141e2a93dc..c1a82890a0 100644 --- a/project_stock/models/project_task.py +++ b/project_stock/models/project_task.py @@ -74,6 +74,9 @@ class ProjectTask(models.Model): ) stock_analytic_tag_ids = fields.Many2many( comodel_name="account.analytic.tag", + relation="account_analytic_tag_project_task_stock_rel", + column1="project_task_id", + column2="account_analytic_tag_id", string="Move Analytic Tags", ) stock_analytic_line_ids = fields.One2many( @@ -221,11 +224,11 @@ def action_done(self): for move in self.move_ids.filtered(lambda x: x.state == "done"): vals = move._prepare_analytic_line_from_task() if vals: - analytic_line_model.create(move._prepare_analytic_line_from_task()) + analytic_line_model.create(vals) def action_see_move_scrap(self): self.ensure_one() - action = self.env.ref("stock.action_stock_scrap").read()[0] + action = self.env["ir.actions.actions"]._for_xml_id("stock.action_stock_scrap") action["domain"] = [("task_id", "=", self.id)] action["context"] = dict(self._context, default_origin=self.name) return action diff --git a/project_stock/models/stock_move.py b/project_stock/models/stock_move.py index bc9bafa2bf..c5cc1094dd 100644 --- a/project_stock/models/stock_move.py +++ b/project_stock/models/stock_move.py @@ -16,12 +16,13 @@ class StockMove(models.Model): ) @api.onchange("product_id") - def onchange_product_id(self): + def _onchange_product_id(self): """It is necessary to overwrite the name to prevent set product name from being auto-defined.""" - super().onchange_product_id() + res = super()._onchange_product_id() if self.raw_material_task_id: self.name = self.raw_material_task_id.name + return res def _prepare_analytic_line_from_task(self): product = self.product_id @@ -59,13 +60,6 @@ def _prepare_analytic_line_from_task(self): vals["ref"] = task.name if "product_id" in analytic_line_fields: vals["product_id"] = product.id - # Extra field added in hr_timesheet addon - if "employee_id" in analytic_line_fields: - vals["employee_id"] = ( - self.env["hr.employee"] - .search([("user_id", "=", task.user_id.id)], limit=1) - .id - ) # tags + distributions if task.stock_analytic_tag_ids: vals["tag_ids"] = [(6, 0, task.stock_analytic_tag_ids.ids)] diff --git a/project_stock/readme/CONFIGURE.rst b/project_stock/readme/CONFIGURE.rst index feee42e6b7..36683c33fc 100644 --- a/project_stock/readme/CONFIGURE.rst +++ b/project_stock/readme/CONFIGURE.rst @@ -12,6 +12,6 @@ To configure this module, you need to: #. Create a new project with the following options: * `Name`: Task material * `Operation type`: Task material -#. Go to *Project -> Configuration -> Stages* and edit some records. +#. Go to *Project -> Configuration -> Task Stages* and edit some records. * `In progress`: Check Use Stock Moves option and add the created project. * `Done`: Check Use Stock Moves option + Lock Stock Moves and add the created project. diff --git a/project_stock/security/project_stock_security.xml b/project_stock/security/project_stock_security.xml new file mode 100644 index 0000000000..97357bc0a8 --- /dev/null +++ b/project_stock/security/project_stock_security.xml @@ -0,0 +1,12 @@ + + + + account.analytic.line.project_stock + + [('stock_task_id', '!=', False)] + + + diff --git a/project_stock/static/description/index.html b/project_stock/static/description/index.html index f5aad05634..7d4bf6a7db 100644 --- a/project_stock/static/description/index.html +++ b/project_stock/static/description/index.html @@ -3,7 +3,7 @@ - + Project Stock