2019-03-25 18:41:48 +01:00
|
|
|
# Copyright 2019 ACSONE SA/NV
|
2019-12-30 11:49:20 +01:00
|
|
|
# Copyright 2019 ForgeFlow S.L. (http://www.forgeflow.com)
|
2019-03-25 18:41:48 +01:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
|
|
|
from odoo import _, api, fields, models
|
|
|
|
|
|
|
|
|
|
|
|
class AccountMoveBudget(models.Model):
|
|
|
|
_name = "account.move.budget"
|
|
|
|
_description = "Account Move Budget"
|
2019-12-30 11:26:37 +01:00
|
|
|
_inherit = ["mail.thread", "mail.activity.mixin"]
|
2019-03-25 18:41:48 +01:00
|
|
|
|
2022-01-10 15:03:32 +01:00
|
|
|
name = fields.Char(
|
|
|
|
required=True,
|
|
|
|
tracking=True,
|
|
|
|
)
|
|
|
|
description = fields.Char(
|
|
|
|
tracking=True,
|
|
|
|
)
|
2019-12-30 11:26:37 +01:00
|
|
|
date_range_id = fields.Many2one(comodel_name="date.range", string="Date range")
|
2019-03-25 18:41:48 +01:00
|
|
|
date_from = fields.Date(
|
2022-01-10 15:03:32 +01:00
|
|
|
required=True,
|
|
|
|
string="From Date",
|
|
|
|
tracking=True,
|
|
|
|
)
|
|
|
|
date_to = fields.Date(
|
|
|
|
required=True,
|
|
|
|
string="To Date",
|
|
|
|
tracking=True,
|
2019-03-25 18:41:48 +01:00
|
|
|
)
|
|
|
|
state = fields.Selection(
|
2019-12-30 11:26:37 +01:00
|
|
|
[("draft", "Draft"), ("confirmed", "Confirmed"), ("cancelled", "Cancelled")],
|
2019-03-25 18:41:48 +01:00
|
|
|
required=True,
|
2019-12-30 11:26:37 +01:00
|
|
|
default="draft",
|
2022-01-10 15:03:32 +01:00
|
|
|
tracking=True,
|
2019-03-25 18:41:48 +01:00
|
|
|
)
|
|
|
|
line_ids = fields.One2many(
|
2019-12-30 11:26:37 +01:00
|
|
|
comodel_name="account.move.budget.line", inverse_name="budget_id", copy=True
|
2019-03-25 18:41:48 +01:00
|
|
|
)
|
|
|
|
company_id = fields.Many2one(
|
2019-12-30 11:49:20 +01:00
|
|
|
comodel_name="res.company",
|
|
|
|
string="Company",
|
|
|
|
default=lambda self: self.env.company,
|
2019-03-25 18:41:48 +01:00
|
|
|
)
|
|
|
|
|
2019-12-30 11:49:20 +01:00
|
|
|
@api.returns("self", lambda value: value.id)
|
2019-03-25 18:41:48 +01:00
|
|
|
def copy(self, default=None):
|
|
|
|
self.ensure_one()
|
|
|
|
if default is None:
|
|
|
|
default = {}
|
2019-12-30 11:26:37 +01:00
|
|
|
if "name" not in default:
|
|
|
|
default["name"] = _("%s (copy)") % self.name
|
2019-03-25 18:41:48 +01:00
|
|
|
return super(AccountMoveBudget, self).copy(default=default)
|
|
|
|
|
2019-12-30 11:26:37 +01:00
|
|
|
@api.onchange("date_range_id")
|
2019-03-25 18:41:48 +01:00
|
|
|
def _onchange_date_range(self):
|
|
|
|
for rec in self:
|
|
|
|
if rec.date_range_id:
|
|
|
|
rec.date_from = rec.date_range_id.date_start
|
|
|
|
rec.date_to = rec.date_range_id.date_end
|
|
|
|
|
2019-12-30 11:26:37 +01:00
|
|
|
@api.onchange("date_from", "date_to")
|
2019-03-25 18:41:48 +01:00
|
|
|
def _onchange_dates(self):
|
|
|
|
for rec in self:
|
|
|
|
if rec.date_range_id:
|
2019-12-30 11:26:37 +01:00
|
|
|
if (
|
|
|
|
rec.date_from != rec.date_range_id.date_start
|
|
|
|
or rec.date_to != rec.date_range_id.date_end
|
|
|
|
):
|
2019-03-25 18:41:48 +01:00
|
|
|
rec.date_range_id = False
|
|
|
|
|
|
|
|
def action_draft(self):
|
|
|
|
for rec in self:
|
2019-12-30 11:26:37 +01:00
|
|
|
rec.state = "draft"
|
2019-03-25 18:41:48 +01:00
|
|
|
|
|
|
|
def action_cancel(self):
|
|
|
|
for rec in self:
|
2019-12-30 11:26:37 +01:00
|
|
|
rec.state = "cancelled"
|
2019-03-25 18:41:48 +01:00
|
|
|
|
|
|
|
def action_confirm(self):
|
|
|
|
for rec in self:
|
2019-12-30 11:26:37 +01:00
|
|
|
rec.state = "confirmed"
|