Skip to content

Commit

Permalink
[MIG] shopfloor_base: Backport from 13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lmignon committed Mar 18, 2021
1 parent 77cf458 commit 9eefe02
Show file tree
Hide file tree
Showing 37 changed files with 135 additions and 150 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ exclude: |
^delivery_preference_glue_stock_picking_group/|
^sale_stock_available_to_promise_release/|
^shopfloor/|
^shopfloor_base/|
^shopfloor_batch_automatic_creation/|
^shopfloor_checkout_sync/|
^shopfloor_example/|
Expand Down
8 changes: 5 additions & 3 deletions shopfloor_base/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# Copyright 2020 Akretion (http://www.akretion.com)
# Copyright 2020 BCIM
Expand All @@ -6,15 +7,15 @@
{
"name": "Shopfloor Base",
"summary": "Core module for creating mobile apps",
"version": "13.0.1.1.0",
"version": "10.0.1.1.0",
"development_status": "Alpha",
"category": "Inventory",
"website": "https://github.com/OCA/wms",
"author": "Camptocamp, BCIM, Akretion, Odoo Community Association (OCA)",
"maintainers": ["guewen", "simahawk", "sebalix"],
"license": "LGPL-3",
"application": True,
"depends": ["base_jsonify", "base_rest", "base_sparse_field", "auth_api_key"],
"depends": ["base_jsonify", "base_rest", "auth_api_key"],
"data": [
"data/module_category_data.xml",
"security/groups.xml",
Expand All @@ -32,5 +33,6 @@
"demo/shopfloor_profile_demo.xml",
],
"post_init_hook": "post_init_hook",
"installable": False,
"installable": True,
"external_dependencies": {"python": ["slugify"]},
}
1 change: 1 addition & 0 deletions shopfloor_base/actions/base_action.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# Copyright 2021 ACSONE SA/NV (http://www.acsone.eu)
# @author Simone Orsi <simahawk@gmail.com>
Expand Down
1 change: 1 addition & 0 deletions shopfloor_base/actions/data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo.addons.component.core import Component
Expand Down
1 change: 1 addition & 0 deletions shopfloor_base/actions/data_detail.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

Expand Down
1 change: 1 addition & 0 deletions shopfloor_base/actions/message.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo import _
Expand Down
13 changes: 9 additions & 4 deletions shopfloor_base/actions/savepoint.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
import uuid

from psycopg2 import sql

from odoo.sql_db import clear_env, flush_env
from odoo.api import Environment

from odoo.addons.component.core import Component

Expand All @@ -30,17 +31,21 @@ class Savepoint(object):
def __init__(self, cr):
self._cr = cr
self.name = uuid.uuid1().hex
flush_env(self._cr, clear=False)
self._execute("SAVEPOINT {}")

def rollback(self):
clear_env(self._cr)
self._clear_env()
self._execute("ROLLBACK TO SAVEPOINT {}")

def release(self):
flush_env(self._cr, clear=False)
self._execute("RELEASE SAVEPOINT {}")

def _execute(self, query):
# pylint: disable=sql-injection
self._cr.execute(sql.SQL(query).format(sql.Identifier(self.name)))

def _clear_env(self):
for env in list(Environment.envs):
if env.cr is self.cr:
env.clear()
break
1 change: 1 addition & 0 deletions shopfloor_base/actions/schema.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# Copyright 2021 ACSONE SA/NV (http://www.acsone.eu)
# @author Simone Orsi <simahawk@gmail.com>
Expand Down
1 change: 1 addition & 0 deletions shopfloor_base/actions/schema_detail.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo.addons.component.core import Component
Expand Down
1 change: 1 addition & 0 deletions shopfloor_base/actions/search.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo.addons.component.core import Component
Expand Down
1 change: 1 addition & 0 deletions shopfloor_base/controllers/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# Copyright 2020 Akretion (http://www.akretion.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
Expand Down
1 change: 1 addition & 0 deletions shopfloor_base/hooks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2021 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

Expand Down
1 change: 1 addition & 0 deletions shopfloor_base/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import base
from . import shopfloor_menu
from . import shopfloor_profile
from . import shopfloor_scenario
16 changes: 16 additions & 0 deletions shopfloor_base/models/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Copyright 2021 ACSONE SA/NV (http://www.acsone.eu)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo import models


class Base(models.AbstractModel):

_inherit = "base"

def jsonify(self, parser, one=False):
# Add support for params one... provided by base_jsonify from 13.0
if one:
self.ensure_one()
result = super(Base, self).jsonify(parser)
return result[0] if one else result
1 change: 1 addition & 0 deletions shopfloor_base/models/shopfloor_menu.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# Copyright 2021 ACSONE SA/NV (http://www.acsone.eu)
# @author Simone Orsi <simahawk@gmail.com>
Expand Down
1 change: 1 addition & 0 deletions shopfloor_base/models/shopfloor_profile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo import fields, models
Expand Down
30 changes: 16 additions & 14 deletions shopfloor_base/models/shopfloor_scenario.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# -*- coding: utf-8 -*-
# Copyright 2021 ACSONE SA/NV (http://www.acsone.eu)
# @author Simone Orsi <simahawk@gmail.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
import json
import logging

from odoo import api, fields, models
import slugify

from odoo.addons.base_sparse_field.models.fields import Serialized
from odoo.addons.http_routing.models.ir_http import slugify
from odoo import api, fields, models
from odoo.fields import Serialized
from odoo.tools import ustr

_logger = logging.getLogger(__name__)

Expand All @@ -26,9 +28,7 @@ class ShopfloorScenario(models.Model):
"This value must match a service component's `usage`.",
)
options = Serialized(compute="_compute_options", default={})
options_edit = fields.Text(
help="Configure options via JSON", inverse="_inverse_options_edit"
)
options_edit = fields.Text(help="Configure options via JSON")

_sql_constraints = [("key", "unique(key)", "Scenario key must be unique")]

Expand All @@ -37,11 +37,6 @@ def _compute_options(self):
for rec in self:
rec.options = rec._load_options()

def _inverse_options_edit(self):
for rec in self:
# Make sure options_edit is always readable
rec.options_edit = json.dumps(rec.options or {}, indent=4, sort_keys=True)

def _load_options(self):
return json.loads(self.options_edit or "{}")

Expand All @@ -61,11 +56,14 @@ def _onchange_key(self):
@api.model
def create(self, vals):
self._handle_key(vals)
return super().create(vals)
self._ensure_options_edit_readability(vals)
return super(ShopfloorScenario, self).create(vals)

def write(self, vals):
self._handle_key(vals)
return super().write(vals)
if "options_edit" in vals:
self._ensure_options_edit_readability(vals)
return super(ShopfloorScenario, self).write(vals)

def _handle_key(self, vals):
# make sure technical names are always there
Expand All @@ -74,7 +72,11 @@ def _handle_key(self, vals):

@staticmethod
def _normalize_key(name):
return slugify(name).replace("-", "_")
return slugify.slugify(ustr(name)).replace("-", "_")

def has_option(self, key):
return self.options.get(key, False)

def _ensure_options_edit_readability(self, vals):
value = json.loads(vals.get("options_edit", "{}"))
vals["options_edit"] = json.dumps(value, indent=4, sort_keys=True)
5 changes: 1 addition & 4 deletions shopfloor_base/security/groups.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
<record id="group_shopfloor_manager" model="res.groups">
<field name="name">Shopfloor Manager</field>
<field name="category_id" ref="shopfloor_base.module_category_shopfloor" />
<field
name="users"
eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"
/>
<field name="users" eval="[(4, ref('base.user_root'))]" />
</record>
</odoo>
1 change: 1 addition & 0 deletions shopfloor_base/services/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo.addons.component.core import Component
Expand Down
1 change: 1 addition & 0 deletions shopfloor_base/services/forms/form_mixin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# @author Simone Orsi <simahawk@gmail.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
Expand Down
3 changes: 2 additions & 1 deletion shopfloor_base/services/menu.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo.osv import expression
Expand All @@ -21,7 +22,7 @@ class ShopfloorMenu(Component):
_description = __doc__

def _get_base_search_domain(self):
base_domain = super()._get_base_search_domain()
base_domain = super(ShopfloorMenu, self)._get_base_search_domain()
return expression.AND(
[
base_domain,
Expand Down
1 change: 1 addition & 0 deletions shopfloor_base/services/profile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo.addons.base_rest.components.service import to_int
Expand Down
1 change: 1 addition & 0 deletions shopfloor_base/services/scan_anything.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# Copyright 2021 ACSONE SA/NV (http://www.acsone.eu)
# @author Simone Orsi <simahawk@gmail.com>
Expand Down
25 changes: 21 additions & 4 deletions shopfloor_base/services/service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# Copyright 2020 Akretion (http://www.akretion.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
Expand All @@ -7,11 +8,11 @@
from odoo import _, exceptions
from odoo.http import request
from odoo.osv import expression
from odoo.tools import DotDict

from odoo.addons.component.core import AbstractComponent

from ..actions.base_action import get_actions_for
from ..utils import DotDict


class BaseShopfloorService(AbstractComponent):
Expand All @@ -22,9 +23,11 @@ class BaseShopfloorService(AbstractComponent):
_collection = "shopfloor.service"
_expose_model = None

def dispatch(self, method_name, *args, params=None):
def dispatch(self, method_name, _id=None, params=None):
self._validate_headers_update_work_context(request, method_name)
return super().dispatch(method_name, *args, params=params)
return super(BaseShopfloorService, self).dispatch(
method_name, _id=_id, params=params
)

def _actions_for(self, usage, **kw):
return get_actions_for(self, usage, **kw)
Expand Down Expand Up @@ -53,6 +56,20 @@ def _to_json(self, records):
res.append(self._convert_one_record(record))
return res

def _get_input_validator(self, method_name):
# override the method to get the validator in a component
# instead of a method, to keep things apart
validator_component = self.component(usage="%s.validator" % self._usage)
return validator_component._get_validator(method_name)

def _get_output_validator(self, method_name):
# override the method to get the validator in a component
# instead of a method, to keep things apart
validator_component = self.component(
usage="%s.validator.response" % self._usage
)
return validator_component._get_validator(method_name)

def _response(
self, base_response=None, data=None, next_state=None, message=None, popup=None
):
Expand Down Expand Up @@ -107,7 +124,7 @@ def _response(
_requires_header_profile = False

def _get_openapi_default_parameters(self):
defaults = super()._get_openapi_default_parameters()
defaults = super(BaseShopfloorService, self)._get_openapi_default_parameters()
# Normal users can't read an API key, ignore it using sudo() only
# because it's a demo key.
demo_api_key = self.env.ref("shopfloor.api_key_demo", raise_if_not_found=False)
Expand Down
1 change: 1 addition & 0 deletions shopfloor_base/services/user.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo.addons.base_rest.components.service import to_int
Expand Down
Loading

0 comments on commit 9eefe02

Please sign in to comment.