-
-
Notifications
You must be signed in to change notification settings - Fork 723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[13.0] stock_location_bin_name migration to 13.0 #806
Merged
OCA-git-bot
merged 5 commits into
OCA:13.0
from
guewen:13.0-add-stock_location_bin_name
May 28, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0b141fd
12.0 Add stock_location_bin_name (split from stock_location_zone)
grindtildeath 7f8102a
Change the area field as a related field
guewen 8ed44d0
[IMP] stock_location_bin_name: black, isort
guewen 284633c
[MIG] stock_location_bin_name: Migration to 13.0
guewen 3939415
run pre-commit with new prettiers
guewen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
setup/stock_location_bin_name/odoo/addons/stock_location_bin_name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../stock_location_bin_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2017 Syvain Van Hoof (Okia sprl) <[email protected]> | ||
# Copyright 2016-2019 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# Copyright 2019 Camptocamp SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
{ | ||
"name": "Stock Location Bin Name", | ||
"version": "13.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_position"], | ||
"data": ["views/stock_location.xml"], | ||
"installable": True, | ||
"development_status": "Alpha", | ||
"license": "AGPL-3", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import stock_location |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Copyright 2017 Syvain Van Hoof (Okia sprl) <[email protected]> | ||
# Copyright 2016-2019 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# Copyright 2019 Camptocamp SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
import string | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class PartialFormatter(string.Formatter): | ||
def __init__(self, missing="~", bad_fmt="!"): | ||
self.missing = missing | ||
self.bad_fmt = bad_fmt | ||
|
||
def get_field(self, field_name, args, kwargs): | ||
# Handle a key not found | ||
try: | ||
val = super().get_field(field_name, args, kwargs) | ||
except (KeyError, AttributeError): | ||
val = None, field_name | ||
return val | ||
|
||
def format_field(self, value, spec): | ||
# handle an invalid format | ||
if value is None: | ||
return self.missing | ||
try: | ||
return super().format_field(value, spec) | ||
except ValueError: | ||
if self.bad_fmt is not None: | ||
return self.bad_fmt | ||
else: | ||
raise | ||
|
||
|
||
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}'\n" | ||
"Missing fields are replaced by '~' and formatting errors by '!'.", | ||
) | ||
|
||
@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. | ||
values = dict(location._cache) | ||
values["area"] = area.name | ||
location.name = PartialFormatter().format(template, **values) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* Syvain Van Hoof (Okia sprl) <[email protected]> | ||
* Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
* Guewen Baconnier (Camptocamp) <[email protected]> | ||
* Akim Juillerat <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This module allows to compute automatically Bin location names based on | ||
locations attributes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?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> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still Alpha ?