Skip to content

Commit

Permalink
[MIG] project_stock: Migration to 15.0
Browse files Browse the repository at this point in the history
TT40363
  • Loading branch information
victoralmau committed Nov 9, 2022
1 parent 832cd86 commit fb3f2ed
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 88 deletions.
16 changes: 8 additions & 8 deletions project_stock/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -49,19 +49,19 @@ 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.
* `Done`: Check Use Stock Moves option + Done Stock Moves and add the created project.

Usage
=====

#. Go to *Projects -> Task material (project)* and create a task and edit it.
#. *Stock Info* is displayed in the *Extra info* tab with the same project information, but it can be modified.
#. Add some product to *Stock Info* tab and set some initial demand (1 for example).
#. Click on the button *Confirm material* to confirm all moves.
#. Change the stage to Done.
#. *Stock Info* tab is readonly and some buttons show in header:
* `Confirm material`: Confirm all moves.
* `Check availability materials`: Product availability will be checked.
* `Transfer Materials`: Stock moves are confirmed and moved from one location to another.
* `Unreserve`: Remove the reservation stock of the products.
Expand All @@ -74,7 +74,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/project/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 <https://github.com/OCA/project/issues/new?body=module:%20project_stock%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/project/issues/new?body=module:%20project_stock%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Expand Down Expand Up @@ -115,6 +115,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-victoralmau|

This module is part of the `OCA/project <https://github.com/OCA/project/tree/14.0/project_stock>`_ project on GitHub.
This module is part of the `OCA/project <https://github.com/OCA/project/tree/15.0/project_stock>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
6 changes: 5 additions & 1 deletion project_stock/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -15,5 +15,9 @@
"views/stock_move_view.xml",
"views/project_task_view.xml",
],
"demo": [
"demo/stock_picking_type_data.xml",
"demo/project_data.xml",
],
"maintainers": ["victoralmau"],
}
25 changes: 25 additions & 0 deletions project_stock/demo/project_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="project_project_tm_test" model="project.project">
<field name="name">Task material</field>
<field name="picking_type_id" ref="project_stock.stock_picking_type_tm_test" />
<field name="location_id" ref="stock.stock_location_stock" />
<field name="location_dest_id" ref="stock.stock_location_components" />
<field name="stock_analytic_date">1990-01-01</field>
</record>
<record id="project.project_stage_1" model="project.task.type">
<field name="use_stock_moves" eval="True" />
<field
name="project_ids"
eval="[(4, ref('project_stock.project_project_tm_test'))]"
/>
</record>
<record id="project.project_stage_2" model="project.task.type">
<field name="use_stock_moves" eval="True" />
<field name="done_stock_moves" eval="True" />
<field
name="project_ids"
eval="[(4, ref('project_stock.project_project_tm_test'))]"
/>
</record>
</odoo>
11 changes: 11 additions & 0 deletions project_stock/demo/stock_picking_type_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="stock_picking_type_tm_test" model="stock.picking.type">
<field name="name">Task material</field>
<field name="sequence_code">TM</field>
<field name="code">outgoing</field>
<field name="warehouse_id" ref="stock.warehouse0" />
<field name="default_location_src_id" ref="stock.stock_location_stock" />
<field name="default_location_dest_id" ref="stock.stock_location_components" />
</record>
</odoo>
16 changes: 16 additions & 0 deletions project_stock/migrations/15.0.1.0.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 5 additions & 2 deletions project_stock/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions project_stock/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions project_stock/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* `Done`: Check Use Stock Moves option + Done Stock Moves and add the created project.
2 changes: 1 addition & 1 deletion project_stock/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#. Go to *Projects -> Task material (project)* and create a task and edit it.
#. *Stock Info* is displayed in the *Extra info* tab with the same project information, but it can be modified.
#. Add some product to *Stock Info* tab and set some initial demand (1 for example).
#. Click on the button *Confirm material* to confirm all moves.
#. Change the stage to Done.
#. *Stock Info* tab is readonly and some buttons show in header:
* `Confirm material`: Confirm all moves.
* `Check availability materials`: Product availability will be checked.
* `Transfer Materials`: Stock moves are confirmed and moved from one location to another.
* `Unreserve`: Remove the reservation stock of the products.
Expand Down
14 changes: 7 additions & 7 deletions project_stock/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Project Stock</title>
<style type="text/css">

Expand Down Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Project Stock</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/project/tree/14.0/project_stock"><img alt="OCA/project" src="https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/project-14-0/project-14-0-project_stock"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/140/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/project/tree/15.0/project_stock"><img alt="OCA/project" src="https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/project-15-0/project-15-0-project_stock"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/140/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module allows to consume products directly from a project task.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
Expand Down Expand Up @@ -412,10 +412,10 @@ <h1><a class="toc-backref" href="#id1">Configuration</a></h1>
</dl>
</li>
<li><dl class="first docutils">
<dt>Go to <em>Project -&gt; Configuration -&gt; Stages</em> and edit some records.</dt>
<dt>Go to <em>Project -&gt; Configuration -&gt; Task Stages</em> and edit some records.</dt>
<dd><ul class="first last">
<li><cite>In progress</cite>: Check Use Stock Moves option and add the created project.</li>
<li><cite>Done</cite>: Check Use Stock Moves option + Lock Stock Moves and add the created project.</li>
<li><cite>Done</cite>: Check Use Stock Moves option + Done Stock Moves and add the created project.</li>
</ul>
</dd>
</dl>
Expand All @@ -428,11 +428,11 @@ <h1><a class="toc-backref" href="#id2">Usage</a></h1>
<li>Go to <em>Projects -&gt; Task material (project)</em> and create a task and edit it.</li>
<li><em>Stock Info</em> is displayed in the <em>Extra info</em> tab with the same project information, but it can be modified.</li>
<li>Add some product to <em>Stock Info</em> tab and set some initial demand (1 for example).</li>
<li>Click on the button <em>Confirm material</em> to confirm all moves.</li>
<li>Change the stage to Done.</li>
<li><dl class="first docutils">
<dt><em>Stock Info</em> tab is readonly and some buttons show in header:</dt>
<dd><ul class="first last">
<li><cite>Confirm material</cite>: Confirm all moves.</li>
<li><cite>Check availability materials</cite>: Product availability will be checked.</li>
<li><cite>Transfer Materials</cite>: Stock moves are confirmed and moved from one location to another.</li>
<li><cite>Unreserve</cite>: Remove the reservation stock of the products.</li>
Expand All @@ -449,7 +449,7 @@ <h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/project/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/project/issues/new?body=module:%20project_stock%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/project/issues/new?body=module:%20project_stock%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -479,7 +479,7 @@ <h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external" href="https://github.com/victoralmau"><img alt="victoralmau" src="https://github.com/victoralmau.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/project/tree/14.0/project_stock">OCA/project</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/project/tree/15.0/project_stock">OCA/project</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
50 changes: 12 additions & 38 deletions project_stock/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,22 @@
from odoo.tests import Form, common


class TestProjectStockBase(common.SavepointCase):
class TestProjectStockBase(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.product_a = cls.env["product.product"].create(
{"name": "Test product A", "type": "product", "standard_price": 10}
{"name": "Test product A", "detailed_type": "product", "standard_price": 10}
)
cls.product_b = cls.env["product.product"].create(
{"name": "Test product B", "type": "product", "standard_price": 20}
{"name": "Test product B", "detailed_type": "product", "standard_price": 20}
)
cls.product_c = cls.env["product.product"].create(
{"name": "Test product C", "type": "product", "standard_price": 0}
)
warehouse = cls.env["stock.warehouse"].search(
[("company_id", "=", cls.env.company.id)], limit=1
)
cls.location = warehouse.lot_stock_id
cls.location_dest = cls.env["stock.location"].create(
{"name": "Test internal", "usage": "internal"}
)
cls.picking_type = cls.env["stock.picking.type"].create(
{
"name": "Test",
"code": "outgoing",
"sequence_code": "PS-TEST",
"warehouse_id": warehouse.id,
"default_location_src_id": cls.location.id,
"default_location_dest_id": cls.location_dest.id,
}
{"name": "Test product C", "detailed_type": "product", "standard_price": 0}
)
cls.picking_type = cls.env.ref("project_stock.stock_picking_type_tm_test")
cls.location = cls.picking_type.default_location_src_id
cls.location_dest = cls.picking_type.default_location_dest_id
cls.analytic_account = cls.env["account.analytic.account"].create(
{"name": "Test account"}
)
Expand All @@ -57,22 +43,10 @@ def setUpClass(cls):
],
}
)
cls.project = cls.env["project.project"].create(
{
"name": "Test project",
"analytic_account_id": cls.analytic_account.id,
"picking_type_id": cls.picking_type.id,
"location_id": cls.picking_type.default_location_src_id.id,
"location_dest_id": cls.picking_type.default_location_dest_id.id,
"stock_analytic_date": "1990-01-01",
}
)
cls.stage_in_progress = cls.env["project.task.type"].create(
{"name": "In progress", "use_stock_moves": True}
)
cls.stage_done = cls.env["project.task.type"].create(
{"name": "Done", "done_stock_moves": True}
)
cls.project = cls.env.ref("project_stock.project_project_tm_test")
cls.project.analytic_account_id = cls.analytic_account
cls.stage_in_progress = cls.env.ref("project.project_stage_1")
cls.stage_done = cls.env.ref("project.project_stage_2")

def _prepare_context_task(self):
return {
Expand All @@ -86,7 +60,7 @@ def _prepare_context_task(self):

def _create_task(self, products):
task_form = Form(
self.env["project.task"].with_context(self._prepare_context_task(self))
self.env["project.task"].with_context(**self._prepare_context_task(self))
)
task_form.name = "Test task"
# Save task to use default_get() correctlly in stock.moves
Expand Down
Loading

0 comments on commit fb3f2ed

Please sign in to comment.