Skip to content

Commit

Permalink
Correction to bug in module "account_invoice_analytic_search".
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiBForgeFlow committed Mar 25, 2015
1 parent 042aacc commit 32ec0d6
Showing 1 changed file with 67 additions and 12 deletions.
79 changes: 67 additions & 12 deletions account_invoice_analytic_search/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,74 @@ class account_invoice(osv.osv):

_inherit = "account.invoice"

def _get_analytic_accounts(self, cursor, user, ids, name, arg,
context=None):
res = {}
for invoice in self.browse(cursor, user, ids, context=context):
res[invoice.id] = []
for invoice_line in invoice.invoice_line:
if invoice_line.account_analytic_id:
res[invoice.id].append(
invoice_line.account_analytic_id.id)
return res

def _get_analytic_account_user_ids(self, cursor, user, ids, name, arg,
context=None):
res = {}
for invoice in self.browse(cursor, user, ids, context=context):
res[invoice.id] = []
for invoice_line in invoice.invoice_line:
if invoice_line.account_analytic_id:
if invoice_line.account_analytic_id.user_id:
res[invoice.id].append(
invoice_line.account_analytic_id.user_id.id)
return res

def _search_analytic_accounts(self, cr, uid, obj, name, args, context):

invoice_line_obj = self.pool.get('account.invoice.line')
res = []
for field, operator, value in args:
assert field == name
invoice_line_ids = invoice_line_obj.search(cr, uid,
[('account_analytic_id',
operator, value)])
invoice_ids = [invoice_line.invoice_id and
invoice_line.invoice_id.id
for invoice_line in invoice_line_obj.browse(cr, uid,
invoice_line_ids)]
res.append(('id', 'in', invoice_ids))
return res

def _search_analytic_account_user_ids(self, cr, uid, obj, name, args,
context):

invoice_line_obj = self.pool.get('account.invoice.line')
res = []
for field, operator, value in args:
assert field == name
invoice_line_ids = invoice_line_obj.search(cr, uid,
[('account_analytic_user_id',
operator, value)])
invoice_ids = [invoice_line.invoice_id and
invoice_line.invoice_id.id
for invoice_line in invoice_line_obj.browse(cr, uid,
invoice_line_ids)]
res.append(('id', 'in', invoice_ids))
return res

_columns = {
'account_analytic_ids': fields.related('invoice_line',
'account_analytic_id',
type='many2many',
relation='account.analytic.account',
string='Analytic Account',
readonly=True),
'account_analytic_user_ids': fields.related('invoice_line',
'account_analytic_user_id',
type='many2many',
relation='res.users',
string='Project Manager',
readonly=True),
'account_analytic_ids': fields.function(
_get_analytic_accounts, type='many2many',
string='Analytic Account', method=True,
fnct_search=_search_analytic_accounts,
readonly=True),

'account_analytic_user_ids': fields.function(
_get_analytic_account_user_ids, type='many2many',
string='Project Manager', method=True,
fnct_search=_search_analytic_account_user_ids,
readonly=True),
}

account_invoice()

0 comments on commit 32ec0d6

Please sign in to comment.