[IMP] stock_removal_location_by_priority: black, isort

[MIG] stock_removal_location_by_priority: Migration to 13.0
This commit is contained in:
ps-tubtim
2019-12-18 17:37:20 +07:00
committed by Aritz Olea
parent 7c0b2dd835
commit 30968aa5f9
9 changed files with 139 additions and 117 deletions

View File

@@ -14,13 +14,13 @@ Stock Removal Location by Priority
: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_removal_location_by_priority
:target: https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_removal_location_by_priority
: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_removal_location_by_priority
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-13-0/stock-logistics-warehouse-13-0-stock_removal_location_by_priority
: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/13.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -65,7 +65,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_removal_location_by_priority%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_removal_location_by_priority%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.
@@ -82,6 +82,7 @@ Contributors
* Miquel Raïch <miquel.raich@eficent.com>
* Lois Rilo <lois.rilo@eficent.com>
* Pimolnat Suntian <pimolnats@ecosoft.co.th>
Maintainers
~~~~~~~~~~~
@@ -96,6 +97,6 @@ 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 <https://github.com/OCA/stock-logistics-warehouse/tree/12.0/stock_removal_location_by_priority>`_ project on GitHub.
This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_removal_location_by_priority>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -4,19 +4,18 @@
{
"name": "Stock Removal Location by Priority",
"summary": "Establish a removal priority on stock locations.",
"version": "12.0.1.0.0",
"author": "Eficent, "
"Odoo Community Association (OCA)",
"version": "13.0.1.0.0",
"author": "Eficent, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Warehouse",
"depends": ["stock"],
"data": [
'security/stock_security.xml',
'views/res_config_settings_views.xml',
'views/stock_location_view.xml',
"security/stock_security.xml",
"views/res_config_settings_views.xml",
"views/stock_location_view.xml",
],
"license": "AGPL-3",
'installable': True,
'application': False,
'pre_init_hook': 'pre_init_hook',
"installable": True,
"application": False,
"pre_init_hook": "pre_init_hook",
}

View File

@@ -19,30 +19,36 @@ def pre_init_hook(cr):
def set_stock_location_removal_priority_default(cr):
cr.execute("""SELECT column_name
cr.execute(
"""SELECT column_name
FROM information_schema.columns
WHERE table_name='stock_location' AND
column_name='removal_priority'""")
column_name='removal_priority'"""
)
if not cr.fetchone():
logger.info('Creating field removal_priority on stock_location')
logger.info("Creating field removal_priority on stock_location")
cr.execute(
"""
ALTER TABLE stock_location
ADD COLUMN removal_priority integer
DEFAULT 10;
""")
"""
)
def set_stock_quant_removal_priority_default(cr):
cr.execute("""SELECT column_name
cr.execute(
"""SELECT column_name
FROM information_schema.columns
WHERE table_name='stock_quant' AND
column_name='removal_priority'""")
column_name='removal_priority'"""
)
if not cr.fetchone():
logger.info('Creating field removal_priority on stock_quant')
logger.info("Creating field removal_priority on stock_quant")
cr.execute(
"""
ALTER TABLE stock_quant
ADD COLUMN removal_priority integer
DEFAULT 10;
""")
"""
)

View File

@@ -6,12 +6,11 @@ from odoo import fields, models
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
_inherit = "res.config.settings"
group_removal_priority = fields.Boolean(
string="Removal Priority",
implied_group='stock_removal_location_by_priority.'
'group_removal_priority',
implied_group="stock_removal_location_by_priority." "group_removal_priority",
help="Removal priority that applies when the incoming dates "
"are equal in both locations.",
"are equal in both locations.",
)

View File

@@ -6,10 +6,11 @@ from odoo import fields, models
class StockLocation(models.Model):
_inherit = 'stock.location'
_inherit = "stock.location"
removal_priority = fields.Integer(
string="Removal Priority", default=10,
string="Removal Priority",
default=10,
help="This priority applies when removing stock and incoming dates "
"are equal.",
"are equal.",
)

View File

@@ -2,28 +2,30 @@
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models, _
from odoo import _, api, fields, models
from odoo.exceptions import UserError
class StockQuant(models.Model):
_inherit = 'stock.quant'
_inherit = "stock.quant"
removal_priority = fields.Integer(
related='location_id.removal_priority',
store=True,
related="location_id.removal_priority", store=True
)
@api.model
def _get_removal_strategy_order(self, removal_strategy=None):
if self.user_has_groups(
'stock_removal_location_by_priority.group_removal_priority'):
if removal_strategy == 'fifo':
return 'in_date ASC NULLS FIRST, removal_priority ASC, id'
elif removal_strategy == 'lifo':
return 'in_date DESC NULLS LAST, removal_priority ASC, id desc'
raise UserError(_('Removal strategy %s not implemented.') % (
removal_strategy,))
"stock_removal_location_by_priority.group_removal_priority"
):
if removal_strategy == "fifo":
return "in_date ASC NULLS FIRST, removal_priority ASC, id"
elif removal_strategy == "lifo":
return "in_date DESC NULLS LAST, removal_priority ASC, id desc"
raise UserError(
_("Removal strategy %s not implemented.") % (removal_strategy,)
)
else:
return super()._get_removal_strategy_order(
removal_strategy=removal_strategy)
removal_strategy=removal_strategy
)

View File

@@ -1,2 +1,3 @@
* Miquel Raïch <miquel.raich@eficent.com>
* Lois Rilo <lois.rilo@eficent.com>
* Pimolnat Suntian <pimolnats@ecosoft.co.th>

View File

@@ -367,7 +367,7 @@ ul.auto-toc {
!! 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_removal_location_by_priority"><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_removal_location_by_priority"><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/13.0/stock_removal_location_by_priority"><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-13-0/stock-logistics-warehouse-13-0-stock_removal_location_by_priority"><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/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module adds a removal priority field on stock locations.
This priority applies when removing a product from different stock locations
and the incoming dates are equal in both locations.</p>
@@ -415,7 +415,7 @@ use FIFO or LIFO removal strategy.</p>
<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_removal_location_by_priority%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_removal_location_by_priority%0Aversion:%2013.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">
@@ -431,6 +431,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<ul class="simple">
<li>Miquel Raïch &lt;<a class="reference external" href="mailto:miquel.raich&#64;eficent.com">miquel.raich&#64;eficent.com</a>&gt;</li>
<li>Lois Rilo &lt;<a class="reference external" href="mailto:lois.rilo&#64;eficent.com">lois.rilo&#64;eficent.com</a>&gt;</li>
<li>Pimolnat Suntian &lt;<a class="reference external" href="mailto:pimolnats&#64;ecosoft.co.th">pimolnats&#64;ecosoft.co.th</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
@@ -440,7 +441,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/12.0/stock_removal_location_by_priority">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/13.0/stock_removal_location_by_priority">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>

View File

@@ -3,103 +3,113 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from datetime import date
from odoo.tests.common import TransactionCase
class TestStockRemovalLocationByPriority(TransactionCase):
def setUp(self):
super(TestStockRemovalLocationByPriority, self).setUp()
self.res_users_model = self.env['res.users']
self.stock_location_model = self.env['stock.location']
self.stock_warehouse_model = self.env['stock.warehouse']
self.stock_picking_model = self.env['stock.picking']
self.stock_change_model = self.env['stock.change.product.qty']
self.product_model = self.env['product.product']
self.quant_model = self.env['stock.quant']
self.res_users_model = self.env["res.users"]
self.stock_location_model = self.env["stock.location"]
self.stock_warehouse_model = self.env["stock.warehouse"]
self.stock_picking_model = self.env["stock.picking"]
self.stock_change_model = self.env["stock.change.product.qty"]
self.product_model = self.env["product.product"]
self.quant_model = self.env["stock.quant"]
self.picking_internal = self.env.ref('stock.picking_type_internal')
self.picking_out = self.env.ref('stock.picking_type_out')
self.location_supplier = self.env.ref('stock.stock_location_suppliers')
self.picking_internal = self.env.ref("stock.picking_type_internal")
self.picking_out = self.env.ref("stock.picking_type_out")
self.location_supplier = self.env.ref("stock.stock_location_suppliers")
self.company = self.env.ref('base.main_company')
self.company = self.env.ref("base.main_company")
grp_rem_priority = self.env.ref(
'stock_removal_location_by_priority.group_removal_priority')
"stock_removal_location_by_priority.group_removal_priority"
)
# We assign the group to admin, as the _get_removal_strategy_order
# method is going to be always executed as sudo.
user_admin = self.env.ref('base.user_root')
user_admin = self.env.ref("base.user_root")
user_admin.groups_id = [(4, grp_rem_priority.id, 0)]
self.wh1 = self.stock_warehouse_model.create({
'name': 'WH1',
'code': 'WH1',
})
self.wh1 = self.stock_warehouse_model.create({"name": "WH1", "code": "WH1"})
# Removal strategies:
self.fifo = self.env.ref('stock.removal_fifo')
self.lifo = self.env.ref('stock.removal_lifo')
self.fifo = self.env.ref("stock.removal_fifo")
self.lifo = self.env.ref("stock.removal_lifo")
# Create locations:
self.stock = self.stock_location_model.create({
'name': 'Stock Base',
'usage': 'internal',
})
self.shelf_A = self.stock_location_model.create({
'name': 'Shelf_A',
'usage': 'internal',
'location_id': self.stock.id,
'removal_priority': 10,
})
self.shelf_B = self.stock_location_model.create({
'name': 'Shelf_B',
'usage': 'internal',
'location_id': self.stock.id,
'removal_priority': 5,
})
self.stock_2 = self.stock_location_model.create({
'name': 'Another Stock Location',
'usage': 'internal',
})
self.stock = self.stock_location_model.create(
{"name": "Stock Base", "usage": "internal"}
)
self.shelf_A = self.stock_location_model.create(
{
"name": "Shelf_A",
"usage": "internal",
"location_id": self.stock.id,
"removal_priority": 10,
}
)
self.shelf_B = self.stock_location_model.create(
{
"name": "Shelf_B",
"usage": "internal",
"location_id": self.stock.id,
"removal_priority": 5,
}
)
self.stock_2 = self.stock_location_model.create(
{"name": "Another Stock Location", "usage": "internal"}
)
# Create a product:
self.product_1 = self.product_model.create({
'name': 'Test Product 1',
'type': 'product',
})
self.product_1 = self.product_model.create(
{"name": "Test Product 1", "type": "product"}
)
# Create quants:
today = date.today()
q1 = self.quant_model.create({
'product_id': self.product_1.id,
'location_id': self.shelf_A.id,
'quantity': 5.0,
'in_date': today,
})
q2 = self.quant_model.create({
'product_id': self.product_1.id,
'location_id': self.shelf_B.id,
'quantity': 5.0,
'in_date': today,
})
q1 = self.quant_model.create(
{
"product_id": self.product_1.id,
"location_id": self.shelf_A.id,
"quantity": 5.0,
"in_date": today,
}
)
q2 = self.quant_model.create(
{
"product_id": self.product_1.id,
"location_id": self.shelf_B.id,
"quantity": 5.0,
"in_date": today,
}
)
self.quants = q1 + q2
def _create_picking(self, picking_type, location, location_dest, qty):
picking = self.stock_picking_model.create({
'picking_type_id': picking_type.id,
'location_id': location.id,
'location_dest_id': location_dest.id,
'move_lines': [
(0, 0, {
'name': 'Test move',
'product_id': self.product_1.id,
'product_uom': self.product_1.uom_id.id,
'product_uom_qty': qty,
'location_id': location.id,
'location_dest_id': location_dest.id,
'price_unit': 2,
})]
})
picking = self.stock_picking_model.create(
{
"picking_type_id": picking_type.id,
"location_id": location.id,
"location_dest_id": location_dest.id,
"move_lines": [
(
0,
0,
{
"name": "Test move",
"product_id": self.product_1.id,
"product_uom": self.product_1.uom_id.id,
"product_uom_qty": qty,
"location_id": location.id,
"location_dest_id": location_dest.id,
"price_unit": 2,
},
)
],
}
)
return picking
def test_01_stock_removal_location_by_priority_fifo(self):
@@ -114,7 +124,8 @@ class TestStockRemovalLocationByPriority(TransactionCase):
self.assertEqual(q.removal_priority, 5)
self.assertEqual(self.quants[0].in_date, self.quants[1].in_date)
picking_1 = self._create_picking(
self.picking_internal, self.stock, self.stock_2, 5)
self.picking_internal, self.stock, self.stock_2, 5
)
picking_1.action_confirm()
picking_1.action_assign()
@@ -137,7 +148,8 @@ class TestStockRemovalLocationByPriority(TransactionCase):
self.assertEqual(q.removal_priority, 5)
self.assertEqual(self.quants[0].in_date, self.quants[1].in_date)
picking_1 = self._create_picking(
self.picking_internal, self.stock, self.stock_2, 5)
self.picking_internal, self.stock, self.stock_2, 5
)
picking_1.action_confirm()
picking_1.action_assign()