diff --git a/setup/stock_location_zone/odoo/addons/stock_location_zone b/setup/stock_location_zone/odoo/addons/stock_location_zone new file mode 120000 index 000000000000..7d216d8f919f --- /dev/null +++ b/setup/stock_location_zone/odoo/addons/stock_location_zone @@ -0,0 +1 @@ +../../../../stock_location_zone \ No newline at end of file diff --git a/setup/stock_location_zone/setup.py b/setup/stock_location_zone/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/stock_location_zone/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_location_zone/README.rst b/stock_location_zone/README.rst new file mode 100644 index 000000000000..1f57cd2bad63 --- /dev/null +++ b/stock_location_zone/README.rst @@ -0,0 +1,85 @@ +=================== +Stock Location Zone +=================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :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_location_zone + :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_location_zone + :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 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Add coordinate attributes on stock location. +Define picking zone with links to picking type. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +In Inventory Settings, you must have: + + * Storage Locations + +Set coordinate attibute on the locations. + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* BCIM +* Okia + +Contributors +~~~~~~~~~~~~ + +* Syvain Van Hoof (Okia sprl) +* Jacques-Etienne Baudoux (BCIM) + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_location_zone/__init__.py b/stock_location_zone/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/stock_location_zone/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_location_zone/__manifest__.py b/stock_location_zone/__manifest__.py new file mode 100644 index 000000000000..3ed81d847c12 --- /dev/null +++ b/stock_location_zone/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2017 Syvain Van Hoof (Okia sprl) +# Copyright 2016-2019 Jacques-Etienne Baudoux (BCIM) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'Stock Location Zone', + 'version': '12.0.1.0.0', + 'author': "BCIM, Okia, Camptocamp, Odoo Community Association (OCA)", + 'website': "https://github.com/OCA/stock-logistics-warehouse", + 'summary': "Add coordinate attributes on stock location. " + "Define picking zone with links to picking type.", + 'category': 'Stock Management', + 'depends': [ + 'stock', + ], + 'data': [ + 'views/stock_picking_zone.xml', + 'views/stock_location.xml', + 'security/ir.model.access.csv', + ], + 'installable': True, + 'development_status': 'Alpha', + 'license': 'AGPL-3', +} diff --git a/stock_location_zone/models/__init__.py b/stock_location_zone/models/__init__.py new file mode 100644 index 000000000000..408b07ec6496 --- /dev/null +++ b/stock_location_zone/models/__init__.py @@ -0,0 +1,2 @@ +from . import stock_picking_zone +from . import stock_location diff --git a/stock_location_zone/models/stock_location.py b/stock_location_zone/models/stock_location.py new file mode 100644 index 000000000000..d1bee86ce976 --- /dev/null +++ b/stock_location_zone/models/stock_location.py @@ -0,0 +1,144 @@ +# Copyright 2017 Sylvain Van Hoof +# Copyright 2018-2019 Jacques-Etienne Baudoux (BCIM sprl) +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from psycopg2 import sql + +from odoo import _, api, fields, models, SUPERUSER_ID +from odoo.tools.sql import index_exists, _schema + + +def create_unique_index_where(cr, indexname, tablename, expressions, where): + """Create the given unique index unless it exists.""" + if index_exists(cr, indexname): + return + + args = ', '.join(expressions) + # pylint: disable=sql-injection + cr.execute( + sql.SQL( + 'CREATE UNIQUE INDEX {} ON {} ({}) WHERE {}').format( + sql.Identifier(indexname), + sql.Identifier(tablename), + sql.SQL(args), + sql.SQL(where), + ) + ) + _schema.debug( + "Table %r: created unique index %r (%s) WHERE {}", + tablename, indexname, args, where + ) + + +class StockLocation(models.Model): + _inherit = 'stock.location' + + # FIXME: add in selection: shuttle, tray (module vertical lift) + kind = fields.Selection([ + ('zone', 'Picking Zone'), + ('area', 'Area'), + ('bin', 'Bin')], + string='Kind') + + picking_zone_id = fields.Many2one( + 'stock.picking.zone', + string='Picking zone', + index=True, + ) + + picking_type_id = fields.Many2one( + related='picking_zone_id.picking_type_id', + help="Picking type for operations from this location", + oldname='barcode_picking_type_id') + + area = fields.Char( + 'Area', + compute='_compute_area', store=True, + oldname='zone') + + @api.depends('name', 'kind', 'location_id.area') + def _compute_area(self): + for location in self: + if location.kind == 'area': + location.area = location.name + else: + location.area = location.location_id.area + + corridor = fields.Char('Corridor', help="Street") + row = fields.Char('Row', help="Side in the street") + rack = fields.Char('Rack', oldname='shelf', help="House number") + level = fields.Char('Level', help="Height on the shelf") + posx = fields.Integer('Box (X)') + posy = fields.Integer('Box (Y)') + posz = fields.Integer('Box (Z)') + + location_name_format = fields.Char( + 'Location Name Format', + help="Format string that will compute the name of the location. " + "Use location fields. Example: " + "'{area}-{corridor:0>2}.{rack:0>3}" + ".{level:0>2}'") + + @api.multi + @api.onchange('corridor', 'row', 'rack', 'level', + 'posx', 'posy', 'posz') + def _compute_name(self): + for location in self: + if not location.kind == 'bin': + continue + area = location + while area and not area.location_name_format: + area = area.location_id + if not area: + continue + template = area.location_name_format + # We don't want to use the full browse record as it would + # give too much access to internals for the users. + # We cannot use location.read() as we may have a NewId. + # We should have the record's values in the cache at this + # point. We must be cautious not to leak an environment through + # relational fields. + location.name = template.format(**location._cache) + + @api.multi + @api.returns('self', lambda value: value.id) + def copy(self, default=None): + self.ensure_one() + default = dict(default or {}) + if 'name' not in default: + default['name'] = _("%s (copy)") % (self.name) + return super().copy(default=default) + + @api.model_cr + def init(self): + env = api.Environment(self._cr, SUPERUSER_ID, {}) + self._init_zone_index(env) + + def _init_zone_index(self, env): + """Add unique index on name per zone + + We cannot use _sql_constraints because it doesn't support + WHERE conditions. We need to apply the unique constraint + only within the same zone, otherwise the constraint fails + even on demo data (locations created automatically for + warehouses). + """ + index_name = 'stock_location_unique_name_zone_index' + create_unique_index_where( + env.cr, index_name, self._table, + ['name', 'picking_zone_id'], + 'picking_zone_id IS NOT NULL' + ) + + @classmethod + def _init_constraints_onchanges(cls): + # As the unique index created in this model acts as a unique + # constraints but cannot be registered in '_sql_constraints' + # (it doesn't support WHERE clause), associate an error + # message manually (reproduce what _sql_constraints does). + key = 'unique_name_zone' + message = ('Another location with the same name exists in the same' + ' zone. Please rename the location.') + cls.pool._sql_error[cls._table + '_' + key] = message + super()._init_constraints_onchanges() diff --git a/stock_location_zone/models/stock_picking_zone.py b/stock_location_zone/models/stock_picking_zone.py new file mode 100644 index 000000000000..57d586c11f9b --- /dev/null +++ b/stock_location_zone/models/stock_picking_zone.py @@ -0,0 +1,26 @@ +# Copyright 2017 Syvain Van Hoof (Okia sprl) +# Copyright 2017-2019 Jacques-Etienne Baudoux (BCIM sprl) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class PickingZone(models.Model): + _name = 'stock.picking.zone' + _description = "Stock Picking Zone" + + name = fields.Char('Name', required=True, translate=True) + code = fields.Char('Code', required=True) + picking_type_id = fields.Many2one( + 'stock.picking.type', + string='Pick Type', + help="Picking type for operations from this location", + ) + + _sql_constraints = [ + ( + 'unique_picking_zone', + 'unique (code)', + 'The picking zone code must be unique', + ) + ] diff --git a/stock_location_zone/readme/CONFIGURE.rst b/stock_location_zone/readme/CONFIGURE.rst new file mode 100644 index 000000000000..1d20f0c1ce78 --- /dev/null +++ b/stock_location_zone/readme/CONFIGURE.rst @@ -0,0 +1,5 @@ +In Inventory Settings, you must have: + + * Storage Locations + +Set coordinate attibute on the locations. diff --git a/stock_location_zone/readme/CONTRIBUTORS.rst b/stock_location_zone/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..8ef4d90eb11c --- /dev/null +++ b/stock_location_zone/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Syvain Van Hoof (Okia sprl) +* Jacques-Etienne Baudoux (BCIM) +* Guewen Baconnier (Camptocamp) diff --git a/stock_location_zone/readme/DESCRIPTION.rst b/stock_location_zone/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..ba44b8538e7e --- /dev/null +++ b/stock_location_zone/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +Add coordinate attributes on stock location. +Define picking zone with links to picking type. diff --git a/stock_location_zone/security/ir.model.access.csv b/stock_location_zone/security/ir.model.access.csv new file mode 100644 index 000000000000..af447933955b --- /dev/null +++ b/stock_location_zone/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_picking_zone,access_picking_zone,model_stock_picking_zone,base.group_user,1,0,0,0 +access_picking_zone_manager,access_picking_zone_manager,model_stock_picking_zone,base.group_system,1,1,1,1 diff --git a/stock_location_zone/static/description/index.html b/stock_location_zone/static/description/index.html new file mode 100644 index 000000000000..8f68ab0bb566 --- /dev/null +++ b/stock_location_zone/static/description/index.html @@ -0,0 +1,433 @@ + + + + + + +Stock Location Zone + + + +
+

Stock Location Zone

+ + +

Beta License: AGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runbot

+

Add coordinate attributes on stock location. +Define picking zone with links to picking type.

+

Table of contents

+ +
+

Configuration

+

In Inventory Settings, you must have:

+
+
    +
  • Storage Locations
  • +
+
+

Set coordinate attibute on the locations.

+
+
+

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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • BCIM
  • +
  • Okia
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/stock_location_zone/views/stock_location.xml b/stock_location_zone/views/stock_location.xml new file mode 100644 index 000000000000..aa2fdd5b2900 --- /dev/null +++ b/stock_location_zone/views/stock_location.xml @@ -0,0 +1,47 @@ + + + + + stock.location.zone + stock.location + + + + + + + + + + + + + + + + + + + + + + + view.location.search.inherit + stock.location + + + + + + + + + + + + + + + + + diff --git a/stock_location_zone/views/stock_picking_zone.xml b/stock_location_zone/views/stock_picking_zone.xml new file mode 100644 index 000000000000..9ac330587a81 --- /dev/null +++ b/stock_location_zone/views/stock_picking_zone.xml @@ -0,0 +1,41 @@ + + + + stock.picking.zone.view.filter + stock.picking.zone + + + + + + + + + stock.picking.zone.view.tree + stock.picking.zone + + + + + + + + + + + Picking Zones + stock.picking.zone + ir.actions.act_window + form + +

+ Define the picking zones of your warehouses +

+
+
+ + +