From 30968aa5f9dfb9e6bd08e2e1386e8752f7d1554f Mon Sep 17 00:00:00 2001
From: ps-tubtim
Date: Wed, 18 Dec 2019 17:37:20 +0700
Subject: [PATCH] [IMP] stock_removal_location_by_priority: black, isort
[MIG] stock_removal_location_by_priority: Migration to 13.0
---
stock_removal_location_by_priority/README.rst | 11 +-
.../__manifest__.py | 17 +-
.../init_hook.py | 22 ++-
.../models/res_config_settings.py | 7 +-
.../models/stock_location.py | 7 +-
.../models/stock_quant.py | 26 +--
.../readme/CONTRIBUTORS.rst | 1 +
.../static/description/index.html | 7 +-
...test_stock_removal_location_by_priority.py | 158 ++++++++++--------
9 files changed, 139 insertions(+), 117 deletions(-)
diff --git a/stock_removal_location_by_priority/README.rst b/stock_removal_location_by_priority/README.rst
index ad12e3b1e..ff539abd0 100644
--- a/stock_removal_location_by_priority/README.rst
+++ b/stock_removal_location_by_priority/README.rst
@@ -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 `_.
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.
@@ -82,6 +82,7 @@ Contributors
* Miquel Raïch
* Lois Rilo
+* Pimolnat Suntian
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 `_ project on GitHub.
+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_removal_location_by_priority/__manifest__.py b/stock_removal_location_by_priority/__manifest__.py
index 2b296c48e..60589aea6 100644
--- a/stock_removal_location_by_priority/__manifest__.py
+++ b/stock_removal_location_by_priority/__manifest__.py
@@ -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",
}
diff --git a/stock_removal_location_by_priority/init_hook.py b/stock_removal_location_by_priority/init_hook.py
index 3774c1680..9f4c58fdb 100644
--- a/stock_removal_location_by_priority/init_hook.py
+++ b/stock_removal_location_by_priority/init_hook.py
@@ -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;
- """)
+ """
+ )
diff --git a/stock_removal_location_by_priority/models/res_config_settings.py b/stock_removal_location_by_priority/models/res_config_settings.py
index 99ef62790..fd19c6d00 100644
--- a/stock_removal_location_by_priority/models/res_config_settings.py
+++ b/stock_removal_location_by_priority/models/res_config_settings.py
@@ -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.",
)
diff --git a/stock_removal_location_by_priority/models/stock_location.py b/stock_removal_location_by_priority/models/stock_location.py
index c067823cf..bd6dfd1a3 100644
--- a/stock_removal_location_by_priority/models/stock_location.py
+++ b/stock_removal_location_by_priority/models/stock_location.py
@@ -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.",
)
diff --git a/stock_removal_location_by_priority/models/stock_quant.py b/stock_removal_location_by_priority/models/stock_quant.py
index a0b50e5dc..885f8559f 100644
--- a/stock_removal_location_by_priority/models/stock_quant.py
+++ b/stock_removal_location_by_priority/models/stock_quant.py
@@ -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
+ )
diff --git a/stock_removal_location_by_priority/readme/CONTRIBUTORS.rst b/stock_removal_location_by_priority/readme/CONTRIBUTORS.rst
index 9843f5f12..ee08c1532 100644
--- a/stock_removal_location_by_priority/readme/CONTRIBUTORS.rst
+++ b/stock_removal_location_by_priority/readme/CONTRIBUTORS.rst
@@ -1,2 +1,3 @@
* Miquel Raïch
* Lois Rilo
+* Pimolnat Suntian
diff --git a/stock_removal_location_by_priority/static/description/index.html b/stock_removal_location_by_priority/static/description/index.html
index d38250a12..a3512e411 100644
--- a/stock_removal_location_by_priority/static/description/index.html
+++ b/stock_removal_location_by_priority/static/description/index.html
@@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-

+

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.
@@ -415,7 +415,7 @@ use FIFO or LIFO removal strategy.
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.
@@ -431,6 +431,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
@@ -440,7 +441,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
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.
+
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_removal_location_by_priority/tests/test_stock_removal_location_by_priority.py b/stock_removal_location_by_priority/tests/test_stock_removal_location_by_priority.py
index b89214855..80a16036e 100644
--- a/stock_removal_location_by_priority/tests/test_stock_removal_location_by_priority.py
+++ b/stock_removal_location_by_priority/tests/test_stock_removal_location_by_priority.py
@@ -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()