Skip to content

Commit 78d7aad

Browse files
committed
[ADD] stock_location_history
1 parent 5350586 commit 78d7aad

30 files changed

+821
-192
lines changed

stock_location_history/README.rst

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
======================
2+
Stock Location History
3+
======================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:8ef2e101fc89b5c5da4407bd4a206ff4616465f468c30b5d56604b0ba2299927
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github
20+
:target: https://github.com/OCA/stock-logistics-warehouse/tree/18.0/stock_location_history
21+
:alt: OCA/stock-logistics-warehouse
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-18-0/stock-logistics-warehouse-18-0-stock_location_history
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module allows you to manage stages of location and their history.
32+
This was developed to manage silos and similar storage locations for
33+
bulk products.
34+
35+
**Table of contents**
36+
37+
.. contents::
38+
:local:
39+
40+
Configuration
41+
=============
42+
43+
- Go to Inventory > Configuration > Location Stages.
44+
45+
- Click New to create a stage and configure only the following
46+
parameters:
47+
48+
- Name
49+
- Sequence
50+
- Status: Active
51+
- Allowed Validation Groups
52+
- Allowed Stage Change Groups
53+
54+
- Set Stage Properties
55+
56+
- For each stage, specify whether it applies to one of the following
57+
categories (these fields are used for form validations):
58+
59+
- Is First
60+
- Is Final
61+
- Is Pause
62+
- Is Use
63+
64+
- Configure Stage Transitions
65+
66+
- After creating all the stages, define the allowed transitions for
67+
each stage to establish a proper flow.
68+
69+
Usage
70+
=====
71+
72+
- Go to Inventory > Operations > Locations
73+
- Open a location to see its stages and history
74+
- Use the buttons to change the stages of the location
75+
76+
\* Based on its stage, the location will be available to receive a new
77+
lot of bulk products or not.
78+
79+
Bug Tracker
80+
===========
81+
82+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/issues>`_.
83+
In case of trouble, please check there if your issue has already been reported.
84+
If you spotted it first, help us to smash it by providing a detailed and welcomed
85+
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_location_history%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
86+
87+
Do not contact contributors directly about support or help with technical issues.
88+
89+
Credits
90+
=======
91+
92+
Authors
93+
-------
94+
95+
* Open Source Integrators
96+
97+
Contributors
98+
------------
99+
100+
- Johannan Luna <jluna@opensourceintegrators.com>
101+
102+
Maintainers
103+
-----------
104+
105+
This module is maintained by the OCA.
106+
107+
.. image:: https://odoo-community.org/logo.png
108+
:alt: Odoo Community Association
109+
:target: https://odoo-community.org
110+
111+
OCA, or the Odoo Community Association, is a nonprofit organization whose
112+
mission is to support the collaborative development of Odoo features and
113+
promote its widespread use.
114+
115+
.. |maintainer-jasiel-OSI| image:: https://github.com/jasiel-OSI.png?size=40px
116+
:target: https://github.com/jasiel-OSI
117+
:alt: jasiel-OSI
118+
119+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
120+
121+
|maintainer-jasiel-OSI|
122+
123+
This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/18.0/stock_location_history>`_ project on GitHub.
124+
125+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

stock_location_history/__manifest__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
"name": "Stock Location History",
33
"version": "18.0.1.0.0",
44
"license": "AGPL-3",
5+
"website": "https://github.com/OCA/stock-logistics-warehouse",
56
"author": "Open Source Integrators, Odoo Community Association (OCA)",
67
"depends": ["stock"],
78
"category": "Stock",
89
"data": [
910
"security/ir.model.access.csv",
1011
"views/stock_location_views.xml",
11-
"views/stock_location_stage_views.xml"
12+
"views/stock_location_stage_views.xml",
1213
],
1314
"development_status": "Beta",
1415
"maintainers": ["jasiel-OSI"],
Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,71 @@
1-
from odoo import models, fields, api
2-
from odoo.exceptions import ValidationError, UserError
3-
from odoo.addons.queue_job.delay import group, chain
1+
from odoo import _, api, fields, models
2+
from odoo.exceptions import ValidationError
43

5-
from sqlalchemy import text
64

75
class StockLocation(models.Model):
86
_inherit = "stock.location"
97

108
track_stage = fields.Boolean(
119
string="Track location stage?",
1210
default=False,
13-
help="If enabled, the location stages will be tracked."
14-
)
15-
stage_id = fields.Many2one(
16-
"location.stage",
17-
string="Stage"
18-
)
19-
last_stage_id = fields.Many2one(
20-
"location.stage",
21-
string="Last stage"
11+
help="If enabled, the location stages will be tracked.",
2212
)
13+
stage_id = fields.Many2one("location.stage", string="Stage")
14+
last_stage_id = fields.Many2one("location.stage", string="Last stage")
2315
location_history_ids = fields.One2many(
24-
'location.history', 'location_id', string="Location History"
16+
"location.history", "location_id", string="Location History"
2517
)
2618
last_stage_validated = fields.Boolean(
2719
string="Is the last stage progress validated?"
2820
)
2921

30-
@api.constrains('stage_id')
22+
@api.constrains("stage_id")
3123
def check_stage_change(self):
3224
self.ensure_one()
3325

34-
if self.stage_id and not any(g in self.env.user.groups_id for g in self.stage_id.change_group_ids):
35-
raise ValidationError("Stage change not allowed for your user")
26+
if self.stage_id and not any(
27+
g in self.env.user.groups_id for g in self.stage_id.change_group_ids
28+
):
29+
raise ValidationError(_("Stage change not allowed for your user"))
3630

37-
if self.past_stage_id and self.past_stage_id.validation and not self.last_stage_validated:
38-
raise ValidationError("Validation required")
31+
if (
32+
self.past_stage_id
33+
and self.past_stage_id.validation
34+
and not self.last_stage_validated
35+
):
36+
raise ValidationError(_("Validation required"))
3937

4038
if self.stage_id != self.past_stage_id and self.past_stage_id:
4139
if not self.validate_stage_route():
42-
raise ValidationError("Invalid stage change")
40+
raise ValidationError(_("Invalid stage change"))
4341
else:
4442
if self.stage_id.is_first:
45-
self.create_location_history('free')
43+
self.create_location_history("free")
4644
elif self.stage_id.is_final:
47-
self.create_location_history('maint')
45+
self.create_location_history("maint")
4846
elif self.stage_id.is_pause:
49-
self.create_location_history('paused')
47+
self.create_location_history("paused")
5048
elif self.stage_id.is_use:
5149
if not self.verifyBDSource():
52-
raise ValidationError("Database not found")
50+
raise ValidationError(_("Database not found"))
5351
else:
5452
self.with_delay().PLC_Complete()
55-
self.create_location_history('prog')
56-
elif self.past_stage_id.is_first and not self.macrolot_product_id and self.stage_id:
57-
raise ValidationError("Product required")
53+
self.create_location_history("prog")
54+
elif (
55+
self.past_stage_id.is_first
56+
and not self.macrolot_product_id
57+
and self.stage_id
58+
):
59+
raise ValidationError(_("Product required"))
5860
elif self.past_stage_id.is_first and self.macrolot_product_id:
5961
self.create_new_macrolot()
60-
self.create_location_history('prog')
62+
self.create_location_history("prog")
6163
elif self.past_stage_id.is_pause:
62-
self.create_location_history('reg')
64+
self.create_location_history("reg")
6365
else:
64-
self.create_location_history('prog')
66+
self.create_location_history("prog")
6567
elif not self.past_stage_id and self.stage_id:
66-
self.create_location_history('free')
68+
self.create_location_history("free")
6769

6870
self.past_stage_id = self.stage_id
6971

@@ -72,17 +74,15 @@ def check_stage_change(self):
7274
else:
7375
self.last_stage_validated = True
7476

75-
@api.constrains('location_history_ids')
77+
@api.constrains("location_history_ids")
7678
def check_last_history_change(self):
77-
last_history = self.env['location.history'].search(
78-
[('location_id', '=', self.id)],
79-
order='create_date desc',
80-
limit=1
79+
last_history = self.env["location.history"].search(
80+
[("location_id", "=", self.id)], order="create_date desc", limit=1
8181
)
8282
if not last_history:
8383
self.last_stage_validated = True
8484
else:
85-
if last_history.registry_type == 'val':
85+
if last_history.registry_type == "val":
8686
self.last_stage_validated = True
8787

8888
def validate_stage_route(self):
@@ -91,22 +91,24 @@ def validate_stage_route(self):
9191
destination_ids = self.last_stage_id.allowed_destination_location_ids
9292
return self.stage_id in destination_ids
9393

94-
def create_location_history(self, type):
94+
def create_location_history(self, registry_type):
9595
history_vals = {
96-
'location_id': self.id,
97-
'before_stage_id': self.past_stage_id.id,
98-
'after_stage_id': self.stage_id.id,
99-
'registry_type': type,
100-
'user_id': self.env.uid,
96+
"location_id": self.id,
97+
"before_stage_id": self.past_stage_id.id,
98+
"after_stage_id": self.stage_id.id,
99+
"registry_type": registry_type,
100+
"user_id": self.env.uid,
101101
}
102102
if self.actual_macrolot_id:
103-
history_vals['macrolot_id'] = self.actual_macrolot_id.id
103+
history_vals["macrolot_id"] = self.actual_macrolot_id.id
104104

105-
self.env['location.history'].create(history_vals)
105+
self.env["location.history"].create(history_vals)
106106

107107
def validate_stage(self):
108-
if not any(g in self.env.user.groups_id for g in self.stage_id.validation_group_ids):
109-
raise ValidationError("Stage change not allowed for your user")
110-
else:
111-
self.create_location_history('val')
108+
if not any(
109+
g in self.env.user.groups_id for g in self.stage_id.validation_group_ids
110+
):
111+
raise ValidationError(_("Stage change not allowed for your user"))
112+
else:
113+
self.create_location_history("val")
112114
self.last_stage_validated = True
Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
from odoo import models, fields
1+
from odoo import fields, models
2+
23

34
class StockLocationHistory(models.Model):
45
_name = "stock.location.history"
56
_description = "Stock Location History"
67
_order = "registry_date desc"
78

8-
location_id = fields.Many2one(
9-
'stock.location', string="Location", required=True
10-
)
11-
before_stage_id = fields.Many2one(
12-
"location.stage",
13-
string="Previous Stage"
14-
)
15-
after_stage_id = fields.Many2one(
16-
"location.stage",
17-
string="Next Stage"
18-
)
19-
user_id = fields.Many2one(
20-
"res.users",
21-
string="Performed by"
22-
)
9+
location_id = fields.Many2one("stock.location", string="Location", required=True)
10+
before_stage_id = fields.Many2one("location.stage", string="Previous Stage")
11+
after_stage_id = fields.Many2one("location.stage", string="Next Stage")
12+
user_id = fields.Many2one("res.users", string="Performed by")
2313
registry_date = fields.Datetime(string="Record date", default=fields.Datetime.now)
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
from odoo import models, fields
1+
from odoo import fields, models
2+
23

34
class StockLocationStage(models.Model):
45
_name = "stock.location.stage"
56
_description = "Stock Location Stage"
67
_order = "sequence, name, id"
78

8-
name = fields.Char(string="Name")
9+
name = fields.Char(required=True)
910
validation = fields.Boolean(string="Requires validation?")
1011
sequence = fields.Integer(default=1)
1112
active = fields.Boolean(help="If active, the stage will be displayed")
@@ -15,34 +16,34 @@ class StockLocationStage(models.Model):
1516
"there are no record in that stage to display.",
1617
)
1718
is_closed = fields.Boolean(
18-
"Is a close stage",
19-
help="Locations in this stage are considered as closed."
19+
"Is a close stage", help="Locations in this stage are considered as closed."
2020
)
2121
is_default = fields.Boolean("Is a default stage", help="Used a default stage")
2222
next_ids = fields.Many2many(
23-
'location.stage',
24-
'location_stage_rel',
25-
'stage_id',
26-
'allowed_stage_id',
27-
string='Allowed next stages'
23+
"location.stage",
24+
"location_stage_rel",
25+
"stage_id",
26+
"allowed_stage_id",
27+
string="Allowed next stages",
2828
)
2929
is_use = fields.Boolean(
3030
string="Usage stage?",
31-
help="Mark this stage as a usage stage if raw material is being taken from the location"
31+
help="Mark this stage as a usage stage if raw material is being taken "
32+
"from the location",
3233
)
3334
validation_group_ids = fields.Many2many(
3435
"res.groups",
3536
"location_stage_validation_group_rel",
3637
"stage_id",
3738
"group_id",
3839
string="Group allowed to validate",
39-
help="Only users in this group can validate the current stage"
40+
help="Only users in this group can validate the current stage",
4041
)
4142
change_group_ids = fields.Many2many(
4243
"res.groups",
4344
"location_stage_change_group_rel",
4445
"stage_id",
4546
"group_id",
4647
string="Group allowed to change the current stage",
47-
help="Only users in this group can move the process forward from this stage"
48+
help="Only users in this group can move the process forward from this stage",
4849
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"

0 commit comments

Comments
 (0)