diff --git a/addons/analytic/__init__.py b/addons/analytic/__init__.py
index d84fb182e8f..11529f98733 100644
--- a/addons/analytic/__init__.py
+++ b/addons/analytic/__init__.py
@@ -2,5 +2,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import models
-import report
import wizard
diff --git a/addons/analytic/__openerp__.py b/addons/analytic/__openerp__.py
index cdc13af2619..31d781b26ff 100644
--- a/addons/analytic/__openerp__.py
+++ b/addons/analytic/__openerp__.py
@@ -21,25 +21,12 @@ that have no counterpart in the general financial accounts.
'data/analytic_sequence.xml',
'views/analytic_view.xml',
'data/analytic_data.xml',
- 'analytic_report.xml',
- 'wizard/account_analytic_balance_report_view.xml',
- 'wizard/account_analytic_cost_ledger_view.xml',
- 'wizard/account_analytic_inverted_balance_report.xml',
- 'wizard/account_analytic_cost_ledger_for_journal_report_view.xml',
'wizard/account_analytic_chart_view.xml',
- 'views/report_analyticbalance.xml',
- 'views/report_analyticjournal.xml',
- 'views/report_analyticcostledgerquantity.xml',
- 'views/report_analyticcostledger.xml',
- 'views/report_invertedanalyticbalance.xml',
],
'demo': [
'data/analytic_demo.xml',
'data/analytic_account_demo.xml',
],
- 'test': [
- 'test/analytic_hierarchy.yml',
- ],
'installable': True,
'auto_install': False,
}
diff --git a/addons/analytic/analytic_report.xml b/addons/analytic/analytic_report.xml
deleted file mode 100644
index 88109e01fd6..00000000000
--- a/addons/analytic/analytic_report.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/addons/analytic/data/analytic_account_demo.xml b/addons/analytic/data/analytic_account_demo.xml
index 678afaf0dc2..09ddaf96846 100644
--- a/addons/analytic/data/analytic_account_demo.xml
+++ b/addons/analytic/data/analytic_account_demo.xml
@@ -1,235 +1,87 @@
-
-
- Leaves
- view
- Internal
- view
- Our Super Product
- open
- view
-
-
-
- Project 1
- view
-
-
-
- Project 2
- view
-
-
-
- Training
- view
-
-
-
- In House
- normal
-
-
-
- Online
- normal
-
-
-
- Support
- view
-
-
-
- Partners
- view
-
-
-
- Customers
- view
-
-
-
- Internal
- contract
-
-
-
- Integration
- view
-
-
-
- Consultancy
- contract
-
-
-
- Training
- contract
-
-
-
- Seagate P1
-
- normal
- open
+ Seagate P2
- normal
-
- open
+ normal
+ Millennium Industries
-
- normal
+ normal
+ CampToCamp
- normal
-
-
-
+ normal
- open
+ Agrolait
-
- normal
+ normalAsustek
- normal
-
+ normalDelta PC
-
- normal
+ normalSpark Systems
-
-
-
- normal
+ normal
- openNebula
-
-
- normal
-
+ normal
- openLuminous Technologies
-
-
- normal
-
+ normalDesertic - Hispafuentes
-
-
- normal
-
+ normalThink Big Systems
- normal
-
+ normalCamp to Camp
-
-
- normal
-
+ normal
- open
-
-
- Support
- normal
-
-
-
- Development
- normal
-
-
-
- Training
- normal
-
-
-
- Development
- normal
- Administrative
- normal
-
+ normalCommercial & Marketing
- normal
-
-
-
- Our Super Product Development
- view
-
-
-
- Stable
- normal
-
-
-
- Trunk
- normal
-
-
-
- Paid
- normal
-
-
-
- Unpaid
- normal
-
+ normal
diff --git a/addons/analytic/data/analytic_demo.xml b/addons/analytic/data/analytic_demo.xml
index 5ce34521b45..7b8635d3c1b 100644
--- a/addons/analytic/data/analytic_demo.xml
+++ b/addons/analytic/data/analytic_demo.xml
@@ -1,15 +1,10 @@
-
- SAL
- Sales
- sale
-
-
- START
- Miscellaneous Operation
- situation
+
+
+ Contracts
+
diff --git a/addons/analytic/models/analytic.py b/addons/analytic/models/analytic.py
index 2583d015f93..063bc5f9e38 100644
--- a/addons/analytic/models/analytic.py
+++ b/addons/analytic/models/analytic.py
@@ -1,405 +1,119 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-import time
-from datetime import datetime
+from openerp import api, fields, models
-from openerp.osv import fields, osv
-from openerp import tools
-from openerp.tools.translate import _
-import openerp.addons.decimal_precision as dp
-from openerp.exceptions import UserError
-ANALYTIC_ACCOUNT_STATE = [
- ('template', 'Template'),
- ('draft','New'),
- ('open','In Progress'),
- ('pending','To Renew'),
- ('close','Closed'),
- ('cancelled', 'Cancelled')
-]
+class account_analytic_tag(models.Model):
+ _name = 'account.analytic.tag'
+ _description = 'Analytic Tags'
+ name = fields.Char(string='Analytic Tag', index=True, required=True)
-class account_analytic_account(osv.osv):
+
+class account_analytic_account(models.Model):
_name = 'account.analytic.account'
_inherit = ['mail.thread']
_description = 'Analytic Account'
-
- def _compute_level_tree(self, cr, uid, ids, child_ids, res, field_names, context=None):
- currency_obj = self.pool.get('res.currency')
- recres = {}
- def recursive_computation(account):
- result2 = res[account.id].copy()
- for son in account.child_ids:
- result = recursive_computation(son)
- for field in field_names:
- if (account.currency_id.id != son.currency_id.id) and (field!='quantity'):
- result[field] = currency_obj.compute(cr, uid, son.currency_id.id, account.currency_id.id, result[field], context=context)
- result2[field] += result[field]
- return result2
- for account in self.browse(cr, uid, ids, context=context):
- if account.id not in child_ids:
- continue
- recres[account.id] = recursive_computation(account)
- return recres
-
- def _debit_credit_bal_qtty(self, cr, uid, ids, fields, arg, context=None):
- res = {}
- if context is None:
- context = {}
- child_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
- for i in child_ids:
- res[i] = {}
- for n in fields:
- res[i][n] = 0.0
-
- if not child_ids:
- return res
-
- where_date = ''
- where_clause_args = [tuple(child_ids)]
- if context.get('from_date', False):
- where_date += " AND l.date >= %s"
- where_clause_args += [context['from_date']]
- if context.get('to_date', False):
- where_date += " AND l.date <= %s"
- where_clause_args += [context['to_date']]
- cr.execute("""
- SELECT a.id,
- sum(
- CASE WHEN l.amount > 0
- THEN l.amount
- ELSE 0.0
- END
- ) as debit,
- sum(
- CASE WHEN l.amount < 0
- THEN -l.amount
- ELSE 0.0
- END
- ) as credit,
- COALESCE(SUM(l.amount),0) AS balance,
- COALESCE(SUM(l.unit_amount),0) AS quantity
- FROM account_analytic_account a
- LEFT JOIN account_analytic_line l ON (a.id = l.account_id)
- WHERE a.id IN %s
- """ + where_date + """
- GROUP BY a.id""", where_clause_args)
- for row in cr.dictfetchall():
- res[row['id']] = {}
- for field in fields:
- res[row['id']][field] = row[field]
- return self._compute_level_tree(cr, uid, ids, child_ids, res, fields, context)
-
- def name_get(self, cr, uid, ids, context=None):
- res = []
- if not ids:
- return res
- if isinstance(ids, (int, long)):
- ids = [ids]
- for id in ids:
- elmt = self.browse(cr, uid, id, context=context)
- res.append((id, self._get_one_full_name(elmt)))
- return res
-
- def _get_full_name(self, cr, uid, ids, name=None, args=None, context=None):
- if context == None:
- context = {}
- res = {}
- for elmt in self.browse(cr, uid, ids, context=context):
- res[elmt.id] = self._get_one_full_name(elmt)
- return res
-
- def _get_one_full_name(self, elmt, level=6):
- if level<=0:
- return '...'
- if elmt.parent_id and not elmt.type == 'template':
- parent_path = self._get_one_full_name(elmt.parent_id, level-1) + " / "
- else:
- parent_path = ''
- return parent_path + elmt.name
-
- def _child_compute(self, cr, uid, ids, name, arg, context=None):
- result = {}
- if context is None:
- context = {}
-
- for account in self.browse(cr, uid, ids, context=context):
- result[account.id] = map(lambda x: x.id, [child for child in account.child_ids if child.state != 'template'])
-
- return result
-
- def _get_analytic_account(self, cr, uid, ids, context=None):
- company_obj = self.pool.get('res.company')
- analytic_obj = self.pool.get('account.analytic.account')
- accounts = []
- for company in company_obj.browse(cr, uid, ids, context=context):
- accounts += analytic_obj.search(cr, uid, [('company_id', '=', company.id)])
- return accounts
-
- def _set_company_currency(self, cr, uid, ids, name, value, arg, context=None):
- if isinstance(ids, (int, long)):
- ids=[ids]
- for account in self.browse(cr, uid, ids, context=context):
- if account.company_id:
- if account.company_id.currency_id.id != value:
- raise UserError(_("If you set a company, the currency selected has to be the same as it's currency. \nYou can remove the company belonging, and thus change the currency, only on analytic account of type 'view'. This can be really useful for consolidation purposes of several companies charts with different currencies, for example."))
- if value:
- cr.execute("""update account_analytic_account set currency_id=%s where id=%s""", (value, account.id))
- self.invalidate_cache(cr, uid, ['currency_id'], [account.id], context=context)
-
- def _currency(self, cr, uid, ids, field_name, arg, context=None):
- result = {}
- for rec in self.browse(cr, uid, ids, context=context):
- if rec.company_id:
- result[rec.id] = rec.company_id.currency_id.id
- else:
- result[rec.id] = rec.currency_id.id
- return result
-
- def _get_contract_type_selection(self, cr, uid, context=None):
- return [('regular', 'Regular'), ('prepaid', 'Prepaid Support Hours')]
-
- _contract_type_selection = lambda self, *args, **kwargs: self._get_contract_type_selection(*args, **kwargs)
-
- _columns = {
- 'name': fields.char('Account/Contract Name', required=True, track_visibility='onchange'),
- 'complete_name': fields.function(_get_full_name, type='char', string='Full Name'),
- 'code': fields.char('Reference', select=True, track_visibility='onchange', copy=False),
- 'type': fields.selection([('view','Analytic View'), ('normal','Analytic Account'),('contract','Contract or Project'),('template','Template of Contract')], 'Type of Account', required=True,
- help="If you select the View Type, it means you won\'t allow to create journal entries using that account.\n"\
- "The type 'Analytic account' stands for usual accounts that you only want to use in accounting.\n"\
- "If you select Contract or Project, it offers you the possibility to manage the validity and the invoicing options for this account.\n"\
- "The special type 'Template of Contract' allows you to define a template with default data that you can reuse easily."),
- 'template_id': fields.many2one('account.analytic.account', 'Template of Contract', ondelete='restrict'),
- 'description': fields.text('Description'),
- 'parent_id': fields.many2one('account.analytic.account', 'Parent Analytic Account', select=2),
- 'child_ids': fields.one2many('account.analytic.account', 'parent_id', 'Child Accounts', copy=True),
- 'child_complete_ids': fields.function(_child_compute, relation='account.analytic.account', string="Account Hierarchy", type='many2many'),
- 'line_ids': fields.one2many('account.analytic.line', 'account_id', 'Analytic Entries', copy=False),
- 'balance': fields.function(_debit_credit_bal_qtty, type='float', string='Balance', multi='debit_credit_bal_qtty', digits=0),
- 'debit': fields.function(_debit_credit_bal_qtty, type='float', string='Debit', multi='debit_credit_bal_qtty', digits=0),
- 'credit': fields.function(_debit_credit_bal_qtty, type='float', string='Credit', multi='debit_credit_bal_qtty', digits=0),
- 'quantity': fields.function(_debit_credit_bal_qtty, type='float', string='Quantity', multi='debit_credit_bal_qtty'),
- 'quantity_max': fields.float('Prepaid Service Units', help='Sets the higher limit of time to work on the contract, based on the timesheet. (for instance, number of hours in a limited support contract.)'),
- 'partner_id': fields.many2one('res.partner', 'Customer'),
- 'user_id': fields.many2one('res.users', 'Project Manager', track_visibility='onchange'),
- 'manager_id': fields.many2one('res.users', 'Sales Rep', track_visibility='onchange'),
- 'date_start': fields.date('Start Date'),
- 'date': fields.date('Expiration Date', select=True, track_visibility='onchange'),
- 'company_id': fields.many2one('res.company', 'Company', required=False), #not required because we want to allow different companies to use the same chart of account, except for leaf accounts.
- 'state': fields.selection(ANALYTIC_ACCOUNT_STATE, 'Status', required=True,
- track_visibility='onchange', copy=False),
- 'currency_id': fields.function(_currency, fnct_inv=_set_company_currency, #the currency_id field is readonly except if it's a view account and if there is no company
- store = {
- 'res.company': (_get_analytic_account, ['currency_id'], 10),
- }, string='Currency', type='many2one', relation='res.currency'),
- 'contract_type': fields.selection(_contract_type_selection, 'Type of Contract', required=True),
- }
-
- def create(self, cr, uid, vals, context=None):
- context = dict(context or {}, mail_create_nolog=True)
- if vals.get('type') == 'template' or vals.get('type') == 'contract':
- body = _('Contract Created')
- elif vals.get('type') == 'view':
- body = _('Analytic View Created')
- else:
- body = _('Analytic Account Created')
- analytic_account_id = super(account_analytic_account, self).create(cr, uid, vals, context=context)
- self.message_post(cr, uid, [analytic_account_id], body=body, context=context)
- return analytic_account_id
-
- def on_change_template(self, cr, uid, ids, template_id, date_start=False, context=None):
- if not template_id:
- return {}
- res = {'value':{}}
- template = self.browse(cr, uid, template_id, context=context)
- if template.date_start and template.date:
- from_dt = datetime.strptime(template.date_start, tools.DEFAULT_SERVER_DATE_FORMAT)
- to_dt = datetime.strptime(template.date, tools.DEFAULT_SERVER_DATE_FORMAT)
- timedelta = to_dt - from_dt
- res['value']['date'] = datetime.strftime(datetime.now() + timedelta, tools.DEFAULT_SERVER_DATE_FORMAT)
- if not date_start:
- res['value']['date_start'] = fields.date.today()
- res['value']['quantity_max'] = template.quantity_max
- res['value']['parent_id'] = template.parent_id and template.parent_id.id or False
- res['value']['description'] = template.description
- res['value']['contract_type'] = template.contract_type
- return res
-
- def on_change_partner_id(self, cr, uid, ids,partner_id, name, context=None):
- res={}
- if partner_id:
- partner = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
- if partner.user_id:
- res['manager_id'] = partner.user_id.id
- if not name:
- res['name'] = _('Contract: ') + partner.name
- return {'value': res}
-
- def _default_company(self, cr, uid, context=None):
- user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
- if user.company_id:
- return user.company_id.id
- return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
-
- def _get_default_currency(self, cr, uid, context=None):
- user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
- return user.company_id.currency_id.id
-
- _defaults = {
- 'type': 'normal',
- 'company_id': _default_company,
- 'code' : lambda obj, cr, uid, context: obj.pool.get('ir.sequence').next_by_code(cr, uid, 'account.analytic.account'),
- 'state': 'open',
- 'user_id': lambda self, cr, uid, ctx: uid,
- 'partner_id': lambda self, cr, uid, ctx: ctx.get('partner_id', False),
- 'manager_id': lambda self, cr, uid, ctx: ctx.get('manager_id', False),
- 'date_start': lambda *a: time.strftime('%Y-%m-%d'),
- 'currency_id': _get_default_currency,
- 'contract_type': 'regular',
- }
-
- def check_recursion(self, cr, uid, ids, context=None, parent=None):
- return super(account_analytic_account, self)._check_recursion(cr, uid, ids, context=context, parent=parent)
-
_order = 'code, name asc'
- _constraints = [
- (check_recursion, 'Error! You cannot create recursive analytic accounts.', ['parent_id']),
- ]
- def name_create(self, cr, uid, name, context=None):
- raise UserError(_("Quick account creation disallowed."))
+ @api.multi
+ def _compute_debit_credit_balance(self):
+ analytic_line_obj = self.env['account.analytic.line']
+ domain = [('account_id', 'in', self.mapped('id'))]
+ if self._context.get('from_date', False):
+ domain.append(('date', '>=', self._context['from_date']))
+ if self._context.get('to_date', False):
+ domain.append(('date', '<=', self._context['to_date']))
- def copy(self, cr, uid, id, default=None, context=None):
- """ executed only on the toplevel copied object of the hierarchy.
- Subobject are actually copied with copy_data"""
- if not default:
- default = {}
- analytic = self.browse(cr, uid, id, context=context)
- default['name'] = _("%s (copy)") % analytic['name']
- return super(account_analytic_account, self).copy(cr, uid, id, default, context=context)
+ account_amounts = analytic_line_obj.search_read(domain, ['account_id', 'amount'])
+ account_ids = set([line['account_id'][0] for line in account_amounts])
+ data_debit = {account_id: 0.0 for account_id in account_ids}
+ data_credit = {account_id: 0.0 for account_id in account_ids}
+ for account_amount in account_amounts:
+ if account_amount['amount'] < 0.0:
+ data_debit[account_amount['account_id'][0]] += account_amount['amount']
+ else:
+ data_credit[account_amount['account_id'][0]] += account_amount['amount']
- def on_change_company(self, cr, uid, id, company_id):
- if not company_id:
- return {}
- currency = self.pool.get('res.company').read(cr, uid, [company_id], ['currency_id'])[0]['currency_id']
- return {'value': {'currency_id': currency}}
+ for account in self:
+ account.debit = abs(data_debit.get(account.id, 0.0))
+ account.credit = data_credit.get(account.id, 0.0)
+ account.balance = account.credit - account.debit
- def on_change_parent(self, cr, uid, id, parent_id):
- if not parent_id:
- return {}
- parent = self.read(cr, uid, [parent_id], ['partner_id','code'])[0]
- if parent['partner_id']:
- partner = parent['partner_id'][0]
- else:
- partner = False
- res = {'value': {}}
- if partner:
- res['value']['partner_id'] = partner
+ @api.model
+ def _default_company(self):
+ return self.env.user.company_id.id
+
+ @api.model
+ def _default_user(self):
+ return self.env.user.id
+
+ name = fields.Char(string='Analytic Account', index=True, required=True, track_visibility='onchange')
+ code = fields.Char(string='Reference', index=True, track_visibility='onchange', default=lambda s: s.env['ir.sequence'].next_by_code('account.analytic.account'))
+ account_type = fields.Selection([
+ ('normal', 'Analytic View')
+ ], string='Type of Account', required=True, default='normal')
+
+ tag_ids = fields.Many2many('account.analytic.tag', 'account_analytic_account_tag_rel', 'account_id', 'tag_id', string='Tags', copy=True)
+ line_ids = fields.One2many('account.analytic.line', 'account_id', string="Analytic Lines")
+
+ company_id = fields.Many2one('res.company', string='Company', required=True, default=_default_company)
+ partner_id = fields.Many2one('res.partner', string='Customer')
+
+ balance = fields.Monetary(compute='_compute_debit_credit_balance', string='Balance')
+ debit = fields.Monetary(compute='_compute_debit_credit_balance', string='Debit')
+ credit = fields.Monetary(compute='_compute_debit_credit_balance', string='Credit')
+
+ currency_id = fields.Many2one(related="company_id.currency_id", string="Currency", readonly=True)
+
+ @api.multi
+ def name_get(self):
+ res = []
+ for analytic in self:
+ name = analytic.name
+ if analytic.code:
+ name = '['+analytic.code+'] '+name
+ if analytic.partner_id:
+ name = name +' - '+analytic.partner_id.commercial_partner_id.name
+ res.append((analytic.id, name))
return res
- def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
- if not args:
- args=[]
- if context is None:
- context={}
- account_ids = []
- if name:
- account_ids = self.search(cr, uid, [('code', '=', name)] + args, limit=limit, context=context)
- if not account_ids:
- dom = []
- if '/' in name:
- for name2 in name.split('/'):
- # intermediate search without limit and args - could be expensive for large tables if `name` is not selective
- account_ids = self.search(cr, uid, dom + [('name', operator, name2.strip())], limit=None, context=context)
- if not account_ids: break
- dom = [('parent_id','in',account_ids)]
- if account_ids and args:
- # final filtering according to domain (args)4
- account_ids = self.search(cr, uid, [('id', 'in', account_ids)] + args, limit=limit, context=context)
- if not account_ids:
- return super(account_analytic_account, self).name_search(cr, uid, name, args, operator=operator, context=context, limit=limit)
- return self.name_get(cr, uid, account_ids, context=context)
+ @api.model
+ def name_search(self, name='', args=None, operator='ilike', limit=100):
+ args = args or []
+ recs = self.search(['|', '|', ('code', operator, name), ('partner_id', operator, name), ('name', operator, name)] + args, limit=limit)
+ return recs.name_get()
- def _track_subtype(self, cr, uid, ids, init_values, context=None):
- record = self.browse(cr, uid, ids[0], context=context)
- if 'state' in init_values and record.state == 'open':
+ @api.multi
+ def _track_subtype(self, init_values):
+ self.ensure_one()
+ if 'state' in init_values and self.state == 'open':
return 'analytic.mt_account_opened'
- elif 'state' in init_values and record.state == 'close':
+ elif 'state' in init_values and self.state == 'close':
return 'analytic.mt_account_closed'
- elif 'state' in init_values and record.state == 'pending':
+ elif 'state' in init_values and self.state == 'pending':
return 'analytic.mt_account_pending'
- return super(account_analytic_account, self)._track_subtype(cr, uid, ids, init_values, context=context)
+ return super(account_analytic_account, self)._track_subtype(init_values)
-class account_analytic_line(osv.osv):
+class account_analytic_line(models.Model):
_name = 'account.analytic.line'
_description = 'Analytic Line'
+ _order = 'date desc, id desc'
- _columns = {
- 'name': fields.char('Description', required=True),
- 'date': fields.date('Date', required=True, select=True),
- 'amount': fields.float('Amount', required=True, help='Calculated by multiplying the quantity and the price given in the Product\'s cost price. Always expressed in the company main currency.', digits=0),
- 'unit_amount': fields.float('Quantity', help='Specifies the amount of quantity to count.'),
- 'account_id': fields.many2one('account.analytic.account', 'Analytic Account', required=True, ondelete='restrict', select=True, domain=[('type','<>','view')]),
- 'user_id': fields.many2one('res.users', 'User'),
- 'company_id': fields.related('account_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True),
- 'journal_id': fields.many2one('account.analytic.journal', 'Analytic Journal', required=True, ondelete='restrict', select=True),
- 'partner_id': fields.related('account_id', 'partner_id', type='many2one', relation='res.partner', string='Partner', store=True),
+ @api.model
+ def _default_user(self):
+ return self.env.user.id
- }
+ name = fields.Char('Description', required=True)
+ date = fields.Date('Date', required=True, index=True, default=fields.Date.context_today)
+ amount = fields.Monetary('Amount', required=True, default=0.0)
+ unit_amount = fields.Float('Quantity', default=0.0)
+ account_id = fields.Many2one('account.analytic.account', 'Analytic Account', required=True, ondelete='restrict', index=True)
+ partner_id = fields.Many2one('res.partner', string='Partner')
+ user_id = fields.Many2one('res.users', string='User', default=_default_user)
- def _get_default_date(self, cr, uid, context=None):
- return fields.date.context_today(self, cr, uid, context=context)
+ tag_ids = fields.Many2many('account.analytic.tag', 'account_analytic_line_tag_rel', 'line_id', 'tag_id', string='Tags', copy=True)
- def __get_default_date(self, cr, uid, context=None):
- return self._get_default_date(cr, uid, context=context)
-
- _defaults = {
- 'date': __get_default_date,
- 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', context=c),
- 'amount': 0.00,
- 'user_id': lambda self, cr, uid, ctx: ctx.get('user_id') or uid,
- }
-
- _order = 'date desc'
-
- def _check_no_view(self, cr, uid, ids, context=None):
- analytic_lines = self.browse(cr, uid, ids, context=context)
- for line in analytic_lines:
- if line.account_id.type == 'view':
- return False
- return True
-
- _constraints = [
- (_check_no_view, 'You cannot create analytic line on view account.', ['account_id']),
- ]
-
-class account_analytic_journal(osv.osv):
- _name = 'account.analytic.journal'
- _description = 'Analytic Journal'
- _columns = {
- 'name': fields.char('Journal Name', required=True),
- 'code': fields.char('Journal Code', size=8),
- 'active': fields.boolean('Active', help="If the active field is set to False, it will allow you to hide the analytic journal without removing it."),
- 'type': fields.selection(
- [('sale', 'Sale'), ('purchase', 'Purchase'), ('cash', 'Cash'),
- ('general', 'General'), ('situation', 'Situation')],
- 'Type', required=True, help="Gives the type of the analytic journal. When it needs for a document (eg: an invoice) to create analytic entries, Odoo will look for a matching journal of the same type."),
- 'line_ids': fields.one2many('account.analytic.line', 'journal_id', 'Lines'),
- 'company_id': fields.many2one('res.company', 'Company', required=True),
- }
- _defaults = {
- 'active': True,
- 'type': 'general',
- 'company_id': lambda self, cr, uid, c=None: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
- }
-
-class res_partner(osv.osv):
- """ Inherits partner and adds contract information in the partner form """
- _inherit = 'res.partner'
-
- _columns = {
- 'contract_ids': fields.one2many('account.analytic.account', \
- 'partner_id', 'Contracts', readonly=True),
- }
+ company_id = fields.Many2one(related='account_id.company_id', string='Company', store=True, readonly=True)
+ currency_id = fields.Many2one(related="company_id.currency_id", string="Currency", readonly=True)
diff --git a/addons/analytic/report/__init__.py b/addons/analytic/report/__init__.py
deleted file mode 100644
index 60796081819..00000000000
--- a/addons/analytic/report/__init__.py
+++ /dev/null
@@ -1,8 +0,0 @@
-# -*- coding: utf-8 -*-
-# Part of Odoo. See LICENSE file for full copyright and licensing details.
-
-import analytic_journal
-import analytic_balance
-import analytic_inverted_balance
-import analytic_cost_ledger
-import analytic_quantity_cost_ledger
diff --git a/addons/analytic/report/analytic_balance.py b/addons/analytic/report/analytic_balance.py
deleted file mode 100644
index 54220de6dc6..00000000000
--- a/addons/analytic/report/analytic_balance.py
+++ /dev/null
@@ -1,137 +0,0 @@
-# -*- coding: utf-8 -*-
-# Part of Odoo. See LICENSE file for full copyright and licensing details.
-
-import time
-from openerp.osv import osv
-from openerp.report import report_sxw
-
-
-class account_analytic_balance(report_sxw.rml_parse):
- def __init__(self, cr, uid, name, context):
- super(account_analytic_balance, self).__init__(cr, uid, name, context=context)
- self.localcontext.update( {
- 'time': time,
- 'get_objects': self._get_objects,
- 'lines_g': self._lines_g,
- 'move_sum': self._move_sum,
- 'sum_all': self._sum_all,
- 'sum_balance': self._sum_balance,
- 'move_sum_balance': self._move_sum_balance,
- })
- self.acc_ids = []
- self.read_data = []
- self.empty_acc = False
- self.acc_data_dict = {}# maintains a relation with an account with its successors.
- self.acc_sum_list = []# maintains a list of all ids
-
- def get_children(self, ids):
- read_data = self.pool.get('account.analytic.account').read(self.cr, self.uid, ids,['child_ids','code','complete_name','balance'])
- for data in read_data:
- if (data['id'] not in self.acc_ids):
- inculde_empty = True
- if (not self.empty_acc) and data['balance'] == 0.00:
- inculde_empty = False
- if inculde_empty:
- self.acc_ids.append(data['id'])
- self.read_data.append(data)
- if data['child_ids']:
- self.get_children(data['child_ids'])
- return True
-
- def _get_objects(self, empty_acc):
- if self.read_data:
- return self.read_data
- self.empty_acc = empty_acc
- self.read_data = []
- self.get_children(self.ids)
- return self.read_data
-
- def _lines_g(self, account_id, date1, date2):
- account_analytic_obj = self.pool.get('account.analytic.account')
- ids = account_analytic_obj.search(self.cr, self.uid,
- [('parent_id', 'child_of', [account_id])])
- self.cr.execute("SELECT aa.name AS name, aa.code AS code, \
- sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity \
- FROM account_analytic_line AS aal, account_account AS aa \
- WHERE (aal.general_account_id=aa.id) \
- AND (aal.account_id IN %s)\
- AND (date>=%s) AND (date<=%s) AND aa.active \
- GROUP BY aal.general_account_id, aa.name, aa.code, aal.code \
- ORDER BY aal.code", (tuple(ids), date1, date2))
- res = self.cr.dictfetchall()
-
- for r in res:
- if r['balance'] > 0:
- r['debit'] = r['balance']
- r['credit'] = 0.0
- elif r['balance'] < 0:
- r['debit'] = 0.0
- r['credit'] = -r['balance']
- else:
- r['balance'] == 0
- r['debit'] = 0.0
- r['credit'] = 0.0
- return res
-
- def _move_sum(self, account_id, date1, date2, option):
- if account_id not in self.acc_data_dict:
- account_analytic_obj = self.pool.get('account.analytic.account')
- ids = account_analytic_obj.search(self.cr, self.uid,[('parent_id', 'child_of', [account_id])])
- self.acc_data_dict[account_id] = ids
- else:
- ids = self.acc_data_dict[account_id]
-
- query_params = (tuple(ids), date1, date2)
- if option == "credit":
- self.cr.execute("SELECT COALESCE(-sum(amount),0.0) FROM account_analytic_line \
- WHERE account_id IN %s AND date>=%s AND date<=%s AND amount<0",query_params)
- elif option == "debit":
- self.cr.execute("SELECT COALESCE(sum(amount),0.0) FROM account_analytic_line \
- WHERE account_id IN %s\
- AND date>=%s AND date<=%s AND amount>0",query_params)
- elif option == "quantity":
- self.cr.execute("SELECT COALESCE(sum(unit_amount),0.0) FROM account_analytic_line \
- WHERE account_id IN %s\
- AND date>=%s AND date<=%s",query_params)
- return self.cr.fetchone()[0] or 0.0
-
- def _move_sum_balance(self, account_id, date1, date2):
- debit = self._move_sum(account_id, date1, date2, 'debit')
- credit = self._move_sum(account_id, date1, date2, 'credit')
- return (debit-credit)
-
- def _sum_all(self, accounts, date1, date2, option):
- account_analytic_obj = self.pool.get('account.analytic.account')
- ids = map(lambda x: x['id'], accounts)
- if not ids:
- return 0.0
-
- if not self.acc_sum_list:
- ids2 = account_analytic_obj.search(self.cr, self.uid,[('parent_id', 'child_of', ids)])
- self.acc_sum_list = ids2
- else:
- ids2 = self.acc_sum_list
-
- query_params = (tuple(ids2), date1, date2)
- if option == "debit":
- self.cr.execute("SELECT COALESCE(sum(amount),0.0) FROM account_analytic_line \
- WHERE account_id IN %s AND date>=%s AND date<=%s AND amount>0",query_params)
- elif option == "credit":
- self.cr.execute("SELECT COALESCE(-sum(amount),0.0) FROM account_analytic_line \
- WHERE account_id IN %s AND date>=%s AND date<=%s AND amount<0",query_params)
- elif option == "quantity":
- self.cr.execute("SELECT COALESCE(sum(unit_amount),0.0) FROM account_analytic_line \
- WHERE account_id IN %s AND date>=%s AND date<=%s",query_params)
- return self.cr.fetchone()[0] or 0.0
-
- def _sum_balance(self, accounts, date1, date2):
- debit = self._sum_all(accounts, date1, date2, 'debit') or 0.0
- credit = self._sum_all(accounts, date1, date2, 'credit') or 0.0
- return (debit-credit)
-
-
-class report_analyticbalance(osv.AbstractModel):
- _name = 'report.account.report_analyticbalance'
- _inherit = 'report.abstract_report'
- _template = 'analytic.report_analyticbalance'
- _wrapped_report_class = account_analytic_balance
diff --git a/addons/analytic/report/analytic_cost_ledger.py b/addons/analytic/report/analytic_cost_ledger.py
deleted file mode 100644
index 7c97fa8f9f9..00000000000
--- a/addons/analytic/report/analytic_cost_ledger.py
+++ /dev/null
@@ -1,91 +0,0 @@
-# -*- coding: utf-8 -*-
-# Part of Odoo. See LICENSE file for full copyright and licensing details.
-
-import time
-from openerp.osv import osv
-from openerp.report import report_sxw
-
-
-class account_analytic_cost_ledger(report_sxw.rml_parse):
- def __init__(self, cr, uid, name, context):
- super(account_analytic_cost_ledger, self).__init__(cr, uid, name, context=context)
- self.localcontext.update( {
- 'time': time,
- 'lines_g': self._lines_g,
- 'lines_a': self._lines_a,
- 'account_sum_debit': self._account_sum_debit,
- 'account_sum_credit': self._account_sum_credit,
- 'account_sum_balance': self._account_sum_balance,
- 'sum_debit': self._sum_debit,
- 'sum_credit': self._sum_credit,
- 'sum_balance': self._sum_balance,
- })
- self.children = {} # a memo for the method _get_children
-
- def _get_children(self, accounts):
- """ return all children accounts of the given accounts
- :param accounts: list of browse records of 'account.analytic.account'
- :return: tuple of account ids
- """
- analytic_obj = self.pool.get('account.analytic.account')
- res = set()
- for account in accounts:
- if account.id not in self.children:
- self.children[account.id] = analytic_obj.search(self.cr, self.uid, [('parent_id', 'child_of', [account.id])])
- res.update(self.children[account.id])
- return tuple(res)
-
- def _lines_g(self, account, date1, date2):
- self.cr.execute("SELECT sum(aal.amount) AS balance, aa.code AS code, aa.name AS name, aa.id AS id \
- FROM account_account AS aa, account_analytic_line AS aal \
- WHERE (aal.account_id IN %s) AND (aal.date>=%s) AND (aal.date<=%s) AND (aal.general_account_id=aa.id) AND aa.active \
- GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code", (self._get_children([account]), date1, date2))
- res = self.cr.dictfetchall()
- for r in res:
- r['debit'] = r['balance'] if r['balance'] > 0 else 0.0
- r['credit'] = -r['balance'] if r['balance'] < 0 else 0.0
- return res
-
- def _lines_a(self, general_account, account, date1, date2):
- self.cr.execute("SELECT aal.name AS name, aal.code AS code, aal.amount AS balance, aal.date AS date, aaj.code AS cj FROM account_analytic_line AS aal, account_analytic_journal AS aaj \
- WHERE (aal.general_account_id=%s) AND (aal.account_id IN %s) AND (aal.date>=%s) AND (aal.date<=%s) \
- AND (aal.journal_id=aaj.id) \
- ORDER BY aal.date, aaj.code, aal.code", (general_account['id'], self._get_children([account]), date1, date2))
- res = self.cr.dictfetchall()
- for r in res:
- r['debit'] = r['balance'] if r['balance'] > 0 else 0.0
- r['credit'] = -r['balance'] if r['balance'] < 0 else 0.0
- return res
-
- def _account_sum_debit(self, account, date1, date2):
- return self._sum_debit([account], date1, date2)
-
- def _account_sum_credit(self, account, date1, date2):
- return self._sum_credit([account], date1, date2)
-
- def _account_sum_balance(self, account, date1, date2):
- debit = self._account_sum_debit(account, date1, date2)
- credit = self._account_sum_credit(account, date1, date2)
- return (debit-credit)
-
- def _sum_debit(self, accounts, date1, date2):
- self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id IN %s AND date>=%s AND date<=%s AND amount>0",
- (self._get_children(accounts), date1, date2,))
- return self.cr.fetchone()[0] or 0.0
-
- def _sum_credit(self, accounts, date1, date2):
- self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id IN %s AND date>=%s AND date<=%s AND amount<0",
- (self._get_children(accounts), date1, date2,))
- return self.cr.fetchone()[0] or 0.0
-
- def _sum_balance(self, accounts, date1, date2):
- debit = self._sum_debit(accounts, date1, date2)
- credit = self._sum_credit(accounts, date1, date2)
- return (debit-credit)
-
-
-class report_analyticcostledger(osv.AbstractModel):
- _name = 'report.account.report_analyticcostledger'
- _inherit = 'report.abstract_report'
- _template = 'analytic.report_analyticcostledger'
- _wrapped_report_class = account_analytic_cost_ledger
diff --git a/addons/analytic/report/analytic_inverted_balance.py b/addons/analytic/report/analytic_inverted_balance.py
deleted file mode 100644
index ca77d2dc795..00000000000
--- a/addons/analytic/report/analytic_inverted_balance.py
+++ /dev/null
@@ -1,110 +0,0 @@
-# -*- coding: utf-8 -*-
-# Part of Odoo. See LICENSE file for full copyright and licensing details.
-
-import time
-from openerp.osv import osv
-from openerp.report import report_sxw
-
-class account_inverted_analytic_balance(report_sxw.rml_parse):
- def __init__(self, cr, uid, name, context):
- super(account_inverted_analytic_balance, self).__init__(cr, uid, name, context=context)
- self.localcontext.update( {
- 'time': time,
- 'lines_g': self._lines_g,
- 'lines_a': self._lines_a,
- 'sum_debit': self._sum_debit,
- 'sum_credit': self._sum_credit,
- 'sum_balance': self._sum_balance,
- 'sum_quantity': self._sum_quantity,
- })
-
- def _lines_g(self, accounts, date1, date2):
- ids = map(lambda x: x.id, accounts)
- self.cr.execute("SELECT aa.name AS name, aa.code AS code, "
- "sum(aal.amount) AS balance, "
- "sum(aal.unit_amount) AS quantity, aa.id AS id \
- FROM account_analytic_line AS aal, account_account AS aa \
- WHERE (aal.general_account_id=aa.id) "
- "AND (aal.account_id IN %s) "
- "AND (date>=%s) AND (date<=%s) AND aa.active \
- GROUP BY aal.general_account_id, aa.name, aa.code, aal.code, aa.id "
- "ORDER BY aal.code",
- (tuple(ids), date1, date2))
- res = self.cr.dictfetchall()
- for r in res:
- if r['balance'] > 0:
- r['debit'] = r['balance']
- r['credit'] = 0.0
- elif r['balance'] < 0:
- r['debit'] = 0.0
- r['credit'] = -r['balance']
- else:
- r['debit'] = 0.0
- r['credit'] = 0.0
- return res
-
- def _lines_a(self, accounts, general_account_id, date1, date2):
- ids = map(lambda x: x.id, accounts)
- self.cr.execute("SELECT sum(aal.amount) AS balance, "
- "sum(aal.unit_amount) AS quantity, "
- "aaa.code AS code, aaa.name AS name, account_id \
- FROM account_analytic_line AS aal, "
- "account_analytic_account AS aaa \
- WHERE aal.account_id=aaa.id AND aal.account_id IN %s "
- "AND aal.general_account_id=%s AND aal.date>=%s "
- "AND aal.date<=%s \
- GROUP BY aal.account_id, general_account_id, aaa.code, aaa.name "
- "ORDER BY aal.account_id",
- (tuple(ids), general_account_id, date1, date2))
- res = self.cr.dictfetchall()
-
- aaa_obj = self.pool.get('account.analytic.account')
- res2 = aaa_obj.read(self.cr, self.uid, ids, ['complete_name'])
- complete_name = {}
- for r in res2:
- complete_name[r['id']] = r['complete_name']
- for r in res:
- r['complete_name'] = complete_name[r['account_id']]
- if r['balance'] > 0:
- r['debit'] = r['balance']
- r['credit'] = 0.0
- elif r['balance'] < 0:
- r['debit'] = 0.0
- r['credit'] = -r['balance']
- else:
- r['debit'] = 0.0
- r['credit'] = 0.0
- return res
-
- def _sum_debit(self, accounts, date1, date2):
- ids = map(lambda x: x.id, accounts)
- self.cr.execute("SELECT sum(amount) \
- FROM account_analytic_line \
- WHERE account_id IN %s AND date>=%s AND date<=%s AND amount>0", (tuple(ids),date1, date2,))
- return self.cr.fetchone()[0] or 0.0
-
- def _sum_credit(self, accounts, date1, date2):
- ids = map(lambda x: x.id, accounts)
- self.cr.execute("SELECT -sum(amount) \
- FROM account_analytic_line \
- WHERE account_id IN %s AND date>=%s AND date<=%s AND amount<0", (tuple(ids),date1, date2,))
- return self.cr.fetchone()[0] or 0.0
-
- def _sum_balance(self, accounts, date1, date2):
- debit = self._sum_debit(accounts, date1, date2)
- credit = self._sum_credit(accounts, date1, date2)
- return (debit-credit)
-
- def _sum_quantity(self, accounts, date1, date2):
- ids = map(lambda x: x.id, accounts)
- self.cr.execute("SELECT sum(unit_amount) \
- FROM account_analytic_line \
- WHERE account_id IN %s AND date>=%s AND date<=%s", (tuple(ids),date1, date2,))
- return self.cr.fetchone()[0] or 0.0
-
-
-class report_invertedanalyticbalance(osv.AbstractModel):
- _name = 'report.account.report_invertedanalyticbalance'
- _inherit = 'report.abstract_report'
- _template = 'analytic.report_invertedanalyticbalance'
- _wrapped_report_class = account_inverted_analytic_balance
diff --git a/addons/analytic/report/analytic_journal.py b/addons/analytic/report/analytic_journal.py
deleted file mode 100644
index 5e70d0a43cd..00000000000
--- a/addons/analytic/report/analytic_journal.py
+++ /dev/null
@@ -1,48 +0,0 @@
-# -*- coding: utf-8 -*-
-# Part of Odoo. See LICENSE file for full copyright and licensing details.
-
-import time
-from openerp.osv import osv
-from openerp.report import report_sxw
-
-
-#
-# Use period and Journal for selection or resources
-#
-class account_analytic_journal(report_sxw.rml_parse):
- def __init__(self, cr, uid, name, context):
- super(account_analytic_journal, self).__init__(cr, uid, name, context=context)
- self.localcontext.update( {
- 'time': time,
- 'lines': self._lines,
- 'lines_a': self._lines_a,
- 'sum_general': self._sum_general,
- 'sum_analytic': self._sum_analytic,
- })
-
- def _lines(self, journal_id, date1, date2):
- self.cr.execute('SELECT DISTINCT move_id FROM account_analytic_line WHERE (date>=%s) AND (date<=%s) AND (journal_id=%s) AND (move_id is not null)', (date1, date2, journal_id,))
- ids = map(lambda x: x[0], self.cr.fetchall())
- return self.pool.get('account.move.line').browse(self.cr, self.uid, ids)
-
- def _lines_a(self, move_id, journal_id, date1, date2):
- ids = self.pool.get('account.analytic.line').search(self.cr, self.uid, [('move_id','=',move_id), ('journal_id','=',journal_id), ('date','>=',date1), ('date','<=',date2)])
- if not ids:
- return []
- return self.pool.get('account.analytic.line').browse(self.cr, self.uid, ids)
-
- def _sum_general(self, journal_id, date1, date2):
- self.cr.execute('SELECT SUM(debit-credit) FROM account_move_line WHERE id IN (SELECT move_id FROM account_analytic_line WHERE (date>=%s) AND (date<=%s) AND (journal_id=%s) AND (move_id is not null))', (date1, date2, journal_id,))
- return self.cr.fetchall()[0][0] or 0
-
- def _sum_analytic(self, journal_id, date1, date2):
- self.cr.execute("SELECT SUM(amount) FROM account_analytic_line WHERE date>=%s AND date<=%s AND journal_id=%s", (date1, date2, journal_id))
- res = self.cr.dictfetchone()
- return res['sum'] or 0
-
-
-class report_analyticjournal(osv.AbstractModel):
- _name = 'report.account.report_analyticjournal'
- _inherit = 'report.abstract_report'
- _template = 'analytic.report_analyticjournal'
- _wrapped_report_class = account_analytic_journal
diff --git a/addons/analytic/report/analytic_quantity_cost_ledger.py b/addons/analytic/report/analytic_quantity_cost_ledger.py
deleted file mode 100644
index c6176a744fd..00000000000
--- a/addons/analytic/report/analytic_quantity_cost_ledger.py
+++ /dev/null
@@ -1,107 +0,0 @@
-# -*- coding: utf-8 -*-
-# Part of Odoo. See LICENSE file for full copyright and licensing details.
-import time
-from openerp.osv import osv
-from openerp.report import report_sxw
-
-
-class account_analytic_quantity_cost_ledger(report_sxw.rml_parse):
- def __init__(self, cr, uid, name, context):
- super(account_analytic_quantity_cost_ledger, self).__init__(cr, uid, name, context=context)
- self.localcontext.update( {
- 'time': time,
- 'lines_g': self._lines_g,
- 'lines_a': self._lines_a,
- 'sum_quantity': self._sum_quantity,
- 'account_sum_quantity': self._account_sum_quantity,
- })
-
- def _lines_g(self, account_id, date1, date2, journals):
- if not journals:
- self.cr.execute("SELECT sum(aal.unit_amount) AS quantity, \
- aa.code AS code, aa.name AS name, aa.id AS id \
- FROM account_account AS aa, account_analytic_line AS aal \
- WHERE (aal.account_id=%s) AND (aal.date>=%s) \
- AND (aal.date<=%s) AND (aal.general_account_id=aa.id) \
- AND aa.active \
- GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code",
- (account_id, date1, date2))
- else:
- journal_ids = journals
- self.cr.execute("SELECT sum(aal.unit_amount) AS quantity, \
- aa.code AS code, aa.name AS name, aa.id AS id \
- FROM account_account AS aa, account_analytic_line AS aal \
- WHERE (aal.account_id=%s) AND (aal.date>=%s) \
- AND (aal.date<=%s) AND (aal.general_account_id=aa.id) \
- AND aa.active \
- AND (aal.journal_id IN %s ) \
- GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code",
- (account_id, date1, date2, tuple(journal_ids)))
- res = self.cr.dictfetchall()
- return res
-
- def _lines_a(self, general_account_id, account_id, date1, date2, journals):
- if not journals:
- self.cr.execute("SELECT aal.name AS name, aal.code AS code, \
- aal.unit_amount AS quantity, aal.date AS date, \
- aaj.code AS cj \
- FROM account_analytic_line AS aal, \
- account_analytic_journal AS aaj \
- WHERE (aal.general_account_id=%s) AND (aal.account_id=%s) \
- AND (aal.date>=%s) AND (aal.date<=%s) \
- AND (aal.journal_id=aaj.id) \
- ORDER BY aal.date, aaj.code, aal.code",
- (general_account_id, account_id, date1, date2))
- else:
- journal_ids = journals
- self.cr.execute("SELECT aal.name AS name, aal.code AS code, \
- aal.unit_amount AS quantity, aal.date AS date, \
- aaj.code AS cj \
- FROM account_analytic_line AS aal, \
- account_analytic_journal AS aaj \
- WHERE (aal.general_account_id=%s) AND (aal.account_id=%s) \
- AND (aal.date>=%s) AND (aal.date<=%s) \
- AND (aal.journal_id=aaj.id) AND (aaj.id IN %s) \
- ORDER BY aal.date, aaj.code, aal.code",
- (general_account_id, account_id, date1, date2,tuple(journal_ids)))
- res = self.cr.dictfetchall()
- return res
-
- def _account_sum_quantity(self, account_id, date1, date2, journals):
- if not journals:
- self.cr.execute("SELECT sum(unit_amount) \
- FROM account_analytic_line \
- WHERE account_id=%s AND date>=%s AND date<=%s",
- (account_id, date1, date2))
- else:
- journal_ids = journals
- self.cr.execute("SELECT sum(unit_amount) \
- FROM account_analytic_line \
- WHERE account_id = %s AND date >= %s AND date <= %s \
- AND journal_id IN %s",
- (account_id, date1, date2, tuple(journal_ids),))
- return self.cr.fetchone()[0] or 0.0
-
- def _sum_quantity(self, accounts, date1, date2, journals):
- ids = map(lambda x: x.id, accounts)
- if not ids:
- return 0.0
- if not journals:
- self.cr.execute("SELECT sum(unit_amount) \
- FROM account_analytic_line \
- WHERE account_id IN %s AND date>=%s AND date<=%s",
- (tuple(ids), date1, date2,))
- else:
- journal_ids = journals
- self.cr.execute("SELECT sum(unit_amount) \
- FROM account_analytic_line \
- WHERE account_id IN %s AND date >= %s AND date <= %s \
- AND journal_id IN %s",(tuple(ids), date1, date2, tuple(journal_ids)))
- return self.cr.fetchone()[0] or 0.0
-
-
-class report_analyticcostledgerquantity(osv.AbstractModel):
- _name = 'report.account.report_analyticcostledgerquantity'
- _inherit = 'report.abstract_report'
- _template = 'analytic.report_analyticcostledgerquantity'
- _wrapped_report_class = account_analytic_quantity_cost_ledger
diff --git a/addons/analytic/security/analytic_security.xml b/addons/analytic/security/analytic_security.xml
index 43bf89de406..c11cce92c54 100644
--- a/addons/analytic/security/analytic_security.xml
+++ b/addons/analytic/security/analytic_security.xml
@@ -15,14 +15,6 @@
['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]
-
-
- Analytic journal multi-company
-
-
- ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]
-
-
diff --git a/addons/analytic/security/ir.model.access.csv b/addons/analytic/security/ir.model.access.csv
index 9ca53cdff14..32ee04d9f9d 100644
--- a/addons/analytic/security/ir.model.access.csv
+++ b/addons/analytic/security/ir.model.access.csv
@@ -1,4 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
-access_account_analytic_account,access_account_analytic_account,model_account_analytic_account,group_analytic_accounting,1,0,0,0
-access_account_analytic_line,access_account_analytic_line,model_account_analytic_line,group_analytic_accounting,1,0,0,0
-access_account_analytic_journal,access_account_analytic_journal,model_account_analytic_journal,group_analytic_accounting,1,0,0,0
+access_account_analytic_account,access_account_analytic_account,model_account_analytic_account,group_analytic_accounting,1,1,1,1
+access_account_analytic_line,access_account_analytic_line,model_account_analytic_line,group_analytic_accounting,1,1,1,1
+access_account_analytic_tag,access_account_analytic_tag,model_account_analytic_tag,group_analytic_accounting,1,1,1,1
diff --git a/addons/analytic/test/analytic_hierarchy.yml b/addons/analytic/test/analytic_hierarchy.yml
deleted file mode 100644
index 222e03aa062..00000000000
--- a/addons/analytic/test/analytic_hierarchy.yml
+++ /dev/null
@@ -1,54 +0,0 @@
--
- We create a simple hierarchy like this
- Toplevel view account
- ├ Real analytic account 1
- └ Real analytic account 2
--
- !record {model: account.analytic.account, id: analytic_account_view1}:
- name: 'Toplevel view account'
- type: 'view'
--
- !record {model: account.analytic.account, id: analytic_account1}:
- name: 'Real analytic account 1'
- type: 'normal'
- parent_id: analytic_account_view1
--
- !record {model: account.analytic.account, id: analytic_account2}:
- name: 'Real analytic account 2'
- type: 'normal'
- parent_id: analytic_account_view1
--
- We add analytic lines in real accounts and journal
--
- !record {model: account.analytic.journal, id: analytic_journal1}:
- name: 'Analytic journal'
--
- !record {model: account.analytic.line, id: analytic_line1}:
- name: 'Analytic line 1'
- account_id: analytic_account1
- journal_id: analytic_journal1
--
- !record {model: account.analytic.line, id: analytic_line2}:
- name: 'Analytic line 2'
- account_id: analytic_account2
- journal_id: analytic_journal1
--
- Now we copy the toplevel account
--
- !function {model: account.analytic.account, name: copy, id: analytic_account_view1}:
- - eval: "ref('analytic_account_view1')"
--
- !python {model: account.analytic.account}: |
- # the toplevel account has been copied with the (copy) suffix
- accounts = self.search(cr, uid, [('name', 'like', '%Toplevel view account%')])
- assert len(accounts) == 2, 'The toplevel account has not been copied'
- accounts = self.search(cr, uid, [('name', '=', 'Toplevel view account')])
- assert len(accounts) == 1, 'The toplevel account copy has a bad name'
- # the sub-accounts and sub-accounts have been copied without the (copy) suffix
- accounts = self.search(cr, uid, [('name', '=', 'Real analytic account 1')])
- assert len(accounts) == 2, 'The sub-account has not been copied'
- accounts = self.search(cr, uid, [('name', '=', 'Real analytic account 2')])
- assert len(accounts) == 2, 'The sub-account has not been copied'
- # the analytic lines should not be duplicated
- lines = self.pool.get('account.analytic.line').search(cr, uid, [('name', 'like', '%Analytic line %')])
- assert len(lines) == 2, "The analytic lines shouldn't have been copied"
diff --git a/addons/analytic/views/analytic_view.xml b/addons/analytic/views/analytic_view.xml
index d45e4ea960e..1df97577254 100644
--- a/addons/analytic/views/analytic_view.xml
+++ b/addons/analytic/views/analytic_view.xml
@@ -1,6 +1,48 @@
+
+ account.analytic.line.tree
+ account.analytic.line
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {'search_default_group_date': 1, 'search_default_group_journal': 1, 'default_account_id': active_id}
+ [('account_id','=', active_id)]
+ Costs & Revenues
+ account.analytic.line
+ tree,form,graph,pivot
+
+ form
+
+
+ No activity yet on this account.
+
+ In Odoo, sale orders and projects are implemented using
+ analytic account. You can track costs and revenues to analyse
+ your margins easily.
+
+ Costs will be created automatically when you register supplier
+ invoices, expenses or timesheets.
+
+ Revenues will be created automatically when you create customer
+ invoices. Customer invoices can be created based on sale orders
+ (fixed price invoices), on timesheets (based on the work done) or
+ on expenses (e.g. reinvoicing of travel costs).
+