Skip to content

Commit e307701

Browse files
committed
Start working on unit base
1 parent 7b3714e commit e307701

24 files changed

+544
-25
lines changed

account_budget_activity/models/account_budget.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class AccountBudget(models.Model):
5252
creating_user_id = fields.Many2one(
5353
'res.users',
5454
string='Responsible User',
55-
default=lambda self: self._uid,
55+
default=lambda self: self.env.user,
5656
)
5757
validating_user_id = fields.Many2one(
5858
'res.users',

pabi_budget_plan/__openerp__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
'security/ir.model.access.csv',
1818
'data/sequence.xml',
1919
'data/history_rule.xml',
20-
'wizard/cost_control_breakdown_wizard.xml',
20+
# 'wizard/cost_control_breakdown_wizard.xml',
2121
'wizard/convert_to_budget_control_wizard.xml',
2222
'wizard/asset_plan_to_budget_plan_wizard.xml',
2323
'wizard/invest_asset_select_wizard_view.xml',
24+
'wizard/generate_budget_plan_wizard.xml',
2425
'views/budget_plan_menu.xml',
25-
'views/budget_plan_unit_view.xml',
26+
'view/budget_plan_unit_view.xml',
27+
# 'views/budget_plan_unit_view.xml',
2628
'views/budget_plan_project_view.xml',
2729
'views/budget_plan_personnel_view.xml',
2830
'views/budget_plan_invest_asset_view.xml',

pabi_budget_plan/model/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
22

33
from . import budget_plan_common
4+
from . import budget_plan_unit
45
from . import budget_plan_invest_construction

pabi_budget_plan/model/budget_plan_common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class BPCommon(object):
2727
user_id = fields.Many2one(
2828
'res.users',
2929
string='Responsible User',
30-
default=lambda self: self._uid,
30+
default=lambda self: self.env.user,
3131
)
3232
date = fields.Date(
3333
string='Date',
@@ -38,7 +38,7 @@ class BPCommon(object):
3838
'account.fiscalyear',
3939
string='Fiscal Year',
4040
required=True,
41-
default=lambda self: self.env['account.fiscalyear'].find(),
41+
default=lambda self: self.env['account.period'].find().fiscalyear_id,
4242
)
4343
date_from = fields.Date(
4444
string='Start Date',

pabi_budget_plan/model/budget_plan_invest_construction.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,12 @@ class BudgetPlanInvestConstruction(BPCommon, LogCommon, models.Model):
3636
domain=[('budget_method', '=', 'expense')], # Have domain
3737
track_visibility='onchange',
3838
)
39-
# --
39+
# Select Dimension - ORG
4040
org_id = fields.Many2one(
4141
'res.org',
4242
string='Org',
4343
required=True,
4444
)
45-
plan_line_ids = fields.One2many(
46-
'budget.plan.invest.construction.line',
47-
'plan_id',
48-
string='Budget Plan Lines',
49-
copy=True,
50-
track_visibility='onchange',
51-
)
5245
info_line_ids = fields.One2many(
5346
'budget.plan.invest.construction.line',
5447
'plan_id',
+207
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
# -*- coding: utf-8 -*-
2+
from openerp import tools
3+
from openerp import models, fields, api, _
4+
from openerp.exceptions import ValidationError
5+
from .budget_plan_common import BPCommon, BPLMonthCommon
6+
from openerp.addons.account_budget_activity.models.account_activity \
7+
import ActivityCommon
8+
from openerp.addons.document_status_history.models.document_history import \
9+
LogCommon
10+
11+
12+
class BudgetPlanUnit(BPCommon, LogCommon, models.Model):
13+
_name = 'budget.plan.unit'
14+
_inherit = ['mail.thread']
15+
_description = "Unit - Budget Plan"
16+
17+
# COMMON
18+
plan_line_ids = fields.One2many(
19+
'budget.plan.unit.line',
20+
'plan_id',
21+
string='Budget Plan Lines',
22+
copy=True,
23+
track_visibility='onchange',
24+
)
25+
plan_revenue_line_ids = fields.One2many(
26+
'budget.plan.unit.line',
27+
'plan_id',
28+
string='Revenue Plan Lines',
29+
copy=True,
30+
domain=[('budget_method', '=', 'revenue')], # Have domain
31+
track_visibility='onchange',
32+
)
33+
plan_expense_line_ids = fields.One2many(
34+
'budget.plan.unit.line',
35+
'plan_id',
36+
string='Expense Plan Lines',
37+
copy=True,
38+
domain=[('budget_method', '=', 'expense')], # Have domain
39+
track_visibility='onchange',
40+
)
41+
plan_summary_revenue_line_ids = fields.One2many(
42+
'budget.plan.unit.summary',
43+
'plan_id',
44+
string='Summary by Activity Group',
45+
domain=[('budget_method', '=', 'revenue')],
46+
readonly=True,
47+
help="Summary by Activity Group View",
48+
)
49+
plan_summary_expense_line_ids = fields.One2many(
50+
'budget.plan.unit.summary',
51+
'plan_id',
52+
string='Summary by Activity Group',
53+
domain=[('budget_method', '=', 'expense')],
54+
readonly=True,
55+
help="Summary by Activity Group View",
56+
)
57+
# Select Dimension - Section
58+
section_id = fields.Many2one(
59+
'res.section',
60+
string='Section',
61+
required=True,
62+
)
63+
org_id = fields.Many2one(
64+
'res.org',
65+
string='Org',
66+
related='section_id.org_id',
67+
readonly=True,
68+
store=True,
69+
)
70+
division_id = fields.Many2one(
71+
'res.division',
72+
string='Division',
73+
related='section_id.division_id',
74+
readonly=True,
75+
store=True,
76+
)
77+
78+
@api.model
79+
def generate_plans(self, fiscalyear_id=None):
80+
if not fiscalyear_id:
81+
raise ValidationError(_('No fiscal year provided!'))
82+
# Find existing plans, and exclude them
83+
plans = self.search([('fiscalyear_id', '=', fiscalyear_id)])
84+
_ids = plans.mapped('section_id')._ids
85+
# Find sections
86+
sections = self.env['res.section'].search([('id', 'not in', _ids)])
87+
plan_ids = []
88+
for section in sections:
89+
plan = self.create({'fiscalyear_id': fiscalyear_id,
90+
'section_id': section.id,
91+
'user_id': False})
92+
plan_ids.append(plan.id)
93+
return plan_ids
94+
95+
96+
class BudgetPlanUnitLine(BPLMonthCommon, ActivityCommon, models.Model):
97+
_name = 'budget.plan.unit.line'
98+
_description = "Unit - Budget Plan Line"
99+
100+
# COMMON
101+
chart_view = fields.Selection(
102+
default='unit_base', # Unit
103+
)
104+
plan_id = fields.Many2one(
105+
'budget.plan.unit',
106+
string='Budget Plan',
107+
ondelete='cascade',
108+
index=True,
109+
required=True,
110+
)
111+
# Extra
112+
section_id = fields.Many2one(
113+
related='plan_id.section_id',
114+
store=True,
115+
readonly=True,
116+
)
117+
unit = fields.Float(
118+
string='Unit',
119+
)
120+
activity_unit_price = fields.Float(
121+
string='Unit Price',
122+
)
123+
activity_unit = fields.Float(
124+
string='Activity Unit',
125+
)
126+
total_budget = fields.Float(
127+
string='Total Budget',
128+
)
129+
130+
@api.multi
131+
def _write(self, vals): # Use _write, as it triggered on related field
132+
res = super(BudgetPlanUnitLine, self)._write(vals)
133+
print self.section_id
134+
if not self._context.get('MyModelLoopBreaker', False):
135+
self.update_related_dimension({'section_id': self.section_id.id})
136+
return res
137+
138+
139+
class BudgetPlanUnitSummary(models.Model):
140+
_name = 'budget.plan.unit.summary'
141+
_auto = False
142+
_order = 'budget_method desc, activity_group_id'
143+
144+
plan_id = fields.Many2one(
145+
'budget.plan.unit',
146+
string='Budget Plan',
147+
)
148+
budget_method = fields.Selection(
149+
[('revenue', 'Revenue'),
150+
('expense', 'Expense')],
151+
string='Budget Method',
152+
)
153+
activity_group_id = fields.Many2one(
154+
'account.activity.group',
155+
string='Activity Group',
156+
)
157+
m1 = fields.Float(
158+
string='Oct',
159+
)
160+
m2 = fields.Float(
161+
string='Nov',
162+
)
163+
m3 = fields.Float(
164+
string='Dec',
165+
)
166+
m4 = fields.Float(
167+
string='Jan',
168+
)
169+
m5 = fields.Float(
170+
string='Feb',
171+
)
172+
m6 = fields.Float(
173+
string='Mar',
174+
)
175+
m7 = fields.Float(
176+
string='Apr',
177+
)
178+
m8 = fields.Float(
179+
string='May',
180+
)
181+
m9 = fields.Float(
182+
string='Jun',
183+
)
184+
m10 = fields.Float(
185+
string='July',
186+
)
187+
m11 = fields.Float(
188+
string='Aug',
189+
)
190+
m12 = fields.Float(
191+
string='Sep',
192+
)
193+
planned_amount = fields.Float(
194+
string='Planned Amount',
195+
)
196+
197+
def init(self, cr):
198+
tools.drop_view_if_exists(cr, self._table)
199+
cr.execute("""CREATE or REPLACE VIEW %s as (
200+
select min(id) id, plan_id, activity_group_id, budget_method,
201+
sum(m1) m1, sum(m2) m2, sum(m3) m3, sum(m4) m4,
202+
sum(m5) m5, sum(m6) m6, sum(m7) m7, sum(m8) m8, sum(m9) m9,
203+
sum(m10) m10, sum(m11) m11, sum(m12) m12,
204+
sum(planned_amount) planned_amount
205+
from budget_plan_unit_line l
206+
group by plan_id, activity_group_id, budget_method
207+
)""" % (self._table, ))

pabi_budget_plan/models/__init__.py

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

33
from . import account_budget
44
from . import budget_plan_template
5-
from . import budget_plan_unit
5+
# from . import budget_plan_unit
66
from . import budget_plan_project
77
from . import budget_plan_personnel
88
from . import budget_plan_invest_asset

pabi_budget_plan/models/budget_fiscal_policy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _get_currency(self):
5959
creating_user_id = fields.Many2one(
6060
'res.users',
6161
string='Responsible User',
62-
default=lambda self: self._uid,
62+
default=lambda self: self.env.user,
6363
readonly=True,
6464
)
6565
validating_user_id = fields.Many2one(

pabi_budget_plan/models/budget_fiscal_policy_breakdown.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def _get_currency(self):
5252
creating_user_id = fields.Many2one(
5353
'res.users',
5454
string='Responsible User',
55-
default=lambda self: self._uid,
55+
default=lambda self: self.env.user,
5656
readonly=True,
5757
)
5858
validating_user_id = fields.Many2one(

pabi_budget_plan/models/budget_plan_template.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _get_currency(self):
100100
creating_user_id = fields.Many2one(
101101
'res.users',
102102
string='Responsible User',
103-
default=lambda self: self._uid,
103+
default=lambda self: self.env.user,
104104
)
105105
submiting_user_id = fields.Many2one(
106106
'res.users',

pabi_budget_plan/models/invest_asset_plan.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class InvestAssetPlan(models.Model):
1313
creating_user_id = fields.Many2one(
1414
'res.users',
1515
string='Responsible User',
16-
default=lambda self: self._uid,
16+
default=lambda self: self.env.user,
1717
)
1818
validating_user_id = fields.Many2one(
1919
'res.users',

pabi_budget_plan/security/ir.model.access.csv

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ access_budget_plan_template,access_budget_plan_template,model_budget_plan_templa
33
access_budget_plan_line_template,access_budget_plan_line_template,model_budget_plan_line_template,pabi_base.group_budget_user,1,1,1,1
44
access_budget_plan_unit,access_budget_plan_unit,model_budget_plan_unit,pabi_base.group_budget_user,1,1,1,1
55
access_budget_plan_unit_line,access_budget_plan_unit_line,model_budget_plan_unit_line,pabi_base.group_budget_user,1,1,1,1
6-
access_budget_plan_unit_cost_control,access_budget_plan_unit_cost_control,model_budget_plan_unit_cost_control,pabi_base.group_budget_user,1,1,1,1
7-
access_budget_plan_unit_cost_control_line,access_budget_plan_unit_cost_control_line,model_budget_plan_unit_cost_control_line,pabi_base.group_budget_user,1,1,1,1
86
access_budget_plan_project,access_budget_plan_project,model_budget_plan_project,pabi_base.group_budget_user,1,1,1,1
97
access_budget_plan_project_line,access_budget_plan_project_line,model_budget_plan_project_line,pabi_base.group_budget_user,1,1,1,1
108
access_budget_fiscal_policy,access_budget_fiscal_policy,model_budget_fiscal_policy,pabi_base.group_cooperate_budget,1,1,1,1

0 commit comments

Comments
 (0)