[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:
@@ -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
|
||||
|
@@ -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")
|
||||
|
37
account_budget_forecast/models/budget_forecast_model.py
Normal file
37
account_budget_forecast/models/budget_forecast_model.py
Normal 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)
|
Reference in New Issue
Block a user