-
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[14.0][ADD] stock_request_operating_unit, stock_request_operating_uni…
…t_access_all
- Loading branch information
Showing
21 changed files
with
1,273 additions
and
0 deletions.
There are no files selected for viewing
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,80 @@ | ||
============================ | ||
Stock Request Operating Unit | ||
============================ | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:89902efe4a64926dddc0e0f296c9588b4fb7bf94967fc6f8949385870cbecbdd | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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%2Foperating--unit-lightgray.png?logo=github | ||
:target: https://github.com/OCA/operating-unit/tree/14.0/stock_request_operating_unit | ||
:alt: OCA/operating-unit | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/operating-unit-14-0/operating-unit-14-0-stock_request_operating_unit | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/operating-unit&target_branch=14.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module introduces the operating unit to the Stock Request. | ||
Security rules are defined to ensure that users can only display | ||
the Stock Requests in which they are allowed access to. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/operating-unit/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`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**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Ecosoft | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `Ecosoft <http://ecosoft.co.th>`__: | ||
|
||
* Pimolnat Suntian <[email protected]> | ||
|
||
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/operating-unit <https://github.com/OCA/operating-unit/tree/14.0/stock_request_operating_unit>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
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,3 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
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,19 @@ | ||
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Stock Request Operating Unit", | ||
"summary": "Introduces Operating Unit (OU) in stock request", | ||
"version": "14.0.1.0.0", | ||
"author": "Ecosoft, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/operating-unit", | ||
"category": "Warehouse Management", | ||
"depends": ["stock_request", "operating_unit"], | ||
"license": "AGPL-3", | ||
"data": [ | ||
"security/stock_request_security.xml", | ||
"views/stock_request_views.xml", | ||
"views/stock_request_order_views.xml", | ||
], | ||
"installable": 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,4 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import stock_request | ||
from . import stock_request_order |
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,49 @@ | ||
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class StockRequest(models.Model): | ||
_inherit = "stock.request" | ||
|
||
operating_unit_id = fields.Many2one( | ||
comodel_name="operating.unit", | ||
string="Operating Unit", | ||
compute="_compute_operating_unit", | ||
readonly=False, | ||
store=True, | ||
) | ||
|
||
@api.depends("order_id", "order_id.operating_unit_id") | ||
def _compute_operating_unit(self): | ||
default_operating_unit = self.env["res.users"].operating_unit_default_get(self.env.uid) | ||
for record in self: | ||
if record.order_id: | ||
record.operating_unit_id = record.order_id.operating_unit_id | ||
else: | ||
record.operating_unit_id = default_operating_unit | ||
|
||
@api.constrains("operating_unit_id", "company_id") | ||
def _check_company_operating_unit(self): | ||
for record in self: | ||
if ( | ||
record.company_id | ||
and record.operating_unit_id | ||
and record.company_id != record.operating_unit_id.company_id | ||
): | ||
raise ValidationError( | ||
_( | ||
"Configuration error. The Company in the Stock Request " | ||
"and in the Operating Unit must be the same." | ||
) | ||
) | ||
|
||
def _prepare_procurement_values(self, group_id=False): | ||
""" | ||
Add operating unit to procurement values | ||
""" | ||
res = super()._prepare_procurement_values(group_id=group_id) | ||
if self.operating_unit_id: | ||
res.update({"operating_unit_id": self.operating_unit_id.id}) | ||
return res | ||
34 changes: 34 additions & 0 deletions
34
stock_request_operating_unit/models/stock_request_order.py
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,34 @@ | ||
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class StockRequestOrder(models.Model): | ||
_inherit = "stock.request.order" | ||
|
||
operating_unit_id = fields.Many2one( | ||
comodel_name="operating.unit", | ||
string="Operating Unit", | ||
default=lambda self: ( | ||
self.env["res.users"].operating_unit_default_get(self.env.uid) | ||
), | ||
readonly=True, | ||
states={"draft": [("readonly", False)]}, | ||
) | ||
|
||
@api.constrains("operating_unit_id", "company_id") | ||
def _check_company_operating_unit(self): | ||
for record in self: | ||
if ( | ||
record.company_id | ||
and record.operating_unit_id | ||
and record.company_id != record.operating_unit_id.company_id | ||
): | ||
raise ValidationError( | ||
_( | ||
"Configuration error. The Company in the Stock Request " | ||
"and in the Operating Unit must be the same." | ||
) | ||
) |
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,3 @@ | ||
* `Ecosoft <http://ecosoft.co.th>`__: | ||
|
||
* Pimolnat Suntian <[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,3 @@ | ||
This module introduces the operating unit to the Stock Request. | ||
Security rules are defined to ensure that users can only display | ||
the Stock Requests in which they are allowed access to. |
25 changes: 25 additions & 0 deletions
25
stock_request_operating_unit/security/stock_request_security.xml
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,25 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<record id="ir_rule_stock_request_order_allowed_operating_units" model="ir.rule"> | ||
<field name="model_id" ref="stock_request.model_stock_request_order" /> | ||
<field name="domain_force">['|',('operating_unit_id','=',False), | ||
('operating_unit_id','in',[g.id for g in user.operating_unit_ids])]</field> | ||
<field name="name">Stock Request Orders from allowed operating units</field> | ||
<field name="global" eval="True" /> | ||
<field eval="0" name="perm_unlink" /> | ||
<field eval="0" name="perm_write" /> | ||
<field eval="1" name="perm_read" /> | ||
<field eval="0" name="perm_create" /> | ||
</record> | ||
<record id="ir_rule_stock_request_allowed_operating_units" model="ir.rule"> | ||
<field name="model_id" ref="stock_request.model_stock_request" /> | ||
<field name="domain_force">['|',('operating_unit_id','=',False), | ||
('operating_unit_id','in',[g.id for g in user.operating_unit_ids])]</field> | ||
<field name="name">Stock Requests from allowed operating units</field> | ||
<field name="global" eval="True" /> | ||
<field eval="0" name="perm_unlink" /> | ||
<field eval="0" name="perm_write" /> | ||
<field eval="1" name="perm_read" /> | ||
<field eval="0" name="perm_create" /> | ||
</record> | ||
</odoo> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.