diff --git a/addons/account_budget/__openerp__.py b/addons/account_budget/__openerp__.py
index 289edb993a6..9b9efd35a0e 100644
--- a/addons/account_budget/__openerp__.py
+++ b/addons/account_budget/__openerp__.py
@@ -3,7 +3,6 @@
{
'name': 'Budgets Management',
- 'version': '1.0',
'category': 'Accounting',
'description': """
This module allows accountants to manage analytic and crossovered budgets.
@@ -37,13 +36,5 @@ Three reports are available:
'views/account_analytic_account_views.xml',
'views/account_budget_views.xml',
],
- 'demo': ['data/account_budget_demo.xml', 'data/account_budget_demo.yml'],
- 'test': [
- '../account/test/account_minimal_test.xml',
- 'test/account_budget.yml',
- 'test/account_budget_report.yml',
- 'test/account_budget_spread.yml',
- ],
- 'installable': True,
- 'auto_install': False,
+ 'demo': ['data/account_budget_demo.xml'],
}
diff --git a/addons/account_budget/data/account_budget_demo.xml b/addons/account_budget/data/account_budget_demo.xml
index ff421bea628..2c8654419ee 100644
--- a/addons/account_budget/data/account_budget_demo.xml
+++ b/addons/account_budget/data/account_budget_demo.xml
@@ -1,5 +1,5 @@
-
-
+
+
@@ -19,4 +19,4 @@
-
+
diff --git a/addons/account_budget/data/account_budget_demo.yml b/addons/account_budget/data/account_budget_demo.yml
deleted file mode 100644
index 2d4d8135e82..00000000000
--- a/addons/account_budget/data/account_budget_demo.yml
+++ /dev/null
@@ -1,174 +0,0 @@
--
- !python {model: ir.model.data} : |
- import time
- xml_id = self.pool.get('ir.model.data').xmlid_to_res_id(cr, uid, 'account.data_account_type_revenue')
- account_ids = self.pool.get('account.account').search(cr, uid, [('user_type_id', '=', xml_id), ('tag_ids.name', 'in', ['Operating Activities'])])
- if account_ids:
- vals = {
- 'name': 'Sales',
- 'account_ids': [(6, None, account_ids)],
- }
- self._update(cr, uid, 'account.budget.post', 'account_budget', vals, 'account_budget_post_sales0')
- vals = {
- 'analytic_account_id': ref('analytic.analytic_partners_camp_to_camp'),
- 'general_budget_id': ref('account_budget_post_sales0'),
- 'date_from': str(time.localtime(time.time())[0]+1)+'-01-01',
- 'date_to': str(time.localtime(time.time())[0]+1)+'-01-31',
- 'planned_amount': 500.0,
- 'crossovered_budget_id': ref('crossovered_budget_budgetpessimistic0'),
- }
- self._update(cr, uid, 'crossovered.budget.lines', 'account_budget', vals, 'crossovered_budget_lines_2')
- vals = {
- 'analytic_account_id': ref('analytic.analytic_partners_camp_to_camp'),
- 'general_budget_id': ref('account_budget_post_sales0'),
- 'date_from': str(time.localtime(time.time())[0]+1)+'-02-07',
- 'date_to': str(time.localtime(time.time())[0]+1)+'-02-28',
- 'planned_amount': 900.0,
- 'crossovered_budget_id': ref('crossovered_budget_budgetoptimistic0'),
- }
- self._update(cr, uid, 'crossovered.budget.lines', 'account_budget', vals, 'crossovered_budget_lines_3')
- vals = {
- 'analytic_account_id': ref('analytic.analytic_partners_camp_to_camp'),
- 'general_budget_id': ref('account_budget_post_sales0'),
- 'date_from': str(time.localtime(time.time())[0]+1)+'-03-01',
- 'date_to': str(time.localtime(time.time())[0]+1)+'-03-15',
- 'planned_amount': 300.0,
- 'crossovered_budget_id': ref('crossovered_budget_budgetoptimistic0'),
- }
- self._update(cr, uid, 'crossovered.budget.lines', 'account_budget', vals, 'crossovered_budget_lines_4')
- vals = {
- 'analytic_account_id': ref('analytic.analytic_our_super_product'),
- 'general_budget_id': ref('account_budget_post_sales0'),
- 'date_from': str(time.localtime(time.time())[0]+1)+'-03-16',
- 'paid_date': str(time.localtime(time.time())[0]+1)+'-12-03',
- 'date_to': str(time.localtime(time.time())[0]+1)+'-03-31',
- 'planned_amount': 375.0,
- 'crossovered_budget_id': ref('crossovered_budget_budgetpessimistic0'),
- }
- self._update(cr, uid, 'crossovered.budget.lines', 'account_budget', vals, 'crossovered_budget_lines_5')
- vals = {
- 'analytic_account_id': ref('analytic.analytic_our_super_product'),
- 'general_budget_id': ref('account_budget_post_sales0'),
- 'date_from': str(time.localtime(time.time())[0]+1)+'-05-01',
- 'paid_date': str(time.localtime(time.time())[0]+1)+'-12-03',
- 'date_to': str(time.localtime(time.time())[0]+1)+'-05-31',
- 'planned_amount': 375.0,
- 'crossovered_budget_id': ref('crossovered_budget_budgetoptimistic0'),
- }
- self._update(cr, uid, 'crossovered.budget.lines', 'account_budget', vals, 'crossovered_budget_lines_7')
- vals = {
- 'analytic_account_id': ref('analytic.analytic_seagate_p2'),
- 'general_budget_id': ref('account_budget_post_sales0'),
- 'date_from': str(time.localtime(time.time())[0]+1)+'-07-16',
- 'date_to': str(time.localtime(time.time())[0]+1)+'-07-31',
- 'planned_amount': 20000.0,
- 'crossovered_budget_id': ref('crossovered_budget_budgetpessimistic0'),
- }
- self._update(cr, uid, 'crossovered.budget.lines', 'account_budget', vals, 'crossovered_budget_lines_11')
- vals = {
- 'analytic_account_id': ref('analytic.analytic_seagate_p2'),
- 'general_budget_id': ref('account_budget_post_sales0'),
- 'date_from': str(time.localtime(time.time())[0]+1)+'-02-01',
- 'date_to': str(time.localtime(time.time())[0]+1)+'-02-28',
- 'planned_amount': 20000.0,
- 'crossovered_budget_id': ref('crossovered_budget_budgetoptimistic0'),
- }
- self._update(cr, uid, 'crossovered.budget.lines', 'account_budget', vals, 'crossovered_budget_lines_12')
- vals = {
- 'analytic_account_id': ref('analytic.analytic_seagate_p2'),
- 'general_budget_id': ref('account_budget_post_sales0'),
- 'date_from': str(time.localtime(time.time())[0]+1)+'-09-16',
- 'date_to': str(time.localtime(time.time())[0]+1)+'-09-30',
- 'planned_amount': 10000.0,
- 'crossovered_budget_id': ref('crossovered_budget_budgetpessimistic0'),
- }
- self._update(cr, uid, 'crossovered.budget.lines', 'account_budget', vals, 'crossovered_budget_lines_15')
- vals = {
- 'analytic_account_id': ref('analytic.analytic_seagate_p2'),
- 'general_budget_id': ref('account_budget_post_sales0'),
- 'date_from': str(time.localtime(time.time())[0]+1)+'-10-01',
- 'date_to': str(time.localtime(time.time())[0]+1)+'-12-31',
- 'planned_amount': 10000.0,
- 'crossovered_budget_id': ref('crossovered_budget_budgetoptimistic0'),
- }
- self._update(cr, uid, 'crossovered.budget.lines', 'account_budget', vals, 'crossovered_budget_lines_16')
-
- account_ids = self.pool.get('account.account').search(cr, uid, [('user_type_id.name', '=', 'Expenses'), ('tag_ids.name', 'in', ['Operating Activities'])])
- if account_ids:
- vals = {
- 'name': 'Purchases',
- 'account_ids': [(6, None, account_ids)],
- }
- self._update(cr, uid, 'account.budget.post', 'account_budget', vals, 'account_budget_post_purchase0')
- vals = {
- 'analytic_account_id': ref('analytic.analytic_partners_camp_to_camp'),
- 'general_budget_id': ref('account_budget_post_purchase0'),
- 'date_from': str(time.localtime(time.time())[0]+1)+'-01-01',
- 'date_to': str(time.localtime(time.time())[0]+1)+'-01-31',
- 'planned_amount': -500.0,
- 'crossovered_budget_id': ref('crossovered_budget_budgetpessimistic0'),
- }
- self._update(cr, uid, 'crossovered.budget.lines', 'account_budget', vals, 'crossovered_budget_lines_0')
- vals = {
- 'analytic_account_id': ref('analytic.analytic_partners_camp_to_camp'),
- 'general_budget_id': ref('account_budget_post_purchase0'),
- 'date_from': str(time.localtime(time.time())[0]+1)+'-02-01',
- 'date_to': str(time.localtime(time.time())[0]+1)+'-02-28',
- 'planned_amount': -250.0,
- 'crossovered_budget_id': ref('crossovered_budget_budgetoptimistic0'),
- }
- self._update(cr, uid, 'crossovered.budget.lines', 'account_budget', vals, 'crossovered_budget_lines_1')
- vals = {
- 'analytic_account_id': ref('analytic.analytic_our_super_product'),
- 'general_budget_id': ref('account_budget_post_purchase0'),
- 'date_from': str(time.localtime(time.time())[0]+1)+'-04-01',
- 'date_to': str(time.localtime(time.time())[0]+1)+'-04-30',
- 'planned_amount': -150.0,
- 'crossovered_budget_id': ref('crossovered_budget_budgetpessimistic0'),
- }
- self._update(cr, uid, 'crossovered.budget.lines', 'account_budget', vals, 'crossovered_budget_lines_6')
- vals = {
- 'analytic_account_id': ref('analytic.analytic_seagate_p2'),
- 'general_budget_id': ref('account_budget_post_purchase0'),
- 'date_from': str(time.localtime(time.time())[0]+1)+'-06-01',
- 'date_to': str(time.localtime(time.time())[0]+1)+'-06-15',
- 'planned_amount': -7500.0,
- 'crossovered_budget_id': ref('crossovered_budget_budgetpessimistic0'),
- }
- self._update(cr, uid, 'crossovered.budget.lines', 'account_budget', vals, 'crossovered_budget_lines_8')
- vals = {
- 'analytic_account_id': ref('analytic.analytic_seagate_p2'),
- 'general_budget_id': ref('account_budget_post_purchase0'),
- 'date_from': str(time.localtime(time.time())[0]+1)+'-06-16',
- 'date_to': str(time.localtime(time.time())[0]+1)+'-06-30',
- 'planned_amount': -5000.0,
- 'crossovered_budget_id': ref('crossovered_budget_budgetpessimistic0'),
- }
- self._update(cr, uid, 'crossovered.budget.lines', 'account_budget', vals, 'crossovered_budget_lines_9')
- vals = {
- 'analytic_account_id': ref('analytic.analytic_seagate_p2'),
- 'general_budget_id': ref('account_budget_post_purchase0'),
- 'date_from': str(time.localtime(time.time())[0]+1)+'-07-01',
- 'date_to': str(time.localtime(time.time())[0]+1)+'-07-15',
- 'planned_amount': -2000.0,
- 'crossovered_budget_id': ref('crossovered_budget_budgetoptimistic0'),
- }
- self._update(cr, uid, 'crossovered.budget.lines', 'account_budget', vals, 'crossovered_budget_lines_10')
- vals = {
- 'analytic_account_id': ref('analytic.analytic_seagate_p2'),
- 'general_budget_id': ref('account_budget_post_purchase0'),
- 'date_from': str(time.localtime(time.time())[0]+1)+'-08-16',
- 'date_to': str(time.localtime(time.time())[0]+1)+'-08-31',
- 'planned_amount': -3000.0,
- 'crossovered_budget_id': ref('crossovered_budget_budgetpessimistic0'),
- }
- self._update(cr, uid, 'crossovered.budget.lines', 'account_budget', vals, 'crossovered_budget_lines_13')
- vals = {
- 'analytic_account_id': ref('analytic.analytic_seagate_p2'),
- 'general_budget_id': ref('account_budget_post_purchase0'),
- 'date_from': str(time.localtime(time.time())[0]+1)+'-09-01',
- 'date_to': str(time.localtime(time.time())[0]+1)+'-09-15',
- 'planned_amount': -1000.0,
- 'crossovered_budget_id': ref('crossovered_budget_budgetoptimistic0'),
- }
- self._update(cr, uid, 'crossovered.budget.lines', 'account_budget', vals, 'crossovered_budget_lines_14')
diff --git a/addons/account_budget/data/account_budget_workflow.xml b/addons/account_budget/data/account_budget_workflow.xml
index f285ff1e4c6..a0e890299ba 100644
--- a/addons/account_budget/data/account_budget_workflow.xml
+++ b/addons/account_budget/data/account_budget_workflow.xml
@@ -1,7 +1,5 @@
-
-
-
-
+
+
@@ -86,5 +84,4 @@
draft
-
-
+
diff --git a/addons/account_budget/models/__init__.py b/addons/account_budget/models/__init__.py
index f2e78ebb530..84be2515324 100644
--- a/addons/account_budget/models/__init__.py
+++ b/addons/account_budget/models/__init__.py
@@ -2,4 +2,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import account_budget
-import account_analytic_account
\ No newline at end of file
+import account_analytic_account
diff --git a/addons/account_budget/models/account_analytic_account.py b/addons/account_budget/models/account_analytic_account.py
index ece8dde3b90..4f80f8ce7a8 100644
--- a/addons/account_budget/models/account_analytic_account.py
+++ b/addons/account_budget/models/account_analytic_account.py
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-from openerp.osv import fields, osv
+from odoo import fields, models
-class account_analytic_account(osv.osv):
+class AccountAnalyticAccount(models.Model):
_inherit = "account.analytic.account"
- _columns = {
- 'crossovered_budget_line': fields.one2many('crossovered.budget.lines', 'analytic_account_id', 'Budget Lines'),
- }
+ crossovered_budget_line = fields.One2many('crossovered.budget.lines', 'analytic_account_id', 'Budget Lines')
diff --git a/addons/account_budget/models/account_budget.py b/addons/account_budget/models/account_budget.py
index 04c9a7bffaf..d3c94e8e445 100644
--- a/addons/account_budget/models/account_budget.py
+++ b/addons/account_budget/models/account_budget.py
@@ -1,205 +1,156 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-from datetime import date, datetime
-
-from openerp.osv import fields, osv
-from openerp.tools import ustr, DEFAULT_SERVER_DATE_FORMAT
-from openerp.tools.translate import _
-from openerp.exceptions import UserError
-
-import openerp.addons.decimal_precision as dp
-
-
-# ---------------------------------------------------------
-# Utils
-# ---------------------------------------------------------
-def strToDate(dt):
- return date(int(dt[0:4]), int(dt[5:7]), int(dt[8:10]))
-
-def strToDatetime(strdate):
- return datetime.strptime(strdate, DEFAULT_SERVER_DATE_FORMAT)
+from odoo import api, fields, models, _
+from odoo.tools import ustr
+from odoo.exceptions import UserError
# ---------------------------------------------------------
# Budgets
# ---------------------------------------------------------
-class account_budget_post(osv.osv):
+class AccountBudgetPost(models.Model):
_name = "account.budget.post"
- _description = "Budgetary Position"
- _columns = {
- 'name': fields.char('Name', required=True),
- 'account_ids': fields.many2many('account.account', 'account_budget_rel', 'budget_id', 'account_id', 'Accounts', domain=[('deprecated', '=', False)]),
- 'crossovered_budget_line': fields.one2many('crossovered.budget.lines', 'general_budget_id', 'Budget Lines'),
- 'company_id': fields.many2one('res.company', 'Company', required=True),
- }
- _defaults = {
- 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.budget.post', context=c)
- }
_order = "name"
+ _description = "Budgetary Position"
+
+ name = fields.Char('Name', required=True)
+ account_ids = fields.Many2many('account.account', 'account_budget_rel', 'budget_id', 'account_id', 'Accounts',
+ domain=[('deprecated', '=', False)])
+ crossovered_budget_line = fields.One2many('crossovered.budget.lines', 'general_budget_id', 'Budget Lines')
+ company_id = fields.Many2one('res.company', 'Company', required=True,
+ default=lambda self: self.env['res.company']._company_default_get('account.budget.post'))
-
-class crossovered_budget(osv.osv):
+class CrossoveredBudget(models.Model):
_name = "crossovered.budget"
_description = "Budget"
_inherit = ['mail.thread']
- _columns = {
- 'name': fields.char('Budget Name', required=True, states={'done':[('readonly',True)]}),
- 'creating_user_id': fields.many2one('res.users', 'Responsible'),
- 'date_from': fields.date('Start Date', required=True, states={'done':[('readonly',True)]}),
- 'date_to': fields.date('End Date', required=True, states={'done':[('readonly',True)]}),
- 'state' : fields.selection([('draft','Draft'),('cancel', 'Cancelled'),('confirm','Confirmed'),('validate','Validated'),('done','Done')], 'Status', select=True, required=True, readonly=True, copy=False, track_visibility='always'),
- 'crossovered_budget_line': fields.one2many('crossovered.budget.lines', 'crossovered_budget_id', 'Budget Lines', states={'done':[('readonly',True)]}, copy=True),
- 'company_id': fields.many2one('res.company', 'Company', required=True),
- }
+ name = fields.Char('Budget Name', required=True, states={'done': [('readonly', True)]})
+ creating_user_id = fields.Many2one('res.users', 'Responsible', default=lambda self: self.env.user)
+ date_from = fields.Date('Start Date', required=True, states={'done': [('readonly', True)]})
+ date_to = fields.Date('End Date', required=True, states={'done': [('readonly', True)]})
+ state = fields.Selection([
+ ('draft', 'Draft'),
+ ('cancel', 'Cancelled'),
+ ('confirm', 'Confirmed'),
+ ('validate', 'Validated'),
+ ('done', 'Done')
+ ], 'Status', default='draft', index=True, required=True, readonly=True, copy=False, track_visibility='always')
+ crossovered_budget_line = fields.One2many('crossovered.budget.lines', 'crossovered_budget_id', 'Budget Lines',
+ states={'done': [('readonly', True)]}, copy=True)
+ company_id = fields.Many2one('res.company', 'Company', required=True,
+ default=lambda self: self.env['res.company']._company_default_get('account.budget.post'))
- _defaults = {
- 'state': 'draft',
- 'creating_user_id': lambda self, cr, uid, context: uid,
- 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.budget.post', context=c)
- }
+ @api.multi
+ def budget_confirm(self):
+ self.write({'state': 'confirm'})
- def budget_confirm(self, cr, uid, ids, *args):
- self.write(cr, uid, ids, {
- 'state': 'confirm'
- })
- return True
+ @api.multi
+ def budget_draft(self):
+ self.write({'state': 'draft'})
- def budget_draft(self, cr, uid, ids, *args):
- self.write(cr, uid, ids, {
- 'state': 'draft'
- })
- return True
+ @api.multi
+ def budget_validate(self):
+ self.write({'state': 'validate'})
- def budget_validate(self, cr, uid, ids, *args):
- self.write(cr, uid, ids, {
- 'state': 'validate',
- })
- return True
+ @api.multi
+ def budget_cancel(self):
+ self.write({'state': 'cancel'})
- def budget_cancel(self, cr, uid, ids, *args):
- self.write(cr, uid, ids, {
- 'state': 'cancel'
- })
- return True
-
- def budget_done(self, cr, uid, ids, *args):
- self.write(cr, uid, ids, {
- 'state': 'done'
- })
- return True
+ @api.multi
+ def budget_done(self):
+ self.write({'state': 'done'})
-class crossovered_budget_lines(osv.osv):
+class CrossoveredBudgetLines(models.Model):
+ _name = "crossovered.budget.lines"
+ _description = "Budget Line"
- def _prac_amt(self, cr, uid, ids, context=None):
- res = {}
- result = 0.0
- if context is None:
- context = {}
- for line in self.browse(cr, uid, ids, context=context):
- acc_ids = [x.id for x in line.general_budget_id.account_ids]
+ crossovered_budget_id = fields.Many2one('crossovered.budget', 'Budget', ondelete='cascade', select=True, required=True)
+ analytic_account_id = fields.Many2one('account.analytic.account', 'Analytic Account')
+ general_budget_id = fields.Many2one('account.budget.post', 'Budgetary Position', required=True)
+ date_from = fields.Date('Start Date', required=True)
+ date_to = fields.Date('End Date', required=True)
+ paid_date = fields.Date('Paid Date')
+ planned_amount = fields.Float('Planned Amount', required=True, digits=0)
+ practical_amount = fields.Float(compute='_compute_practical_amount', string='Practical Amount', digits=0)
+ theoritical_amount = fields.Float(compute='_compute_theoritical_amount', string='Theoretical Amount', digits=0)
+ percentage = fields.Float(compute='_compute_percentage', string='Achievement')
+ company_id = fields.Many2one(related='crossovered_budget_id.company_id', comodel_name='res.company',
+ string='Company', store=True, readonly=True)
+
+ @api.multi
+ def _compute_practical_amount(self):
+ for line in self:
+ result = 0.0
+ acc_ids = line.general_budget_id.account_ids.ids
if not acc_ids:
raise UserError(_("The Budget '%s' has no accounts!") % ustr(line.general_budget_id.name))
- date_to = context.get('wizard_date_to') or line.date_to
- date_from = context.get('wizard_date_from') or line.date_from
+ date_to = self.env.context.get('wizard_date_to') or line.date_to
+ date_from = self.env.context.get('wizard_date_from') or line.date_from
if line.analytic_account_id.id:
- cr.execute("SELECT SUM(amount) FROM account_analytic_line WHERE account_id=%s AND (date "
- "between to_date(%s,'yyyy-mm-dd') AND to_date(%s,'yyyy-mm-dd')) AND "
- "general_account_id=ANY(%s)", (line.analytic_account_id.id, date_from, date_to,acc_ids,))
- result = cr.fetchone()[0]
- if result is None:
- result = 0.00
- res[line.id] = result
- return res
+ self.env.cr.execute("""
+ SELECT SUM(amount)
+ FROM account_analytic_line
+ WHERE account_id=%s
+ AND (date between to_date(%s,'yyyy-mm-dd') AND to_date(%s,'yyyy-mm-dd'))
+ AND general_account_id=ANY(%s)""",
+ (line.analytic_account_id.id, date_from, date_to, acc_ids,))
+ result = self.env.cr.fetchone()[0] or 0.0
+ line.practical_amount = result
- def _prac(self, cr, uid, ids, name, args, context=None):
- res={}
- for line in self.browse(cr, uid, ids, context=context):
- res[line.id] = self._prac_amt(cr, uid, [line.id], context=context)[line.id]
- return res
-
- def _theo_amt(self, cr, uid, ids, context=None):
- if context is None:
- context = {}
-
- res = {}
- for line in self.browse(cr, uid, ids, context=context):
- today = datetime.now()
+ @api.multi
+ def _compute_theoritical_amount(self):
+ today = fields.Datetime.now()
+ for line in self:
# Used for the report
- if context.get('wizard_date_from') and context.get('wizard_date_to'):
- date_from = strToDatetime(context.get('wizard_date_from'))
- date_to = strToDatetime(context.get('wizard_date_to'))
- if date_from < strToDatetime(line.date_from):
- date_from = strToDatetime(line.date_from)
- elif date_from > strToDatetime(line.date_to):
+
+ if self.env.context.get('wizard_date_from') and self.env.context.get('wizard_date_to'):
+ date_from = fields.Datetime.from_string(self.env.context.get('wizard_date_from'))
+ date_to = fields.Datetime.from_string(self.env.context.get('wizard_date_to'))
+ if date_from < fields.Datetime.from_string(line.date_from):
+ date_from = fields.Datetime.from_string(line.date_from)
+ elif date_from > fields.Datetime.from_string(line.date_to):
date_from = False
- if date_to > strToDatetime(line.date_to):
- date_to = strToDatetime(line.date_to)
- elif date_to < strToDatetime(line.date_from):
+ if date_to > fields.Datetime.from_string(line.date_to):
+ date_to = fields.Datetime.from_string(line.date_to)
+ elif date_to < fields.Datetime.from_string(line.date_from):
date_to = False
theo_amt = 0.00
if date_from and date_to:
- line_timedelta = strToDatetime(line.date_to) - strToDatetime(line.date_from)
+ line_timedelta = fields.Datetime.from_string(line.date_to) - fields.Datetime.from_string(line.date_from)
elapsed_timedelta = date_to - date_from
if elapsed_timedelta.days > 0:
theo_amt = (elapsed_timedelta.total_seconds() / line_timedelta.total_seconds()) * line.planned_amount
else:
if line.paid_date:
- if strToDate(line.date_to) <= strToDate(line.paid_date):
+ if fields.Datetime.from_string(line.date_to) <= fields.Datetime.from_string(line.paid_date):
theo_amt = 0.00
else:
theo_amt = line.planned_amount
else:
-
- line_timedelta = strToDatetime(line.date_to) - strToDatetime(line.date_from)
- elapsed_timedelta = today - (strToDatetime(line.date_from))
+ print type(today)
+ line_timedelta = fields.Datetime.from_string(line.date_to) - fields.Datetime.from_string(line.date_from)
+ elapsed_timedelta = fields.Datetime.from_string(today) - (fields.Datetime.from_string(line.date_from))
if elapsed_timedelta.days < 0:
# If the budget line has not started yet, theoretical amount should be zero
theo_amt = 0.00
- elif line_timedelta.days > 0 and today < strToDatetime(line.date_to):
+ elif line_timedelta.days > 0 and fields.Datetime.from_string(today) < fields.Datetime.from_string(line.date_to):
# If today is between the budget line date_from and date_to
- # from pudb import set_trace; set_trace()
theo_amt = (elapsed_timedelta.total_seconds() / line_timedelta.total_seconds()) * line.planned_amount
else:
theo_amt = line.planned_amount
- res[line.id] = theo_amt
- return res
+ line.theoritical_amount = theo_amt
- def _theo(self, cr, uid, ids, name, args, context=None):
- res = {}
- for line in self.browse(cr, uid, ids, context=context):
- res[line.id] = self._theo_amt(cr, uid, [line.id], context=context)[line.id]
- return res
-
- def _perc(self, cr, uid, ids, name, args, context=None):
- res = {}
- for line in self.browse(cr, uid, ids, context=context):
- if line.theoritical_amount <> 0.00:
- res[line.id] = float((line.practical_amount or 0.0) / line.theoritical_amount) * 100
+ @api.multi
+ def _compute_percentage(self):
+ for line in self:
+ if line.theoritical_amount != 0.00:
+ line.percentage = float((line.practical_amount or 0.0) / line.theoritical_amount) * 100
else:
- res[line.id] = 0.00
- return res
-
- _name = "crossovered.budget.lines"
- _description = "Budget Line"
- _columns = {
- 'crossovered_budget_id': fields.many2one('crossovered.budget', 'Budget', ondelete='cascade', select=True, required=True),
- 'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account'),
- 'general_budget_id': fields.many2one('account.budget.post', 'Budgetary Position',required=True),
- 'date_from': fields.date('Start Date', required=True),
- 'date_to': fields.date('End Date', required=True),
- 'paid_date': fields.date('Paid Date'),
- 'planned_amount':fields.float('Planned Amount', required=True, digits=0),
- 'practical_amount':fields.function(_prac, string='Practical Amount', type='float', digits=0),
- 'theoritical_amount':fields.function(_theo, string='Theoretical Amount', type='float', digits=0),
- 'percentage':fields.function(_perc, string='Achievement', type='float'),
- 'company_id': fields.related('crossovered_budget_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True)
- }
-
-
+ line.percentage = 0.00
diff --git a/addons/account_budget/security/account_budget_security.xml b/addons/account_budget/security/account_budget_security.xml
index 05a67c00077..edd9638188a 100644
--- a/addons/account_budget/security/account_budget_security.xml
+++ b/addons/account_budget/security/account_budget_security.xml
@@ -1,5 +1,5 @@
-
+
@@ -28,4 +28,4 @@
-
+
diff --git a/addons/account_budget/test/account_budget.yml b/addons/account_budget/test/account_budget.yml
deleted file mode 100644
index bfc5fd207a2..00000000000
--- a/addons/account_budget/test/account_budget.yml
+++ /dev/null
@@ -1,91 +0,0 @@
--
- In order to check account budget module in OpenERP I created a budget with few budget positions
--
- Checking if the budgetary positions have accounts or not
--
- !python {model: ir.model.data} : |
- if not self.pool.get('account.budget.post').browse(cr, uid, ref('account_budget_post_sales0')).account_ids:
- vals = {
- 'name': 'Product Sales - (test)',
- 'code': 'X2020',
- 'user_type_id': ref('account.data_account_type_revenue'),
- 'tag_ids': [(6,0,[ref('account.account_tag_operating')])],
- }
- self._update(cr, uid, 'account.account', 'account_budget', vals, 'a_sale')
- self.pool.get('account.budget.post').write(cr, uid, [ref('account_budget_post_sales0')], {'account_ids': [(6,0,[ref('a_sale')])]})
- if not self.pool.get('account.budget.post').browse(cr, uid, ref('account_budget_post_purchase0')).account_ids:
- vals = {
- 'name': 'Expense - (test)',
- 'code': 'X2120',
- 'user_type_id': ref('account.data_account_type_expenses'),
- 'tag_ids': [(6,0,[ref('account.account_tag_operating')])],
- }
- self._update(cr, uid, 'account.account', 'account_budget', vals, 'a_expense')
- self.pool.get('account.budget.post').write(cr, uid, [ref('account_budget_post_purchase0')], {'account_ids': [(6,0,[ref('a_expense')])]})
--
- Creating a crossovered.budget record
--
- !record {model: crossovered.budget, id: crossovered_budget_budget0}:
- date_from: !eval "'%s-01-01' %(datetime.now().year+1)"
- date_to: !eval "'%s-12-31' %(datetime.now().year+1)"
- name: !eval "'Budget %s' %(datetime.now().year+1)"
- state: draft
--
- I created two different budget lines
--
- Modifying a crossovered.budget record
--
- !record {model: crossovered.budget, id: crossovered_budget_budget0}:
- crossovered_budget_line:
- - analytic_account_id: analytic.analytic_partners_camp_to_camp
- date_from: !eval "'%s-01-01' %(datetime.now().year+1)"
- date_to: !eval "'%s-12-31' %(datetime.now().year+1)"
- general_budget_id: account_budget.account_budget_post_purchase0
- planned_amount: 10000.0
- - analytic_account_id: analytic.analytic_our_super_product
- date_from: !eval "'%s-09-01' %(datetime.now().year+1)"
- date_to: !eval "'%s-09-30' %(datetime.now().year+1)"
- general_budget_id: account_budget.account_budget_post_sales0
- planned_amount: 400000.0
-
--
- I check that Initially Budget is in "draft" state
--
- !assert {model: crossovered.budget, id: crossovered_budget_budget0}:
- - state == 'draft'
-
--
- I pressed the confirm button to confirm the Budget
--
- Performing a workflow action confirm on module crossovered.budget
--
- !workflow {model: crossovered.budget, action: confirm, ref: crossovered_budget_budget0}
--
- I check that budget is in "Confirmed" state
--
- !assert {model: crossovered.budget, id: crossovered_budget_budget0}:
- - state == 'confirm'
-
--
- I pressed the validate button to validate the Budget
--
- Performing a workflow action validate on module crossovered.budget
--
- !workflow {model: crossovered.budget, action: validate, ref: crossovered_budget_budget0}
--
- I check that budget is in "Validated" state
--
- !assert {model: crossovered.budget, id: crossovered_budget_budget0}:
- - state == 'validate'
-
--
- I pressed the done button to set the Budget to "Done" state
--
- Performing a workflow action done on module crossovered.budget
--
- !workflow {model: crossovered.budget, action: done, ref: crossovered_budget_budget0}
--
- I check that budget is in "done" state
--
- !assert {model: crossovered.budget, id: crossovered_budget_budget0}:
- - state == 'done'
diff --git a/addons/account_budget/test/account_budget_report.yml b/addons/account_budget/test/account_budget_report.yml
deleted file mode 100644
index a7abfbe2103..00000000000
--- a/addons/account_budget/test/account_budget_report.yml
+++ /dev/null
@@ -1,24 +0,0 @@
--
- Print the Analytic Budget Report through wizard
--
- !python {model: account.analytic.account}: |
- ctx = {'model': 'account.analytic.account','active_ids': [ref('analytic.analytic_internal')]}
- from openerp.tools import test_reports
- test_reports.try_report_action(cr, uid, 'action_account_budget_analytic',wiz_data={}, context=ctx, our_module='account_budget')
-
--
- Print the Budget Report through wizard
--
- !python {model: account.budget.post}: |
- ctx = {'model': 'account.budget.post','active_ids': [ref('account_budget.account_budget_post_sales0')]}
- from openerp.tools import test_reports
- test_reports.try_report_action(cr, uid, 'action_account_budget_report',wiz_data={}, context=ctx, our_module='account_budget')
-
-# FIXME: functionality is ok, but test fails, probably because of demo data
-# -
-# Print the CrossOvered Budget Report mode through wizard
-# -
-# !python {model: crossovered.budget}: |
-# ctx = {'model': 'account.budget.post','active_ids': [ref('account_budget.crossovered_budget_budgetoptimistic0')]}
-# from openerp.tools import test_reports
-# test_reports.try_report_action(cr, uid, 'action_account_budget_crossvered_report',wiz_data={}, context=ctx, our_module='account_budget')
diff --git a/addons/account_budget/test/account_budget_spread.yml b/addons/account_budget/test/account_budget_spread.yml
deleted file mode 100644
index c996c647025..00000000000
--- a/addons/account_budget/test/account_budget_spread.yml
+++ /dev/null
@@ -1,19 +0,0 @@
--
- In order to test Spread Wizard of account_budget module I spread record with amount=1000
--
- Creating a account.budget.spread record
--
- !record {model: account.budget.spread, id: account_budget_spread_0}:
- amount: 1000.0
- fiscalyear: account.data_fiscalyear
-
-
--
- Performing an osv_memory action check_spread on model account.budget.spread
--
- !python {model: account.budget.spread}: |
- self.check_spread(cr, uid, [ref("account_budget_spread_0")], {"lang": 'en_US',
- "active_model": "account.budget.post", "active_ids": [ref("account_budget.account_budget_post_sales0")],
- "tz": False, "active_id": ref("account_budget.account_budget_post_sales0"),
- })
-
diff --git a/addons/account_budget/tests/__init__.py b/addons/account_budget/tests/__init__.py
index 106987b3a3c..f7e3c174b5b 100644
--- a/addons/account_budget/tests/__init__.py
+++ b/addons/account_budget/tests/__init__.py
@@ -1 +1,6 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+import common
import test_theoreticalamount
+import test_account_budget
diff --git a/addons/account_budget/tests/common.py b/addons/account_budget/tests/common.py
new file mode 100644
index 00000000000..55774dd2f49
--- /dev/null
+++ b/addons/account_budget/tests/common.py
@@ -0,0 +1,172 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from openerp.addons.account.tests.account_test_classes import AccountingTestCase
+
+import time
+
+class TestAccountBudgetCommon(AccountingTestCase):
+
+ def setUp(self):
+ super(TestAccountBudgetCommon, self).setUp()
+ account_ids = self.env['account.account'].search([
+ ('user_type_id', '=', self.ref('account.data_account_type_revenue')),
+ ('tag_ids.name', 'in', ['Operating Activities'])
+ ]).ids
+
+ if account_ids:
+ self.account_budget_post_sales0 = self.env['account.budget.post'].create({
+ 'name': 'Sales',
+ 'account_ids': [(6, None, account_ids)],
+ })
+
+ self.env['crossovered.budget.lines'].create({
+ 'analytic_account_id': self.ref('analytic.analytic_partners_camp_to_camp'),
+ 'general_budget_id': self.account_budget_post_sales0.id,
+ 'date_from': str(time.localtime(time.time())[0] + 1) + '-01-01',
+ 'date_to': str(time.localtime(time.time())[0] + 1) + '-01-31',
+ 'planned_amount': 500.0,
+ 'crossovered_budget_id': self.ref('account_budget.crossovered_budget_budgetpessimistic0'),
+ })
+ self.env['crossovered.budget.lines'].create({
+ 'analytic_account_id': self.ref('analytic.analytic_partners_camp_to_camp'),
+ 'general_budget_id': self.account_budget_post_sales0.id,
+ 'date_from': str(time.localtime(time.time())[0] + 1) + '-02-07',
+ 'date_to': str(time.localtime(time.time())[0] + 1) + '-02-28',
+ 'planned_amount': 900.0,
+ 'crossovered_budget_id': self.ref('account_budget.crossovered_budget_budgetoptimistic0'),
+ })
+ self.env['crossovered.budget.lines'].create({
+ 'analytic_account_id': self.ref('analytic.analytic_partners_camp_to_camp'),
+ 'general_budget_id': self.account_budget_post_sales0.id,
+ 'date_from': str(time.localtime(time.time())[0] + 1) + '-03-01',
+ 'date_to': str(time.localtime(time.time())[0] + 1) + '-03-15',
+ 'planned_amount': 300.0,
+ 'crossovered_budget_id': self.ref('account_budget.crossovered_budget_budgetoptimistic0'),
+ })
+ self.env['crossovered.budget.lines'].create({
+ 'analytic_account_id': self.ref('analytic.analytic_our_super_product'),
+ 'general_budget_id': self.account_budget_post_sales0.id,
+ 'date_from': str(time.localtime(time.time())[0] + 1) + '-03-16',
+ 'paid_date': str(time.localtime(time.time())[0] + 1) + '-12-03',
+ 'date_to': str(time.localtime(time.time())[0] + 1) + '-03-31',
+ 'planned_amount': 375.0,
+ 'crossovered_budget_id': self.ref('account_budget.crossovered_budget_budgetpessimistic0'),
+ })
+ self.env['crossovered.budget.lines'].create({
+ 'analytic_account_id': self.ref('analytic.analytic_our_super_product'),
+ 'general_budget_id': self.account_budget_post_sales0.id,
+ 'date_from': str(time.localtime(time.time())[0] + 1) + '-05-01',
+ 'paid_date': str(time.localtime(time.time())[0] + 1) + '-12-03',
+ 'date_to': str(time.localtime(time.time())[0] + 1) + '-05-31',
+ 'planned_amount': 375.0,
+ 'crossovered_budget_id': self.ref('account_budget.crossovered_budget_budgetoptimistic0'),
+ })
+ self.env['crossovered.budget.lines'].create({
+ 'analytic_account_id': self.ref('analytic.analytic_seagate_p2'),
+ 'general_budget_id': self.account_budget_post_sales0.id,
+ 'date_from': str(time.localtime(time.time())[0] + 1) + '-07-16',
+ 'date_to': str(time.localtime(time.time())[0] + 1) + '-07-31',
+ 'planned_amount': 20000.0,
+ 'crossovered_budget_id': self.ref('account_budget.crossovered_budget_budgetpessimistic0'),
+ })
+ self.env['crossovered.budget.lines'].create({
+ 'analytic_account_id': self.ref('analytic.analytic_seagate_p2'),
+ 'general_budget_id': self.account_budget_post_sales0.id,
+ 'date_from': str(time.localtime(time.time())[0] + 1) + '-02-01',
+ 'date_to': str(time.localtime(time.time())[0] + 1) + '-02-28',
+ 'planned_amount': 20000.0,
+ 'crossovered_budget_id': self.ref('account_budget.crossovered_budget_budgetoptimistic0'),
+ })
+ self.env['crossovered.budget.lines'].create({
+ 'analytic_account_id': self.ref('analytic.analytic_seagate_p2'),
+ 'general_budget_id': self.account_budget_post_sales0.id,
+ 'date_from': str(time.localtime(time.time())[0] + 1) + '-09-16',
+ 'date_to': str(time.localtime(time.time())[0] + 1) + '-09-30',
+ 'planned_amount': 10000.0,
+ 'crossovered_budget_id': self.ref('account_budget.crossovered_budget_budgetpessimistic0'),
+ })
+ self.env['crossovered.budget.lines'].create({
+ 'analytic_account_id': self.ref('analytic.analytic_seagate_p2'),
+ 'general_budget_id': self.account_budget_post_sales0.id,
+ 'date_from': str(time.localtime(time.time())[0] + 1) + '-10-01',
+ 'date_to': str(time.localtime(time.time())[0] + 1) + '-12-31',
+ 'planned_amount': 10000.0,
+ 'crossovered_budget_id': self.ref('account_budget.crossovered_budget_budgetoptimistic0'),
+ })
+
+ account_ids = self.env['account.account'].search([
+ ('user_type_id.name', '=', 'Expenses'),
+ ('tag_ids.name', 'in', ['Operating Activities'])
+ ]).ids
+
+ if account_ids:
+ self.account_budget_post_purchase0 = self.env['account.budget.post'].create({
+ 'name': 'Purchases',
+ 'account_ids': [(6, None, account_ids)],
+ })
+
+ self.env['crossovered.budget.lines'].create({
+ 'analytic_account_id': self.ref('analytic.analytic_partners_camp_to_camp'),
+ 'general_budget_id': self.account_budget_post_purchase0.id,
+ 'date_from': str(time.localtime(time.time())[0] + 1) + '-01-01',
+ 'date_to': str(time.localtime(time.time())[0] + 1) + '-01-31',
+ 'planned_amount': -500.0,
+ 'crossovered_budget_id': self.ref('account_budget.crossovered_budget_budgetpessimistic0'),
+ })
+ self.env['crossovered.budget.lines'].create({
+ 'analytic_account_id': self.ref('analytic.analytic_partners_camp_to_camp'),
+ 'general_budget_id': self.account_budget_post_purchase0.id,
+ 'date_from': str(time.localtime(time.time())[0] + 1) + '-02-01',
+ 'date_to': str(time.localtime(time.time())[0] + 1) + '-02-28',
+ 'planned_amount': -250.0,
+ 'crossovered_budget_id': self.ref('account_budget.crossovered_budget_budgetoptimistic0'),
+ })
+ self.env['crossovered.budget.lines'].create({
+ 'analytic_account_id': self.ref('analytic.analytic_our_super_product'),
+ 'general_budget_id': self.account_budget_post_purchase0.id,
+ 'date_from': str(time.localtime(time.time())[0] + 1) + '-04-01',
+ 'date_to': str(time.localtime(time.time())[0] + 1) + '-04-30',
+ 'planned_amount': -150.0,
+ 'crossovered_budget_id': self.ref('account_budget.crossovered_budget_budgetpessimistic0'),
+ })
+ self.env['crossovered.budget.lines'].create({
+ 'analytic_account_id': self.ref('analytic.analytic_seagate_p2'),
+ 'general_budget_id': self.account_budget_post_purchase0.id,
+ 'date_from': str(time.localtime(time.time())[0] + 1) + '-06-01',
+ 'date_to': str(time.localtime(time.time())[0] + 1) + '-06-15',
+ 'planned_amount': -7500.0,
+ 'crossovered_budget_id': self.ref('account_budget.crossovered_budget_budgetpessimistic0'),
+ })
+ self.env['crossovered.budget.lines'].create({
+ 'analytic_account_id': self.ref('analytic.analytic_seagate_p2'),
+ 'general_budget_id': self.account_budget_post_purchase0.id,
+ 'date_from': str(time.localtime(time.time())[0] + 1) + '-06-16',
+ 'date_to': str(time.localtime(time.time())[0] + 1) + '-06-30',
+ 'planned_amount': -5000.0,
+ 'crossovered_budget_id': self.ref('account_budget.crossovered_budget_budgetpessimistic0'),
+ })
+ self.env['crossovered.budget.lines'].create({
+ 'analytic_account_id': self.ref('analytic.analytic_seagate_p2'),
+ 'general_budget_id': self.account_budget_post_purchase0.id,
+ 'date_from': str(time.localtime(time.time())[0] + 1) + '-07-01',
+ 'date_to': str(time.localtime(time.time())[0] + 1) + '-07-15',
+ 'planned_amount': -2000.0,
+ 'crossovered_budget_id': self.ref('account_budget.crossovered_budget_budgetoptimistic0'),
+ })
+ self.env['crossovered.budget.lines'].create({
+ 'analytic_account_id': self.ref('analytic.analytic_seagate_p2'),
+ 'general_budget_id': self.account_budget_post_purchase0.id,
+ 'date_from': str(time.localtime(time.time())[0] + 1) + '-08-16',
+ 'date_to': str(time.localtime(time.time())[0] + 1) + '-08-31',
+ 'planned_amount': -3000.0,
+ 'crossovered_budget_id': self.ref('account_budget.crossovered_budget_budgetpessimistic0'),
+ })
+ self.env['crossovered.budget.lines'].create({
+ 'analytic_account_id': self.ref('analytic.analytic_seagate_p2'),
+ 'general_budget_id': self.account_budget_post_purchase0.id,
+ 'date_from': str(time.localtime(time.time())[0] + 1) + '-09-01',
+ 'date_to': str(time.localtime(time.time())[0] + 1) + '-09-15',
+ 'planned_amount': -1000.0,
+ 'crossovered_budget_id': self.ref('account_budget.crossovered_budget_budgetoptimistic0'),
+ })
diff --git a/addons/account_budget/tests/test_account_budget.py b/addons/account_budget/tests/test_account_budget.py
new file mode 100644
index 00000000000..9daa5558dd7
--- /dev/null
+++ b/addons/account_budget/tests/test_account_budget.py
@@ -0,0 +1,82 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from .common import TestAccountBudgetCommon
+from odoo.fields import Date
+
+import datetime
+
+# ---------------------------------------------------------
+# Tests
+# ---------------------------------------------------------
+class TestAccountBudget(TestAccountBudgetCommon):
+
+ def test_account_budget(self):
+ # In order to check account budget module in Odoo I created a budget with few budget positions
+ # Checking if the budgetary positions have accounts or not
+ if not self.account_budget_post_sales0.account_ids:
+ a_sale = self.env['account.account'].create({
+ 'name': 'Product Sales - (test)',
+ 'code': 'X2020',
+ 'user_type_id': self.ref('account.data_account_type_revenue'),
+ 'tag_ids': [(6, 0, [self.ref('account.account_tag_operating')])],
+ })
+ self.account_budget_post_sales0.write({'account_ids': [(6, 0, [a_sale.id])]})
+ if not self.account_budget_post_purchase0.account_ids:
+ a_expense = self.env['account.account'].create({
+ 'name': 'Expense - (test)',
+ 'code': 'X2120',
+ 'user_type_id': self.ref('account.data_account_type_expenses'),
+ 'tag_ids': [(6, 0, [self.ref('account.account_tag_operating')])],
+ })
+ self.account_budget_post_purchase0.write({'account_ids': [(6, 0, [a_expense.id])]})
+
+ # Creating a crossovered.budget record
+ budget = self.env['crossovered.budget'].create({
+ 'date_from': Date.from_string('%s-01-01' % (datetime.datetime.now().year + 1)),
+ 'date_to': Date.from_string('%s-12-31' % (datetime.datetime.now().year + 1)),
+ 'name': 'Budget %s' % (datetime.datetime.now().year + 1),
+ 'state': 'draft'
+ })
+
+ # I created two different budget lines
+ # Modifying a crossovered.budget record
+ self.env['crossovered.budget.lines'].create({
+ 'crossovered_budget_id': budget.id,
+ 'analytic_account_id': self.ref('analytic.analytic_partners_camp_to_camp'),
+ 'date_from': Date.from_string('%s-01-01' % (datetime.datetime.now().year + 1)),
+ 'date_to': Date.from_string('%s-12-31' % (datetime.datetime.now().year + 1)),
+ 'general_budget_id': self.account_budget_post_purchase0.id,
+ 'planned_amount': 10000.0,
+ })
+ self.env['crossovered.budget.lines'].create({
+ 'crossovered_budget_id': budget.id,
+ 'analytic_account_id': self.ref('analytic.analytic_our_super_product'),
+ 'date_from': Date.from_string('%s-09-01' % (datetime.datetime.now().year + 1)),
+ 'date_to': Date.from_string('%s-09-30' % (datetime.datetime.now().year + 1)),
+ 'general_budget_id': self.account_budget_post_sales0.id,
+ 'planned_amount': 400000.0,
+ })
+ # I check that Initially Budget is in "draft" state
+ self.assertEqual(budget.state, 'draft')
+
+ # I pressed the confirm button to confirm the Budget
+ # Performing a workflow action confirm on module crossovered.budget
+ budget.signal_workflow('confirm')
+
+ # I check that budget is in "Confirmed" state
+ self.assertEqual(budget.state, 'confirm')
+
+ # I pressed the validate button to validate the Budget
+ # Performing a workflow action validate on module crossovered.budget
+ budget.signal_workflow('validate')
+
+ # I check that budget is in "Validated" state
+ self.assertEqual(budget.state, 'validate')
+
+ # I pressed the done button to set the Budget to "Done" state
+ # Performing a workflow action done on module crossovered.budget
+ budget.signal_workflow('done')
+
+ # I check that budget is in "done" state
+ self.assertEqual(budget.state, 'done')
diff --git a/addons/account_budget/tests/test_theoreticalamount.py b/addons/account_budget/tests/test_theoreticalamount.py
index 1c82a076fe7..6af2c956d69 100644
--- a/addons/account_budget/tests/test_theoreticalamount.py
+++ b/addons/account_budget/tests/test_theoreticalamount.py
@@ -1,100 +1,103 @@
# -*- coding: utf-8 -*-
-from datetime import datetime
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from .common import TestAccountBudgetCommon
from mock import patch
-from openerp.tests.common import TransactionCase
-from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
-
+from odoo.fields import Datetime
# ---------------------------------------------------------
# Tests
# ---------------------------------------------------------
-class TestTheoreticalAmount(TransactionCase):
+class TestTheoreticalAmount(TestAccountBudgetCommon):
def setUp(self):
super(TestTheoreticalAmount, self).setUp()
- cr, uid, = self.cr, self.uid
- crossovered_budget_id = self.registry('crossovered.budget').create(cr, uid, {
+ crossovered_budget = self.env['crossovered.budget'].create({
'name': 'test budget name',
'date_from': '2014-01-01',
'date_to': '2014-12-31',
})
- crossovered_budget_line_obj = self.registry('crossovered.budget.lines')
+ crossovered_budget_line_obj = self.env['crossovered.budget.lines']
user_type_id = self.ref('account.data_account_type_revenue')
tag_id = self.ref('account.account_tag_operating')
- account_rev_id = self.registry('account.account').create(cr, uid, {'code': 'X2020', 'name': 'Budget - Test Revenue Account', 'user_type_id': user_type_id, 'tag_ids': [(4, tag_id, 0)]})
- buget_post = self.registry('account.budget.post').create(cr, uid, {
- 'name': 'Sales',
- 'account_ids': [(4, account_rev_id, 0)],
+ account_rev = self.env['account.account'].create({
+ 'code': 'X2020',
+ 'name': 'Budget - Test Revenue Account',
+ 'user_type_id': user_type_id,
+ 'tag_ids': [(4, tag_id, 0)]
})
- crossovered_budget_line_id = crossovered_budget_line_obj.create(cr, uid, {
- 'crossovered_budget_id': crossovered_budget_id,
- 'general_budget_id': buget_post,
+ buget_post = self.env['account.budget.post'].create({
+ 'name': 'Sales',
+ 'account_ids': [(4, account_rev.id, 0)],
+ })
+ self.line = crossovered_budget_line_obj.create({
+ 'crossovered_budget_id': crossovered_budget.id,
+ 'general_budget_id': buget_post.id,
'date_from': '2014-01-01',
'date_to': '2014-12-31',
'planned_amount': -364,
})
- self.line = crossovered_budget_line_obj.browse(cr, uid, crossovered_budget_line_id)
- self.patcher = patch('openerp.addons.account_budget.account_budget.datetime', wraps=datetime)
+ self.patcher = patch('odoo.addons.account_budget.models.account_budget.fields.Datetime', wraps=Datetime)
self.mock_datetime = self.patcher.start()
def test_01(self):
"""Start"""
- date = datetime.strptime('2014-01-01 00:00:00', DEFAULT_SERVER_DATETIME_FORMAT)
+ date = Datetime.to_string(Datetime.from_string('2014-01-01 00:00:00'))
self.mock_datetime.now.return_value = date
self.assertAlmostEqual(self.line.theoritical_amount, 0)
def test_02(self):
"""After 24 hours"""
- date = datetime.strptime('2014-01-02 00:00:00', DEFAULT_SERVER_DATETIME_FORMAT)
+ date = Datetime.to_string(Datetime.from_string('2014-01-02 00:00:00'))
self.mock_datetime.now.return_value = date
self.assertAlmostEqual(self.line.theoritical_amount, -1)
def test_03(self):
"""After 36 hours"""
- date = datetime.strptime('2014-01-02 12:00:00', DEFAULT_SERVER_DATETIME_FORMAT)
+ date = Datetime.to_string(Datetime.from_string('2014-01-02 12:00:00'))
self.mock_datetime.now.return_value = date
self.assertAlmostEqual(self.line.theoritical_amount, -1.5)
def test_04(self):
"""After 48 hours"""
- date = datetime.strptime('2014-01-03 00:00:00', DEFAULT_SERVER_DATETIME_FORMAT)
+ date = Datetime.to_string(Datetime.from_string('2014-01-03 00:00:00'))
self.mock_datetime.now.return_value = date
self.assertAlmostEqual(self.line.theoritical_amount, -2)
def test_05(self):
"""After 10 days"""
- date = datetime.strptime('2014-01-11 00:00:00', DEFAULT_SERVER_DATETIME_FORMAT)
+ date = Datetime.to_string(Datetime.from_string('2014-01-11 00:00:00'))
self.mock_datetime.now.return_value = date
self.assertAlmostEqual(self.line.theoritical_amount, -10)
def test_06(self):
"""After 50 days"""
- date = datetime.strptime('2014-02-20 00:00:00', DEFAULT_SERVER_DATETIME_FORMAT)
+ date = Datetime.to_string(Datetime.from_string('2014-02-20 00:00:00'))
self.mock_datetime.now.return_value = date
self.assertAlmostEqual(self.line.theoritical_amount, -50)
def test_07(self):
"""After 182 days, exactly half of the budget line"""
- date = datetime.strptime('2014-07-02 00:00:00', DEFAULT_SERVER_DATETIME_FORMAT)
+ date = Datetime.to_string(Datetime.from_string('2014-07-02 00:00:00'))
self.mock_datetime.now.return_value = date
self.assertAlmostEqual(self.line.theoritical_amount, -182)
def test_08(self):
"""After 308 days at noon"""
- date = datetime.strptime('2014-11-05 12:00:00', DEFAULT_SERVER_DATETIME_FORMAT) # remember, remember
+ date = Datetime.to_string(Datetime.from_string('2014-11-05 12:00:00')) # remember, remember
self.mock_datetime.now.return_value = date
self.assertAlmostEqual(self.line.theoritical_amount, -308.5)
def test_09(self):
"""One day before"""
- date = datetime.strptime('2014-12-30 00:00:00', DEFAULT_SERVER_DATETIME_FORMAT)
+ date = Datetime.to_string(Datetime.from_string('2014-12-30 00:00:00'))
self.mock_datetime.now.return_value = date
self.assertAlmostEqual(self.line.theoritical_amount, -363)
def test_10(self):
"""At last"""
- date = datetime.strptime('2014-12-31 00:00:00', DEFAULT_SERVER_DATETIME_FORMAT)
+ date = Datetime.to_string(Datetime.from_string('2014-12-31 00:00:00'))
self.mock_datetime.now.return_value = date
self.assertAlmostEqual(self.line.theoritical_amount, -364)
diff --git a/addons/account_budget/views/account_analytic_account_views.xml b/addons/account_budget/views/account_analytic_account_views.xml
index 251009dce0b..0b19a8eaa6c 100644
--- a/addons/account_budget/views/account_analytic_account_views.xml
+++ b/addons/account_budget/views/account_analytic_account_views.xml
@@ -1,6 +1,5 @@
-
-
-
+
+
account.analytic.account.form.inherit.budget
account.analytic.account
@@ -36,5 +35,4 @@
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/addons/account_budget/views/account_budget_views.xml b/addons/account_budget/views/account_budget_views.xml
index eecb862323b..122e838f143 100644
--- a/addons/account_budget/views/account_budget_views.xml
+++ b/addons/account_budget/views/account_budget_views.xml
@@ -1,6 +1,5 @@
-
-
-
+
+
@@ -267,5 +266,4 @@
src_model="account.analytic.account"
id="act_account_analytic_account_cb_lines"/>
-
-
+