Skip to content

Commit 455ef30

Browse files
committed
[14.0][ADD] stock_request_operating_unit, stock_request_operating_unit_access_all
1 parent ca6dd21 commit 455ef30

File tree

25 files changed

+1290
-0
lines changed

25 files changed

+1290
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../stock_request_operating_unit
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../stock_request_operating_unit_access_all
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
============================
2+
Stock Request Operating Unit
3+
============================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:89902efe4a64926dddc0e0f296c9588b4fb7bf94967fc6f8949385870cbecbdd
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%2Foperating--unit-lightgray.png?logo=github
20+
:target: https://github.com/OCA/operating-unit/tree/14.0/stock_request_operating_unit
21+
:alt: OCA/operating-unit
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/operating-unit-14-0/operating-unit-14-0-stock_request_operating_unit
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/operating-unit&target_branch=14.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module introduces the operating unit to the Stock Request.
32+
Security rules are defined to ensure that users can only display
33+
the Stock Requests in which they are allowed access to.
34+
35+
**Table of contents**
36+
37+
.. contents::
38+
:local:
39+
40+
Bug Tracker
41+
===========
42+
43+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/operating-unit/issues>`_.
44+
In case of trouble, please check there if your issue has already been reported.
45+
If you spotted it first, help us to smash it by providing a detailed and welcomed
46+
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20stock_request_operating_unit%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
47+
48+
Do not contact contributors directly about support or help with technical issues.
49+
50+
Credits
51+
=======
52+
53+
Authors
54+
~~~~~~~
55+
56+
* Ecosoft
57+
58+
Contributors
59+
~~~~~~~~~~~~
60+
61+
* `Ecosoft <http://ecosoft.co.th>`__:
62+
63+
* Pimolnat Suntian <pimolnats@ecosoft.co.th>
64+
65+
Maintainers
66+
~~~~~~~~~~~
67+
68+
This module is maintained by the OCA.
69+
70+
.. image:: https://odoo-community.org/logo.png
71+
:alt: Odoo Community Association
72+
:target: https://odoo-community.org
73+
74+
OCA, or the Odoo Community Association, is a nonprofit organization whose
75+
mission is to support the collaborative development of Odoo features and
76+
promote its widespread use.
77+
78+
This module is part of the `OCA/operating-unit <https://github.com/OCA/operating-unit/tree/14.0/stock_request_operating_unit>`_ project on GitHub.
79+
80+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
2+
3+
from . import models
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Stock Request Operating Unit",
6+
"summary": "Introduces Operating Unit (OU) in stock request",
7+
"version": "14.0.1.0.0",
8+
"author": "Ecosoft, Odoo Community Association (OCA)",
9+
"website": "https://github.com/OCA/operating-unit",
10+
"category": "Warehouse Management",
11+
"depends": ["stock_request", "operating_unit"],
12+
"license": "AGPL-3",
13+
"data": [
14+
"security/stock_request_security.xml",
15+
"views/stock_request_views.xml",
16+
"views/stock_request_order_views.xml",
17+
],
18+
"installable": True,
19+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
2+
3+
from . import stock_request
4+
from . import stock_request_order
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import _, api, fields, models
5+
from odoo.exceptions import ValidationError
6+
7+
8+
class StockRequest(models.Model):
9+
_inherit = "stock.request"
10+
11+
operating_unit_id = fields.Many2one(
12+
comodel_name="operating.unit",
13+
string="Operating Unit",
14+
compute="_compute_operating_unit",
15+
readonly=False,
16+
store=True,
17+
)
18+
19+
@api.depends("order_id", "order_id.operating_unit_id")
20+
def _compute_operating_unit(self):
21+
default_operating_unit = self.env["res.users"].operating_unit_default_get(
22+
self.env.uid
23+
)
24+
for record in self:
25+
if record.order_id:
26+
record.operating_unit_id = record.order_id.operating_unit_id
27+
else:
28+
record.operating_unit_id = default_operating_unit
29+
30+
@api.constrains("operating_unit_id", "company_id")
31+
def _check_company_operating_unit(self):
32+
for record in self:
33+
if (
34+
record.company_id
35+
and record.operating_unit_id
36+
and record.company_id != record.operating_unit_id.company_id
37+
):
38+
raise ValidationError(
39+
_(
40+
"Configuration error. The Company in the Stock Request "
41+
"and in the Operating Unit must be the same."
42+
)
43+
)
44+
45+
def _prepare_procurement_values(self, group_id=False):
46+
"""
47+
Add operating unit to procurement values
48+
"""
49+
res = super()._prepare_procurement_values(group_id=group_id)
50+
if self.operating_unit_id:
51+
res.update({"operating_unit_id": self.operating_unit_id.id})
52+
return res
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import _, api, fields, models
5+
from odoo.exceptions import ValidationError
6+
7+
8+
class StockRequestOrder(models.Model):
9+
_inherit = "stock.request.order"
10+
11+
operating_unit_id = fields.Many2one(
12+
comodel_name="operating.unit",
13+
string="Operating Unit",
14+
default=lambda self: (
15+
self.env["res.users"].operating_unit_default_get(self.env.uid)
16+
),
17+
readonly=True,
18+
states={"draft": [("readonly", False)]},
19+
)
20+
21+
@api.constrains("operating_unit_id", "company_id")
22+
def _check_company_operating_unit(self):
23+
for record in self:
24+
if (
25+
record.company_id
26+
and record.operating_unit_id
27+
and record.company_id != record.operating_unit_id.company_id
28+
):
29+
raise ValidationError(
30+
_(
31+
"Configuration error. The Company in the Stock Request "
32+
"and in the Operating Unit must be the same."
33+
)
34+
)

0 commit comments

Comments
 (0)