[NEW] Add budget model funcitonnalities

User is able to generate budget model and model lines
User can reset a budget and generate one using an existing model
This commit is contained in:
Stéphan Sainléger
2022-05-22 18:36:48 +02:00
parent cc9101429a
commit 33521aef9b
12 changed files with 203 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ from . import account_analytic_account
from . import account_analytic_line
from . import account_move
from . import budget_forecast
from . import budget_forecast_model
from . import sale_order
from . import product
from . import project

View File

@@ -16,7 +16,6 @@ class BudgetForecast(models.Model):
"account.analytic.account",
"Analytic Account",
required=True,
ondelete="restrict",
index=True,
copy=True,
)
@@ -138,25 +137,24 @@ class BudgetForecast(models.Model):
parent_ids = self.mapped("parent_id")
if not child_unlink:
for record in self:
if not record.is_summary and (
record.display_type
in [
"line_section",
"line_subsection",
]
):
# find similar section/sub_section lines
lines = record.env["budget.forecast"].search(
[
if record.display_type in [
"line_section",
"line_subsection",
]:
if record.is_summary:
domain = [("summary_id", "=", record.id)]
else:
domain = [
("id", "!=", record.id),
"|",
("summary_id", "=", record.summary_id.id),
("id", "=", record.summary_id.id),
]
)
# find similar section/sub_section lines
lines = record.env["budget.forecast"].search(domain)
for line in lines:
line.unlink(True)
res = super(BudgetForecast, self).unlink()
parent_ids.exists()._calc_plan()
return res
@api.onchange("product_id")

View File

@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
class BudgetForecastModel(models.Model):
_name = "budget.forecast.model"
_description = _name
name = fields.Char("Name", copy=False)
class BudgetForecastModelLine(models.Model):
_name = "budget.forecast.model.line"
_description = _name
budget_model = fields.Many2one("budget.forecast.model", copy=True)
name = fields.Char("Name", copy=True)
display_type = fields.Selection(
[
("line_section", "Section"),
("line_subsection", "Sub-Section"),
],
copy=True,
store=True,
)
product_id = fields.Many2one(
"product.product", copy=True, domain="[('budget_level', '=', display_type)]"
)
parent_id = fields.Many2one(
"budget.forecast.model.line",
store=True,
copy=False,
)
child_ids = fields.One2many("budget.forecast.model.line", "parent_id", copy=False)