Skip to content

Commit

Permalink
[14.0][ADD] stock_request_operating_unit, stock_request_operating_uni…
Browse files Browse the repository at this point in the history
…t_access_all
  • Loading branch information
ps-tubtim committed Sep 23, 2023
1 parent ca6dd21 commit 89de2f3
Show file tree
Hide file tree
Showing 21 changed files with 1,273 additions and 0 deletions.
80 changes: 80 additions & 0 deletions stock_request_operating_unit/README.rst
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.
3 changes: 3 additions & 0 deletions stock_request_operating_unit/__init__.py
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
19 changes: 19 additions & 0 deletions stock_request_operating_unit/__manifest__.py
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,
}
4 changes: 4 additions & 0 deletions stock_request_operating_unit/models/__init__.py
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
49 changes: 49 additions & 0 deletions stock_request_operating_unit/models/stock_request.py
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)

Check warning on line 20 in stock_request_operating_unit/models/stock_request.py

View check run for this annotation

Codecov / codecov/patch

stock_request_operating_unit/models/stock_request.py#L20

Added line #L20 was not covered by tests
for record in self:
if record.order_id:
record.operating_unit_id = record.order_id.operating_unit_id

Check warning on line 23 in stock_request_operating_unit/models/stock_request.py

View check run for this annotation

Codecov / codecov/patch

stock_request_operating_unit/models/stock_request.py#L23

Added line #L23 was not covered by tests
else:
record.operating_unit_id = default_operating_unit

Check warning on line 25 in stock_request_operating_unit/models/stock_request.py

View check run for this annotation

Codecov / codecov/patch

stock_request_operating_unit/models/stock_request.py#L25

Added line #L25 was not covered by tests

@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(

Check warning on line 35 in stock_request_operating_unit/models/stock_request.py

View check run for this annotation

Codecov / codecov/patch

stock_request_operating_unit/models/stock_request.py#L35

Added line #L35 was not covered by tests
_(
"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)

Check warning on line 46 in stock_request_operating_unit/models/stock_request.py

View check run for this annotation

Codecov / codecov/patch

stock_request_operating_unit/models/stock_request.py#L46

Added line #L46 was not covered by tests
if self.operating_unit_id:
res.update({"operating_unit_id": self.operating_unit_id.id})
return res

Check warning on line 49 in stock_request_operating_unit/models/stock_request.py

View check run for this annotation

Codecov / codecov/patch

stock_request_operating_unit/models/stock_request.py#L48-L49

Added lines #L48 - L49 were not covered by tests
34 changes: 34 additions & 0 deletions stock_request_operating_unit/models/stock_request_order.py
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(

Check warning on line 29 in stock_request_operating_unit/models/stock_request_order.py

View check run for this annotation

Codecov / codecov/patch

stock_request_operating_unit/models/stock_request_order.py#L29

Added line #L29 was not covered by tests
_(
"Configuration error. The Company in the Stock Request "
"and in the Operating Unit must be the same."
)
)
3 changes: 3 additions & 0 deletions stock_request_operating_unit/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Ecosoft <http://ecosoft.co.th>`__:

* Pimolnat Suntian <[email protected]>
3 changes: 3 additions & 0 deletions stock_request_operating_unit/readme/DESCRIPTION.rst
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 stock_request_operating_unit/security/stock_request_security.xml
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.
Loading

0 comments on commit 89de2f3

Please sign in to comment.