Skip to content

Commit

Permalink
[ADD] mrp_stock_owner_restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed May 31, 2024
1 parent da308c1 commit a9e376b
Show file tree
Hide file tree
Showing 17 changed files with 802 additions and 0 deletions.
79 changes: 79 additions & 0 deletions mrp_stock_owner_restriction/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
===========================
MRP Stock Owner Restriction
===========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:00dc2315a91f43ef42e2ae6f4d5657da81307bbe2f4856dd21bc1f3d48c7ee86
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fmanufacture-lightgray.png?logo=github
:target: https://github.com/OCA/manufacture/tree/16.0/mrp_stock_owner_restriction
:alt: OCA/manufacture
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/manufacture-16-0/manufacture-16-0-mrp_stock_owner_restriction
: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/manufacture&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module adapts the functionality of stock_owner_restriction in the manufacturing
order.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/manufacture/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/manufacture/issues/new?body=module:%20mrp_stock_owner_restriction%0Aversion:%2016.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
~~~~~~~

* Quartile Limited

Contributors
~~~~~~~~~~~~

* `Quartile <https://www.quartile.co>`_:

* Yoshi Tashiro

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/manufacture <https://github.com/OCA/manufacture/tree/16.0/mrp_stock_owner_restriction>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions mrp_stock_owner_restriction/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions mrp_stock_owner_restriction/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2023 Quartile Limited
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "MRP Stock Owner Restriction",
"version": "16.0.1.0.0",
"category": "Manufacturing",
"website": "https://github.com/OCA/manufacture",
"author": "Quartile Limited, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["mrp", "stock_owner_restriction"],
"data": ["views/mrp_production_views.xml"],
"installable": True,
}
46 changes: 46 additions & 0 deletions mrp_stock_owner_restriction/i18n/ja.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mrp_stock_owner_restriction
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-04-12 07:13+0000\n"
"PO-Revision-Date: 2023-04-12 07:13+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: mrp_stock_owner_restriction
#: model:ir.model.fields,field_description:mrp_stock_owner_restriction.field_mrp_production__owner_id
msgid "Assign Owner"
msgstr "オーナー割当"

#. module: mrp_stock_owner_restriction
#: model:ir.model.fields,field_description:mrp_stock_owner_restriction.field_mrp_production__owner_restriction
msgid "Owner Restriction"
msgstr "オーナー制限"

#. module: mrp_stock_owner_restriction
#: model:ir.model.fields,help:mrp_stock_owner_restriction.field_mrp_production__owner_id
msgid "Produced products will be assigned to this owner."
msgstr "生産された製品は、このオーナーに割り当てられます。"

#. module: mrp_stock_owner_restriction
#: model:ir.model,name:mrp_stock_owner_restriction.model_stock_move_line
msgid "Product Moves (Stock Move Line)"
msgstr "製品の移動(在庫移動ライン)"

#. module: mrp_stock_owner_restriction
#: model:ir.model,name:mrp_stock_owner_restriction.model_mrp_production
msgid "Production Order"
msgstr "製造オーダ"

#. module: mrp_stock_owner_restriction
#: model:ir.model,name:mrp_stock_owner_restriction.model_stock_move
msgid "Stock Move"
msgstr "在庫移動"
4 changes: 4 additions & 0 deletions mrp_stock_owner_restriction/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import mrp_production
from . import mrp_unbuild
from . import stock_move_line
from . import stock_move
26 changes: 26 additions & 0 deletions mrp_stock_owner_restriction/models/mrp_production.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2023 Quartile Limited
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class MrpProduction(models.Model):
_inherit = "mrp.production"

owner_id = fields.Many2one(
"res.partner",
"Assign Owner",
readonly=True,
states={"draft": [("readonly", False)], "confirmed": [("readonly", False)]},
check_company=True,
help="Produced products will be assigned to this owner.",
)
owner_restriction = fields.Selection(related="picking_type_id.owner_restriction")

def write(self, vals):
if "owner_id" in vals:
for production in self:
owner_restriction = self.picking_type_id.owner_restriction

Check warning on line 23 in mrp_stock_owner_restriction/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_stock_owner_restriction/models/mrp_production.py#L23

Added line #L23 was not covered by tests
if owner_restriction in ("unassigned_owner", "picking_partner"):
production.move_line_raw_ids.unlink()

Check warning on line 25 in mrp_stock_owner_restriction/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_stock_owner_restriction/models/mrp_production.py#L25

Added line #L25 was not covered by tests
return super().write(vals)
26 changes: 26 additions & 0 deletions mrp_stock_owner_restriction/models/mrp_unbuild.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2023 Quartile Limited
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class MrpUnbuild(models.Model):
_inherit = "mrp.unbuild"

# FIXME handle unbuild cases without MO
# owner_id = fields.Many2one(
# "res.partner",
# "Assign Owner",
# readonly=True,
# states={"draft": [("readonly", False)], "confirmed": [("readonly", False)]},
# check_company=True,
# help="Produced products will be assigned to this owner.",
# )
# owner_restriction = fields.Selection(related="picking_type_id.owner_restriction")

def action_validate(self):
owner_restriction = self.mo_id.picking_type_id.owner_restriction
owner = self.mo_id.owner_id
if owner and owner_restriction in ("unassigned_owner", "picking_partner"):
self = self.with_context(force_restricted_owner_id=owner)

Check warning on line 25 in mrp_stock_owner_restriction/models/mrp_unbuild.py

View check run for this annotation

Codecov / codecov/patch

mrp_stock_owner_restriction/models/mrp_unbuild.py#L25

Added line #L25 was not covered by tests
return super().action_validate()
42 changes: 42 additions & 0 deletions mrp_stock_owner_restriction/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2023 Quartile Limited
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models


class StockMove(models.Model):
_inherit = "stock.move"

# Just to add a trigger
@api.depends("production_id.owner_id")
def _compute_restrict_partner_id(self):
return super()._compute_restrict_partner_id()

Check warning on line 13 in mrp_stock_owner_restriction/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_stock_owner_restriction/models/stock_move.py#L13

Added line #L13 was not covered by tests

def _get_mo_to_unbuild(self):
self.ensure_one()
return self.consume_unbuild_id.mo_id or self.unbuild_id.mo_id

def _get_owner_for_assign(self):
self.ensure_one()
if self.raw_material_production_id:
return self.raw_material_production_id.owner_id
# Manufactured product should not consider the owner for assignment, or the
# result might be messed up (e.g. tries to move stock from the internal location
# instead of the production location).
if self.production_id:
return False
# For chained origin moves for production component moves.
production = self.move_dest_ids.raw_material_production_id
if production:
return production.owner_id

Check warning on line 31 in mrp_stock_owner_restriction/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_stock_owner_restriction/models/stock_move.py#L31

Added line #L31 was not covered by tests
mo_to_unbuild = self._get_mo_to_unbuild()
if mo_to_unbuild:
return mo_to_unbuild.owner_id
return super()._get_owner_for_assign()

def _get_owner_restriction(self):
self.ensure_one()
mo_to_unbuild = self._get_mo_to_unbuild()

Check warning on line 39 in mrp_stock_owner_restriction/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_stock_owner_restriction/models/stock_move.py#L38-L39

Added lines #L38 - L39 were not covered by tests
if mo_to_unbuild:
return mo_to_unbuild.picking_type_id.owner_restriction
return super()._get_owner_restriction()

Check warning on line 42 in mrp_stock_owner_restriction/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_stock_owner_restriction/models/stock_move.py#L41-L42

Added lines #L41 - L42 were not covered by tests
18 changes: 18 additions & 0 deletions mrp_stock_owner_restriction/models/stock_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 Quartile Limited
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class StockMoveLine(models.Model):
_inherit = "stock.move.line"

def _action_done(self):
for line in self:
owner = line.move_id.production_id.owner_id or self.env.context.get(
"force_restricted_owner_id", None
)
if owner:
line.move_id.write({"restrict_partner_id": owner.id})
line.write({"owner_id": owner.id})
return super()._action_done()
3 changes: 3 additions & 0 deletions mrp_stock_owner_restriction/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Quartile <https://www.quartile.co>`_:

* Yoshi Tashiro
2 changes: 2 additions & 0 deletions mrp_stock_owner_restriction/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module adapts the functionality of stock_owner_restriction in the manufacturing
order.
Loading

0 comments on commit a9e376b

Please sign in to comment.