Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][MIG] product_operating_unit: Migration to 15.0 #492

Open
wants to merge 25 commits into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
49265e2
New module product_operating_unit to introduce the operating unit to …
Mar 28, 2019
88a75dc
[ADD] Added a product_operating_unit v12
nikul-serpentcs Dec 30, 2019
04c879d
[FIX] Uncomment rule
nikul-serpentcs Jan 20, 2020
d36df77
[FIX] Default Get + Show OU on Small Form
osi-scampbell Jan 30, 2020
0c27b45
[IMP] Create Product Access Error
osi-scampbell Feb 11, 2020
d21da80
Update product_operating_unit/views/product_template_view.xml
nikul-serpentcs Mar 25, 2020
bc3e964
[IMP] Improved code
murtuzasaleh Apr 20, 2020
2209144
New module product_operating_unit to introduce the operating unit to …
Mar 28, 2019
7b6b5aa
[ADD] Added a product_operating_unit v12
nikul-serpentcs Dec 30, 2019
0acca41
[FIX] Uncomment rule
nikul-serpentcs Jan 20, 2020
29f7c46
[FIX] Default Get + Show OU on Small Form
osi-scampbell Jan 30, 2020
4fbe281
[IMP] Create Product Access Error
osi-scampbell Feb 11, 2020
34cc635
[IMP] Improved code
murtuzasaleh Apr 20, 2020
234d05b
[IMP] product_operating_unit
max3903 Apr 21, 2020
dfb129f
[UPD] Update product_operating_unit.pot README.rst
OCA-git-bot Apr 27, 2020
316ca4b
Added translation using Weblate (Portuguese)
pedrocs-exo Mar 2, 2021
7bda263
[IMP] product_operating_unit: black, isort, prettier
jesus01x Jul 5, 2021
3239a08
[MIG] product_operating_unit: Migration to 14.0
jesus01x Jul 5, 2021
eb518ee
[UPD] README.rst Update product_operating_unit.pot
oca-travis Aug 12, 2021
5ad0c24
[FIX] Fixed OU constrains with product
nikul-serpentcs Oct 27, 2021
00928b1
product_operating_unit 14.0.1.0.1
OCA-git-bot Oct 29, 2021
503ab8e
[IMP] update dotfiles [ci skip]
OCA-git-bot Mar 31, 2022
b3bd265
[IMP] product_operating_unit: black, isort, prettier
BT-pcavero Aug 1, 2022
7bb89e5
[15.0][MIG] product_operating_unit: Migration to 15.0
BT-pcavero Aug 1, 2022
53dc471
[15.0][IMP] product_operating_unit.
BT-pcavero Nov 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env/lib64
95 changes: 95 additions & 0 deletions product_operating_unit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
==========================
Operating Unit in Products
==========================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-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/product_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-product_operating_unit
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/213/14.0
:alt: Try me on Runbot

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

This module introduces the following features:

- It introduces the operating unit to the product template.
- The operating unit from the user is assigned by default when creating a new
product template.
- In case of multi-company, no operating unit from another company to that
assigned to the product can be set for it
- It implements user's security rules.

**Table of contents**

.. contents::
:local:

Usage
=====

#. Create a Product: the Default Operating Unit of the user is assigned to it.
If you want, you can change to another Operating Unit.
#. Assignment of an operating unit of another company to the one set in the
product raises an error for a multi-company setting.
#. Access rules allow to just show those products having the same operating
units as the user

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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20product_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
~~~~~~~

* brain-tec AG
* Open Source Integrators
* Serpent Consulting Services Pvt. Ltd.

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

* Raul Martin Felez <raul.martin@braintec-group.com>
* Nikul Chaudhary <nikul.chaudhary.serpentcs@gmail.com>
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com>
* Jesus Alcala <jesus.alcala@jarsa.com.mx>

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/product_operating_unit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions product_operating_unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import models
22 changes: 22 additions & 0 deletions product_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com)
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2019 Serpent Consulting Services
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": "Operating Unit in Products",
"summary": "Adds the concept of operating unit (OU) in products",
"version": "15.0.1.0.0",
"author": "brain-tec AG, "
"Open Source Integrators, "
"Serpent Consulting Services Pvt. Ltd.,"
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/operating-unit",
"category": "Product",
"depends": ["product", "operating_unit"],
"license": "LGPL-3",
"data": [
"security/product_template_security.xml",
"views/product_template_view.xml",
"views/product_category_view.xml",
],
}
79 changes: 79 additions & 0 deletions product_operating_unit/i18n/product_operating_unit.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_operating_unit
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \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: product_operating_unit
#: model:ir.model.fields,field_description:product_operating_unit.field_product_category__display_name
#: model:ir.model.fields,field_description:product_operating_unit.field_product_template__display_name
msgid "Display Name"
msgstr ""

#. module: product_operating_unit
#: code:addons/product_operating_unit/models/product_template.py:0
#, python-format
msgid "Go to Product Categories"
msgstr ""

#. module: product_operating_unit
#: model:ir.model.fields,field_description:product_operating_unit.field_product_category__id
#: model:ir.model.fields,field_description:product_operating_unit.field_product_template__id
msgid "ID"
msgstr ""

#. module: product_operating_unit
#: model:ir.model.fields,field_description:product_operating_unit.field_product_category____last_update
#: model:ir.model.fields,field_description:product_operating_unit.field_product_template____last_update
msgid "Last Modified on"
msgstr ""

#. module: product_operating_unit
#: model:ir.model.fields,field_description:product_operating_unit.field_product_category__operating_unit_ids
#: model:ir.model.fields,field_description:product_operating_unit.field_product_product__operating_unit_ids
#: model:ir.model.fields,field_description:product_operating_unit.field_product_template__operating_unit_ids
msgid "Operating Units"
msgstr ""

#. module: product_operating_unit
#: model:ir.model,name:product_operating_unit.model_product_category
#: model:ir.model.fields,field_description:product_operating_unit.field_product_product__categ_id
#: model:ir.model.fields,field_description:product_operating_unit.field_product_template__categ_id
msgid "Product Category"
msgstr ""

#. module: product_operating_unit
#: model:ir.model,name:product_operating_unit.model_product_template
msgid "Product Template"
msgstr ""

#. module: product_operating_unit
#: model:ir.model.fields,help:product_operating_unit.field_product_product__categ_id
#: model:ir.model.fields,help:product_operating_unit.field_product_template__categ_id
msgid "Select category for the current product"
msgstr ""

#. module: product_operating_unit
#: code:addons/product_operating_unit/models/product_template.py:0
#, python-format
msgid ""
"The operating units of the product must include the ones from the category."
msgstr ""

#. module: product_operating_unit
#: code:addons/product_operating_unit/models/product_template.py:0
#, python-format
msgid ""
"You must define at least one product category within"
" your Operating Unit in order to be able to create "
"products."
msgstr ""
58 changes: 58 additions & 0 deletions product_operating_unit/i18n/pt.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_operating_unit
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"Language: pt\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n > 1;\n"

#. module: product_operating_unit
#: code:addons/product_operating_unit/models/product_template.py:60
#, python-format
msgid "Go to Product Categories"
msgstr ""

#. module: product_operating_unit
#: model:ir.model.fields,field_description:product_operating_unit.field_product_category__operating_unit_ids
#: model:ir.model.fields,field_description:product_operating_unit.field_product_product__operating_unit_ids
#: model:ir.model.fields,field_description:product_operating_unit.field_product_template__operating_unit_ids
msgid "Operating Units"
msgstr ""

#. module: product_operating_unit
#: model:ir.model,name:product_operating_unit.model_product_category
#: model:ir.model.fields,field_description:product_operating_unit.field_product_product__categ_id
#: model:ir.model.fields,field_description:product_operating_unit.field_product_template__categ_id
msgid "Product Category"
msgstr ""

#. module: product_operating_unit
#: model:ir.model,name:product_operating_unit.model_product_template
msgid "Product Template"
msgstr ""

#. module: product_operating_unit
#: model:ir.model.fields,help:product_operating_unit.field_product_product__categ_id
#: model:ir.model.fields,help:product_operating_unit.field_product_template__categ_id
msgid "Select category for the current product"
msgstr ""

#. module: product_operating_unit
#: code:addons/product_operating_unit/models/product_template.py:34
#, python-format
msgid "The operating units of the product must include the ones from the category."
msgstr ""

#. module: product_operating_unit
#: code:addons/product_operating_unit/models/product_template.py:57
#, python-format
msgid "You must define at least one product category within your Operating Unit in order to be able to create products."
msgstr ""
3 changes: 3 additions & 0 deletions product_operating_unit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import product_template
from . import product_category
30 changes: 30 additions & 0 deletions product_operating_unit/models/product_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2019 Serpent Consulting Services
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import fields, models


class ProductCategory(models.Model):
_inherit = "product.category"

operating_unit_ids = fields.Many2many(
"operating.unit",
"product_category_operating_unit_rel",
string="Operating Units",
)

def write(self, vals):
res = super(ProductCategory, self).write(vals)

product_template_obj = self.env["product.template"]
if vals.get("operating_unit_ids"):
for rec in self:
products = product_template_obj.search(
[("categ_id", "child_of", rec.id)]
)
for product in products:
ou_ids = product.operating_unit_ids.ids
ou_ids.extend(vals.get("operating_unit_ids")[0][2])
product.operating_unit_ids = [(6, 0, ou_ids)]

return res
94 changes: 94 additions & 0 deletions product_operating_unit/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com)
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2019 Serpent Consulting Services
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).


import logging

from odoo import _, api, fields, models
from odoo.exceptions import AccessError, RedirectWarning, ValidationError

_logger = logging.getLogger(__name__)


class ProductTemplate(models.Model):
_inherit = "product.template"

@api.model
def _default_operating_unit_ids(self):
if self.categ_id and self.categ_id.operating_unit_ids:
return [(6, 0, self.categ_id.operating_unit_ids.ids)]
if self.env.user.default_operating_unit_id:
return [
(
6,
0,
[self.env["res.users"].operating_unit_default_get(self.env.uid).id],
)
]

operating_unit_ids = fields.Many2many(
"operating.unit",
"product_operating_unit_rel",
string="Operating Units",
default=_default_operating_unit_ids,
)

@api.constrains("operating_unit_ids", "categ_id")
def _check_operating_unit(self):
for record in self:
if (
record.operating_unit_ids and record.categ_id.operating_unit_ids
) and not all(
ou in record.operating_unit_ids.ids
for ou in record.categ_id.operating_unit_ids.ids
):
raise ValidationError(
_(
"The operating units of the product must include the "
"ones from the category."
)
)

@api.onchange("categ_id")
def onchange_operating_unit_ids(self):
for record in self:
if record.categ_id.operating_unit_ids:
record.operating_unit_ids = [
(6, 0, record.categ_id.operating_unit_ids.ids)
]

def _get_default_category_id(self):
for ou_id in self.env.user.operating_unit_ids:
_logger.info("%s" % (ou_id.name))
category = self.env["product.category"].search([], limit=1)
if category:
return category.id
else:
try:
self.env.ref(
"product.product_category_all", raise_if_not_found=False
).name
except AccessError:
err_msg = _(
"You must define at least one product \
category within your Operating Unit in order to be \
able to create products."
)
redir_msg = _("Go to Product Categories")
raise RedirectWarning(
err_msg,
self.env.ref("product.product_category_action_form").id,
redir_msg,
) from AccessError
return super()._get_default_category_id()

categ_id = fields.Many2one(
"product.category",
"Product Category",
change_default=True,
default=_get_default_category_id,
required=True,
help="Select category for the current product",
)
5 changes: 5 additions & 0 deletions product_operating_unit/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* Raul Martin Felez <raul.martin@braintec-group.com>
* Nikul Chaudhary <nikul.chaudhary.serpentcs@gmail.com>
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com>
* Jesus Alcala <jesus.alcala@jarsa.com.mx>
* Pablo Cavero Perez <pablo.cavero@braintec.com>
Loading
Loading