[IMP] account_analytic_analysis, account_analytic_default, account_analytic_plans: code cleaning
bzr revid: psi@tinyerp.co.in-20101011112550-ygkqmzmuhu1j7dm3
This commit is contained in:
parent
15da4879d9
commit
faf70e7b3a
|
@ -56,18 +56,7 @@
|
|||
</field>
|
||||
</group>
|
||||
<newline/>
|
||||
<group expand="0" string="Extended Filters..." groups="base.group_extended">
|
||||
<field name="currency_id" widget="selection"/>
|
||||
<field name="general_account_id" widget="selection"/>
|
||||
<field name="product_uom_id" widget="selection"/>
|
||||
<field name="journal_id" widget="selection"/>
|
||||
<separator orientation="vertical"/>
|
||||
<field name="name"/>
|
||||
<field name="account_id" groups="analytic.group_analytic_accounting"/>
|
||||
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<group expand="1" string="Group By...">
|
||||
<group expand="0" string="Group By...">
|
||||
<filter string="User" name="User" icon="terp-personal" context="{'group_by':'user_id'}"/>
|
||||
<filter string="Partner" icon="terp-personal" context="{'group_by':'partner_id'}"/>
|
||||
<filter string="Company" icon="terp-go-home" context="{'group_by':'company_id'}" groups="base.group_multi_company"/>
|
||||
|
@ -83,6 +72,17 @@
|
|||
<filter string="Month" name="Month" icon="terp-go-month" context="{'group_by':'month'}"/>
|
||||
<filter string="Year" icon="terp-go-year" context="{'group_by':'year'}"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<group expand="0" string="Extended Filters..." groups="base.group_extended">
|
||||
<field name="currency_id" widget="selection"/>
|
||||
<field name="general_account_id" widget="selection"/>
|
||||
<field name="product_uom_id" widget="selection"/>
|
||||
<field name="journal_id" widget="selection"/>
|
||||
<separator orientation="vertical"/>
|
||||
<field name="name"/>
|
||||
<field name="account_id" groups="analytic.group_analytic_accounting"/>
|
||||
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
|
|
@ -34,7 +34,7 @@ class account_analytic_account(osv.osv):
|
|||
dp = 2
|
||||
res = dict([(i, {}) for i in ids])
|
||||
|
||||
parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
|
||||
parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)], context=context))
|
||||
accounts = self.browse(cr, uid, ids, context=context)
|
||||
|
||||
for f in fields:
|
||||
|
@ -62,10 +62,10 @@ class account_analytic_account(osv.osv):
|
|||
for id in ids:
|
||||
res[id][f] = 0.0
|
||||
if parent_ids:
|
||||
cr.execute("select account_analytic_line.account_id, max(date) \
|
||||
from account_analytic_line \
|
||||
where account_id IN %s \
|
||||
and invoice_id is not null \
|
||||
cr.execute("SELECT account_analytic_line.account_id, MAX(date) \
|
||||
FROM account_analytic_line \
|
||||
WHERE account_id IN %s \
|
||||
AND invoice_id IS NOT NULL \
|
||||
GROUP BY account_analytic_line.account_id;", (parent_ids,))
|
||||
for account_id, sum in cr.fetchall():
|
||||
if account_id not in res:
|
||||
|
@ -85,25 +85,25 @@ class account_analytic_account(osv.osv):
|
|||
# This computation doesn't take care of pricelist !
|
||||
# Just consider list_price
|
||||
cr.execute("""SELECT account_analytic_account.id, \
|
||||
COALESCE(sum (product_template.list_price * \
|
||||
COALESCE(SUM (product_template.list_price * \
|
||||
account_analytic_line.unit_amount * \
|
||||
((100-hr_timesheet_invoice_factor.factor)/100)),0.0) \
|
||||
((100-hr_timesheet_invoice_factor.factor)/100)), 0.0) \
|
||||
AS ca_to_invoice \
|
||||
FROM product_template \
|
||||
join product_product \
|
||||
on product_template.id = product_product.product_tmpl_id \
|
||||
JOIN product_product \
|
||||
ON product_template.id = product_product.product_tmpl_id \
|
||||
JOIN account_analytic_line \
|
||||
on account_analytic_line.product_id = product_product.id \
|
||||
ON account_analytic_line.product_id = product_product.id \
|
||||
JOIN account_analytic_journal \
|
||||
on account_analytic_line.journal_id = account_analytic_journal.id \
|
||||
ON account_analytic_line.journal_id = account_analytic_journal.id \
|
||||
JOIN account_analytic_account \
|
||||
on account_analytic_account.id = account_analytic_line.account_id \
|
||||
ON account_analytic_account.id = account_analytic_line.account_id \
|
||||
JOIN hr_timesheet_invoice_factor \
|
||||
on hr_timesheet_invoice_factor.id = account_analytic_account.to_invoice \
|
||||
ON hr_timesheet_invoice_factor.id = account_analytic_account.to_invoice \
|
||||
WHERE account_analytic_account.id IN %s \
|
||||
AND account_analytic_line.invoice_id is null \
|
||||
AND account_analytic_line.invoice_id IS NULL \
|
||||
AND account_analytic_line.to_invoice IS NOT NULL \
|
||||
and account_analytic_journal.type in ('purchase','general') \
|
||||
AND account_analytic_journal.type IN ('purchase','general') \
|
||||
GROUP BY account_analytic_account.id;""", (parent_ids,))
|
||||
for account_id, sum in cr.fetchall():
|
||||
if account_id not in res:
|
||||
|
@ -124,13 +124,13 @@ class account_analytic_account(osv.osv):
|
|||
for id in ids:
|
||||
res[id][f] = ''
|
||||
if parent_ids:
|
||||
cr.execute ("select account_analytic_line.account_id, \
|
||||
date(max(account_invoice.date_invoice)) \
|
||||
from account_analytic_line \
|
||||
join account_invoice \
|
||||
on account_analytic_line.invoice_id = account_invoice.id \
|
||||
where account_analytic_line.account_id IN %s \
|
||||
and account_analytic_line.invoice_id is not null \
|
||||
cr.execute ("SELECT account_analytic_line.account_id, \
|
||||
DATE(MAX(account_invoice.date_invoice)) \
|
||||
FROM account_analytic_line \
|
||||
JOIN account_invoice \
|
||||
ON account_analytic_line.invoice_id = account_invoice.id \
|
||||
WHERE account_analytic_line.account_id IN %s \
|
||||
AND account_analytic_line.invoice_id IS NOT NULL \
|
||||
GROUP BY account_analytic_line.account_id",(parent_ids,))
|
||||
for account_id, lid in cr.fetchall():
|
||||
res[account_id][f] = lid
|
||||
|
@ -142,11 +142,11 @@ class account_analytic_account(osv.osv):
|
|||
for id in ids:
|
||||
res[id][f] = ''
|
||||
if parent_ids:
|
||||
cr.execute("select account_analytic_line.account_id, max(date) \
|
||||
from account_analytic_line \
|
||||
where account_id IN %s \
|
||||
and invoice_id is null \
|
||||
GROUP BY account_analytic_line.account_id", (parent_ids,))
|
||||
cr.execute("SELECT account_analytic_line.account_id, MAX(date) \
|
||||
FROM account_analytic_line \
|
||||
WHERE account_id IN %s \
|
||||
AND invoice_id IS NULL \
|
||||
GROUP BY account_analytic_line.account_id" ,(parent_ids,))
|
||||
for account_id, lwd in cr.fetchall():
|
||||
if account_id not in res:
|
||||
res[account_id] = {}
|
||||
|
@ -159,13 +159,13 @@ class account_analytic_account(osv.osv):
|
|||
for id in ids:
|
||||
res[id][f] = 0.0
|
||||
if parent_ids:
|
||||
cr.execute("select account_analytic_line.account_id, COALESCE(sum(unit_amount),0.0) \
|
||||
from account_analytic_line \
|
||||
join account_analytic_journal \
|
||||
on account_analytic_line.journal_id = account_analytic_journal.id \
|
||||
where account_analytic_line.account_id IN %s \
|
||||
and account_analytic_journal.type='general' \
|
||||
and invoice_id is null \
|
||||
cr.execute("SELECT account_analytic_line.account_id, COALESCE(SUM(unit_amount), 0.0) \
|
||||
FROM account_analytic_line \
|
||||
JOIN account_analytic_journal \
|
||||
ON account_analytic_line.journal_id = account_analytic_journal.id \
|
||||
WHERE account_analytic_line.account_id IN %s \
|
||||
AND account_analytic_journal.type='general' \
|
||||
AND invoice_id IS NULL \
|
||||
AND to_invoice IS NOT NULL \
|
||||
GROUP BY account_analytic_line.account_id;",(parent_ids,))
|
||||
for account_id, sua in cr.fetchall():
|
||||
|
@ -182,12 +182,12 @@ class account_analytic_account(osv.osv):
|
|||
for id in ids:
|
||||
res[id][f] = 0.0
|
||||
if parent_ids:
|
||||
cr.execute("select account_analytic_line.account_id,COALESCE(SUM(unit_amount),0.0) \
|
||||
from account_analytic_line \
|
||||
join account_analytic_journal \
|
||||
on account_analytic_line.journal_id = account_analytic_journal.id \
|
||||
where account_analytic_line.account_id IN %s \
|
||||
and account_analytic_journal.type='general' \
|
||||
cr.execute("SELECT account_analytic_line.account_id, COALESCE(SUM(unit_amount), 0.0) \
|
||||
FROM account_analytic_line \
|
||||
JOIN account_analytic_journal \
|
||||
ON account_analytic_line.journal_id = account_analytic_journal.id \
|
||||
WHERE account_analytic_line.account_id IN %s \
|
||||
AND account_analytic_journal.type='general' \
|
||||
GROUP BY account_analytic_line.account_id",(parent_ids,))
|
||||
ff = cr.fetchall()
|
||||
for account_id, hq in ff:
|
||||
|
@ -211,24 +211,24 @@ class account_analytic_account(osv.osv):
|
|||
# This computation doesn't take care of pricelist !
|
||||
# Just consider list_price
|
||||
if parent_ids:
|
||||
cr.execute("""select account_analytic_line.account_id as account_id, \
|
||||
COALESCE(sum((account_analytic_line.unit_amount * pt.list_price) \
|
||||
cr.execute("""SELECT account_analytic_line.account_id AS account_id, \
|
||||
COALESCE(SUM((account_analytic_line.unit_amount * pt.list_price) \
|
||||
- (account_analytic_line.unit_amount * pt.list_price \
|
||||
* hr.factor)),0.0) as somme
|
||||
from account_analytic_line \
|
||||
left join account_analytic_journal \
|
||||
on (account_analytic_line.journal_id = account_analytic_journal.id) \
|
||||
join product_product pp \
|
||||
on (account_analytic_line.product_id = pp.id) \
|
||||
join product_template pt \
|
||||
on (pp.product_tmpl_id = pt.id) \
|
||||
join account_analytic_account a \
|
||||
on (a.id=account_analytic_line.account_id) \
|
||||
join hr_timesheet_invoice_factor hr \
|
||||
on (hr.id=a.to_invoice) \
|
||||
where account_analytic_line.account_id IN %s \
|
||||
and a.to_invoice IS NOT NULL \
|
||||
and account_analytic_journal.type IN ('purchase','general')
|
||||
* hr.factor)), 0.0) AS somme
|
||||
FROM account_analytic_line \
|
||||
LEFT JOIN account_analytic_journal \
|
||||
ON (account_analytic_line.journal_id = account_analytic_journal.id) \
|
||||
JOIN product_product pp \
|
||||
ON (account_analytic_line.product_id = pp.id) \
|
||||
JOIN product_template pt \
|
||||
ON (pp.product_tmpl_id = pt.id) \
|
||||
JOIN account_analytic_account a \
|
||||
ON (a.id=account_analytic_line.account_id) \
|
||||
JOIN hr_timesheet_invoice_factor hr \
|
||||
ON (hr.id=a.to_invoice) \
|
||||
WHERE account_analytic_line.account_id IN %s \
|
||||
AND a.to_invoice IS NOT NULL \
|
||||
AND account_analytic_journal.type IN ('purchase', 'general')
|
||||
GROUP BY account_analytic_line.account_id""",(parent_ids,))
|
||||
for account_id, sum in cr.fetchall():
|
||||
res2[account_id] = round(sum, dp)
|
||||
|
@ -250,53 +250,51 @@ class account_analytic_account(osv.osv):
|
|||
|
||||
def _ca_invoiced_calc(self, cr, uid, ids, name, arg, context=None):
|
||||
res = {}
|
||||
parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
|
||||
parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)], context=context))
|
||||
if parent_ids:
|
||||
cr.execute("select account_analytic_line.account_id, COALESCE(sum(amount_currency),0.0) \
|
||||
from account_analytic_line \
|
||||
join account_analytic_journal \
|
||||
on account_analytic_line.journal_id = account_analytic_journal.id \
|
||||
where account_analytic_line.account_id IN %s \
|
||||
and account_analytic_journal.type = 'sale' \
|
||||
group by account_analytic_line.account_id", (parent_ids,))
|
||||
cr.execute("SELECT account_analytic_line.account_id, COALESCE(SUM(amount_currency), 0.0) \
|
||||
FROM account_analytic_line \
|
||||
JOIN account_analytic_journal \
|
||||
ON account_analytic_line.journal_id = account_analytic_journal.id \
|
||||
WHERE account_analytic_line.account_id IN %s \
|
||||
AND account_analytic_journal.type = 'sale' \
|
||||
GROUP BY account_analytic_line.account_id", (parent_ids,))
|
||||
for account_id, sum in cr.fetchall():
|
||||
res[account_id] = round(sum,2)
|
||||
|
||||
return self._compute_currency_for_level_tree(cr, uid, ids, parent_ids, res, context)
|
||||
return self._compute_currency_for_level_tree(cr, uid, ids, parent_ids, res, context=context)
|
||||
|
||||
def _total_cost_calc(self, cr, uid, ids, name, arg, context=None):
|
||||
res = {}
|
||||
parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
|
||||
parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)], context=context))
|
||||
if parent_ids:
|
||||
cr.execute("""select account_analytic_line.account_id,COALESCE(sum(amount_currency),0.0) \
|
||||
|
||||
from account_analytic_line \
|
||||
join account_analytic_journal \
|
||||
on account_analytic_line.journal_id = account_analytic_journal.id \
|
||||
where account_analytic_line.account_id IN %s \
|
||||
and amount<0 \
|
||||
cr.execute("""SELECT account_analytic_line.account_id, COALESCE(SUM(amount_currency), 0.0) \
|
||||
FROM account_analytic_line \
|
||||
JOIN account_analytic_journal \
|
||||
ON account_analytic_line.journal_id = account_analytic_journal.id \
|
||||
WHERE account_analytic_line.account_id IN %s \
|
||||
AND amount<0 \
|
||||
GROUP BY account_analytic_line.account_id""",(parent_ids,))
|
||||
for account_id, sum in cr.fetchall():
|
||||
res[account_id] = round(sum,2)
|
||||
return self._compute_currency_for_level_tree(cr, uid, ids, parent_ids, res, context)
|
||||
return self._compute_currency_for_level_tree(cr, uid, ids, parent_ids, res, context=context)
|
||||
|
||||
def _remaining_hours_calc(self, cr, uid, ids, name, arg, context=None):
|
||||
res = {}
|
||||
for account in self.browse(cr, uid, ids):
|
||||
for account in self.browse(cr, uid, ids, context=context):
|
||||
if account.quantity_max != 0:
|
||||
res[account.id] = account.quantity_max - account.hours_quantity
|
||||
else:
|
||||
res[account.id]=0.0
|
||||
res[account.id] = 0.0
|
||||
for id in ids:
|
||||
res[id] = round(res.get(id, 0.0),2)
|
||||
return res
|
||||
|
||||
def _hours_qtt_invoiced_calc(self, cr, uid, ids, name, arg, context=None):
|
||||
res = {}
|
||||
for account in self.browse(cr, uid, ids):
|
||||
for account in self.browse(cr, uid, ids, context=context):
|
||||
res[account.id] = account.hours_quantity - account.hours_qtt_non_invoiced
|
||||
if res[account.id] < 0:
|
||||
res[account.id]=0.0
|
||||
res[account.id] = 0.0
|
||||
for id in ids:
|
||||
res[id] = round(res.get(id, 0.0),2)
|
||||
return res
|
||||
|
@ -414,7 +412,7 @@ class account_analytic_account_summary_user(osv.osv):
|
|||
max_user = cr.fetchone()[0]
|
||||
account_ids = [int(str(x/max_user - (x%max_user == 0 and 1 or 0))) for x in ids]
|
||||
user_ids = [int(str(x-((x/max_user - (x%max_user == 0 and 1 or 0)) *max_user))) for x in ids]
|
||||
parent_ids = tuple(account_obj.search(cr, uid, [('parent_id', 'child_of', account_ids)]))
|
||||
parent_ids = tuple(account_obj.search(cr, uid, [('parent_id', 'child_of', account_ids)], context=context))
|
||||
if parent_ids:
|
||||
cr.execute('SELECT id, unit_amount ' \
|
||||
'FROM account_analytic_analysis_summary_user ' \
|
||||
|
@ -477,19 +475,19 @@ class account_analytic_account_summary_user(osv.osv):
|
|||
|
||||
def _read_flat(self, cr, user, ids, fields, context=None, load='_classic_read'):
|
||||
if not context:
|
||||
context={}
|
||||
context = {}
|
||||
if not ids:
|
||||
return []
|
||||
|
||||
if fields==None:
|
||||
if fields is None:
|
||||
fields = self._columns.keys()
|
||||
res_trans_obj = self.pool.get('ir.translation')
|
||||
|
||||
# construct a clause for the rules:
|
||||
d1, d2, tables = self.pool.get('ir.rule').domain_get(cr, user, self._name, 'read', context=context)
|
||||
|
||||
# all inherited fields + all non inherited fields for which the attribute whose name is in load is True
|
||||
fields_pre = filter(lambda x: x in self._columns and getattr(self._columns[x],'_classic_write'), fields) + self._inherits.values()
|
||||
|
||||
res = []
|
||||
cr.execute('SELECT MAX(id) FROM res_users')
|
||||
max_user = cr.fetchone()[0]
|
||||
|
@ -498,9 +496,9 @@ class account_analytic_account_summary_user(osv.osv):
|
|||
for i in range(0, len(ids), cr.IN_MAX):
|
||||
sub_ids = ids[i:i+cr.IN_MAX]
|
||||
if d1:
|
||||
cr.execute('select %s from \"%s\" where id IN (%s) ' \
|
||||
'and account_id IN (%s) ' \
|
||||
'and "user" IN (%s) and %s order by %s' % \
|
||||
cr.execute('SELECT %s FROM \"%s\" WHERE id IN (%s) ' \
|
||||
'AND account_id IN (%s) ' \
|
||||
'AND "user" IN (%s) AND %s ORDER BY %s' % \
|
||||
(','.join(fields_pre2 + ['id']), self._table,
|
||||
','.join([str(x) for x in sub_ids]),
|
||||
','.join([str(x/max_user - (x%max_user == 0 and 1 or 0)) for x in sub_ids]),
|
||||
|
@ -510,9 +508,9 @@ class account_analytic_account_summary_user(osv.osv):
|
|||
raise except_orm(_('AccessError'),
|
||||
_('You try to bypass an access rule (Document type: %s).') % self._description)
|
||||
else:
|
||||
cr.execute('select %s from \"%s\" where id IN (%s) ' \
|
||||
'and account_id IN (%s) ' \
|
||||
'and "user" IN (%s) order by %s' % \
|
||||
cr.execute('SELECT %s FROM \"%s\" WHERE id IN (%s) ' \
|
||||
'AND account_id IN (%s) ' \
|
||||
'AND "user" IN (%s) ORDER BY %s' % \
|
||||
(','.join(fields_pre2 + ['id']), self._table,
|
||||
','.join([str(x) for x in sub_ids]),
|
||||
','.join([str(x/max_user - (x%max_user == 0 and 1 or 0)) for x in sub_ids]),
|
||||
|
@ -521,7 +519,6 @@ class account_analytic_account_summary_user(osv.osv):
|
|||
res.extend(cr.dictfetchall())
|
||||
else:
|
||||
res = map(lambda x: {'id': x}, ids)
|
||||
res_trans_obj = self.pool.get('ir.translation')
|
||||
for f in fields_pre:
|
||||
if self._columns[f].translate:
|
||||
ids = map(lambda x: x['id'], res)
|
||||
|
@ -579,7 +576,7 @@ class account_analytic_account_summary_month(osv.osv):
|
|||
account_obj = self.pool.get('account.analytic.account')
|
||||
account_ids = [int(str(int(x))[:-6]) for x in ids]
|
||||
month_ids = [int(str(int(x))[-6:]) for x in ids]
|
||||
parent_ids = tuple(account_obj.search(cr, uid, [('parent_id', 'child_of', account_ids)]))
|
||||
parent_ids = tuple(account_obj.search(cr, uid, [('parent_id', 'child_of', account_ids)], context=context))
|
||||
if parent_ids:
|
||||
cr.execute('SELECT id, unit_amount ' \
|
||||
'FROM account_analytic_analysis_summary_month ' \
|
||||
|
@ -598,11 +595,9 @@ class account_analytic_account_summary_month(osv.osv):
|
|||
return res
|
||||
|
||||
_columns = {
|
||||
'account_id': fields.many2one('account.analytic.account', 'Analytic Account',
|
||||
readonly=True),
|
||||
'unit_amount': fields.function(_unit_amount, method=True, type='float',
|
||||
string='Total Time'),
|
||||
'month': fields.char('Month', size=25, readonly=True),
|
||||
'account_id': fields.many2one('account.analytic.account', 'Analytic Account', readonly=True),
|
||||
'unit_amount': fields.function(_unit_amount, method=True, type='float', string='Total Time'),
|
||||
'month': fields.char('Month', size=32, readonly=True),
|
||||
}
|
||||
|
||||
def init(self, cr):
|
||||
|
@ -654,28 +649,27 @@ class account_analytic_account_summary_month(osv.osv):
|
|||
|
||||
def _read_flat(self, cr, user, ids, fields, context=None, load='_classic_read'):
|
||||
if not context:
|
||||
context={}
|
||||
context = {}
|
||||
if not ids:
|
||||
return []
|
||||
|
||||
if fields==None:
|
||||
if fields is None:
|
||||
fields = self._columns.keys()
|
||||
|
||||
# construct a clause for the rules:
|
||||
d1, d2, tables = self.pool.get('ir.rule').domain_get(cr, user, self._name)
|
||||
res_trans_obj = self.pool.get('ir.translation')
|
||||
# construct a clause for the rules :
|
||||
d1, d2, tables= self.pool.get('ir.rule').domain_get(cr, user, self._name)
|
||||
|
||||
# all inherited fields + all non inherited fields for which the attribute whose name is in load is True
|
||||
fields_pre = filter(lambda x: x in self._columns and getattr(self._columns[x],'_classic_write'), fields) + self._inherits.values()
|
||||
|
||||
res = []
|
||||
if fields_pre:
|
||||
fields_pre2 = map(lambda x: (x in ('create_date', 'write_date')) and ('date_trunc(\'second\', '+x+') as '+x) or '"'+x+'"', fields_pre)
|
||||
for i in range(0, len(ids), cr.IN_MAX):
|
||||
sub_ids = ids[i:i+cr.IN_MAX]
|
||||
if d1:
|
||||
cr.execute('select %s from \"%s\" where id IN (%s) ' \
|
||||
'and account_id IN (%s) ' \
|
||||
'and month_id IN (%s) and %s order by %s' % \
|
||||
cr.execute('SELECT %s FROM \"%s\" WHERE id IN (%s) ' \
|
||||
'AND account_id IN (%s) ' \
|
||||
'AND month_id IN (%s) AND %s ORDER BY %s' % \
|
||||
(','.join(fields_pre2 + ['id']), self._table,
|
||||
','.join([str(x) for x in sub_ids]),
|
||||
','.join([str(x)[:-6] for x in sub_ids]),
|
||||
|
@ -685,9 +679,9 @@ class account_analytic_account_summary_month(osv.osv):
|
|||
raise except_orm(_('AccessError'),
|
||||
_('You try to bypass an access rule (Document type: %s).') % self._description)
|
||||
else:
|
||||
cr.execute('select %s from \"%s\" where id IN (%s) ' \
|
||||
'and account_id IN (%s) ' \
|
||||
'and month_id IN (%s) order by %s' % \
|
||||
cr.execute('SELECT %s FROM \"%s\" WHERE id IN (%s) ' \
|
||||
'AND account_id IN (%s) ' \
|
||||
'AND month_id IN (%s) ORDER BY %s' % \
|
||||
(','.join(fields_pre2 + ['id']), self._table,
|
||||
','.join([str(x) for x in sub_ids]),
|
||||
','.join([str(x)[:-6] for x in sub_ids]),
|
||||
|
@ -697,7 +691,6 @@ class account_analytic_account_summary_month(osv.osv):
|
|||
else:
|
||||
res = map(lambda x: {'id': x}, ids)
|
||||
|
||||
res_trans_obj = self.pool.get('ir.translation')
|
||||
for f in fields_pre:
|
||||
if self._columns[f].translate:
|
||||
ids = map(lambda x: x['id'], res)
|
||||
|
@ -739,10 +732,8 @@ class account_analytic_account_summary_month(osv.osv):
|
|||
res2 = self._columns[f].get(cr, self, ids, f, user, context=context, values=res)
|
||||
for record in res:
|
||||
record[f] = res2[record['id']]
|
||||
|
||||
return res
|
||||
|
||||
account_analytic_account_summary_month()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -21,13 +21,13 @@
|
|||
|
||||
import time
|
||||
|
||||
from osv import fields,osv
|
||||
from osv import fields, osv
|
||||
|
||||
class account_analytic_default(osv.osv):
|
||||
_name = 'account.analytic.default'
|
||||
_description = 'Analytic Distribution'
|
||||
_rec_name = 'analytic_id'
|
||||
_order = 'sequence'
|
||||
_name = "account.analytic.default"
|
||||
_description = "Analytic Distribution"
|
||||
_rec_name = "analytic_id"
|
||||
_order = "sequence"
|
||||
_columns = {
|
||||
'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of analytic distribution."),
|
||||
'analytic_id': fields.many2one('account.analytic.account', 'Analytic Account'),
|
||||
|
@ -38,50 +38,50 @@ class account_analytic_default(osv.osv):
|
|||
'date_start': fields.date('Start Date'),
|
||||
'date_stop': fields.date('End Date'),
|
||||
}
|
||||
|
||||
|
||||
def account_get(self, cr, uid, product_id=None, partner_id=None, user_id=None, date=None, context=None):
|
||||
domain = []
|
||||
if product_id:
|
||||
domain += ['|',('product_id','=',product_id)]
|
||||
domain += [('product_id','=',False)]
|
||||
domain += ['|', ('product_id', '=', product_id)]
|
||||
domain += [('product_id','=', False)]
|
||||
if partner_id:
|
||||
domain += ['|',('partner_id','=',partner_id)]
|
||||
domain += [('partner_id','=',False)]
|
||||
domain += ['|', ('partner_id', '=', partner_id)]
|
||||
domain += [('partner_id', '=', False)]
|
||||
if user_id:
|
||||
domain += ['|',('user_id','=',user_id)]
|
||||
domain += [('user_id','=',False)]
|
||||
domain += ['|',('user_id', '=', user_id)]
|
||||
domain += [('user_id','=', False)]
|
||||
if date:
|
||||
domain += ['|',('date_start','<=',date),('date_start','=',False)]
|
||||
domain += ['|',('date_stop','>=',date),('date_stop','=',False)]
|
||||
domain += ['|', ('date_start', '<=', date), ('date_start', '=', False)]
|
||||
domain += ['|', ('date_stop', '>=', date), ('date_stop', '=', False)]
|
||||
best_index = -1
|
||||
res = False
|
||||
for rec in self.browse(cr, uid, self.search(cr, uid, domain, context=context), context=context):
|
||||
index = 0
|
||||
if rec.product_id: index+=1
|
||||
if rec.partner_id: index+=1
|
||||
if rec.user_id: index+=1
|
||||
if rec.date_start: index+=1
|
||||
if rec.date_stop: index+=1
|
||||
if index>best_index:
|
||||
if rec.product_id: index += 1
|
||||
if rec.partner_id: index += 1
|
||||
if rec.user_id: index += 1
|
||||
if rec.date_start: index += 1
|
||||
if rec.date_stop: index += 1
|
||||
if index > best_index:
|
||||
res = rec
|
||||
best_index = index
|
||||
return res
|
||||
|
||||
|
||||
account_analytic_default()
|
||||
|
||||
class account_invoice_line(osv.osv):
|
||||
_inherit = 'account.invoice.line'
|
||||
_description = 'Invoice Line'
|
||||
_inherit = "account.invoice.line"
|
||||
_description = "Invoice Line"
|
||||
|
||||
def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, address_invoice_id=False, currency_id=False, context=None):
|
||||
res_prod = super(account_invoice_line,self).product_id_change(cr, uid, ids, product, uom, qty, name, type, partner_id, fposition_id, price_unit, address_invoice_id, currency_id=currency_id, context=context)
|
||||
rec = self.pool.get('account.analytic.default').account_get(cr, uid, product, partner_id, uid, time.strftime('%Y-%m-%d'), context)
|
||||
res_prod = super(account_invoice_line, self).product_id_change(cr, uid, ids, product, uom, qty, name, type, partner_id, fposition_id, price_unit, address_invoice_id, currency_id=currency_id, context=context)
|
||||
rec = self.pool.get('account.analytic.default').account_get(cr, uid, product, partner_id, uid, time.strftime('%Y-%m-%d'), context=context)
|
||||
if rec:
|
||||
res_prod['value'].update({'account_analytic_id':rec.analytic_id.id})
|
||||
res_prod['value'].update({'account_analytic_id': rec.analytic_id.id})
|
||||
else:
|
||||
res_prod['value'].update({'account_analytic_id':False})
|
||||
res_prod['value'].update({'account_analytic_id': False})
|
||||
return res_prod
|
||||
|
||||
|
||||
account_invoice_line()
|
||||
|
||||
|
||||
|
@ -95,28 +95,27 @@ class stock_picking(osv.osv):
|
|||
if rec:
|
||||
return rec.analytic_id.id
|
||||
|
||||
return super(stock_picking, self)._get_account_analytic_invoice(cursor,
|
||||
user, picking, move_line)
|
||||
return super(stock_picking, self)._get_account_analytic_invoice(cursor, user, picking, move_line)
|
||||
|
||||
stock_picking()
|
||||
|
||||
class sale_order_line(osv.osv):
|
||||
_inherit = 'sale.order.line'
|
||||
_inherit = "sale.order.line"
|
||||
|
||||
# Method overridden to set the analytic account by default on criterion match
|
||||
def invoice_line_create(self, cr, uid, ids, context=None):
|
||||
create_ids = super(sale_order_line,self).invoice_line_create(cr, uid, ids, context)
|
||||
create_ids = super(sale_order_line, self).invoice_line_create(cr, uid, ids, context=context)
|
||||
if not ids:
|
||||
return create_ids
|
||||
sale_line = self.browse(cr, uid, ids[0], context)
|
||||
sale_line = self.browse(cr, uid, ids[0], context=context)
|
||||
inv_line_obj = self.pool.get('account.invoice.line')
|
||||
anal_def_obj = self.pool.get('account.analytic.default')
|
||||
|
||||
for line in inv_line_obj.browse(cr, uid, create_ids, context):
|
||||
rec = anal_def_obj.account_get(cr, uid, line.product_id.id, sale_line.order_id.partner_id.id, sale_line.order_id.user_id.id, time.strftime('%Y-%m-%d'), context)
|
||||
for line in inv_line_obj.browse(cr, uid, create_ids, context=context):
|
||||
rec = anal_def_obj.account_get(cr, uid, line.product_id.id, sale_line.order_id.partner_id.id, sale_line.order_id.user_id.id, time.strftime('%Y-%m-%d'), context=context)
|
||||
|
||||
if rec:
|
||||
inv_line_obj.write(cr, uid, [line.id], {'account_analytic_id':rec.analytic_id.id}, context=context)
|
||||
inv_line_obj.write(cr, uid, [line.id], {'account_analytic_id': rec.analytic_id.id}, context=context)
|
||||
return create_ids
|
||||
|
||||
sale_order_line()
|
||||
|
|
|
@ -18,8 +18,9 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from lxml import etree
|
||||
|
||||
import time
|
||||
from lxml import etree
|
||||
|
||||
from osv import fields, osv
|
||||
import tools
|
||||
|
@ -34,10 +35,10 @@ class one2many_mod2(fields.one2many):
|
|||
res[id] = []
|
||||
ids2 = None
|
||||
if 'journal_id' in context:
|
||||
journal = obj.pool.get('account.journal').browse(cr, user, context['journal_id'], context)
|
||||
journal = obj.pool.get('account.journal').browse(cr, user, context['journal_id'], context=context)
|
||||
pnum = int(name[7]) -1
|
||||
plan = journal.plan_id
|
||||
if plan and len(plan.plan_ids)>pnum:
|
||||
if plan and len(plan.plan_ids) > pnum:
|
||||
acc_id = plan.plan_ids[pnum].root_analytic_id.id
|
||||
ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id,'in',ids),('analytic_account_id','child_of',[acc_id])], limit=self._limit)
|
||||
if ids2 is None:
|
||||
|
@ -50,8 +51,8 @@ class account_analytic_plan(osv.osv):
|
|||
_name = "account.analytic.plan"
|
||||
_description = "Analytic Plan"
|
||||
_columns = {
|
||||
'name': fields.char('Analytic Plan', size=64, required=True, select=True,),
|
||||
'plan_ids': fields.one2many('account.analytic.plan.line','plan_id','Analytic Plans'),
|
||||
'name': fields.char('Analytic Plan', size=64, required=True, select=True),
|
||||
'plan_ids': fields.one2many('account.analytic.plan.line', 'plan_id', 'Analytic Plans'),
|
||||
}
|
||||
|
||||
account_analytic_plan()
|
||||
|
@ -61,10 +62,10 @@ class account_analytic_plan_line(osv.osv):
|
|||
_description = "Analytic Plan Line"
|
||||
_order = "sequence, id"
|
||||
_columns = {
|
||||
'plan_id':fields.many2one('account.analytic.plan','Analytic Plan'),
|
||||
'plan_id': fields.many2one('account.analytic.plan','Analytic Plan'),
|
||||
'name': fields.char('Plan Name', size=64, required=True, select=True),
|
||||
'sequence':fields.integer('Sequence'),
|
||||
'root_analytic_id': fields.many2one('account.analytic.account','Root Account',help="Root account of this plan.",required=False),
|
||||
'sequence': fields.integer('Sequence'),
|
||||
'root_analytic_id': fields.many2one('account.analytic.account', 'Root Account', help="Root account of this plan.", required=False),
|
||||
'min_required': fields.float('Minimum Allowed (%)'),
|
||||
'max_required': fields.float('Maximum Allowed (%)'),
|
||||
}
|
||||
|
@ -76,27 +77,28 @@ class account_analytic_plan_line(osv.osv):
|
|||
account_analytic_plan_line()
|
||||
|
||||
class account_analytic_plan_instance(osv.osv):
|
||||
_name = 'account.analytic.plan.instance'
|
||||
_description = 'Analytic Plan Instance'
|
||||
_name = "account.analytic.plan.instance"
|
||||
_description = "Analytic Plan Instance"
|
||||
_columns = {
|
||||
'name':fields.char('Analytic Distribution', size=64),
|
||||
'code':fields.char('Distribution Code', size=16),
|
||||
'name': fields.char('Analytic Distribution', size=64),
|
||||
'code': fields.char('Distribution Code', size=16),
|
||||
'journal_id': fields.many2one('account.analytic.journal', 'Analytic Journal' ),
|
||||
'account_ids':fields.one2many('account.analytic.plan.instance.line', 'plan_id', 'Account Id'),
|
||||
'account1_ids':one2many_mod2('account.analytic.plan.instance.line', 'plan_id', 'Account1 Id'),
|
||||
'account2_ids':one2many_mod2('account.analytic.plan.instance.line', 'plan_id', 'Account2 Id'),
|
||||
'account3_ids':one2many_mod2('account.analytic.plan.instance.line', 'plan_id', 'Account3 Id'),
|
||||
'account4_ids':one2many_mod2('account.analytic.plan.instance.line', 'plan_id', 'Account4 Id'),
|
||||
'account5_ids':one2many_mod2('account.analytic.plan.instance.line', 'plan_id', 'Account5 Id'),
|
||||
'account6_ids':one2many_mod2('account.analytic.plan.instance.line', 'plan_id', 'Account6 Id'),
|
||||
'plan_id':fields.many2one('account.analytic.plan', "Model's Plan"),
|
||||
'account_ids': fields.one2many('account.analytic.plan.instance.line', 'plan_id', 'Account Id'),
|
||||
'account1_ids': one2many_mod2('account.analytic.plan.instance.line', 'plan_id', 'Account1 Id'),
|
||||
'account2_ids': one2many_mod2('account.analytic.plan.instance.line', 'plan_id', 'Account2 Id'),
|
||||
'account3_ids': one2many_mod2('account.analytic.plan.instance.line', 'plan_id', 'Account3 Id'),
|
||||
'account4_ids': one2many_mod2('account.analytic.plan.instance.line', 'plan_id', 'Account4 Id'),
|
||||
'account5_ids': one2many_mod2('account.analytic.plan.instance.line', 'plan_id', 'Account5 Id'),
|
||||
'account6_ids': one2many_mod2('account.analytic.plan.instance.line', 'plan_id', 'Account6 Id'),
|
||||
'plan_id': fields.many2one('account.analytic.plan', "Model's Plan"),
|
||||
}
|
||||
|
||||
def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False):
|
||||
if context is None:
|
||||
context = {}
|
||||
journal_obj = self.pool.get('account.journal')
|
||||
if context.get('journal_id', False):
|
||||
journal = self.pool.get('account.journal').browse(cr, user, [context['journal_id']], context=context)[0]
|
||||
journal = journal_obj.browse(cr, user, [context['journal_id']], context=context)[0]
|
||||
analytic_journal = journal.analytic_journal_id and journal.analytic_journal_id.id or False
|
||||
args.append('|')
|
||||
args.append(('journal_id', '=', analytic_journal))
|
||||
|
@ -108,15 +110,16 @@ class account_analytic_plan_instance(osv.osv):
|
|||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
if not default:
|
||||
default = {}
|
||||
default.update({'account1_ids':False, 'account2_ids':False, 'account3_ids':False,
|
||||
default.update({'account1_ids':False, 'account2_ids':False, 'account3_ids':False,
|
||||
'account4_ids':False, 'account5_ids':False, 'account6_ids':False})
|
||||
return super(account_analytic_plan_instance, self).copy(cr, uid, id, default, context)
|
||||
return super(account_analytic_plan_instance, self).copy(cr, uid, id, default, context=context)
|
||||
|
||||
def _default_journal(self, cr, uid, context=None):
|
||||
if not context:
|
||||
context = {}
|
||||
journal_obj = self.pool.get('account.journal')
|
||||
if context.has_key('journal_id') and context['journal_id']:
|
||||
journal = self.pool.get('account.journal').browse(cr, uid, context['journal_id'])
|
||||
journal = journal_obj.browse(cr, uid, context['journal_id'], context=context)
|
||||
if journal.analytic_journal_id:
|
||||
return journal.analytic_journal_id.id
|
||||
return False
|
||||
|
@ -127,7 +130,7 @@ class account_analytic_plan_instance(osv.osv):
|
|||
}
|
||||
def name_get(self, cr, uid, ids, context=None):
|
||||
res = []
|
||||
for inst in self.browse(cr, uid, ids, context):
|
||||
for inst in self.browse(cr, uid, ids, context=context):
|
||||
name = inst.name or '/'
|
||||
if name and inst.code:
|
||||
name=name+' ('+inst.code+')'
|
||||
|
@ -135,7 +138,7 @@ class account_analytic_plan_instance(osv.osv):
|
|||
return res
|
||||
|
||||
def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
|
||||
args= args or []
|
||||
args = args or []
|
||||
if name:
|
||||
ids = self.search(cr, uid, [('code', '=', name)] + args, limit=limit, context=context or {})
|
||||
if not ids:
|
||||
|
@ -145,15 +148,16 @@ class account_analytic_plan_instance(osv.osv):
|
|||
return self.name_get(cr, uid, ids, context or {})
|
||||
|
||||
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
|
||||
wiz_id = self.pool.get('ir.actions.act_window').search(cr, uid, [("name","=","analytic.plan.create.model.action")])
|
||||
wiz_id = self.pool.get('ir.actions.act_window').search(cr, uid, [("name","=","analytic.plan.create.model.action")], context=context)
|
||||
res = super(account_analytic_plan_instance,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
|
||||
|
||||
journal_obj = self.pool.get('account.journal')
|
||||
analytic_plan_obj = self.pool.get('account.analytic.plan')
|
||||
if (res['type']=='form'):
|
||||
plan_id = False
|
||||
if context.get('journal_id',False):
|
||||
plan_id = self.pool.get('account.journal').browse(cr, uid, int(context['journal_id']), context).plan_id
|
||||
elif context.get('plan_id',False):
|
||||
plan_id = self.pool.get('account.analytic.plan').browse(cr, uid, int(context['plan_id']), context)
|
||||
if context.get('journal_id', False):
|
||||
plan_id = journal_obj.browse(cr, uid, int(context['journal_id']), context=context).plan_id
|
||||
elif context.get('plan_id', False):
|
||||
plan_id = analytic_plan_obj.browse(cr, uid, int(context['plan_id']), context=context)
|
||||
|
||||
if plan_id:
|
||||
i=1
|
||||
|
@ -183,40 +187,43 @@ class account_analytic_plan_instance(osv.osv):
|
|||
return res
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
journal_obj = self.pool.get('account.journal')
|
||||
ana_plan_instance_obj = self.pool.get('account.analytic.plan.instance')
|
||||
acct_anal_acct = self.pool.get('account.analytic.account')
|
||||
acct_anal_plan_line_obj = self.pool.get('account.analytic.plan.line')
|
||||
if context and 'journal_id' in context:
|
||||
journal= self.pool.get('account.journal').browse(cr, uid, context['journal_id'])
|
||||
journal = journal_obj.browse(cr, uid, context['journal_id'], context=context)
|
||||
|
||||
pids = self.pool.get('account.analytic.plan.instance').search(cr, uid, [('name','=',vals['name']),('code','=',vals['code']),('plan_id','<>',False)])
|
||||
pids = ana_plan_instance_obj.search(cr, uid, [('name','=',vals['name']), ('code','=',vals['code']), ('plan_id','<>',False)], context=context)
|
||||
if pids:
|
||||
raise osv.except_osv(_('Error'), _('A model having this name and code already exists !'))
|
||||
|
||||
acct_anal_acct = self.pool.get('account.analytic.account')
|
||||
acct_anal_plan_line_obj = self.pool.get('account.analytic.plan.line')
|
||||
res = acct_anal_plan_line_obj.search(cr, uid, [('plan_id','=',journal.plan_id.id)])
|
||||
res = acct_anal_plan_line_obj.search(cr, uid, [('plan_id','=',journal.plan_id.id)], context=context)
|
||||
for i in res:
|
||||
total_per_plan = 0
|
||||
item = acct_anal_plan_line_obj.browse(cr, uid, i)
|
||||
temp_list=['account1_ids','account2_ids','account3_ids','account4_ids','account5_ids','account6_ids']
|
||||
item = acct_anal_plan_line_obj.browse(cr, uid, i, context=context)
|
||||
temp_list = ['account1_ids','account2_ids','account3_ids','account4_ids','account5_ids','account6_ids']
|
||||
for l in temp_list:
|
||||
if vals.has_key(l):
|
||||
for tempo in vals[l]:
|
||||
if acct_anal_acct.search(cr, uid,[('parent_id','child_of',[item.root_analytic_id.id]),('id','=',tempo[2]['analytic_account_id'])]):
|
||||
if acct_anal_acct.search(cr, uid, [('parent_id', 'child_of', [item.root_analytic_id.id]), ('id', '=', tempo[2]['analytic_account_id'])], context=context):
|
||||
total_per_plan += tempo[2]['rate']
|
||||
if total_per_plan < item.min_required or total_per_plan > item.max_required:
|
||||
raise osv.except_osv(_('Value Error'),_('The Total Should be Between %s and %s') % (str(item.min_required), str(item.max_required)))
|
||||
|
||||
return super(account_analytic_plan_instance, self).create(cr, uid, vals, context)
|
||||
return super(account_analytic_plan_instance, self).create(cr, uid, vals, context=context)
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
|
||||
this = self.browse(cr, uid, ids[0])
|
||||
this = self.browse(cr, uid, ids[0], context=context)
|
||||
invoice_line_obj = self.pool.get('account.invoice.line')
|
||||
if this.plan_id and not vals.has_key('plan_id'):
|
||||
#this instance is a model, so we have to create a new plan instance instead of modifying it
|
||||
#copy the existing model
|
||||
temp_id = self.copy(cr, uid, this.id, None, context)
|
||||
temp_id = self.copy(cr, uid, this.id, None, context=context)
|
||||
#get the list of the invoice line that were linked to the model
|
||||
list = self.pool.get('account.invoice.line').search(cr, uid, [('analytics_id','=',this.id)])
|
||||
lists = invoice_line_obj.search(cr, uid, [('analytics_id','=',this.id)], context=context)
|
||||
#make them link to the copy
|
||||
self.pool.get('account.invoice.line').write(cr, uid, list, {'analytics_id':temp_id}, context)
|
||||
invoice_line_obj.write(cr, uid, lists, {'analytics_id':temp_id}, context=context)
|
||||
|
||||
#and finally modify the old model to be not a model anymore
|
||||
vals['plan_id'] = False
|
||||
|
@ -224,17 +231,17 @@ class account_analytic_plan_instance(osv.osv):
|
|||
vals['name'] = this.name and (str(this.name)+'*') or "*"
|
||||
if not vals.has_key('code'):
|
||||
vals['code'] = this.code and (str(this.code)+'*') or "*"
|
||||
return super(account_analytic_plan_instance, self).write(cr, uid, ids, vals, context)
|
||||
return super(account_analytic_plan_instance, self).write(cr, uid, ids, vals, context=context)
|
||||
|
||||
account_analytic_plan_instance()
|
||||
|
||||
class account_analytic_plan_instance_line(osv.osv):
|
||||
_name='account.analytic.plan.instance.line'
|
||||
_description = 'Analytic Instance Line'
|
||||
_columns={
|
||||
'plan_id':fields.many2one('account.analytic.plan.instance', 'Plan Id'),
|
||||
'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account', required=True),
|
||||
'rate':fields.float('Rate (%)', required=True),
|
||||
_name = "account.analytic.plan.instance.line"
|
||||
_description = "Analytic Instance Line"
|
||||
_columns = {
|
||||
'plan_id': fields.many2one('account.analytic.plan.instance', 'Plan Id'),
|
||||
'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account', required=True),
|
||||
'rate': fields.float('Rate (%)', required=True),
|
||||
}
|
||||
_defaults = {
|
||||
'rate': 100.0
|
||||
|
@ -242,7 +249,7 @@ class account_analytic_plan_instance_line(osv.osv):
|
|||
def name_get(self, cr, uid, ids, context=None):
|
||||
if not ids:
|
||||
return []
|
||||
reads = self.read(cr, uid, ids, ['analytic_account_id'], context)
|
||||
reads = self.read(cr, uid, ids, ['analytic_account_id'], context=context)
|
||||
res = []
|
||||
for record in reads:
|
||||
res.append((record['id'], record['analytic_account_id']))
|
||||
|
@ -251,44 +258,44 @@ class account_analytic_plan_instance_line(osv.osv):
|
|||
account_analytic_plan_instance_line()
|
||||
|
||||
class account_journal(osv.osv):
|
||||
_inherit='account.journal'
|
||||
_name='account.journal'
|
||||
_inherit = "account.journal"
|
||||
_name = "account.journal"
|
||||
_columns = {
|
||||
'plan_id':fields.many2one('account.analytic.plan', 'Analytic Plans'),
|
||||
'plan_id': fields.many2one('account.analytic.plan', 'Analytic Plans'),
|
||||
}
|
||||
|
||||
account_journal()
|
||||
|
||||
class account_invoice_line(osv.osv):
|
||||
_inherit='account.invoice.line'
|
||||
_name='account.invoice.line'
|
||||
_inherit = "account.invoice.line"
|
||||
_name = "account.invoice.line"
|
||||
_columns = {
|
||||
'analytics_id':fields.many2one('account.analytic.plan.instance', 'Analytic Distribution'),
|
||||
'analytics_id': fields.many2one('account.analytic.plan.instance', 'Analytic Distribution'),
|
||||
}
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
if 'analytics_id' in vals and isinstance(vals['analytics_id'],tuple):
|
||||
if 'analytics_id' in vals and isinstance(vals['analytics_id'], tuple):
|
||||
vals['analytics_id'] = vals['analytics_id'][0]
|
||||
return super(account_invoice_line, self).create(cr, uid, vals, context)
|
||||
return super(account_invoice_line, self).create(cr, uid, vals, context=context)
|
||||
|
||||
def move_line_get_item(self, cr, uid, line, context=None):
|
||||
res= super(account_invoice_line,self).move_line_get_item(cr, uid, line, context={})
|
||||
res ['analytics_id']=line.analytics_id and line.analytics_id.id or False
|
||||
res = super(account_invoice_line, self).move_line_get_item(cr, uid, line, context=context)
|
||||
res ['analytics_id'] = line.analytics_id and line.analytics_id.id or False
|
||||
return res
|
||||
|
||||
def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, address_invoice_id=False, currency_id=False, context=None):
|
||||
res_prod = super(account_invoice_line,self).product_id_change(cr, uid, ids, product, uom, qty, name, type, partner_id, fposition_id, price_unit, address_invoice_id, currency_id, context=context)
|
||||
rec = self.pool.get('account.analytic.default').account_get(cr, uid, product, partner_id, uid, time.strftime('%Y-%m-%d'), context)
|
||||
res_prod = super(account_invoice_line, self).product_id_change(cr, uid, ids, product, uom, qty, name, type, partner_id, fposition_id, price_unit, address_invoice_id, currency_id, context=context)
|
||||
rec = self.pool.get('account.analytic.default').account_get(cr, uid, product, partner_id, uid, time.strftime('%Y-%m-%d'), context=context)
|
||||
if rec and rec.analytics_id:
|
||||
res_prod['value'].update({'analytics_id':rec.analytics_id.id})
|
||||
res_prod['value'].update({'analytics_id': rec.analytics_id.id})
|
||||
return res_prod
|
||||
|
||||
account_invoice_line()
|
||||
|
||||
class account_move_line(osv.osv):
|
||||
|
||||
_inherit='account.move.line'
|
||||
_name='account.move.line'
|
||||
_inherit = "account.move.line"
|
||||
_name = "account.move.line"
|
||||
_columns = {
|
||||
'analytics_id':fields.many2one('account.analytic.plan.instance', 'Analytic Distribution'),
|
||||
}
|
||||
|
@ -300,9 +307,9 @@ class account_move_line(osv.osv):
|
|||
return data
|
||||
|
||||
def create_analytic_lines(self, cr, uid, ids, context=None):
|
||||
super(account_move_line, self).create_analytic_lines(cr, uid, ids, context)
|
||||
super(account_move_line, self).create_analytic_lines(cr, uid, ids, context=context)
|
||||
analytic_line_obj = self.pool.get('account.analytic.line')
|
||||
for line in self.browse(cr, uid, ids, context):
|
||||
for line in self.browse(cr, uid, ids, context=context):
|
||||
if line.analytics_id:
|
||||
if not line.journal_id.analytic_journal_id:
|
||||
raise osv.except_osv(_('No Analytic Journal !'),_("You have to define an analytic journal on the '%s' journal!") % (line.journal_id.name,))
|
||||
|
@ -333,24 +340,25 @@ account_move_line()
|
|||
|
||||
class account_invoice(osv.osv):
|
||||
_name = "account.invoice"
|
||||
_inherit="account.invoice"
|
||||
_inherit = "account.invoice"
|
||||
|
||||
def line_get_convert(self, cr, uid, x, part, date, context=None):
|
||||
res=super(account_invoice,self).line_get_convert(cr, uid, x, part, date, context)
|
||||
res['analytics_id']=x.get('analytics_id',False)
|
||||
res=super(account_invoice,self).line_get_convert(cr, uid, x, part, date, context=context)
|
||||
res['analytics_id'] = x.get('analytics_id', False)
|
||||
return res
|
||||
|
||||
def _get_analytic_lines(self, cr, uid, id):
|
||||
inv = self.browse(cr, uid, [id])[0]
|
||||
cur_obj = self.pool.get('res.currency')
|
||||
invoice_line_obj = self.pool.get('account.invoice.line')
|
||||
acct_ins_obj = self.pool.get('account.analytic.plan.instance')
|
||||
company_currency = inv.company_id.currency_id.id
|
||||
if inv.type in ('out_invoice', 'in_refund'):
|
||||
sign = 1
|
||||
else:
|
||||
sign = -1
|
||||
|
||||
iml = self.pool.get('account.invoice.line').move_line_get(cr, uid, inv.id)
|
||||
acct_ins_obj = self.pool.get('account.analytic.plan.instance')
|
||||
iml = invoice_line_obj.move_line_get(cr, uid, inv.id)
|
||||
|
||||
for il in iml:
|
||||
if il.get('analytics_id', False):
|
||||
|
@ -369,8 +377,8 @@ class account_invoice(osv.osv):
|
|||
al_vals = {
|
||||
'name': il['name'],
|
||||
'date': inv['date_invoice'],
|
||||
'unit_amount':qtty,
|
||||
'product_id':il['product_id'],
|
||||
'unit_amount': qtty,
|
||||
'product_id': il['product_id'],
|
||||
'account_id': line2.analytic_account_id.id,
|
||||
'amount': amt,
|
||||
'product_uom_id': il['uos_id'],
|
||||
|
@ -378,7 +386,7 @@ class account_invoice(osv.osv):
|
|||
'journal_id': self._get_journal_analytic(cr, uid, inv.type),
|
||||
'ref': ref,
|
||||
}
|
||||
il['analytic_lines'].append((0,0,al_vals))
|
||||
il['analytic_lines'].append((0, 0, al_vals))
|
||||
return iml
|
||||
|
||||
account_invoice()
|
||||
|
@ -391,7 +399,7 @@ class account_analytic_plan(osv.osv):
|
|||
account_analytic_plan()
|
||||
|
||||
class analytic_default(osv.osv):
|
||||
_inherit = 'account.analytic.default'
|
||||
_inherit = "account.analytic.default"
|
||||
_columns = {
|
||||
'analytics_id': fields.many2one('account.analytic.plan.instance', 'Analytic Distribution'),
|
||||
}
|
||||
|
@ -399,21 +407,20 @@ class analytic_default(osv.osv):
|
|||
analytic_default()
|
||||
|
||||
class sale_order_line(osv.osv):
|
||||
_inherit = 'sale.order.line'
|
||||
_inherit = "sale.order.line"
|
||||
|
||||
# Method overridden to set the analytic account by default on criterion match
|
||||
def invoice_line_create(self, cr, uid, ids, context=None):
|
||||
create_ids = super(sale_order_line,self).invoice_line_create(cr, uid, ids, context)
|
||||
create_ids = super(sale_order_line,self).invoice_line_create(cr, uid, ids, context=context)
|
||||
inv_line_obj = self.pool.get('account.invoice.line')
|
||||
acct_anal_def_obj = self.pool.get('account.analytic.default')
|
||||
if ids:
|
||||
sale_line = self.browse(cr, uid, ids[0], context)
|
||||
inv_line_obj = self.pool.get('account.invoice.line')
|
||||
acct_anal_def_obj = self.pool.get('account.analytic.default')
|
||||
|
||||
for line in inv_line_obj.browse(cr, uid, create_ids, context):
|
||||
sale_line = self.browse(cr, uid, ids[0], context=context)
|
||||
for line in inv_line_obj.browse(cr, uid, create_ids, context=context):
|
||||
rec = acct_anal_def_obj.account_get(cr, uid, line.product_id.id, sale_line.order_id.partner_id.id, uid, time.strftime('%Y-%m-%d'), context)
|
||||
|
||||
if rec:
|
||||
inv_line_obj.write(cr, uid, [line.id], {'analytics_id':rec.analytics_id.id}, context=context)
|
||||
inv_line_obj.write(cr, uid, [line.id], {'analytics_id': rec.analytics_id.id}, context=context)
|
||||
return create_ids
|
||||
|
||||
sale_order_line()
|
||||
|
|
|
@ -39,11 +39,12 @@ class crossovered_analytic(report_sxw.rml_parse):
|
|||
final_list = []
|
||||
parent_list = []
|
||||
set_list = []
|
||||
analytic_obj = self.pool.get('account.analytic.account')
|
||||
for id in ref_ids:
|
||||
# to avoid duplicate entries
|
||||
if id not in to_return_ids:
|
||||
to_return_ids.append(self.pool.get('account.analytic.account').search(self.cr,self.uid,[('parent_id','child_of',[id])]))
|
||||
data_accnt = self.pool.get('account.analytic.account').browse(self.cr,self.uid,to_return_ids[0])
|
||||
to_return_ids.append(analytic_obj.search(self.cr,self.uid,[('parent_id','child_of',[id])]))
|
||||
data_accnt = analytic_obj.browse(self.cr,self.uid,to_return_ids[0])
|
||||
for data in data_accnt:
|
||||
if data.parent_id and data.parent_id.id == ref_ids[0]:
|
||||
parent_list.append(data.id)
|
||||
|
@ -54,7 +55,7 @@ class crossovered_analytic(report_sxw.rml_parse):
|
|||
|
||||
def set_account(self,cats):
|
||||
lst = []
|
||||
category = self.pool.get('account.analytic.account').read(self.cr,self.uid,cats)
|
||||
category = self.pool.get('account.analytic.account').read(self.cr, self.uid, cats)
|
||||
for cat in category:
|
||||
lst.append(cat['id'])
|
||||
if cat['child_ids']:
|
||||
|
@ -75,44 +76,44 @@ class crossovered_analytic(report_sxw.rml_parse):
|
|||
else:
|
||||
journal = 'is not null'
|
||||
|
||||
query_general = "select id from account_analytic_line where (journal_id " + journal +") AND date>='"+ str(form['date1']) +"'"" AND date<='" + str(form['date2']) + "'"
|
||||
query_general = "SELECT id FROM account_analytic_line WHERE (journal_id " + journal +") AND date>='"+ str(form['date1']) +"'"" AND date<='" + str(form['date2']) + "'"
|
||||
|
||||
self.cr.execute(query_general)
|
||||
l_ids=self.cr.fetchall()
|
||||
l_ids = self.cr.fetchall()
|
||||
line_ids = [x[0] for x in l_ids]
|
||||
|
||||
obj_line = line_pool.browse(self.cr,self.uid,line_ids)
|
||||
|
||||
#this structure will be usefull for easily knowing the account_analytic_line that are related to the reference account. At this purpose, we save the move_id of analytic lines.
|
||||
self.dict_acc_ref[form['ref']] = []
|
||||
children_list = self.pool.get('account.analytic.account').search(self.cr,self.uid,[('parent_id','child_of',[form['ref']])])
|
||||
children_list = acc_pool.search(self.cr, self.uid, [('parent_id', 'child_of', [form['ref']])])
|
||||
for obj in obj_line:
|
||||
if obj.account_id.id in children_list:
|
||||
if obj.move_id and obj.move_id.id not in self.dict_acc_ref[form['ref']]:
|
||||
self.dict_acc_ref[form['ref']].append(obj.move_id.id)
|
||||
|
||||
res['ref_name'] = acc_pool.name_get(self.cr,self.uid,[form['ref']])[0][1]
|
||||
res['ref_code'] = acc_pool.browse(self.cr,self.uid,form['ref']).code
|
||||
res['ref_name'] = acc_pool.name_get(self.cr, self.uid, [form['ref']])[0][1]
|
||||
res['ref_code'] = acc_pool.browse(self.cr, self.uid, form['ref']).code
|
||||
|
||||
self.final_list = children_list
|
||||
selected_ids = line_pool.search(self.cr,self.uid,[('account_id','in',self.final_list)])
|
||||
selected_ids = line_pool.search(self.cr, self.uid, [('account_id', 'in' ,self.final_list)])
|
||||
if selected_ids:
|
||||
query="SELECT sum(aal.amount) AS amt, sum(aal.unit_amount) AS qty FROM account_analytic_line AS aal, account_analytic_account AS aaa \
|
||||
WHERE aal.account_id=aaa.id AND aal.id IN ("+','.join(map(str,selected_ids))+") AND (aal.journal_id " + journal +") AND aal.date>='"+ str(form['date1']) +"'"" AND aal.date<='" + str(form['date2']) + "'"
|
||||
query = "SELECT SUM(aal.amount) AS amt, SUM(aal.unit_amount) AS qty FROM account_analytic_line AS aal, account_analytic_account AS aaa \
|
||||
WHERE aal.account_id = aaa.id AND aal.id IN ("+','.join(map(str,selected_ids))+") AND (aal.journal_id " + journal +") AND aal.date>='"+ str(form['date1']) +"'"" AND aal.date<='" + str(form['date2']) + "'"
|
||||
|
||||
self.cr.execute(query)
|
||||
info=self.cr.dictfetchall()
|
||||
|
||||
res['ref_qty']=info[0]['qty']
|
||||
res['ref_amt']=info[0]['amt']
|
||||
self.base_amount= info[0]['amt']
|
||||
res['ref_qty']=0.0
|
||||
res['ref_amt']=0.0
|
||||
self.base_amount= 0.0
|
||||
res['ref_qty'] = info[0]['qty']
|
||||
res['ref_amt'] = info[0]['amt']
|
||||
self.base_amount = info[0]['amt']
|
||||
res['ref_qty'] = 0.0
|
||||
res['ref_amt'] = 0.0
|
||||
self.base_amount = 0.0
|
||||
result.append(res)
|
||||
return result
|
||||
|
||||
def _lines(self,form,ids={}):
|
||||
def _lines(self, form, ids={}):
|
||||
if not ids:
|
||||
ids = self.ids
|
||||
|
||||
|
@ -122,43 +123,43 @@ class crossovered_analytic(report_sxw.rml_parse):
|
|||
journal= 'is not null'
|
||||
|
||||
acc_pool = self.pool.get('account.analytic.account')
|
||||
line_pool=self.pool.get('account.analytic.line')
|
||||
acc_id=[]
|
||||
final=[]
|
||||
child_ids=[]
|
||||
self.list_ids=[]
|
||||
line_pool = self.pool.get('account.analytic.line')
|
||||
acc_id = []
|
||||
final = []
|
||||
child_ids = []
|
||||
self.list_ids = []
|
||||
|
||||
self.final_list = self.find_children(ids)
|
||||
|
||||
for acc_id in self.final_list:
|
||||
selected_ids = line_pool.search(self.cr,self.uid,[('account_id','=',acc_id),('move_id','in',self.dict_acc_ref[form['ref']])])
|
||||
selected_ids = line_pool.search(self.cr, self.uid, [('account_id','=',acc_id), ('move_id', 'in', self.dict_acc_ref[form['ref']])])
|
||||
if selected_ids:
|
||||
query="SELECT aaa.code as code, sum(aal.amount) AS amt, sum(aal.unit_amount) AS qty,aaa.name as acc_name,aal.account_id as id FROM account_analytic_line AS aal, account_analytic_account AS aaa \
|
||||
query="SELECT aaa.code AS code, SUM(aal.amount) AS amt, SUM(aal.unit_amount) AS qty, aaa.name AS acc_name, aal.account_id AS id FROM account_analytic_line AS aal, account_analytic_account AS aaa \
|
||||
WHERE aal.account_id=aaa.id AND aal.id IN ("+','.join(map(str,selected_ids))+") AND (aal.journal_id " + journal +") AND aal.date>='"+ str(form['date1']) +"'"" AND aal.date<='" + str(form['date2']) + "'"" GROUP BY aal.account_id,aaa.name,aaa.code ORDER BY aal.account_id"
|
||||
|
||||
self.cr.execute(query)
|
||||
res = self.cr.dictfetchall()
|
||||
if res:
|
||||
for element in res:
|
||||
if self.base_amount<>0.00:
|
||||
element['perc']= (element['amt'] / self.base_amount) * 100.00
|
||||
if self.base_amount <> 0.00:
|
||||
element['perc'] = (element['amt'] / self.base_amount) * 100.00
|
||||
else:
|
||||
element['perc']=0.00
|
||||
element['perc'] = 0.00
|
||||
else:
|
||||
result={}
|
||||
res=[]
|
||||
result['id']=acc_id
|
||||
data_account = acc_pool.browse(self.cr,self.uid,acc_id)
|
||||
result['acc_name']=data_account.name
|
||||
result = {}
|
||||
res = []
|
||||
result['id'] = acc_id
|
||||
data_account = acc_pool.browse(self.cr, self.uid, acc_id)
|
||||
result['acc_name'] = data_account.name
|
||||
result['code'] = data_account.code
|
||||
result['amt']=result['qty']=result['perc']=0.00
|
||||
result['amt'] = result['qty'] = result['perc'] = 0.00
|
||||
if not form['empty_line']:
|
||||
res.append(result)
|
||||
else:
|
||||
result = {}
|
||||
res = []
|
||||
result['id'] = acc_id
|
||||
data_account = acc_pool.browse(self.cr,self.uid,acc_id)
|
||||
data_account = acc_pool.browse(self.cr, self.uid, acc_id)
|
||||
result['acc_name'] = data_account.name
|
||||
result['code'] = data_account.code
|
||||
result['amt'] = result['qty'] = result['perc'] = 0.00
|
||||
|
|
|
@ -18,37 +18,38 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
|
||||
from osv import osv, fields
|
||||
from tools.translate import _
|
||||
|
||||
class account_crossovered_analytic(osv.osv_memory):
|
||||
_name = 'account.crossovered.analytic'
|
||||
_description = 'Print Crossovered Analytic'
|
||||
_name = "account.crossovered.analytic"
|
||||
_description = "Print Crossovered Analytic"
|
||||
_columns = {
|
||||
'date1': fields.date('Start Date', required=True),
|
||||
'date2': fields.date('End Date', required=True),
|
||||
'journal_ids': fields.many2many('account.analytic.journal', 'crossovered_journal_rel', 'crossover_id', 'journal_id', 'Analytic Journal'),
|
||||
'ref': fields.many2one('account.analytic.account', 'Analytic Account Reference', required=False),
|
||||
'empty_line': fields.boolean('Dont show empty lines'),
|
||||
}
|
||||
}
|
||||
_defaults = {
|
||||
'date1': lambda *a: time.strftime('%Y-01-01'),
|
||||
'date2': lambda *a: time.strftime('%Y-%m-%d'),
|
||||
}
|
||||
'date1': time.strftime('%Y-01-01'),
|
||||
'date2': time.strftime('%Y-%m-%d'),
|
||||
}
|
||||
|
||||
def print_report(self, cr, uid, ids, context=None):
|
||||
cr.execute('select account_id from account_analytic_line')
|
||||
cr.execute('SELECT account_id FROM account_analytic_line')
|
||||
res = cr.fetchall()
|
||||
acc_ids = [x[0] for x in res]
|
||||
|
||||
data = self.read(cr, uid, ids, [], context=context)[0]
|
||||
|
||||
obj_acc = self.pool.get('account.analytic.account').browse(cr, uid, data['ref'])
|
||||
obj_acc = self.pool.get('account.analytic.account').browse(cr, uid, data['ref'], context=context)
|
||||
name = obj_acc.name
|
||||
|
||||
account_ids = self.pool.get('account.analytic.account').search(cr, uid, [('parent_id', 'child_of', [data['ref']])])
|
||||
account_ids = self.pool.get('account.analytic.account').search(cr, uid, [('parent_id', 'child_of', [data['ref']])], context=context)
|
||||
|
||||
flag = True
|
||||
for acc in account_ids:
|
||||
|
@ -62,12 +63,12 @@ class account_crossovered_analytic(osv.osv_memory):
|
|||
'ids': [],
|
||||
'model': 'account.analytic.account',
|
||||
'form': data
|
||||
}
|
||||
}
|
||||
return {
|
||||
'type': 'ir.actions.report.xml',
|
||||
'report_name': 'account.analytic.account.crossovered.analytic',
|
||||
'datas': datas,
|
||||
}
|
||||
}
|
||||
|
||||
account_crossovered_analytic()
|
||||
|
||||
|
|
|
@ -18,24 +18,26 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import osv
|
||||
from tools.translate import _
|
||||
|
||||
class analytic_plan_create_model(osv.osv_memory):
|
||||
_name = 'analytic.plan.create.model'
|
||||
_description = 'analytic.plan.create.model'
|
||||
_name = "analytic.plan.create.model"
|
||||
_description = "analytic.plan.create.model"
|
||||
|
||||
def activate(self, cr, uid, ids, context=None):
|
||||
plan_obj = self.pool.get('account.analytic.plan.instance')
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
anlytic_plan_obj = self.pool.get('account.analytic.plan')
|
||||
if 'active_id' in context and context['active_id']:
|
||||
plan = plan_obj.browse(cr, uid, context['active_id'], context=context)
|
||||
if (not plan.name) or (not plan.code):
|
||||
raise osv.except_osv(_('Error'), _('Please put a name and a code before saving the model !'))
|
||||
pids = self.pool.get('account.analytic.plan').search(cr, uid, [], context=context)
|
||||
if (not pids):
|
||||
pids = anlytic_plan_obj.search(cr, uid, [], context=context)
|
||||
if not pids:
|
||||
raise osv.except_osv(_('Error'), _('No analytic plan defined !'))
|
||||
plan_obj.write(cr, uid, [context['active_id']], {'plan_id':pids[0]})
|
||||
plan_obj.write(cr, uid, [context['active_id']], {'plan_id':pids[0]}, context=context)
|
||||
|
||||
model_data_ids = mod_obj.search(cr, uid, [('model', '=', 'ir.ui.view'),('name', '=', 'view_analytic_plan_create_model')], context=context)
|
||||
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
|
||||
|
|
Loading…
Reference in New Issue