Skip to content

Commit 82912ea

Browse files
committed
Small UI enh for budget plan and control
1 parent 60b041c commit 82912ea

File tree

5 files changed

+23
-79
lines changed

5 files changed

+23
-79
lines changed

account_budget_activity/models/account_budget.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class AccountBudget(models.Model):
163163
store=True,
164164
)
165165
past_consumed = fields.Float(
166-
string='Past Actual',
166+
string='Consumed',
167167
compute='_compute_past_future_rolling',
168168
help="Commitment + Actual for the past months",
169169
)
@@ -192,13 +192,22 @@ def _get_past_consumed_domain(self):
192192
('period_id', '<', current_period.id)]
193193
return dom
194194

195+
@api.multi
196+
def _budget_expense_lines_hook(self):
197+
self.ensure_one()
198+
return self.budget_expense_line_ids
199+
195200
@api.multi
196201
def _get_future_plan_amount(self):
197202
self.ensure_one()
198203
Period = self.env['account.period']
199-
period_num = Period.get_num_period_by_period() # Now
204+
period_num = 1
205+
date_start = Period.find().date_start
206+
if self.fiscalyear_id.date_start <= date_start:
207+
period_num = Period.get_num_period_by_period() # Now
200208
future_plan = 0.0
201-
for line in self.budget_expense_line_ids:
209+
expense_lines = self._budget_expense_lines_hook()
210+
for line in expense_lines:
202211
for i in range(period_num, 13):
203212
future_plan += line['m%s' % (i,)]
204213
return future_plan
@@ -694,9 +703,12 @@ def write(self, vals):
694703
@api.depends()
695704
def _compute_current_period(self):
696705
Period = self.env['account.period']
706+
date_start = Period.find().date_start
697707
for rec in self:
698708
if rec.budget_id.budget_level_id.adjust_past_plan:
699709
rec.current_period = 0
710+
elif rec.fiscalyear_id.date_start > date_start:
711+
rec.current_period = 0
700712
else:
701713
rec.current_period = Period.get_num_period_by_period()
702714

account_budget_activity/views/account_budget_view.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
<field name="creating_user_id"/>
9999
<field name="budgeted_revenue"/>
100100
<field name="budgeted_expense"/>
101-
<field name="budgeted_overall"/>
101+
<field name="budgeted_overall" invisible="1"/>
102102
<field name="budget_level_id" invisible="1"/>
103103
</group>
104104
<group>
@@ -172,7 +172,7 @@
172172
<field name="name"/>
173173
<field name="budgeted_revenue"/>
174174
<field name="budgeted_expense"/>
175-
<field name="budgeted_overall"/>
175+
<field name="budgeted_overall" invisible="1"/>
176176
<field name="released_amount" sum="Released Amount"/>
177177
<field name="creating_user_id"/>
178178
<field name="state"/>

pabi_budget_internal_charge/models/account_budget.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,10 @@ def _compute_budgeted_overall(self):
6060
rec.budgeted_expense_internal = expense_internal
6161

6262
@api.multi
63-
def _get_future_plan_amount(self):
64-
""" Overwrite """
63+
def _budget_expense_lines_hook(self):
6564
self.ensure_one()
66-
Period = self.env['account.period']
67-
period_num = Period.get_num_period_by_period() # Now
68-
future_plan = 0.0
69-
for line in self.budget_expense_line_ids.\
70-
filtered(lambda l: l.charge_type == 'external'): # Add this
71-
for i in range(period_num, 13):
72-
future_plan += line['m%s' % (i,)]
73-
return future_plan
65+
return self.budget_expense_line_ids.\
66+
filtered(lambda l: l.charge_type == 'external')
7467

7568

7669
class AccountBudgetLine(models.Model):

pabi_budget_plan/models/account_budget.py

-61
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,10 @@ class AccountBudget(models.Model):
77
_inherit = 'account.budget'
88
_order = 'create_date desc'
99

10-
# prev_planned_amount = fields.Float(
11-
# string='Planned Amount',
12-
# readonly=True,
13-
# )
1410
policy_amount = fields.Float(
1511
string='Policy Amount',
1612
readonly=True,
1713
)
18-
# ref_breakdown_id = fields.Many2one(
19-
# 'budget.fiscal.policy.breakdown',
20-
# string="Breakdown Reference",
21-
# copy=True,
22-
# readonly=True,
23-
# )
2414

2515
@api.multi
2616
def _get_doc_number(self):
@@ -92,25 +82,6 @@ def _check_fiscalyear_section_unique(self):
9282
raise ValidationError(
9383
_('Duplicated budget on the same fiscal year!'))
9484

95-
# @api.multi
96-
# def budget_confirm(self):
97-
# for rec in self:
98-
# name = self.env['ir.sequence'].next_by_code('budget.control.unit')
99-
# rec.write({'name': name})
100-
# # rec.ref_budget_id.budget_cancel()
101-
# return super(AccountBudget, self).budget_confirm()
102-
103-
# # New Revision
104-
# @api.multi
105-
# def new_minor_revision(self):
106-
# result = super(AccountBudget, self).new_minor_revision()
107-
# if result.get('domain', []):
108-
# new_budget_id = result['domain'][0][2]
109-
# new_budget = self.browse(new_budget_id)
110-
# new_budget.ref_budget_id = self.id
111-
# new_budget.name = '/'
112-
# return result
113-
11485
@api.multi
11586
def unlink(self):
11687
for policy in self:
@@ -119,35 +90,3 @@ def unlink(self):
11990
_('Cannot delete budget(s)\
12091
which are not in draft or cancelled.'))
12192
return super(AccountBudget, self).unlink()
122-
123-
# @api.multi
124-
# def get_all_version(self):
125-
# self.ensure_one()
126-
# budget_ids = []
127-
# if self.ref_budget_id:
128-
# budget = self.ref_budget_id
129-
# while budget:
130-
# budget_ids.append(budget.id)
131-
# budget = budget.ref_budget_id
132-
# budget = self
133-
# while budget:
134-
# ref_budget =\
135-
# self.search([('ref_budget_id', '=', budget.id)])
136-
# if ref_budget:
137-
# budget_ids.append(ref_budget.id)
138-
# budget = ref_budget
139-
# act = 'account_budget_activity.act_account_budget_view'
140-
# action = self.env.ref(act)
141-
# result = action.read()[0]
142-
# dom = [('id', 'in', budget_ids)]
143-
# result.update({'domain': dom})
144-
# return result
145-
146-
147-
class AccountBudgetLine(models.Model):
148-
_inherit = 'account.budget.line'
149-
150-
planned_amount = fields.Float(
151-
string='Current Amount', # Existing field, change label only
152-
help="Current Planned Amount"
153-
)

pabi_chartfield/views/account_budget_view.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197

198198
<!-- ACTIVITY -->
199199
<field name="activity_group_id" invisible="0"/>
200-
<field name="activity_id" invisible="0" domain="[('activity_group_ids', 'in', [activity_group_id or -1]), ('budget_method', '=', budget_method)]"/>
200+
<field name="activity_id" invisible="1" domain="[('activity_group_ids', 'in', [activity_group_id or -1]), ('budget_method', '=', budget_method)]"/>
201201

202202
<!-- PERIOD -->
203203
<field name="planned_amount" sum="Planned Amount"/>
@@ -267,7 +267,7 @@
267267

268268
<!-- ACTIVITY -->
269269
<field name="activity_group_id" invisible="0"/>
270-
<field name="activity_id" invisible="0" domain="[('activity_group_ids', 'in', [activity_group_id or -1]), ('budget_method', '=', budget_method)]"/>
270+
<field name="activity_id" invisible="1" domain="[('activity_group_ids', 'in', [activity_group_id or -1]), ('budget_method', '=', budget_method)]"/>
271271

272272
<!-- PERIOD -->
273273
<field name="planned_amount" sum="Planned Amount"/>
@@ -328,7 +328,7 @@
328328
<field name="cost_control_id" invisible="1" />
329329
<!-- ACTIVITY -->
330330
<field name="activity_group_id" invisible="0"/>
331-
<field name="activity_id" invisible="0" domain="[('activity_group_ids', 'in', [activity_group_id or -1]), ('budget_method', '=', budget_method)]"/>
331+
<field name="activity_id" invisible="1" domain="[('activity_group_ids', 'in', [activity_group_id or -1]), ('budget_method', '=', budget_method)]"/>
332332
<!-- PERIOD -->
333333
<field name="planned_amount" sum="Planned Amount"/>
334334
<field name="budget_release" invisible="0"/>

0 commit comments

Comments
 (0)