Skip to content
Extraits de code Groupes Projets
Valider 59feb04d rédigé par Benjamin - Le Filament's avatar Benjamin - Le Filament
Parcourir les fichiers

[init] init module

parent
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
# © 2022 Le Filament (<https://www.le-filament.com>)
# © 2022 Confédération Générale des Scop (<https://www.les-scop.coop>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from werkzeug.exceptions import MethodNotAllowed
from odoo import _
from odoo.exceptions import (
AccessDenied,
AccessError,
MissingError,
UserError,
ValidationError,
)
from odoo.http import SessionExpiredException
from odoo.addons.component.core import Component
class ExceptionService(Component):
_inherit = "base.rest.service"
_name = "exception.service"
_usage = "exception"
_collection = "base.rest.demo.public.services"
_description = """
Exception Services
Services to test hiw exception are handled by base_erst
"""
def user_error(self):
"""
Simulate an odoo.exceptions.UserError
Should be translated into BadRequest with a description into the json
body
"""
raise UserError(_("UserError message"))
def validation_error(self):
"""
Simulate an odoo.exceptions.ValidationError
Should be translated into BadRequest with a description into the json
body
"""
raise ValidationError(_("ValidationError message"))
def session_expired(self):
"""
Simulate an odoo.http.SessionExpiredException
Should be translated into Unauthorized without description into the
json body
"""
raise SessionExpiredException("Expired message")
def missing_error(self):
"""
Simulate an odoo.exceptions.MissingError
Should be translated into NotFound without description into the json
body
"""
raise MissingError(_("Missing message"))
def access_error(self):
"""
Simulate an odoo.exceptions.AccessError
Should be translated into Forbidden without description into the json
body
"""
raise AccessError(_("Access error message"))
def access_denied(self):
"""
Simulate an odoo.exceptions.AccessDenied
Should be translated into Forbidden without description into the json
body
"""
raise AccessDenied()
def http_exception(self):
"""
Simulate an werkzeug.exceptions.MethodNotAllowed
This exception is not by the framework
"""
raise MethodNotAllowed(description="Method not allowed message")
def bare_exception(self):
"""
Simulate a python exception.
Should be translated into InternalServerError without description into
the json body
"""
raise IOError("My IO error")
# Validator
def _validator_user_error(self):
return {}
def _validator_return_user_error(self):
return {}
def _validator_validation_error(self):
return {}
def _validator_return_validation_error(self):
return {}
def _validator_session_expired(self):
return {}
def _validator_return_session_expired(self):
return {}
def _validator_missing_error(self):
return {}
def _validator_return_missing_error(self):
return {}
def _validator_access_error(self):
return {}
def _validator_return_access_error(self):
return {}
def _validator_access_denied(self):
return {}
def _validator_return_access_denied(self):
return {}
def _validator_http_exception(self):
return {}
def _validator_return_http_exception(self):
return {}
def _validator_bare_exception(self):
return {}
def _validator_return_bare_exception(self):
return {}
# © 2022 Le Filament (<https://www.le-filament.com>)
# © 2022 Confédération Générale des Scop (<https://www.les-scop.coop>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.addons.base_rest import restapi
from odoo.addons.base_rest_datamodel.restapi import Datamodel
from odoo.addons.component.core import Component
from ..datamodels.base_search_param import CgScopGendocBaseSearchParam
class CgScopGendocFileServices(Component):
_inherit = ["base.rest.service", "cgscop_gendoc.utils"]
_name = "cgscopgendoc.gendoc_file.services"
_usage = "file"
_collection = "cgscopgendoc.services.coll"
_description = """
Gendoc File API Services
Services developed with the new api provided by base_rest
"""
@restapi.method(
[(["/<int:id>/get", "/<int:id>"], "GET")],
auth="user",
)
def get(self, _id):
"""
Get file's information
"""
my_search_param = CgScopGendocBaseSearchParam()
my_search_param.id = _id
my_search_param.ur_id = 0
return self._search(my_search_param, True)
@restapi.method(
[(["/", "/search"], "POST")],
input_param=Datamodel("cgscopgendoc.base.search.param"),
auth="user",
)
def search(self, my_search_param):
"""
Search for gendoc files
:param base_search_param: An instance of partner.search.param
"""
return self._search(my_search_param, False)
# The following method are 'private' and should be never never NEVER call
# from the controller.
def _search(self, my_search_param, detailed):
"""
Search for gendoc files
:param base_search_param: An instance of gendoc.search.param
:param detailed: specify detailed output
"""
domain = []
if my_search_param.id:
domain.append(("id", "=", my_search_param.id))
else:
if my_search_param.filter:
domain = [
"|",
"|",
("partner_id.name", "ilike", my_search_param.filter),
("partner_id.sigle", "ilike", my_search_param.filter),
("partner_id.member_number", "=like", my_search_param.filter),
]
# On regarde si il faut limiter à l'UR
if my_search_param.ur_id != 0:
domain.append(("ur_id", "=", my_search_param.ur_id))
offset = 0
if my_search_param.offset:
offset = my_search_param.offset
limit = 0
if my_search_param.limit:
limit = my_search_param.limit
nbrec = self.env["scop.gendoc.file"].search_count(domain)
gfiles = self.env["scop.gendoc.file"].search(domain, limit=limit, offset=offset)
rows = []
res = {"count": nbrec, "rows": rows}
for gfile in gfiles:
rows.append(self._to_json(detailed, gfile))
return res
def _to_json(self, detailed, gfile):
"""
Generate output json
:param gfile: An instance of gendoc file
:param detailed: specify detailed output
"""
res = {
"id": self._getinteger(gfile.id),
"file_type": self._getinteger(gfile.file_type),
"coop_denomination": self._getstring(gfile.coop_denomination),
"coop_sigle": self._getstring(gfile.coop_sigle),
"coop_siege_ville": self._getstring(gfile.coop_siege_ville),
"coop_siren": self._getstring(gfile.coop_siren),
"coop_type_coop": self._getstring(gfile.coop_type_coop),
"coop_forme_juridique": self._getstring(gfile.coop_forme_juridique),
}
if detailed:
res.update(
{
"coop_siege_adresse1": self._getstring(gfile.coop_siege_adresse1),
"coop_siege_adresse2": self._getstring(gfile.coop_siege_adresse2),
"coop_siege_adresse3": self._getstring(gfile.coop_siege_adresse3),
"coop_siege_cp": self._getstring(gfile.coop_siege_cp),
"coop_siret": self._getstring(gfile.coop_siret),
"coop_ville_rcs": self._getstring(gfile.coop_ville_rcs),
"coop_type_acc": self._getstring(gfile.coop_type_acc),
"coop_nom_forme_juridique": self._getstring(
gfile.coop_nom_forme_juridique
),
"coop_forme_juridique_anterieure": self._getstring(
gfile.coop_forme_juridique_anterieure
),
"coop_type_capital_anterieur": self._getstring(
gfile.coop_type_capital_anterieur
),
"coop_montant_capital_anterieur": self._getdecimal(
gfile.coop_montant_capital_anterieur
),
"coop_date_creation_transformation": self._getdate(
gfile.coop_date_creation_transformation
),
"coop_heure_creation_transformation": self._getstring(
gfile.coop_heure_creation_transformation
),
"coop_dateheure_convocation": self._getstring(
gfile.coop_dateheure_convocation
),
"coop_objet_societe": self._getstring(gfile.coop_objet_societe),
"coop_duree_societe": self._getinteger(gfile.coop_duree_societe),
"coop_datefin_societe": self._getstring(gfile.coop_datefin_societe),
"coop_date_cloture": self._getstring(gfile.coop_date_cloture),
"coop_date_premiere_cloture": self._getdate(
gfile.coop_date_premiere_cloture
),
"coop_valeur_part_sociale": self._getdecimal(
gfile.coop_valeur_part_sociale
),
"coop_montant_capital_numeraire": self._getdecimal(
gfile.coop_montant_capital_numeraire
),
"coop_montant_capital_nature": self._getdecimal(
gfile.coop_montant_capital_nature
),
"coop_montant_capital_total": self._getdecimal(
gfile.coop_montant_capital_total
),
"coop_nb_parts_numeraire": self._getinteger(
gfile.coop_nb_parts_numeraire
),
"coop_nb_parts_nature": self._getinteger(
gfile.coop_nb_parts_nature
),
"coop_pourcent_capital_mini": self._getinteger(
gfile.coop_pourcent_capital_mini
),
"coop_montant_capital_mini": self._getdecimal(
gfile.coop_montant_capital_mini
),
"coop_identite_proprietaire": self._getstring(
gfile.coop_identite_proprietaire
),
"coop_cac_1": self._getstring(gfile.coop_cac_1),
"coop_reviseur_1": self._getstring(gfile.coop_reviseur_1),
"coop_reviseur_2": self._getstring(gfile.coop_reviseur_2),
"coop_commissaire_apports": self._getstring(
gfile.coop_commissaire_apports
),
"coop_pouvoirs_formalites": self._getstring(
gfile.coop_pouvoirs_formalites
),
"coop_nb_jours_reponse_conjoint": self._getinteger(
gfile.coop_nb_jours_reponse_conjoint
),
"coop_banque_depositaire": self._getstring(
gfile.coop_banque_depositaire
),
"coop_nom_signataire": self._getstring(gfile.coop_nom_signataire),
"sa_ca_duree": self._getinteger(gfile.coop_sa_ca_duree),
"sa_ca_renouvellement": self._getstring(
gfile.coop_sa_ca_renouvellement
),
"sa_ca_type_organisation": self._getstring(
gfile.coop_sa_ca_type_organisation
),
"sa_dir_duree": self._getinteger(gfile.coop_sa_dir_duree),
"sa_dir_renouvellement": self._getstring(
gfile.coop_sa_dir_renouvellement
),
"sa_dir_cs_duree": self._getstring(gfile.coop_sa_dir_cs_duree),
"oi_nom": self._getstring(gfile.coop_oi_nom),
"oi_duree": self._getinteger(gfile.coop_oi_duree),
"oi_pouvoir": self._getstring(gfile.coop_oi_pouvoir),
}
)
res["associes_pp"] = self._getassopp(gfile.assopp_ids)
res["associes_pm"] = self._getassopm(gfile.assopm_ids)
res["mandataires_sarl"] = self._getmandsarl(gfile.mand_sarl_ids)
res["mandataires_sas"] = self._getmandsas(gfile.mand_sas_ids)
res["mandataires_sa_ca"] = self._getmandsaca(gfile.mand_sa_ca_ids)
res["mandataires_sa_dir"] = self._getmandsadir(gfile.mand_sa_dir_ids)
res["organe_intermediaire"] = self._getoi(gfile.oi_ids)
res["conseil_surveillance"] = self._getcsurv(gfile.csurv_ids)
res["ur"] = self._getnested(gfile.ur_id)
return res
def _getassopp(self, ids):
res = []
if ids:
for asso in ids:
res.append(
{
"nom": self._getstring(asso.assopp_nom),
"adresse": self._getstring(asso.assopp_adresse),
"naissance": self._getstring(asso.assopp_naissance),
"nationalite": self._getstring(asso.assopp_nationalite),
"valeur_part_sociale": self._getdecimal(
asso.assopp_valeur_part_sociale
),
"montant_capital_numeraire": self._getdecimal(
asso.assopp_montant_capital_numeraire
),
"montant_capital_nature": self._getdecimal(
asso.assopp_montant_capital_nature
),
"montant_capital_total": self._getdecimal(
asso.assopp_montant_capital_total
),
"nb_parts_numeraire": self._getinteger(
asso.assopp_nb_parts_numeraire
),
"nb_parts_nature": self._getinteger(
asso.assopp_nb_parts_nature
),
"nb_parts_total": self._getinteger(asso.assopp_nb_parts_total),
"mail": self._getstring(asso.assopp_mail),
"mobile": self._getstring(asso.assopp_mobile),
"marital": self._getstring(asso.assopp_marital),
"conjoint": self._getstring(asso.assopp_conj),
}
)
return res
def _getassopm(self, ids):
res = []
if ids:
for asso in ids:
res.append(
{
"nom": self._getstring(asso.assopm_nom),
"adresse": self._getstring(asso.assopm_adresse),
"naissance": self._getstring(asso.assopm_naissance),
"nationalite": self._getstring(asso.assopm_nationalite),
"valeur_part_sociale": self._getdecimal(
asso.assopm_valeur_part_sociale
),
"montant_capital_numeraire": self._getdecimal(
asso.assopm_montant_capital_numeraire
),
"montant_capital_nature": self._getdecimal(
asso.assopm_montant_capital_nature
),
"montant_capital_total": self._getdecimal(
asso.assopm_montant_capital_total
),
"nb_parts_numeraire": self._getinteger(
asso.assopm_nb_parts_numeraire
),
"nb_parts_nature": self._getinteger(
asso.assopm_nb_parts_nature
),
"nb_parts_total": self._getinteger(asso.assopm_nb_parts_total),
"mail": self._getstring(asso.assopm_mail),
"mobile": self._getstring(asso.assopm_mobile),
"representant": self._getstring(asso.assopm_representant),
"repres_qualite": self._getstring(asso.assopm_repres_qualite),
}
)
return res
def _getmandsarl(self, ids):
res = []
if ids:
for mand in ids:
res.append(
{
"nom": self._getstring(mand.mand_nom),
"adresse": self._getstring(mand.mand_adresse),
"naissance": self._getstring(mand.mand_naissance),
"nationalite": self._getstring(mand.mand_nationalite),
"titre": self._getstring(mand.mand_titre),
"duree": self._getinteger(mand.mand_duree),
"identite_pere": self._getstring(mand.mand_identite_pere),
"identite_mere": self._getstring(mand.mand_identite_mere),
}
)
return res
def _getmandsas(self, ids):
res = []
if ids:
for mand in ids:
res.append(
{
"nom": self._getstring(mand.mand_nom),
"adresse": self._getstring(mand.mand_adresse),
"naissance": self._getstring(mand.mand_naissance),
"nationalite": self._getstring(mand.mand_nationalite),
"titre": self._getstring(mand.mand_titre),
"type": self._getstring(mand.mand_type),
"duree": self._getinteger(mand.mand_duree),
"identite_pere": self._getstring(mand.mand_identite_pere),
"identite_mere": self._getstring(mand.mand_identite_mere),
"representant": self._getstring(mand.mand_representant),
}
)
return res
def _getmandsaca(self, ids):
res = []
if ids:
for mand in ids:
res.append(
{
"administrateur": self._getboolean(mand.mand_administrateur),
"direction": self._getboolean(mand.mand_direction),
"type": self._getstring(mand.mand_type),
"nom": self._getstring(mand.mand_nom),
"adresse": self._getstring(mand.mand_adresse),
"naissance": self._getstring(mand.mand_naissance),
"nationalite": self._getstring(mand.mand_nationalite),
"representant": self._getstring(mand.mand_representant),
"duree_premier_mandat": self._getinteger(
mand.mand_duree_premier_mandat
),
"identite_pere": self._getstring(mand.mand_identite_pere),
"identite_mere": self._getstring(mand.mand_identite_mere),
}
)
return res
def _getmandsadir(self, ids):
res = []
if ids:
for mand in ids:
res.append(
{
"type_organe": self._getstring(mand.mand_type_organe),
"type_direction": self._getstring(mand.mand_type_direction),
"type": self._getstring(mand.mand_type),
"nom": self._getstring(mand.mand_nom),
"adresse": self._getstring(mand.mand_adresse),
"naissance": self._getstring(mand.mand_naissance),
"nationalite": self._getstring(mand.mand_nationalite),
"representant": self._getstring(mand.mand_representant),
"representant_adresse": self._getstring(mand.mand_rep_adresse),
"representant_naissance": self._getstring(
mand.mand_rep_naissance
),
"representant_nationalite": self._getstring(
mand.mand_rep_nationalite
),
"identite_pere": self._getstring(mand.mand_identite_pere),
"identite_mere": self._getstring(mand.mand_identite_mere),
}
)
return res
def _getoi(self, ids):
res = []
if ids:
for oi in ids:
res.append(
{
"type": self._getstring(oi.oi_type),
"nom": self._getstring(oi.oi_nom),
"adresse": self._getstring(oi.oi_adresse),
"naissance": self._getstring(oi.oi_naissance),
"nationalite": self._getstring(oi.oi_nationalite),
"representant": self._getstring(oi.oi_representant),
"identite_pere": self._getstring(oi.oi_identite_pere),
"identite_mere": self._getstring(oi.oi_identite_mere),
}
)
return res
def _getcsurv(self, ids):
res = []
if ids:
for csurv in ids:
res.append(
{
"nom": self._getstring(csurv.csurv_nom),
"adresse": self._getstring(csurv.csurv_adresse),
"naissance": self._getstring(csurv.csurv_naissance),
"nationalite": self._getstring(csurv.csurv_nationalite),
}
)
return res
# © 2022 Le Filament (<https://www.le-filament.com>)
# © 2022 Confédération Générale des Scop (<https://www.les-scop.coop>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.addons.base_rest import restapi
from odoo.addons.component.core import Component
class CgScopGendocUserServices(Component):
_inherit = ["base.rest.service", "cgscop_gendoc.utils"]
_name = "cgscopgendoc.user.services"
_usage = "user"
_collection = "cgscopgendoc.services.coll"
_description = """
Gendoc File API Services
Services developed with the new api provided by base_rest
"""
@restapi.method(
[(["/<int:id>/get", "/<int:id>"], "GET")],
auth="user",
)
def get(self, _id):
"""
Get user's information
"""
return self._get(_id)
# The following method are 'private' and should be never never NEVER call
# from the controller.
def _get(self, userId):
"""
Search for user
"""
user = self.env["res.users"].browse(userId)
rows = []
if not user:
return {"count": 0, "rows": rows}
else:
rows.append(self._to_json(user))
return {"count": 1, "rows": rows}
def _to_json(self, user):
"""
Generate output json
:param partner: An instance of user
"""
res = {
"id": self._getinteger(user.id),
"login": self._getstring(user.login),
}
res["ur"] = self._getnested(user.ur_id)
res["partner"] = self._getpartner(user.partner_id)
return res
def _getpartner(self, partner):
res = {}
if partner:
res.update(
{
"id": self._getinteger(partner.id),
"name": self._getstring(partner.name),
"title": self._getnested(partner.title),
"lastname": self._getstring(partner.lastname),
"firstname": self._getstring(partner.firstname),
"mobile": self._getstring(partner.mobile),
"phone": self._getstring(partner.phone),
"image": partner.image_128.decode("utf-8")
if partner.image_128
else None,
}
)
else:
res.update({"id": 0, "name": ""})
return res
static/description/icon.png

13,6 ko

<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2022 Le Filament (<https://www.le-filament.com>)
2022 Confédération Générale des Scop (<https://www.les-scop.coop>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="base_rest.menu_rest_api_root" model="ir.ui.menu">
<field
name="groups_id"
eval="[(6,0,[ref('cgscop_partner.group_cg_administrator')])]"
/>
</record>
</odoo>
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter