Skip to content

Commit

Permalink
[MIG] stock_putaway_product_template: Migration to 13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
victoralmau committed Feb 10, 2021
1 parent cd4680d commit f71dea3
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 217 deletions.
6 changes: 6 additions & 0 deletions setup/stock_putaway_product_template/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
10 changes: 5 additions & 5 deletions stock_putaway_product_template/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Putaway strategies on product form view
: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/12.0/stock_putaway_product_form
:target: https://github.com/OCA/stock-logistics-warehouse/tree/1.0/stock_putaway_product_template
: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-12-0/stock-logistics-warehouse-12-0-stock_putaway_product_form
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-12-0/stock-logistics-warehouse-12-0-stock_putaway_product_template
: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/12.0
:target: https://runbot.odoo-community.org/runbot/153/1.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -45,7 +45,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/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/stock-logistics-warehouse/issues/new?body=module:%20stock_putaway_product_form%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_putaway_product_template%0Aversion:%2013.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 @@ -92,6 +92,6 @@ Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-kevinkhao| |maintainer-sebastienbeau|

This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/12.0/stock_putaway_product_form>`_ project on GitHub.
This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_putaway_product_template>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 0 additions & 2 deletions stock_putaway_product_template/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
from . import tests
from .hooks import post_init_hook
6 changes: 2 additions & 4 deletions stock_putaway_product_template/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
{
"name": "Putaway strategies on product form view",
"summary": "Edit putaway strategies directly from the product form view",
"version": "12.0.1.0.0",
"version": "13.0.1.0.0",
"category": "Inventory",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"author": "Akretion, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["stock"],
"external_dependencies": {"python": ["openupgradelib"]},
"data": ["views/product.xml"],
"data": ["views/stock_putaway_rule_views.xml"],
"demo": ["demo/putaway_strategies.xml"],
"maintainers": ["kevinkhao", "sebastienbeau"],
"post_init_hook": "post_init_hook",
}
42 changes: 21 additions & 21 deletions stock_putaway_product_template/demo/putaway_strategies.xml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<?xml version="1.0" ?>
<odoo>
<!--Shows simplest case for categories -->
<record id="putaway_strat_1" model="product.putaway">
<field name="name">Putaway Strategy 1</field>
</record>
<record id="putaway_strat_1_line_1" model="stock.fixed.putaway.strat">
<odoo noupdate="1">
<record id="putaway_rule_1" model="stock.putaway.rule">
<field name="sequence">1</field>
<field name="company_id" ref="stock.res_company_1" />
<field name="product_id" ref="product.product_product_11" />
<field name="putaway_id" ref="stock_putaway_product_form.putaway_strat_1" />
<field name="fixed_location_id" ref="stock.stock_location_shop0" />
<field name="location_in_id" ref="stock.stock_location_shop0" />
<field name="location_out_id" ref="stock.stock_location_shop0" />
</record>
<record id="putaway_strat_1_line_2" model="stock.fixed.putaway.strat">
<record id="putaway_rule_2" model="stock.putaway.rule">
<field name="sequence">2</field>
<field name="company_id" ref="stock.res_company_1" />
<field name="category_id" ref="product.product_category_5" />
<field name="putaway_id" ref="stock_putaway_product_form.putaway_strat_1" />
<field name="fixed_location_id" ref="stock.stock_location_shop0" />
</record>
<!--Shows inherited case for categories-->
<record id="putaway_strat_2" model="product.putaway">
<field name="name">Putaway Strategy 2</field>
<field name="location_in_id" ref="stock.stock_location_shop0" />
<field name="location_out_id" ref="stock.stock_location_shop0" />
</record>
<record id="putaway_strat_2_line_1" model="stock.fixed.putaway.strat">
<record id="putaway_rule_3" model="stock.putaway.rule">
<field name="sequence">3</field>
<field name="company_id" ref="stock.res_company_1" />
<field name="category_id" ref="product.product_category_1" />
<field name="putaway_id" ref="stock_putaway_product_form.putaway_strat_2" />
<field name="fixed_location_id" ref="stock.stock_location_stock" />
<field name="location_in_id" ref="stock.stock_location_shop0" />
<field name="location_out_id" ref="stock.stock_location_shop0" />
</record>
<record id="putaway_strat_2_line_2" model="stock.fixed.putaway.strat">
<record id="putaway_rule_4" model="stock.putaway.rule">
<field name="sequence">4</field>
<field name="company_id" ref="stock.res_company_1" />
<field name="category_id" ref="product.product_category_all" />
<field name="putaway_id" ref="stock_putaway_product_form.putaway_strat_2" />
<field name="fixed_location_id" ref="stock.stock_location_stock" />
<field name="location_in_id" ref="stock.stock_location_shop0" />
<field name="location_out_id" ref="stock.stock_location_shop0" />
</record>
</odoo>
21 changes: 0 additions & 21 deletions stock_putaway_product_template/hooks.py

This file was deleted.

2 changes: 1 addition & 1 deletion stock_putaway_product_template/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from . import product_product
from . import product_template
from . import putaway_strategy
from . import stock_putaway_rule
3 changes: 2 additions & 1 deletion stock_putaway_product_template/models/product_product.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright 2020 Víctor Martínez - Tecnativa

from odoo import fields, models

Expand All @@ -7,7 +8,7 @@ class ProductProduct(models.Model):
_inherit = "product.product"

product_product_putaway_ids = fields.One2many(
comodel_name="stock.fixed.putaway.strat",
comodel_name="stock.putaway.rule",
inverse_name="product_id",
string="Product putaway strategies by product variant",
)
26 changes: 5 additions & 21 deletions stock_putaway_product_template/models/product_template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright 2020 Víctor Martínez - Tecnativa

from odoo import api, fields, models

Expand All @@ -7,27 +8,17 @@ class ProductTemplate(models.Model):
_inherit = "product.template"

product_tmpl_putaway_ids = fields.One2many(
comodel_name="stock.fixed.putaway.strat",
comodel_name="stock.putaway.rule",
inverse_name="product_tmpl_id",
string="Product putaway strategies by product",
)

product_putaway_categ_ids = fields.Many2many(
comodel_name="stock.fixed.putaway.strat",
comodel_name="stock.putaway.rule",
string="Product putaway strategies by category",
compute="_compute_putaway_categ_ids",
)

def _find_closest_categ_match(self, categ, putaway_lines):
"""Returns the putaway line with the nearest product category"""
lines_match_categ = putaway_lines.filtered(lambda r: r.category_id == categ)
if lines_match_categ:
return lines_match_categ[0]
elif categ.parent_id:
return self._find_closest_categ_match(categ.parent_id, putaway_lines)
else:
return self.env["stock.fixed.putaway.strat"]

def _get_categ_and_parents(self, categ):
parent_categ_iterator = categ
res = self.env["product.category"]
Expand All @@ -42,17 +33,10 @@ def _compute_putaway_categ_ids(self):
i.e closest to our product category's parents)
putaway.strat per product.putaway"""
for rec in self:
res = self.env["stock.fixed.putaway.strat"]
categ = rec.categ_id
categs = self._get_categ_and_parents(categ)
# get matching lines from our category or its parents
product_putaway_categ_lines = self.env["stock.fixed.putaway.strat"].search(
rules = self.env["stock.putaway.rule"].search(
[("category_id", "in", categs.ids)]
)
# from these, get the matching putaway.strats and find
# the lowest-level category match
product_putaways = product_putaway_categ_lines.mapped("putaway_id")
for el in product_putaways:
lines = el.fixed_location_ids
res += self._find_closest_categ_match(categ, lines)
rec.product_putaway_categ_ids = res
rec.product_putaway_categ_ids = rules
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright 2020 Sergio Teruel - Tecnativa <sergio.teruel@tecnativa.com>
# Copyright 2020 Sergio Teruel - Tecnativa
# Copyright 2020 Víctor Martínez - Tecnativa

from odoo import api, fields, models


class PutAwayStrategy(models.Model):
_inherit = "product.putaway"

# Remove product domain to allow to select product templates
product_location_ids = fields.One2many(domain=[])

def _get_putaway_rule(self, product):
return super(
PutAwayStrategy, self.with_context(filter_putaway_rule=True)
)._get_putaway_rule(product)


class FixedPutAwayStrategy(models.Model):
_inherit = "stock.fixed.putaway.strat"
class StockPutawayRule(models.Model):
_inherit = "stock.putaway.rule"

product_tmpl_id = fields.Many2one(
comodel_name="product.template",
compute="_compute_product_tmpl_id",
store=True,
inverse=lambda self: self,
readonly=False,
ondelete="cascade",
)

@api.depends("product_id")
def _compute_product_tmpl_id(self):
for rec in self:
rec.product_tmpl_id = False
if rec.product_id:
rec.product_tmpl_id = rec.product_id.product_tmpl_id
else:
Expand All @@ -38,7 +28,7 @@ def _compute_product_tmpl_id(self):
rec.product_tmpl_id = params.get("id", False)

def filtered(self, func):
res = super(FixedPutAwayStrategy, self).filtered(func)
res = super(StockPutawayRule, self).filtered(func)
if res or not self.env.context.get("filter_putaway_rule"):
return res
product = func.__closure__[0].cell_contents
Expand Down
1 change: 1 addition & 0 deletions stock_putaway_product_template/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
* `Tecnativa <https://www.tecnativa.com>`_:

* Sergio Teruel
* Víctor Martínez
6 changes: 3 additions & 3 deletions stock_putaway_product_template/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Putaway strategies on product form view</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/stock-logistics-warehouse/tree/12.0/stock_putaway_product_form"><img alt="OCA/stock-logistics-warehouse" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/stock-logistics-warehouse-12-0/stock-logistics-warehouse-12-0-stock_putaway_product_form"><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/153/12.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/stock-logistics-warehouse/tree/12.0/stock_putaway_product_template"><img alt="OCA/stock-logistics-warehouse" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/stock-logistics-warehouse-12-0/stock-logistics-warehouse-12-0-stock_putaway_product_template"><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/153/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module adds an easy way to modify product-specific putaway strategies from the product view for a better UX.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
Expand Down Expand Up @@ -395,7 +395,7 @@ <h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/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/stock-logistics-warehouse/issues/new?body=module:%20stock_putaway_product_form%0Aversion:%2012.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/stock-logistics-warehouse/issues/new?body=module:%20stock_putaway_product_template%0Aversion:%2012.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 @@ -428,7 +428,7 @@ <h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external" href="https://github.com/kevinkhao"><img alt="kevinkhao" src="https://github.com/kevinkhao.png?size=40px" /></a> <a class="reference external" href="https://github.com/sebastienbeau"><img alt="sebastienbeau" src="https://github.com/sebastienbeau.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/12.0/stock_putaway_product_form">OCA/stock-logistics-warehouse</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/12.0/stock_putaway_product_template">OCA/stock-logistics-warehouse</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

0 comments on commit f71dea3

Please sign in to comment.