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
4629e32b
Commit
4629e32b
authored
1 year ago
by
Emanuel Buzey
Committed by
Daniil Digtyar Vasilieva
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
[REF] energy_selfconsumption: refactor generate_contract_button
parent
c981beac
No related branches found
No related tags found
2 merge requests
!253
[REL] Release 06/11/23
,
!211
[IMP] energy_selfconsumption: invoicing acquired power
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
energy_selfconsumption/wizards/contract_generation_wizard.py
+40
-48
40 additions, 48 deletions
energy_selfconsumption/wizards/contract_generation_wizard.py
with
40 additions
and
48 deletions
energy_selfconsumption/wizards/contract_generation_wizard.py
+
40
−
48
View file @
4629e32b
...
...
@@ -34,6 +34,21 @@ class ContractGenerationWizard(models.TransientModel):
)
def
generate_contracts_button
(
self
):
"""
This method generates contracts based on supply point assignations.
It first creates a product and a contract formula. It then
aggregates supply point assignations by partner and owner
to generate the contracts.
Returns:
bool: Always True, indicating successful execution.
Raises:
UserWarning: When no accounting journal is found.
SomeException: When no distribution table in process of activation is found.
"""
# Create product
product_id
=
self
.
env
[
"
product.product
"
].
create
(
{
"
name
"
:
_
(
"
Energy Generated
"
),
...
...
@@ -42,6 +57,7 @@ class ContractGenerationWizard(models.TransientModel):
}
)
# Create contract formula
formula_contract_id
=
self
.
env
[
"
contract.line.qty.formula
"
].
create
(
{
"
name
"
:
_
(
"
Formula - %s
"
)
%
(
self
.
selfconsumption_id
.
name
),
...
...
@@ -49,37 +65,14 @@ class ContractGenerationWizard(models.TransientModel):
}
)
# Search accounting journal
journal_id
=
self
.
env
[
"
account.journal
"
].
search
(
[(
"
company_id
"
,
"
=
"
,
self
.
env
.
company
.
id
),
(
"
type
"
,
"
=
"
,
"
sale
"
)],
limit
=
1
)
if
not
journal_id
:
raise
UserWarning
(
_
(
"
Accounting Journal not found.
"
))
contract_template
=
self
.
env
[
"
contract.template
"
].
create
(
{
"
name
"
:
_
(
"
Contract Template - %s
"
)
%
self
.
selfconsumption_id
.
name
,
"
company_id
"
:
self
.
env
.
company
.
id
,
"
contract_type
"
:
"
sale
"
,
"
journal_id
"
:
journal_id
.
id
,
"
contract_line_ids
"
:
[
(
0
,
0
,
{
"
product_id
"
:
product_id
.
id
,
"
company_id
"
:
self
.
env
.
company
.
id
,
"
qty_type
"
:
"
fixed
"
,
"
quantity
"
:
1
,
"
recurring_interval
"
:
self
.
recurring_interval
,
"
recurring_rule_type
"
:
self
.
recurring_rule_type
,
"
recurring_invoicing_type
"
:
"
post-paid
"
,
"
name
"
:
_
(
"
Energy produced
"
),
},
)
],
}
)
# Get distribution table
distribution_id
=
(
self
.
selfconsumption_id
.
distribution_table_ids
.
filtered_domain
(
[(
"
state
"
,
"
=
"
,
"
process
"
)]
...
...
@@ -88,10 +81,9 @@ class ContractGenerationWizard(models.TransientModel):
if
not
distribution_id
:
raise
_
(
"
There is no distribution table in proces of activation.
"
)
supply_point_assignation_ids
=
distribution_id
.
supply
_
point
_
assign
ation_ids
# Build partner list and
supply
point
assign
ment
partner_list
=
{}
for
supply_point_assignation
in
supply_point_assignation_ids
:
for
supply_point_assignation
in
distribution_id
.
supply_point_assignation_ids
:
key
=
(
supply_point_assignation
.
supply_point_id
.
partner_id
.
id
,
supply_point_assignation
.
owner_id
.
id
,
...
...
@@ -107,31 +99,31 @@ class ContractGenerationWizard(models.TransientModel):
supply_point_assignation
)
for
key
,
value
in
partner_list
.
items
():
contract_lines
=
[]
for
supply_point_assignation_id
in
value
[
"
supply_point_assignation_ids
"
]:
contract_lines
.
append
(
(
0
,
0
,
{
"
product_id
"
:
product_id
.
id
,
"
automatic_price
"
:
True
,
"
company_id
"
:
self
.
env
.
company
.
id
,
"
qty_type
"
:
"
variable
"
,
"
qty_formula_id
"
:
formula_contract_id
.
id
,
"
name
"
:
_
(
supply_point_assignation_id
.
supply_point_id
.
code
),
"
supply_point_assignation_id
"
:
supply_point_assignation_id
.
id
,
},
)
# Create contracts
for
partner_data
in
partner_list
.
values
():
contract_lines
=
[
(
0
,
0
,
{
"
product_id
"
:
product_id
.
id
,
"
automatic_price
"
:
True
,
"
company_id
"
:
self
.
env
.
company
.
id
,
"
qty_type
"
:
"
variable
"
,
"
qty_formula_id
"
:
formula_contract_id
.
id
,
"
name
"
:
_
(
assignation
.
supply_point_id
.
code
),
"
supply_point_assignation_id
"
:
assignation
.
id
,
},
)
for
assignation
in
partner_data
[
"
supply_point_assignation_ids
"
]
]
self
.
env
[
"
contract.contract
"
].
create
(
{
"
name
"
:
_
(
"
Contract - %s - %s
"
)
%
(
self
.
selfconsumption_id
.
name
,
value
[
"
parent_id
"
].
name
),
"
partner_id
"
:
value
[
"
parent_id
"
].
id
,
"
invoice_partner_id
"
:
value
[
"
parent_id
"
].
id
,
%
(
self
.
selfconsumption_id
.
name
,
partner_data
[
"
parent_id
"
].
name
),
"
partner_id
"
:
partner_data
[
"
parent_id
"
].
id
,
"
invoice_partner_id
"
:
partner_data
[
"
parent_id
"
].
id
,
"
journal_id
"
:
journal_id
.
id
,
"
recurring_interval
"
:
self
.
recurring_interval
,
"
recurring_rule_type
"
:
self
.
recurring_rule_type
,
...
...
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