Skip to content

Commit e2dc377

Browse files
committed
Budget Transfer ready
1 parent cffe656 commit e2dc377

26 files changed

+501
-194
lines changed

account_budget_activity/__openerp__.py

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
'security/ir.model.access.csv',
3535
'security/account_budget_security.xml',
3636
'wizard/budget_release_wizard_view.xml',
37+
'wizard/change_release_amount_view.xml',
3738
'views/purchase_view.xml',
3839
'views/purchase_requisition_view.xml',
3940
'views/purchase_request_view.xml',

account_budget_activity/models/account_budget.py

+65-34
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
class AccountBudget(models.Model):
2020
_name = "account.budget"
21+
_inherit = ['mail.thread']
2122
_description = "Budget"
2223

2324
BUDGET_LEVEL = {
@@ -48,6 +49,7 @@ class AccountBudget(models.Model):
4849
string='Responsible User',
4950
default=lambda self: self.env.user,
5051
readonly=True,
52+
states={'draft': [('readonly', False)]},
5153
)
5254
# validating_user_id = fields.Many2one(
5355
# 'res.users',
@@ -72,7 +74,8 @@ class AccountBudget(models.Model):
7274
index=True,
7375
required=True,
7476
readonly=True,
75-
# copy=False,
77+
copy=False,
78+
track_visibility='onchange',
7679
)
7780
budget_line_ids = fields.One2many(
7881
'account.budget.line',
@@ -97,12 +100,6 @@ class AccountBudget(models.Model):
97100
domain=[('budget_method', '=', 'expense')],
98101
# copy=True,
99102
)
100-
company_id = fields.Many2one(
101-
'res.company',
102-
string='Company',
103-
required=True,
104-
default=lambda self: self.env.user.company_id,
105-
)
106103
# version = fields.Float(
107104
# string='Revision',
108105
# readonly=True,
@@ -122,15 +119,12 @@ class AccountBudget(models.Model):
122119
'account.fiscalyear',
123120
string='Fiscal Year',
124121
required=True,
125-
)
126-
currency_id = fields.Many2one(
127-
'res.currency',
128-
string="Currency",
129-
default=lambda self: self.env.user.company_id.currency_id,
130122
readonly=True,
123+
states={'draft': [('readonly', False)]},
131124
)
132125
to_release_amount = fields.Float(
133126
string='Released Amount',
127+
readonly=True,
134128
)
135129
released_amount = fields.Float(
136130
string='Released Amount',
@@ -183,6 +177,11 @@ class AccountBudget(models.Model):
183177
compute='_compute_past_future_rolling',
184178
help="Past Actual + Future Plan",
185179
)
180+
release_diff_rolling = fields.Float(
181+
string='Release - Rolling',
182+
compute='_compute_release_diff_rolling',
183+
help="Release amount - rolling amount",
184+
)
186185

187186
@api.multi
188187
def _get_past_consumed_domain(self):
@@ -217,16 +216,26 @@ def _compute_past_future_rolling(self):
217216
# Rolling
218217
budget.rolling = budget.past_consumed + budget.future_plan
219218

219+
@api.multi
220+
@api.depends()
221+
def _compute_release_diff_rolling(self):
222+
for budget in self:
223+
amount_diff = budget.released_amount - budget.rolling
224+
budget.release_diff_rolling = amount_diff
225+
220226
@api.multi
221227
def write(self, vals):
222228
res = super(AccountBudget, self).write(vals)
223229
for budget in self:
224230
if budget.budget_level_id.budget_release == 'manual_header':
225-
if budget.budget_expense_line_ids:
226-
budget.budget_expense_line_ids.write(
227-
{'released_amount': 0.0})
228-
budget.budget_expense_line_ids[0].write(
229-
{'released_amount': budget.to_release_amount})
231+
if not budget.budget_expense_line_ids:
232+
raise ValidationError(
233+
_('Budget %s has no expense line!\n'
234+
'This operation can not proceed.') % (budget.name,))
235+
budget.budget_expense_line_ids.write(
236+
{'released_amount': 0.0})
237+
budget.budget_expense_line_ids[0].write(
238+
{'released_amount': budget.to_release_amount})
230239
return res
231240

232241
@api.multi
@@ -302,11 +311,12 @@ def _validate_plan_vs_release(self):
302311
if budget.budget_level_id.check_plan_with_released_amount:
303312
if budget.rolling > budget.released_amount:
304313
raise ValidationError(
305-
_('Rolling plan (%s) will exceed released amount (%s) '
306-
'on budget control - %s') %
307-
(budget.rolling,
308-
budget.released_amount,
309-
budget.name_get()[0][1]))
314+
_('%s: rolling plan (%s) will exceed '
315+
'released amount (%s) after this operation!') %
316+
(budget.name_get()[0][1],
317+
'{:,.2f}'.format(budget.rolling),
318+
'{:,.2f}'.format(budget.released_amount),
319+
))
310320
return True
311321

312322
# @api.multi
@@ -417,7 +427,7 @@ def check_budget(self, fiscal_id, budget_type,
417427
'[%s] the requested budget is %s,\n'
418428
'but there is no budget control for it.') % \
419429
(fiscal.name, resource.name_get()[0][1],
420-
'{0:,}'.format(amount))
430+
'{:,.2f}'.format(amount))
421431
return res
422432
else: # Current Budget Status
423433
res['budget_status'].update({
@@ -437,14 +447,14 @@ def check_budget(self, fiscal_id, budget_type,
437447
'%s, not enough budget, this transaction '
438448
'will result in ฿%s over budget!') % \
439449
(fiscal.name, resource.name_get()[0][1],
440-
'{0:,}'.format(-monitors[0].amount_balance))
450+
'{:,.2f}'.format(-monitors[0].amount_balance))
441451
else:
442452
res['message'] = _('%s\n'
443453
'%s, remaining budget is %s,\n'
444454
'but the requested budget is %s') % \
445455
(fiscal.name, resource.name_get()[0][1],
446-
'{0:,}'.format(monitors[0].amount_balance),
447-
'{0:,}'.format(amount))
456+
'{:,.2f}'.format(monitors[0].amount_balance),
457+
'{:,.2f}'.format(amount))
448458

449459
if not blevel.is_budget_control:
450460
res['budget_ok'] = True # No control, just return information
@@ -587,14 +597,6 @@ class AccountBudgetLine(ActivityCommon, models.Model):
587597
index=True,
588598
required=True,
589599
)
590-
company_id = fields.Many2one(
591-
'res.company',
592-
related='budget_id.company_id',
593-
string='Company',
594-
type='many2one',
595-
store=True,
596-
readonly=True,
597-
)
598600
fiscalyear_id = fields.Many2one(
599601
'account.fiscalyear',
600602
string='Fiscal Year',
@@ -681,6 +683,11 @@ def write(self, vals):
681683
if m in vals:
682684
raise ValidationError(
683685
_('Adjusting past plan amount is not allowed!'))
686+
# Post change in tracking fields, m1, ... , m12
687+
for rec in self:
688+
message = self._change_budget_content(rec, vals)
689+
if message:
690+
rec.budget_id.message_post(body=message)
684691
return super(AccountBudgetLine, self).write(vals)
685692

686693
@api.multi
@@ -768,3 +775,27 @@ def release_budget_line(self, release_result):
768775
amount_to_release = release_result.get(rec.id, 0.0)
769776
rec.write({'released_amount': amount_to_release})
770777
return
778+
779+
# Messaging
780+
@api.model
781+
def _change_budget_content(self, line, vals):
782+
_track_fields = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6',
783+
'm7', 'm8', 'm9', 'm10', 'm11', 'm12', ]
784+
if set(_track_fields).isdisjoint(vals.keys()):
785+
return False
786+
title = _('Budget amount change(s)')
787+
message = '<h3>%s</h3><ul>' % title
788+
# Get the line label
789+
line_labels = [line.activity_group_id.name,
790+
line.activity_id.name]
791+
line_labels = filter(lambda a: a is not False, line_labels)
792+
line_label = '/'.join(line_labels)
793+
for field in _track_fields:
794+
if field in vals:
795+
message += _(
796+
'<li><b>%s</b>: %s → %s</li>'
797+
) % (line_label,
798+
'{:,.2f}'.format(line[field]),
799+
'{:,.2f}'.format(vals.get(field)), )
800+
message += '</ul>'
801+
return message

account_budget_activity/security/account_budget_security.xml

-15
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,6 @@
22
<openerp>
33
<data noupdate="1">
44

5-
6-
<record id="budget_comp_rule" model="ir.rule">
7-
<field name="name">Budget multi-company</field>
8-
<field name="model_id" ref="model_account_budget"/>
9-
<field eval="True" name="global"/>
10-
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
11-
</record>
12-
13-
<record id="budget_lines_comp_rule" model="ir.rule">
14-
<field name="name">Budget lines multi-company</field>
15-
<field name="model_id" ref="model_account_budget_line"/>
16-
<field eval="True" name="global"/>
17-
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
18-
</record>
19-
205
<record model="res.users" id="base.user_root">
216
<field eval="[(4,ref('analytic.group_analytic_accounting'))]" name="groups_id"/>
227
</record>

account_budget_activity/views/account_budget_view.xml

+36-33
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@
9292
<field name="name" attrs="{'readonly':[('state','!=','draft')]}"/>
9393
</h1>
9494
</div>
95-
<div class="oe_right oe_button_box" name="buttons">
96-
</div>
95+
<div class="oe_right oe_button_box" name="buttons"></div>
9796
<group>
9897
<group>
9998
<field name="creating_user_id"/>
@@ -104,18 +103,21 @@
104103
</group>
105104
<group>
106105
<field name="fiscalyear_id"/>
107-
<field name="currency_id"/>
108106
<label for="date_from" string="Duration"/>
109107
<div>
110108
<field name="date_from" class="oe_inline" attrs="{'readonly':[('state','!=','draft')]}"/>
111109
-
112110
<field name="date_to" class="oe_inline" attrs="{'readonly':[('state','!=','draft')]}" nolabel="1"/>
113111
</div>
114-
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
115112
<field name="budget_release" invisible="1"/>
116-
<field name="released_amount" widget="monetary" options="{'currency_field': 'currency_id'}" class="oe_inline" attrs="{'invisible': [('budget_release', '=', 'manual_header')]}"/>
117-
<field name="to_release_amount" widget="monetary" options="{'currency_field': 'currency_id'}" class="oe_inline" attrs="{'invisible': [('budget_release', '!=', 'manual_header')],
118-
'required': [('budget_release', '=', 'manual_header')]}"/>
113+
<field name="released_amount" class="oe_inline" attrs="{'invisible': [('budget_release', '=', 'manual_header')]}"/>
114+
<!-- To Release Amount -->
115+
<label for="to_release_amount" attrs="{'invisible': [('budget_release', '!=', 'manual_header')]}"/>
116+
<div attrs="{'invisible': [('budget_release', '!=', 'manual_header')]}">
117+
<field name="to_release_amount" class="oe_inline"
118+
attrs="{'required': [('budget_release', '=', 'manual_header')]}"/>
119+
<button name="%(action_change_release_amount)d" string="⇒ Update" type="action" class="oe_link"/>
120+
</div>
119121
</group>
120122
</group>
121123
<notebook>
@@ -125,9 +127,9 @@
125127
<group>
126128
<group></group>
127129
<group class="oe_subtotal_footer oe_right">
128-
<field name="past_consumed" widget="monetary" options="{'currency_field': 'currency_id'}" />
129-
<field name="future_plan" widget="monetary" options="{'currency_field': 'currency_id'}" />
130-
<field name="rolling" widget="monetary" options="{'currency_field': 'currency_id'}" class="oe_subtotal_footer_separator"/>
130+
<field name="past_consumed"/>
131+
<field name="future_plan"/>
132+
<field name="rolling" class="oe_subtotal_footer_separator"/>
131133
</group>
132134
</group>
133135
</page>
@@ -153,6 +155,10 @@
153155
</page> -->
154156
</notebook>
155157
</sheet>
158+
<div class="oe_chatter">
159+
<field name="message_follower_ids" widget="mail_followers"/>
160+
<field name="message_ids" widget="mail_thread"/>
161+
</div>
156162
</form>
157163
</field>
158164
</record>
@@ -162,12 +168,12 @@
162168
<field name="model">account.budget</field>
163169
<field name="arch" type="xml">
164170
<tree colors="blue:state == 'draft';black:state in ('done')" string="Budget">
165-
<field name="name"/>
166171
<field name="fiscalyear_id"/>
167-
<field name="date_from"/>
168-
<field name="date_to"/>
172+
<field name="name"/>
173+
<field name="budgeted_revenue"/>
174+
<field name="budgeted_expense"/>
175+
<field name="budgeted_overall"/>
169176
<field name="released_amount" sum="Released Amount"/>
170-
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
171177
<field name="creating_user_id"/>
172178
<field name="state"/>
173179
</tree>
@@ -183,7 +189,7 @@
183189
<field name="date_from"/>
184190
<field name="date_to"/>
185191
<filter string="Draft" icon="terp-document-new" domain="[('state','=','draft')]" help="Draft Budgets"/>
186-
<filter string="To Approve" icon="terp-camera_test" domain="[('state','=','confirm')]" help="To Approve Budgets"/>
192+
<filter string="Controlled" icon="terp-camera_test" domain="[('state','=','done')]" help="Controlled Budgets"/>
187193
<field name="state"/>
188194
</search>
189195
</field>
@@ -223,11 +229,8 @@
223229
<field name="fiscalyear_id"/>
224230
<field name="planned_amount" sum="Planned Amount"/>
225231
<field name="budget_release" invisible="1"/>
226-
<button name="%(action_budget_release_wizard)d"
227-
attrs="{'invisible': [('budget_release', 'not in', ('auto', 'manual_line'))]}"
228-
string="Release Budget" type="action" icon="terp-gtk-jump-to-ltr"/>
229-
<field name="released_amount" sum="Released"
230-
attrs="{'invisible': [('budget_release', 'not in', ('auto', 'manual_line'))]}"/>
232+
<button name="%(action_budget_release_wizard)d" attrs="{'invisible': [('budget_release', 'not in', ('auto', 'manual_line'))]}" string="Release Budget" type="action" icon="terp-gtk-jump-to-ltr"/>
233+
<field name="released_amount" sum="Released" attrs="{'invisible': [('budget_release', 'not in', ('auto', 'manual_line'))]}"/>
231234
<field name="current_period" invisible="1"/>
232235
<field name="m1" attrs="{'readonly': [('current_period', '>=', 1)]}" sum="m1"/>
233236
<field name="m2" attrs="{'readonly': [('current_period', '>=', 2)]}" sum="m2"/>
@@ -256,19 +259,19 @@
256259
<field name="released_amount"/>
257260
</group>
258261
<group>
259-
<field name="current_period" invisible="1"/>
260-
<field name="m1" attrs="{'readonly': [('current_period', '>=', 1)]}" sum="m1"/>
261-
<field name="m2" attrs="{'readonly': [('current_period', '>=', 2)]}" sum="m2"/>
262-
<field name="m3" attrs="{'readonly': [('current_period', '>=', 3)]}" sum="m3"/>
263-
<field name="m4" attrs="{'readonly': [('current_period', '>=', 4)]}" sum="m4"/>
264-
<field name="m5" attrs="{'readonly': [('current_period', '>=', 5)]}" sum="m5"/>
265-
<field name="m6" attrs="{'readonly': [('current_period', '>=', 6)]}" sum="m6"/>
266-
<field name="m7" attrs="{'readonly': [('current_period', '>=', 7)]}" sum="m7"/>
267-
<field name="m8" attrs="{'readonly': [('current_period', '>=', 8)]}" sum="m8"/>
268-
<field name="m9" attrs="{'readonly': [('current_period', '>=', 9)]}" sum="m9"/>
269-
<field name="m10" attrs="{'readonly': [('current_period', '>=', 10)]}" sum="m10"/>
270-
<field name="m11" attrs="{'readonly': [('current_period', '>=', 11)]}" sum="m11"/>
271-
<field name="m12" attrs="{'readonly': [('current_period', '>=', 12)]}" sum="m12"/>
262+
<field name="current_period" invisible="1"/>
263+
<field name="m1" attrs="{'readonly': [('current_period', '>=', 1)]}" sum="m1"/>
264+
<field name="m2" attrs="{'readonly': [('current_period', '>=', 2)]}" sum="m2"/>
265+
<field name="m3" attrs="{'readonly': [('current_period', '>=', 3)]}" sum="m3"/>
266+
<field name="m4" attrs="{'readonly': [('current_period', '>=', 4)]}" sum="m4"/>
267+
<field name="m5" attrs="{'readonly': [('current_period', '>=', 5)]}" sum="m5"/>
268+
<field name="m6" attrs="{'readonly': [('current_period', '>=', 6)]}" sum="m6"/>
269+
<field name="m7" attrs="{'readonly': [('current_period', '>=', 7)]}" sum="m7"/>
270+
<field name="m8" attrs="{'readonly': [('current_period', '>=', 8)]}" sum="m8"/>
271+
<field name="m9" attrs="{'readonly': [('current_period', '>=', 9)]}" sum="m9"/>
272+
<field name="m10" attrs="{'readonly': [('current_period', '>=', 10)]}" sum="m10"/>
273+
<field name="m11" attrs="{'readonly': [('current_period', '>=', 11)]}" sum="m11"/>
274+
<field name="m12" attrs="{'readonly': [('current_period', '>=', 12)]}" sum="m12"/>
272275
</group>
273276
</group>
274277
</sheet>

account_budget_activity/wizard/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
from . import purchase_request_line_make_purchase_requisition
44
from . import budget_release_wizard
5+
from . import change_release_amount

0 commit comments

Comments
 (0)