2019-03-25 18:41:48 +01:00
|
|
|
# Copyright 2019 Eficent Business and IT Consulting Services, S.L.
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
|
|
|
from odoo import _, api, fields, models
|
|
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
|
|
|
|
|
|
class AccountMoveBudgetLine(models.Model):
|
|
|
|
_name = "account.move.budget.line"
|
|
|
|
_description = "Account Move Budget Line"
|
|
|
|
_order = "date desc, id desc"
|
|
|
|
|
|
|
|
budget_id = fields.Many2one(
|
2019-12-30 11:26:37 +01:00
|
|
|
comodel_name="account.move.budget",
|
2019-03-25 18:41:48 +01:00
|
|
|
string="Budget",
|
|
|
|
required=True,
|
2019-12-30 11:26:37 +01:00
|
|
|
ondelete="cascade",
|
2019-03-25 18:41:48 +01:00
|
|
|
index=True,
|
|
|
|
)
|
|
|
|
name = fields.Char(string="Label")
|
2019-12-30 11:26:37 +01:00
|
|
|
debit = fields.Monetary(default=0.0, currency_field="company_currency_id")
|
|
|
|
credit = fields.Monetary(default=0.0, currency_field="company_currency_id")
|
2019-03-25 18:41:48 +01:00
|
|
|
balance = fields.Monetary(
|
2019-12-30 11:26:37 +01:00
|
|
|
compute="_compute_store_balance",
|
2019-03-25 18:41:48 +01:00
|
|
|
store=True,
|
2019-12-30 11:26:37 +01:00
|
|
|
currency_field="company_currency_id",
|
2019-03-25 18:41:48 +01:00
|
|
|
help="Technical field holding the debit - "
|
2019-12-30 11:26:37 +01:00
|
|
|
"credit in order to open meaningful "
|
|
|
|
"graph views from reports",
|
2019-03-25 18:41:48 +01:00
|
|
|
)
|
|
|
|
company_currency_id = fields.Many2one(
|
2019-12-30 11:26:37 +01:00
|
|
|
"res.currency",
|
|
|
|
related="company_id.currency_id",
|
2019-03-25 18:41:48 +01:00
|
|
|
string="Company Currency",
|
|
|
|
readonly=True,
|
2019-12-30 11:26:37 +01:00
|
|
|
help="Utility field to express amount currency",
|
2019-03-25 18:41:48 +01:00
|
|
|
store=True,
|
|
|
|
)
|
|
|
|
account_id = fields.Many2one(
|
2019-12-30 11:26:37 +01:00
|
|
|
"account.account",
|
|
|
|
string="Account",
|
2019-03-25 18:41:48 +01:00
|
|
|
required=True,
|
|
|
|
index=True,
|
|
|
|
ondelete="cascade",
|
2019-12-30 11:26:37 +01:00
|
|
|
domain=[("deprecated", "=", False)],
|
|
|
|
default=lambda self: self._context.get("account_id", False),
|
2019-03-25 18:41:48 +01:00
|
|
|
)
|
2019-12-30 11:26:37 +01:00
|
|
|
date = fields.Date(string="Date", index=True, required=True)
|
2019-03-25 18:41:48 +01:00
|
|
|
analytic_account_id = fields.Many2one(
|
2019-12-30 11:26:37 +01:00
|
|
|
"account.analytic.account", string="Analytic Account"
|
2019-03-25 18:41:48 +01:00
|
|
|
)
|
|
|
|
company_id = fields.Many2one(
|
2019-12-30 11:26:37 +01:00
|
|
|
"res.company",
|
|
|
|
related="account_id.company_id",
|
|
|
|
string="Company",
|
2019-03-25 18:41:48 +01:00
|
|
|
store=True,
|
|
|
|
readonly=True,
|
|
|
|
)
|
2019-12-30 11:26:37 +01:00
|
|
|
partner_id = fields.Many2one("res.partner", string="Partner", ondelete="restrict")
|
2019-03-25 18:41:48 +01:00
|
|
|
|
2019-12-30 11:26:37 +01:00
|
|
|
@api.depends("debit", "credit")
|
2019-03-25 18:41:48 +01:00
|
|
|
def _compute_store_balance(self):
|
|
|
|
for line in self:
|
|
|
|
line.balance = line.debit - line.credit
|
|
|
|
|
2019-12-30 11:26:37 +01:00
|
|
|
@api.constrains("date")
|
2019-03-25 18:41:48 +01:00
|
|
|
def _constraint_date(self):
|
|
|
|
for rec in self:
|
2019-12-30 11:26:37 +01:00
|
|
|
if rec.budget_id.date_from > rec.date or rec.budget_id.date_to < rec.date:
|
|
|
|
raise ValidationError(
|
|
|
|
_("The date must be within the " "budget period.")
|
|
|
|
)
|