Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Odoo CE
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coopdevs
Comunitats Energètiques
Odoo CE
Commits
b0e3a2ec
Commit
b0e3a2ec
authored
2 years ago
by
Xavier Bonet
Browse files
Options
Downloads
Patches
Plain Diff
ADD return attributes endpoint community
parent
a777e58f
No related branches found
No related tags found
1 merge request
!50
Add return attributes endpoint community
Pipeline
#19899
passed
2 years ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
ce/models/res_company.py
+82
-43
82 additions, 43 deletions
ce/models/res_company.py
ce/services/ce_community_service.py
+2
-0
2 additions, 0 deletions
ce/services/ce_community_service.py
ce/services/schemas.py
+3
-0
3 additions, 0 deletions
ce/services/schemas.py
with
87 additions
and
43 deletions
ce/models/res_company.py
+
82
−
43
View file @
b0e3a2ec
from
email.policy
import
default
from
sqlite3
import
dbapi2
from
odoo
import
api
,
models
,
fields
,
_
from
datetime
import
datetime
import
re
from
odoo.exceptions
import
UserError
from
odoo.addons
import
decimal_precision
as
dp
from
odoo.addons.auth_signup.controllers.main
import
AuthSignupHome
as
Home
from
odoo.addons.auth_oauth.controllers.main
import
OAuthLogin
as
OAL
from
slugify
import
slugify
class
ResCompany
(
models
.
Model
):
...
...
@@ -15,15 +18,15 @@ class ResCompany(models.Model):
# new fields
kc_realm
=
fields
.
Char
(
string
=
'
KeyCloak realm name
'
)
coordinator
=
fields
.
Boolean
(
string
=
'
Platform coordinator
'
,
help
=
"
Flag to indicate that this company has the rol of
'
Coordinator
'
(=Administrator) for the current
'
Comunitats Energètiques
'
Platform
"
)
ce_admin_key_cloak_provider_id
=
fields
.
Many2one
(
coordinator
=
fields
.
Boolean
(
string
=
'
Platform coordinator
'
,
help
=
"
Flag to indicate that this company has the rol of
'
Coordinator
'
(=Administrator) for the current
'
Comunitats Energètiques
'
Platform
"
)
ce_admin_key_cloak_provider_id
=
fields
.
Many2one
(
string
=
'
OAuth provider for CCEE admin
'
,
comodel_name
=
'
auth.oauth.provider
'
,
)
auth_ce_key_cloak_provider_id
=
fields
.
Many2one
(
auth_ce_key_cloak_provider_id
=
fields
.
Many2one
(
string
=
'
OAuth provider for CCEE login
'
,
comodel_name
=
'
auth.oauth.provider
'
,
)
...
...
@@ -40,20 +43,23 @@ class ResCompany(models.Model):
foundation_date
=
fields
.
Date
(
'
Foundation date
'
)
social_telegram
=
fields
.
Char
(
'
Telegram Account
'
)
initial_subscription_share_amount
=
fields
.
Float
(
'
Initial Subscription Share Amount
'
,
digits
=
dp
.
get_precision
(
'
Product Price
'
)
)
allow_new_members
=
fields
.
Boolean
(
string
=
"
Allow new members
"
,
default
=
True
)
initial_subscription_share_amount
=
fields
.
Float
(
'
Initial Subscription Share Amount
'
,
digits
=
dp
.
get_precision
(
'
Product Price
'
))
allow_new_members
=
fields
.
Boolean
(
string
=
"
Allow new members
"
,
default
=
True
)
@api.model
def
get_real_ce_company_id
(
self
,
api_param_odoo_compant_id
):
if
api_param_odoo_compant_id
==
self
.
API_PARAM_ID_VALUE_FOR_COORDINADORA
:
return
self
.
search
([(
'
coordinator
'
,
'
=
'
,
True
)],
limit
=
1
)
or
None
return
self
.
search
([(
'
coordinator
'
,
'
=
'
,
True
)],
limit
=
1
)
or
None
else
:
return
self
.
search
([(
'
id
'
,
'
=
'
,
api_param_odoo_compant_id
)])
or
None
return
self
.
search
([(
'
id
'
,
'
=
'
,
api_param_odoo_compant_id
)])
or
None
@api.multi
def
check_ce_has_admin
(
self
):
self
.
ensure_one
()
admin_roles_ids
=
[
r
[
'
odoo_role_id
'
]
for
r
in
self
.
env
[
'
res.users
'
].
ce_user_roles_mapping
().
values
()
if
r
[
'
is_admin
'
]]
admin_roles_ids
=
[
r
[
'
odoo_role_id
'
]
for
r
in
self
.
env
[
'
res.users
'
].
ce_user_roles_mapping
().
values
()
if
r
[
'
is_admin
'
]]
company_user_ids
=
self
.
get_ce_members
().
ids
admins_user_ids
=
[]
for
admin_role
in
self
.
env
[
'
res.users.role
'
].
sudo
().
browse
(
admin_roles_ids
):
...
...
@@ -63,8 +69,10 @@ class ResCompany(models.Model):
@api.multi
def
get_ce_members
(
self
,
domain_key
=
'
in_kc_and_active
'
):
domains_dict
=
{
'
in_kc_and_active
'
:
[(
'
company_id
'
,
'
=
'
,
self
.
id
),(
'
oauth_uid
'
,
'
!=
'
,
None
),(
'
active
'
,
'
=
'
,
True
)]}
members
=
self
.
env
[
'
res.users
'
].
sudo
().
search
(
domains_dict
[
'
in_kc_and_active
'
])
domains_dict
=
{
'
in_kc_and_active
'
:
[
(
'
company_id
'
,
'
=
'
,
self
.
id
),
(
'
oauth_uid
'
,
'
!=
'
,
None
),
(
'
active
'
,
'
=
'
,
True
)]}
members
=
self
.
env
[
'
res.users
'
].
sudo
().
search
(
domains_dict
[
'
in_kc_and_active
'
])
return
members
@api.model
...
...
@@ -72,8 +80,8 @@ class ResCompany(models.Model):
# check for VAT
if
vals
.
get
(
'
vat
'
,
False
)
and
vals
.
get
(
'
vat
'
):
sanit_vat
=
re
.
sub
(
r
"
[^a-zA-Z0-9]
"
,
""
,
vals
[
'
vat
'
]).
lower
()
if
sanit_vat
in
[
re
.
sub
(
r
"
[^a-zA-Z0-9]
"
,
""
,
c
.
vat
).
lower
()
for
c
in
self
.
search
([])
if
c
.
vat
]:
sanit_vat
=
re
.
sub
(
r
"
[^a-zA-Z0-9]
"
,
""
,
vals
[
'
vat
'
]).
lower
()
if
sanit_vat
in
[
re
.
sub
(
r
"
[^a-zA-Z0-9]
"
,
""
,
c
.
vat
).
lower
()
for
c
in
self
.
search
([])
if
c
.
vat
]:
raise
UserError
(
_
(
"
Unable to create new company because there is an allready existing company with this VAT number: {}
"
).
format
(
vals
[
'
vat
'
]))
...
...
@@ -84,14 +92,13 @@ class ResCompany(models.Model):
raise
UserError
(
_
(
"
Unable to create new company because there is an allready existing company with this NAME: {}
"
).
format
(
vals
[
'
name
'
]))
@api.model
def
create
(
self
,
vals
):
def
create
(
self
,
vals
):
# check that we are not creating duplicate companies by vat or by name
self
.
_is_not_unique
(
vals
)
new_company
=
super
(
ResCompany
,
self
).
create
(
vals
)
new_company
=
super
(
ResCompany
,
self
).
create
(
vals
)
return
new_company
...
...
@@ -102,18 +109,19 @@ class ResCompany(models.Model):
# [1] Set res.config.settings params that are company dependants
# TODO choose the proper one depending of the legaol type of the new company
pyme_char_template_id
=
self
.
env
[
'
ir.model.data
'
].
get_object_reference
(
'
l10n_es
'
,
'
account_chart_template_pymes
'
)[
1
]
pyme_char_template_id
=
self
.
env
[
'
ir.model.data
'
].
get_object_reference
(
'
l10n_es
'
,
'
account_chart_template_pymes
'
)[
1
]
#assoc_char_template_id = self.env['ir.model.data'].get_object_reference('l10n_es', 'account_chart_template_assoc')[1]
user_active_company_id
=
self
.
env
.
user
.
company_id
.
id
user
=
self
.
env
.
user
user
.
company_ids
=
[(
4
,
self
.
id
)]
user
.
company_ids
=
[(
4
,
self
.
id
)]
user
.
company_id
=
self
.
id
rcs_sudo
=
self
.
env
[
'
res.config.settings
'
].
sudo
(
user
)
rcs_sudo_id
=
rcs_sudo
.
create
({
'
chart_template_id
'
:
pyme_char_template_id
,
'
kc_realm
'
:
str
(
self
.
id
),
})
})
rcs_sudo_id
.
execute
()
user
.
company_id
=
user_active_company_id
...
...
@@ -126,11 +134,11 @@ class ResCompany(models.Model):
'
number next
'
:
1
,
'
number_increment
'
:
1
,
'
company_id
'
:
self
.
id
,
'
date_range_ids
'
:
[(
0
,
0
,{
'
date_from
'
:
'
{}-01-01
'
.
format
(
datetime
.
now
().
year
),
'
date_range_ids
'
:
[(
0
,
0
,
{
'
date_from
'
:
'
{}-01-01
'
.
format
(
datetime
.
now
().
year
),
'
date_to
'
:
'
{}-12-31
'
.
format
(
datetime
.
now
().
year
),
'
number_next
'
:
1
,
'
number_next_actual
'
:
1
})]
'
number_next
'
:
1
,
'
number_next_actual
'
:
1
})]
})
subs_acc_jour
=
self
.
env
[
'
account.journal
'
].
sudo
().
create
({
'
name
'
:
'
Account Subscription Journal
'
,
...
...
@@ -139,23 +147,31 @@ class ResCompany(models.Model):
'
code
'
:
'
SUB_
'
,
'
sequence_number next
'
:
1
,
'
company_id
'
:
self
.
id
,
})
})
self
.
sudo
().
cooperator_journal
=
subs_acc_jour
.
id
# [3] update several accounts
xml_id_4400
=
"
{}_{}
"
.
format
(
self
.
id
,
'
account_common_4400
'
)
# 440000 | Deudores (euros)
account_4400_id
=
self
.
env
[
'
ir.model.data
'
].
sudo
().
get_object_reference
(
'
l10n_es
'
,
xml_id_4400
)[
1
]
# 440000 | Deudores (euros)
xml_id_4400
=
"
{}_{}
"
.
format
(
self
.
id
,
'
account_common_4400
'
)
account_4400_id
=
self
.
env
[
'
ir.model.data
'
].
sudo
(
).
get_object_reference
(
'
l10n_es
'
,
xml_id_4400
)[
1
]
self
.
sudo
().
property_cooperator_account
=
account_4400_id
xml_id_7000
=
"
{}_{}
"
.
format
(
self
.
id
,
'
account_common_7000
'
)
# 700000 | Ventas de mercaderías en España
account_7000_id
=
self
.
env
[
'
ir.model.data
'
].
get_object_reference
(
'
l10n_es
'
,
xml_id_7000
)[
1
]
self
.
env
.
ref
(
'
easy_my_coop.product_category_company_share
'
).
sudo
().
property_account_income_categ_id
=
account_7000_id
# 700000 | Ventas de mercaderías en España
xml_id_7000
=
"
{}_{}
"
.
format
(
self
.
id
,
'
account_common_7000
'
)
account_7000_id
=
self
.
env
[
'
ir.model.data
'
].
get_object_reference
(
'
l10n_es
'
,
xml_id_7000
)[
1
]
self
.
env
.
ref
(
'
easy_my_coop.product_category_company_share
'
).
sudo
(
).
property_account_income_categ_id
=
account_7000_id
xml_id_600
=
"
{}_{}
"
.
format
(
self
.
id
,
'
account_common_600
'
)
# 600000 | Ventas de mercaderías en España
account_600_id
=
self
.
env
[
'
ir.model.data
'
].
get_object_reference
(
'
l10n_es
'
,
xml_id_600
)[
1
]
self
.
env
.
ref
(
'
easy_my_coop.product_category_company_share
'
).
sudo
().
property_account_expense_categ_id
=
account_600_id
# 600000 | Ventas de mercaderías en España
xml_id_600
=
"
{}_{}
"
.
format
(
self
.
id
,
'
account_common_600
'
)
account_600_id
=
self
.
env
[
'
ir.model.data
'
].
get_object_reference
(
'
l10n_es
'
,
xml_id_600
)[
1
]
self
.
env
.
ref
(
'
easy_my_coop.product_category_company_share
'
).
sudo
(
).
property_account_expense_categ_id
=
account_600_id
# [4] create default_share_product
product_vals
=
{
...
...
@@ -174,7 +190,7 @@ class ResCompany(models.Model):
'
by_company
'
:
True
,
'
by_individual
'
:
True
,
'
company_id
'
:
self
.
id
,
}
}
self
.
env
[
'
product.template
'
].
sudo
().
create
(
product_vals
)
@api.multi
...
...
@@ -192,19 +208,20 @@ class ResCompany(models.Model):
def
get_active_services
(
self
):
"""
Return a list of dicts with the key data of each active Service
"""
self
.
ensure_one
()
ret
=
[]
ret
=
[]
# TODO: in a further iteration it will get the data from the "community services model"
# but nowadays (2022-09-26) it still don't exists so we are getting this info from the related crm_lead.tag_ids
creation_ce_source_id
=
self
.
env
[
'
ir.model.data
'
].
get_object_reference
(
'
ce
'
,
'
ce_source_creation_ce_proposal
'
)[
1
]
coordinator_id
=
self
.
get_real_ce_company_id
(
self
.
API_PARAM_ID_VALUE_FOR_COORDINADORA
).
id
creation_ce_source_id
=
self
.
env
[
'
ir.model.data
'
].
get_object_reference
(
'
ce
'
,
'
ce_source_creation_ce_proposal
'
)[
1
]
coordinator_id
=
self
.
get_real_ce_company_id
(
self
.
API_PARAM_ID_VALUE_FOR_COORDINADORA
).
id
lead_from
=
self
.
env
[
'
crm.lead
'
].
sudo
().
search
(
[(
'
company_id
'
,
'
=
'
,
coordinator_id
),
(
'
community_company_id
'
,
'
=
'
,
self
.
id
),
(
'
source_id
'
,
'
=
'
,
creation_ce_source_id
)]
,
limit
=
1
)
[(
'
company_id
'
,
'
=
'
,
coordinator_id
),
(
'
community_company_id
'
,
'
=
'
,
self
.
id
),
(
'
source_id
'
,
'
=
'
,
creation_ce_source_id
)],
limit
=
1
)
if
lead_from
:
for
tag
in
lead_from
.
tag_ids
:
...
...
@@ -214,6 +231,28 @@ class ResCompany(models.Model):
})
return
ret
@api.multi
def
get_public_web_landing_url
(
self
):
"""
Return the URL that points to the public landing web of the CE, reading it from the related
map place (field: external_link_url)
"""
self
.
ensure_one
()
ret
=
[]
coordinator_id
=
self
.
get_real_ce_company_id
(
self
.
API_PARAM_ID_VALUE_FOR_COORDINADORA
).
id
related_map_place
=
self
.
env
[
'
crm.team
'
].
sudo
().
search
(
[(
'
company_id
'
,
'
=
'
,
coordinator_id
),
(
'
community_company_id
'
,
'
=
'
,
self
.
id
),
(
'
map_id
'
,
'
=
'
,
self
.
env
.
ref
(
'
ce.ce_default_cm_map
'
).
id
)],
limit
=
1
)
return
related_map_place
and
related_map_place
.
external_link_url
or
None
@api.multi
def
get_keycloak_odoo_login_url
(
self
):
self
.
ensure_one
()
provider_dict
=
[
p_dict
for
p_dict
in
OAL
().
list_providers
()
if
p_dict
.
get
(
'
id
'
)
and
p_dict
.
get
(
'
id
'
)
==
self
.
auth_ce_key_cloak_provider_id
.
id
]
return
provider_dict
and
provider_dict
[
0
]
and
provider_dict
[
0
][
'
auth_link
'
]
or
''
@api.multi
def
get_kc_groups_data
(
self
):
"""
Proceed to get the list of the KC groups related to the current company > Realm
"""
...
...
@@ -235,4 +274,4 @@ class ResCompany(models.Model):
kc_wizard
.
_validate_setup
()
token
=
kc_wizard
.
_get_token
()
return
kc_wizard
.
_get_realm_groups_data
(
token
)
\ No newline at end of file
return
kc_wizard
.
_get_realm_groups_data
(
token
)
This diff is collapsed.
Click to expand it.
ce/services/ce_community_service.py
+
2
−
0
View file @
b0e3a2ec
...
...
@@ -82,6 +82,8 @@ class CommunityService(Component):
'
telegram
'
:
company
.
social_telegram
or
''
},
'
active_services
'
:
[],
'
allow_new_members
'
:
company
.
allow_new_members
,
"
public_web_landing_url
"
:
company
.
get_public_web_landing_url
()
or
''
,
"
keycloak_odoo_login_url
"
:
company
.
get_keycloak_odoo_login_url
()
or
''
,
}}
resp
[
'
community
'
].
update
(
CommunityService
.
_to_dict_members
(
...
...
This diff is collapsed.
Click to expand it.
ce/services/schemas.py
+
3
−
0
View file @
b0e3a2ec
...
...
@@ -25,6 +25,7 @@ S_CRM_LEAD_CREATE = {
"
type
"
:
"
integer
"
,
}
},
"
partner_description
"
:
{
"
type
"
:
"
string
"
},
}
S_CRM_LEAD_CREATE_ALTA_CE
=
{
...
...
@@ -188,6 +189,8 @@ S_COMMUNITY_RETURN_GET = {
},
},
"
allow_new_members
"
:
{
"
type
"
:
"
boolean
"
},
"
public_web_landing_url
"
:
{
"
type
"
:
"
string
"
},
"
keycloak_odoo_login_url
"
:
{
"
type
"
:
"
string
"
},
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment