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
52b0d418
Commit
52b0d418
authored
1 year ago
by
emanuel buzey
Committed by
Daniil Digtyar Vasilieva
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Coefficient report in .txt file added
parent
53172b03
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!195
[REL] 14.0.2.0.0
,
!192
[IMP] self_consumption: adding reports and documents
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
energy_selfconsumption/models/selfconsumption.py
+57
-38
57 additions, 38 deletions
energy_selfconsumption/models/selfconsumption.py
energy_selfconsumption/views/selfconsumption_views.xml
+7
-0
7 additions, 0 deletions
energy_selfconsumption/views/selfconsumption_views.xml
with
64 additions
and
38 deletions
energy_selfconsumption/models/selfconsumption.py
+
57
−
38
View file @
52b0d418
from
odoo
import
_
,
fields
,
models
from
odoo.exceptions
import
ValidationError
import
io
import
base64
class
Selfconsumption
(
models
.
Model
):
...
...
@@ -22,15 +24,9 @@ class Selfconsumption(models.Model):
"
energy_project.project
"
,
required
=
True
,
ondelete
=
"
cascade
"
)
code
=
fields
.
Char
(
string
=
"
CAU
"
)
cil
=
fields
.
Char
(
string
=
"
CIL
"
,
help
=
"
Production facility code for liquidation purposes
"
)
owner_id
=
fields
.
Many2one
(
"
res.partner
"
,
string
=
"
Owner
"
,
required
=
True
,
default
=
lambda
self
:
self
.
env
.
company
.
partner_id
,
)
cil
=
fields
.
Char
(
string
=
"
CIL
"
,
help
=
"
Production facility code for liquidation purposes
"
)
owner_id
=
fields
.
Many2one
(
"
res.partner
"
,
string
=
"
Owner
"
,
required
=
True
,
default
=
lambda
self
:
self
.
env
.
company
.
partner_id
)
power
=
fields
.
Float
(
string
=
"
Generation Power (kW)
"
)
distribution_table_ids
=
fields
.
One2many
(
"
energy_selfconsumption.distribution_table
"
,
...
...
@@ -38,44 +34,40 @@ class Selfconsumption(models.Model):
readonly
=
True
,
)
distribution_table_count
=
fields
.
Integer
(
compute
=
_compute_distribution_table_count
)
inscription_ids
=
fields
.
One2many
(
"
energy_project.inscription
"
,
"
project_id
"
,
readonly
=
True
)
inscription_ids
=
fields
.
One2many
(
'
energy_project.inscription
'
,
'
project_id
'
,
readonly
=
True
)
inscription_count
=
fields
.
Integer
(
compute
=
_compute_inscription_count
)
report_file
=
fields
.
Binary
(
string
=
"
Report File
"
,
attachment
=
True
)
report_file_name
=
fields
.
Char
(
string
=
"
Report File Name
"
)
def
get_distribution_tables
(
self
):
self
.
ensure_one
()
return
{
"
type
"
:
"
ir.actions.act_window
"
,
"
name
"
:
"
Distribution Tables
"
,
"
view_mode
"
:
"
tree,form
"
,
"
res_model
"
:
"
energy_selfconsumption.distribution_table
"
,
"
domain
"
:
[(
"
selfconsumption_project_id
"
,
"
=
"
,
self
.
id
)],
"
context
"
:
{
"
create
"
:
True
,
"
default_selfconsumption_project_id
"
:
self
.
id
},
'
type
'
:
'
ir.actions.act_window
'
,
'
name
'
:
'
Distribution Tables
'
,
'
view_mode
'
:
'
tree,form
'
,
'
res_model
'
:
'
energy_selfconsumption.distribution_table
'
,
'
domain
'
:
[(
'
selfconsumption_project_id
'
,
'
=
'
,
self
.
id
)],
'
context
'
:
{
'
create
'
:
True
,
'
default_selfconsumption_project_id
'
:
self
.
id
},
}
def
get_inscriptions
(
self
):
self
.
ensure_one
()
return
{
"
type
"
:
"
ir.actions.act_window
"
,
"
name
"
:
"
Inscriptions
"
,
"
view_mode
"
:
"
tree,form
"
,
"
res_model
"
:
"
energy_project.inscription
"
,
"
domain
"
:
[(
"
project_id
"
,
"
=
"
,
self
.
id
)],
"
context
"
:
{
"
create
"
:
True
,
"
default_project_id
"
:
self
.
id
},
'
type
'
:
'
ir.actions.act_window
'
,
'
name
'
:
'
Inscriptions
'
,
'
view_mode
'
:
'
tree,form
'
,
'
res_model
'
:
'
energy_project.inscription
'
,
'
domain
'
:
[(
'
project_id
'
,
'
=
'
,
self
.
id
)],
'
context
'
:
{
'
create
'
:
True
,
'
default_project_id
'
:
self
.
id
},
}
def
distribution_table_state
(
self
,
actual_state
,
new_state
):
distribution_table_to_activate
=
self
.
distribution_table_ids
.
filtered
(
lambda
table
:
table
.
state
==
actual_state
)
distribution_table_to_activate
=
self
.
distribution_table_ids
.
filtered
(
lambda
table
:
table
.
state
==
actual_state
)
distribution_table_to_activate
.
write
({
"
state
"
:
new_state
})
def
set_in_activation_state
(
self
):
for
record
in
self
:
if
not
record
.
distribution_table_ids
.
filtered_domain
(
[(
"
state
"
,
"
=
"
,
"
validated
"
)]
):
if
not
record
.
distribution_table_ids
.
filtered_domain
([(
'
state
'
,
'
=
'
,
'
validated
'
)]):
raise
ValidationError
(
_
(
"
Must have a valid Distribution Table.
"
))
record
.
write
({
"
state
"
:
"
activation
"
})
self
.
distribution_table_state
(
"
validated
"
,
"
process
"
)
...
...
@@ -94,19 +86,19 @@ class Selfconsumption(models.Model):
def
action_selfconsumption_import_wizard
(
self
):
self
.
ensure_one
()
return
{
"
name
"
:
_
(
"
Import Inscriptions and Supply Points
"
),
"
type
"
:
"
ir.actions.act_window
"
,
"
view_mode
"
:
"
form
"
,
"
res_model
"
:
"
energy_selfconsumption.selfconsumption_import.wizard
"
,
"
views
"
:
[(
False
,
"
form
"
)],
"
view_id
"
:
False
,
"
target
"
:
"
new
"
,
'
name
'
:
_
(
'
Import Inscriptions and Supply Points
'
),
'
type
'
:
'
ir.actions.act_window
'
,
'
view_mode
'
:
'
form
'
,
'
res_model
'
:
'
energy_selfconsumption.selfconsumption_import.wizard
'
,
'
views
'
:
[(
False
,
'
form
'
)],
'
view_id
'
:
False
,
'
target
'
:
'
new
'
,
}
def
set_inscription
(
self
,
selfconsumption_state
):
for
record
in
self
:
record
.
write
({
"
state
"
:
"
inscription
"
})
if
selfconsumption_state
==
"
activation
"
:
if
selfconsumption_state
==
'
activation
'
:
self
.
distribution_table_state
(
"
process
"
,
"
validated
"
)
def
set_draft
(
self
):
...
...
@@ -116,3 +108,30 @@ class Selfconsumption(models.Model):
def
action_manager_authorization_report
(
self
):
self
.
ensure_one
()
return
self
.
env
.
ref
(
'
energy_selfconsumption.selfconsumption_manager_authorization_report
'
).
report_action
(
self
)
def
action_manager_partition_coefficient_report
(
self
):
report_data
=
[]
process_tables
=
self
.
distribution_table_ids
.
filtered
(
lambda
table
:
table
.
state
==
'
process
'
)
active_tables
=
self
.
distribution_table_ids
.
filtered
(
lambda
table
:
table
.
state
==
'
active
'
)
tables_to_use
=
process_tables
or
active_tables
for
table
in
tables_to_use
:
for
assignation
in
table
.
supply_point_assignation_ids
:
report_data
.
append
({
'
code
'
:
assignation
.
supply_point_id
.
code
,
'
coefficient
'
:
assignation
.
coefficient
,
})
file_content
=
"
Code;Coefficient
\n
"
for
data
in
report_data
:
line
=
f
"
{
data
[
'
code
'
]
}
;
{
str
(
data
[
'
coefficient
'
]).
replace
(
'
.
'
,
'
,
'
)
}
\n
"
file_content
+=
line
txt_file
=
io
.
BytesIO
(
file_content
.
encode
())
file_name
=
"
coefficient_report.txt
"
self
.
write
({
'
report_file
'
:
base64
.
b64encode
(
txt_file
.
getvalue
()),
'
report_file_name
'
:
file_name
,
})
return
{
'
type
'
:
'
ir.actions.act_url
'
,
'
url
'
:
f
'
web/content/
{
self
.
_name
}
/
{
self
.
id
}
/report_file/
{
file_name
}
?download=true
'
,
'
target
'
:
'
new
'
,
}
This diff is collapsed.
Click to expand it.
energy_selfconsumption/views/selfconsumption_views.xml
+
7
−
0
View file @
52b0d418
...
...
@@ -57,6 +57,13 @@
string=
"Download Self-consumption Manager Authorization"
attrs=
"{'invisible':[('state','not in',['activation', 'active'])]}"
/>
<button
type=
"object"
name=
"action_manager_partition_coefficient_report"
string=
"Download Partition Coefficient"
attrs=
"{'invisible':[('state','not in',['activation', 'active'])]}"
/>
<field
name=
"state"
widget=
"statusbar"
...
...
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