mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
12.0 Add stock_location_bin_name (split from stock_location_zone)
This commit is contained in:
1
stock_location_bin_name/__init__.py
Normal file
1
stock_location_bin_name/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
22
stock_location_bin_name/__manifest__.py
Normal file
22
stock_location_bin_name/__manifest__.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# Copyright 2017 Syvain Van Hoof (Okia sprl) <sylvainvh@okia.be>
|
||||
# Copyright 2016-2019 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
|
||||
# Copyright 2019 Camptocamp SA
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
||||
{
|
||||
'name': 'Stock Location Bin Name',
|
||||
'version': '12.0.1.0.0',
|
||||
'author': "BCIM, Okia, Camptocamp, Odoo Community Association (OCA)",
|
||||
'website': "https://github.com/OCA/stock-logistics-warehouse",
|
||||
'summary': "Compute bin stock location name automatically",
|
||||
'category': 'Stock Management',
|
||||
'depends': [
|
||||
'stock_location_zone',
|
||||
'stock_location_attribute',
|
||||
],
|
||||
'data': [
|
||||
'views/stock_location.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'development_status': 'Alpha',
|
||||
'license': 'AGPL-3',
|
||||
}
|
||||
1
stock_location_bin_name/models/__init__.py
Normal file
1
stock_location_bin_name/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import stock_location
|
||||
52
stock_location_bin_name/models/stock_location.py
Normal file
52
stock_location_bin_name/models/stock_location.py
Normal file
@@ -0,0 +1,52 @@
|
||||
# Copyright 2017 Syvain Van Hoof (Okia sprl) <sylvainvh@okia.be>
|
||||
# Copyright 2016-2019 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
|
||||
# Copyright 2019 Camptocamp SA
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class StockLocation(models.Model):
|
||||
|
||||
_inherit = 'stock.location'
|
||||
|
||||
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}'")
|
||||
|
||||
area = fields.Char(
|
||||
'Area',
|
||||
compute='_compute_area',
|
||||
store=True,
|
||||
)
|
||||
|
||||
@api.depends('name', 'location_kind', 'location_id.area')
|
||||
def _compute_area(self):
|
||||
for location in self:
|
||||
if location.location_kind == 'area':
|
||||
location.area = location.name
|
||||
else:
|
||||
location.area = location.location_id.area
|
||||
|
||||
@api.multi
|
||||
@api.onchange('corridor', 'row', 'rack', 'level',
|
||||
'posx', 'posy', 'posz')
|
||||
def _onchange_attribute_compute_name(self):
|
||||
for location in self:
|
||||
if not location.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)
|
||||
4
stock_location_bin_name/readme/CONTRIBUTORS.rst
Normal file
4
stock_location_bin_name/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1,4 @@
|
||||
* Syvain Van Hoof (Okia sprl) <sylvainvh@okia.be>
|
||||
* Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
|
||||
* Guewen Baconnier (Camptocamp) <guewen.baconnier@camptocamp.com>
|
||||
* Akim Juillerat <akim.juillerat@camptocamp.com>
|
||||
2
stock_location_bin_name/readme/DESCRIPTION.rst
Normal file
2
stock_location_bin_name/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1,2 @@
|
||||
This module allows to compute automatically Bin location names based on
|
||||
locations attributes.
|
||||
13
stock_location_bin_name/views/stock_location.xml
Normal file
13
stock_location_bin_name/views/stock_location.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<odoo>
|
||||
<record id="stock_location_form_inherit" model="ir.ui.view">
|
||||
<field name="name">stock.location.name.format</field>
|
||||
<field name="model">stock.location</field>
|
||||
<field name="inherit_id" ref="stock.view_location_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="usage" position="after">
|
||||
<field name="location_name_format" attrs="{'invisible': [('location_kind', '=', 'bin')]}" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user