Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] project_budget: added more usability #49

Merged
merged 2 commits into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions project_budget/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,25 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-10-05 11:00+0000\n"
"PO-Revision-Date: 2018-10-05 11:00+0000\n"
"POT-Creation-Date: 2018-10-16 22:02+0000\n"
"PO-Revision-Date: 2018-10-16 22:02+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: project_budget
#: model:ir.model.fields,field_description:project_budget.field_project_project_budget_count
msgid "# Budgets"
msgstr "Presupuestos"

#. module: project_budget
#: model:ir.model.fields,field_description:project_budget.field_project_project_current_budget_count
msgid "# Current Budgets"
msgstr "Presupuesto actual"

#. module: project_budget
#: model:ir.actions.act_window,help:project_budget.project_budget_action
msgid "A budget is a forecast of your company's income and/or expenses expected for a period in the future. A budget is defined on some financial accounts and/or analytic accounts (that may represent projects, departments, categories of products, etc.)"
Expand Down Expand Up @@ -48,8 +58,14 @@ msgstr "Archivado"
msgid "Budget"
msgstr "Presupuesto"

#. module: project_budget
#: model:ir.model.fields,field_description:project_budget.field_crossovered_budget_lines_budget_active
msgid "Budget Active"
msgstr "Budget Active"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presupuesto activo


#. module: project_budget
#: model:ir.model.fields,field_description:project_budget.field_crossovered_budget_budget_date
#: model:ir.model.fields,field_description:project_budget.field_crossovered_budget_lines_budget_date
msgid "Budget Date"
msgstr "Fecha del presupuesto"

Expand All @@ -63,14 +79,18 @@ msgstr "Línea de presupuesto"
msgid "Budget Lines"
msgstr "Líneas de Presupuesto"

#. module: project_budget
#: model:ir.ui.view,arch_db:project_budget.crossovered_budget_form_view
msgid "Budget Lines Pivot Report"
msgstr "Informe pivot"

#. module: project_budget
#: model:ir.ui.view,arch_db:project_budget.crossovered_budget_line_search_view
msgid "Budgetary Position"
msgstr "Posición Presupuestaria"

#. module: project_budget
#: model:ir.actions.act_window,name:project_budget.project_budget_action
#: model:ir.model.fields,field_description:project_budget.field_project_project_budget_count
#: model:ir.model.fields,field_description:project_budget.field_project_project_budget_ids
#: model:ir.ui.view,arch_db:project_budget.project_project_form_view
msgid "Budgets"
Expand All @@ -96,11 +116,23 @@ msgstr "Crear presupuesto inicial"
msgid "Create Lines"
msgstr "Crear elementos"

#. module: project_budget
#: model:ir.model.fields,field_description:project_budget.field_project_project_current_budget_id
#: model:ir.ui.view,arch_db:project_budget.crossovered_budget_search_view
#: model:ir.ui.view,arch_db:project_budget.project_project_form_view
msgid "Current Budget"
msgstr "Presupuesto actual"

#. module: project_budget
#: model:ir.ui.view,arch_db:project_budget.crossovered_budget_line_search_view
msgid "Group By"
msgstr "Agrupar por"

#. module: project_budget
#: model:ir.model.fields,field_description:project_budget.field_project_project_has_current_budget
msgid "Has Current Budget"
msgstr "Tiene presupuesto actual"

#. module: project_budget
#: model:ir.model.fields,field_description:project_budget.field_crossovered_budget_initial
#: model:ir.ui.view,arch_db:project_budget.crossovered_budget_search_view
Expand Down Expand Up @@ -131,6 +163,7 @@ msgstr "Importe planificado inicial"

#. module: project_budget
#: code:addons/project_budget/models/project_project.py:33
#: code:addons/project_budget/models/project_project.py:67
#, python-format
msgid "Initial {} budget: {}"
msgstr "Presupuesto inicial {}: {}"
Expand All @@ -156,6 +189,11 @@ msgstr "Proyecto"
msgid "There can only be one initial budget per project and year."
msgstr "Sólo puede haber un presupuesto inicial por proyecto y año."

#. module: project_budget
#: model:ir.ui.view,arch_db:project_budget.project_project_search_view
msgid "Unbudgeted"
msgstr "Sin presupuestar"

#. module: project_budget
#: model:ir.model.fields,field_description:project_budget.field_crossovered_budget_year
msgid "Year"
Expand Down
20 changes: 20 additions & 0 deletions project_budget/models/crossovered_budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ def copy(self, default=None):
})
return new

@api.multi
def open_pivot_view(self):
self.ensure_one()
action = self.env.ref(
'account_budget.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)],
})
return action_dict


class CrossoveredBudgetLines(models.Model):
_inherit = "crossovered.budget.lines"
Expand All @@ -110,6 +124,12 @@ class CrossoveredBudgetLines(models.Model):
related='crossovered_budget_id.project_id', store=True)
sum_amount = fields.Float(
string='Amount Sum', compute='_compute_sum_amount')
budget_active = fields.Boolean(
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)

@api.depends('planned_amount', 'practical_amount')
def _compute_sum_amount(self):
Expand Down
26 changes: 23 additions & 3 deletions project_budget/models/project_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ class ProjectProject(models.Model):
comodel_name='crossovered.budget', inverse_name='project_id',
string='Budgets')
budget_count = fields.Integer(
string='Budgets', compute='_compute_budget_count')
string='# Budgets', compute='_compute_budget_count')
current_budget_id = fields.Many2one(
comodel_name='crossovered.budget', compute='_compute_budget_count')
string='Current Budget', comodel_name='crossovered.budget',
compute='_compute_budget_count')
current_budget_count = fields.Integer(
string='Budgets', compute='_compute_budget_count')
string='# Current Budgets', compute='_compute_budget_count')
has_current_budget = fields.Boolean(
string='Has Current Budget', compute='_compute_budget_count',
search='_search_current_budget')

@api.multi
def _compute_budget_count(self):
Expand All @@ -35,6 +39,22 @@ def _compute_budget_count(self):
lambda b: b.budget_date >= month_start and
b.budget_date <= month_end)
record.current_budget_count = len(record.current_budget_id)
record.has_current_budget = bool(record.current_budget_id)

@api.multi
def _search_current_budget(self, operator, value):
today = from_string(fields.Date.context_today(self))
month_start = to_string(today.replace(day=1))
month_end = \
to_string(today.replace(
day=calendar.monthrange(today.year, today.month)[1]))
current_budgets = self.env['crossovered.budget'].search([
('project_id', '<>', False),
('budget_date', '>=', month_start),
('budget_date', '<=', month_end)])
operator = 'in' if ((operator == '=' and value) or
(operator == '!=' and not value)) else 'not in'
return [('id', operator, current_budgets.mapped('project_id').ids)]

@api.multi
def create_initial_project_budget(self):
Expand Down
8 changes: 6 additions & 2 deletions project_budget/tests/test_project_budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class TestProjectBudget(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestProjectBudget, cls).setUpClass()
project_model = cls.env['project.project']
cls.project = project_model.create({
cls.project_model = cls.env['project.project']
cls.project = cls.project_model.create({
'name': 'New Project'
})

Expand All @@ -23,6 +23,10 @@ def test_project_creation(self):
self.assertTrue(self.project.budget_ids[:1].initial)
self.assertEquals(
len(self.project.budget_ids), self.project.budget_count)
self.assertTrue(self.project.has_current_budget)
self.assertEquals(
self.project,
self.project.search([('has_current_budget', '=', True)]))
self.assertEquals(len(
self.project.mapped('budget_ids.crossovered_budget_line')), 26)
self.project.create_initial_project_budget()
Expand Down
3 changes: 3 additions & 0 deletions project_budget/views/crossovered_budget_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive">
<field name="active" widget="boolean_button"/>
</button>
<button name="open_pivot_view" type="object" class="oe_stat_button" icon="fa-archive">
<label string="Budget Lines Pivot Report" />
</button>
</div>
</div>
<field name="creating_user_id" position="after">
Expand Down
12 changes: 12 additions & 0 deletions project_budget/views/project_project_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@
</field>
</record>

<record id="project_project_search_view" model="ir.ui.view">
<field name="model">project.project</field>
<field name="inherit_id" ref="project.view_project_project_filter" />
<field name="arch" type="xml">
<filter name="inactive" position="after">
<separator />
<filter name="unbudgeted" string="Unbudgeted"
domain="[('has_current_budget', '!=', True)]" />
</filter>
</field>
</record>

<record id="action_create_initial_project_budget"
model="ir.actions.server">
<field name="name">Create Initial Budget</field>
Expand Down