Skip to content

Commit

Permalink
Migrate submodule project_budget to v16
Browse files Browse the repository at this point in the history
  • Loading branch information
marrasbinovo committed Oct 25, 2024
1 parent b9e7494 commit 048f9d2
Show file tree
Hide file tree
Showing 13 changed files with 538 additions and 432 deletions.
8 changes: 2 additions & 6 deletions project_budget/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@
"Oihane Crucelaegui <[email protected]>",
"Ana Juaristi <[email protected]>",
],
"depends": [
"account_budget_oca",
"account_budget_template",
"project",
],
"depends": ["account_budget_oca", "account_budget_template", "project"],
"data": [
"security/ir.model.access.csv",
"security/project_budget_groups.xml",
#"data/project_budget_data.xml",
"data/project_budget_data.xml",
"views/crossovered_budget_view.xml",
"views/crossovered_budget_line_view.xml",
"views/project_project_view.xml",
Expand Down
4 changes: 2 additions & 2 deletions project_budget/data/project_budget_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<record id="account_account_income" model="account.account">
<field name="code">000</field>
<field name="name">Income</field>
<field name="user_type_id" ref="account.data_account_type_revenue" />
<field name="account_type">income</field>
<field name="deprecated">True</field>
</record>

<record id="account_account_expenses" model="account.account">
<field name="code">001</field>
<field name="name">Expenses</field>
<field name="user_type_id" ref="account.data_account_type_expenses" />
<field name="account_type">expense</field>
<field name="deprecated">True</field>
</record>

Expand Down
317 changes: 172 additions & 145 deletions project_budget/i18n/es.po

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions project_budget/migrations/11.0.3.0.0/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@


def update_budget_date(cr):
cr.execute("""
cr.execute(
"""
ALTER TABLE
crossovered_budget
ADD COLUMN
budget_date date;
""")
cr.execute("""
"""
)
cr.execute(
"""
UPDATE
crossovered_budget
SET
budget_date = create_date;
""")
"""
)


def migrate(cr, version):
Expand Down
22 changes: 10 additions & 12 deletions project_budget/models/account_analytic_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@


class AccountAnalyticAccount(models.Model):
_inherit = 'account.analytic.account'
_inherit = "account.analytic.account"

def _domain_budget_line(self):
if not self:
return []
all_lines = self.env['crossovered.budget.lines'].search(
[('analytic_account_id', '=', self.id)])
last_budget = all_lines.mapped('crossovered_budget_id')[-1:]
domain = (
[('crossovered_budget_id', '=', last_budget.id)] if last_budget
else [])
all_lines = self.env["crossovered.budget.lines"].search(
[("analytic_account_id", "=", self.id)]
)
last_budget = all_lines.mapped("crossovered_budget_id")[-1:]
domain = [("crossovered_budget_id", "=", last_budget.id)] if last_budget else []
return domain

crossovered_budget_line = fields.One2many(
comodel_name='crossovered.budget.lines',
inverse_name='analytic_account_id',
string='Budget Lines',
domain=lambda self: self._domain_budget_line()
comodel_name="crossovered.budget.lines",
inverse_name="analytic_account_id",
string="Budget Lines",
domain=lambda self: self._domain_budget_line(),
)

193 changes: 120 additions & 73 deletions project_budget/models/crossovered_budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,144 +8,191 @@


class CrossoveredBudget(models.Model):
_inherit = 'crossovered.budget'
_inherit = "crossovered.budget"

project_id = fields.Many2one(
comodel_name='project.project', string='Project',
states={'done': [('readonly', True)]}, ondelete='cascade')
comodel_name="project.project",
string="Project",
states={"done": [("readonly", True)]},
ondelete="cascade",
)
project_user_id = fields.Many2one(
comodel_name='res.users', string='Project Manager',
related='project_id.user_id', store=True)
comodel_name="res.users",
string="Project Manager",
related="project_id.user_id",
store=True,
)
initial = fields.Boolean(
string='Initial', copy=False, states={'done': [('readonly', True)]})
active = fields.Boolean(string='Active', default=True)
year = fields.Integer(string='Year', compute='_compute_year', store=True)
string="Initial", copy=False, states={"done": [("readonly", True)]}
)
active = fields.Boolean(string="Active", default=True)
year = fields.Integer(string="Year", compute="_compute_year", store=True)
budget_date = fields.Date(
string='Budget Date', default=lambda s: fields.Date.context_today(s))
string="Budget Date", default=lambda s: fields.Date.context_today(s)
)
notes = fields.Text(string="Notes")
crossovered_budget_line = fields.One2many(
comodel_name='crossovered.budget.lines',
inverse_name='crossovered_budget_id',
string='Budget Lines'
comodel_name="crossovered.budget.lines",
inverse_name="crossovered_budget_id",
string="Budget Lines",
)
show_create_lines_button = fields.Boolean(
compute="_compute_show_create_lines_button"
)

@api.depends('date_from')
def _compute_show_create_lines_button(self):
for record in self:
record.show_create_lines_button = (
record.state == "draft"
and record.project_id
and not record.crossovered_budget_line
)

@api.depends("date_from")
def _compute_year(self):
for record in self:
if record.date_from:
record.year = from_string(record.date_from).year

def action_create_period(self):
super(CrossoveredBudget, self).action_create_period()
budget_line_obj = self.env['crossovered.budget.lines']
for budget in self.filtered(lambda b: b.project_id and b.state == 'draft'):
budget.crossovered_budget_line.write({
'analytic_account_id': budget.project_id.analytic_account_id.id,
})
get_param = self.env['ir.config_parameter'].sudo().get_param
if get_param('project_budget.summary_line', 'False').lower() == 'true':
budget_line_obj = self.env["crossovered.budget.lines"]
for budget in self.filtered(lambda b: b.project_id and b.state == "draft"):
budget.crossovered_budget_line.write(
{"analytic_account_id": budget.project_id.analytic_account_id.id}
)
get_param = self.env["ir.config_parameter"].sudo().get_param
if get_param("project_budget.summary_line", "False").lower() == "true":
budget_posts = budget.budget_tmpl_id.budget_post_ids
vals = {
'analytic_account_id': budget.project_id.analytic_account_id.id,
'crossovered_budget_id': budget.id,
'planned_amount': 0.0,
"analytic_account_id": budget.project_id.analytic_account_id.id,
"crossovered_budget_id": budget.id,
"planned_amount": 0.0,
}
ds = from_string(budget.date_from)
final_date = ds.replace(day=30, month=12)
if to_string(final_date) < budget.date_to:
budget_date_to = fields.Date.from_string(budget.date_to)
if final_date < budget_date_to:
for budget_post in budget_posts:
vals.update({
'date_from': to_string(final_date),
'date_to': to_string(final_date),
'general_budget_id': budget_post.id,
})
vals.update(
{
"date_from": to_string(final_date),
"date_to": to_string(final_date),
"general_budget_id": budget_post.id,
}
)
budget_line_obj.create(vals)
return True

@api.constrains('project_id', 'initial', 'date_from')
@api.constrains("project_id", "initial", "date_from")
def _check_initial_by_project(self):
for record in self.filtered('project_id'):
if len(self.search([('project_id', '=', record.project_id.id),
('initial', '=', True),
('year', '=', record.year)])) > 1:
for record in self.filtered("project_id"):
if (
len(
self.search(
[
("project_id", "=", record.project_id.id),
("initial", "=", True),
("year", "=", record.year),
]
)
)
> 1
):
raise exceptions.ValidationError(
_("There can only be one initial budget per project and year."))
_("There can only be one initial budget per project and year.")
)

@api.returns('self', lambda value: value.id)
@api.returns("self", lambda value: value.id)
def copy(self, default=None):
new = super(CrossoveredBudget, self).copy(default=default)
self.filtered(lambda b: not b.initial).write({
'active': False,
})
self.filtered(lambda b: not b.initial).write({"active": False})
return new

def button_recompute_line_amount(self):
self.mapped('crossovered_budget_line').button_recompute_amount()
self.mapped("crossovered_budget_line").button_recompute_amount()

def open_pivot_view(self):
self.ensure_one()
self.button_recompute_line_amount()
action = self.env.ref('account_budget_oca.act_crossovered_budget_lines_view')
action = self.env.ref("account_budget_oca.act_crossovered_budget_lines_view")
action_dict = action.read()[0]
action_dict.update({
'view_mode': 'pivot',
'view_id': False,
'views': [],
'domain': [('crossovered_budget_id', '=', self.id)],
})
action_dict.update(
{
"view_mode": "pivot",
"view_id": False,
"views": [],
"domain": [("crossovered_budget_id", "=", self.id)],
}
)
return action_dict


class CrossoveredBudgetLines(models.Model):
_inherit = "crossovered.budget.lines"

initial_budget_line_id = fields.Many2one(
comodel_name='crossovered.budget.lines', string='Initial Budget Line')
comodel_name="crossovered.budget.lines", string="Initial Budget Line"
)
initial_planned_amount = fields.Float(
string='Initial Planned Amount', digits=0, store=True,
compute='_compute_initial_planned_amount')
notes = fields.Text(string='Notes')
string="Initial Planned Amount",
digits=0,
store=True,
compute="_compute_initial_planned_amount",
)
notes = fields.Text(string="Notes")
project_id = fields.Many2one(
comodel_name='project.project', string='Project',
related='crossovered_budget_id.project_id', store=True)
comodel_name="project.project",
string="Project",
related="crossovered_budget_id.project_id",
store=True,
)
project_user_id = fields.Many2one(
comodel_name='res.users', string='Project Manager',
related='crossovered_budget_id.project_id.user_id', store=True)
comodel_name="res.users",
string="Project Manager",
related="crossovered_budget_id.project_id.user_id",
store=True,
)
sum_amount = fields.Float(
string='Amount Sum', compute='_compute_sum_amount', store=True)
string="Amount Sum", compute="_compute_sum_amount", store=True
)
budget_active = fields.Boolean(
string='Budget Active',
related='crossovered_budget_id.active', store=True)
string="Budget Active", related="crossovered_budget_id.active", store=True
)
budget_date = fields.Date(
string='Budget Date',
related='crossovered_budget_id.budget_date', store=True)
string="Budget Date", related="crossovered_budget_id.budget_date", store=True
)
practical_amount = fields.Float(store=True)


def button_recompute_amount(self):
fields_list = ['practical_amount', 'sum_amount']
for record in self:
for field in fields_list:
record._recompute_field(field)

@api.depends('initial_budget_line_id', 'planned_amount',
'initial_budget_line_id.planned_amount')
fnames = ["practical_amount", "sum_amount"]
for fname in fnames:
self.env.add_to_compute(self._fields[fname], self)
self.modified(fnames)

@api.depends(
"initial_budget_line_id",
"planned_amount",
"initial_budget_line_id.planned_amount",
)
def _compute_initial_planned_amount(self):
for line in self:
line.initial_planned_amount = (
line.initial_budget_line_id.planned_amount
if line.initial_budget_line_id else line.planned_amount)
if line.initial_budget_line_id
else line.planned_amount
)

@api.returns(None, lambda value: value[0])
def copy_data(self, default=None):
self.ensure_one()
default = default or {}
default.update({
'initial_budget_line_id': self.initial_budget_line_id.id or self.id,
})
default.update(
{"initial_budget_line_id": self.initial_budget_line_id.id or self.id}
)
return super(CrossoveredBudgetLines, self).copy_data(default=default)

@api.depends('planned_amount', 'practical_amount')
@api.depends("planned_amount", "practical_amount")
def _compute_sum_amount(self):
for record in self:
record.sum_amount = record.planned_amount + record.practical_amount
Loading

0 comments on commit 048f9d2

Please sign in to comment.