2
0
account-financial-tools/account_move_budget/models/account_move_budget.py

83 lines
2.4 KiB
Python
Raw Permalink Normal View History

2019-03-25 18:41:48 +01:00
# Copyright 2019 ACSONE SA/NV
# 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"
_inherit = ["mail.thread", "mail.activity.mixin"]
2019-03-25 18:41:48 +01:00
name = fields.Char(
required=True,
tracking=True,
)
description = fields.Char(
tracking=True,
)
date_range_id = fields.Many2one(comodel_name="date.range", string="Date range")
2019-03-25 18:41:48 +01:00
date_from = fields.Date(
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(
[("draft", "Draft"), ("confirmed", "Confirmed"), ("cancelled", "Cancelled")],
2019-03-25 18:41:48 +01:00
required=True,
default="draft",
tracking=True,
2019-03-25 18:41:48 +01:00
)
line_ids = fields.One2many(
comodel_name="account.move.budget.line", inverse_name="budget_id", copy=True
2019-03-25 18:41:48 +01:00
)
company_id = fields.Many2one(
comodel_name="res.company",
string="Company",
default=lambda self: self.env.company,
2019-03-25 18:41:48 +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 = {}
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)
@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
@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:
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:
rec.state = "draft"
2019-03-25 18:41:48 +01:00
def action_cancel(self):
for rec in self:
rec.state = "cancelled"
2019-03-25 18:41:48 +01:00
def action_confirm(self):
for rec in self:
rec.state = "confirmed"