generated from OCA/oca-addons-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
42 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,24 @@ | ||
# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, models | ||
from odoo.exceptions import UserError | ||
from odoo import models | ||
|
||
|
||
class BudgetPeriod(models.Model): | ||
_inherit = "budget.period" | ||
|
||
@api.model | ||
def _get_kpi_by_control_key(self, template_lines, control): | ||
activity_id = control["activity_id"] | ||
template_line = self._get_filter_template_line(template_lines, control) | ||
if len(template_line) == 1: | ||
return template_line | ||
# Invalid Template Lines | ||
activity = self.env["budget.activity"].browse(activity_id) | ||
if not template_line: | ||
raise UserError( | ||
_("Chosen activity %s is not valid in template") % activity.display_name | ||
) | ||
raise UserError( | ||
_( | ||
"Template Lines has more than one KPI being " | ||
"referenced by the same account code %s" | ||
) | ||
% (activity.display_name) | ||
) | ||
def _get_control_key_obj(self, control_key, control_id): | ||
if control_key == "activity_id": | ||
control = self.env["budget.activity"].browse(control_id) | ||
control_name = "activity" | ||
return control, control_name | ||
return super()._get_control_key_obj(control_key, control_id) | ||
|
||
def _get_filter_template_line(self, all_template_lines, control): | ||
"""Overwrite filter template line from account_id to activity_id""" | ||
activity_id = control["activity_id"] | ||
template_lines = all_template_lines.filtered( | ||
lambda l: activity_id in l.activity_ids.ids | ||
) | ||
return template_lines | ||
budget_control_key = self.env.company.budget_control_key | ||
control_id = control[budget_control_key] | ||
if budget_control_key == "activity_id": | ||
return all_template_lines.filtered( | ||
lambda l: control_id in l.activity_ids.ids | ||
) | ||
return super()._get_filter_template_line(all_template_lines, control) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2020 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = "res.company" | ||
|
||
budget_control_key = fields.Selection( | ||
selection_add=[("activity_id", "Activity")], | ||
ondelete={"activity_id": "cascade"}, | ||
) |