Hello
I use odoo V8 on windows 7
I would like to add a decimal precision on the print state, for example 20000.0 to 20,000.00.
I tried everything but I did not succeed
attached my code:
## -*- coding: utf-8 -*-
import time
from openerp.report import report_sxw
from openerp.osv import osv
from openerp import pooler
import locale
class etat104(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context=None):
super(etat104, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'time': time,
'_get_etat': self._get_etat,
'_get_year': self._get_year,
'_cpt': self._cpt
})
def _cpt(self, ss):
locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')
if ss < 0.0 :
cpt = (locale.format('%.2f', ss, True))
cpt = '(' + cpt + ')'
else:
cpt = (locale.format('%.2f', ss, True))
return cpt
def _get_year(self,form):
return self.pool.get('account.fiscalyear').browse(self.cr, self.uid, form).name
def _get_etat(self,form):
nbr = 0
fiscalyear = self.pool.get('account.fiscalyear').browse(self.cr, self.uid, form['fiscalyear_id'])
period_ids=self.pool.get('account.period').search(self.cr, self.uid, [('fiscalyear_id', '=', form['fiscalyear_id'])])
if period_ids:
self.cr.execute("SELECT MIN(date_start) AS date_start, MAX(date_stop) AS date_stop FROM account_period WHERE id = ANY(%s)", (period_ids,))
dates = self.cr.dictfetchall()
else:
dates = False
if dates:
if form['tri']==False :
query = "SELECT ai.partner_id as partner, SUM(aml.credit-aml.debit) as ht FROM account_invoice ai, account_move am,account_move_line aml, account_account aa where ai.state IN ('open','paid') "\
"AND ai.date_invoice >= '%s' AND ai.date_invoice <= '%s' AND ai.move_id=aml.move_id "\
"AND ai.move_id=am.id AND aml.account_id=aa.id AND aa.code like '%s' AND aa.code not like '%s' "\
"AND ai.type like '%s' GROUP BY partner" % (dates[0]['date_start'], dates[0]['date_stop'],'70%','706%','out_%')
else:
query = "SELECT ai.partner_id as partner,p.name as nom, SUM(aml.credit-aml.debit) as ht FROM account_invoice ai, account_move am,account_move_line aml, account_account aa, res_partner p where ai.state IN ('open','paid') "\
"AND ai.date_invoice >= '%s' AND ai.date_invoice <= '%s' AND ai.move_id=aml.move_id AND p.id=ai.partner_id "\
"AND ai.move_id=am.id AND aml.account_id=aa.id AND aa.code like '%s' AND aa.code not like '%s' "\
"AND ai.type like '%s' GROUP BY partner,nom ORDER BY nom" % (dates[0]['date_start'], dates[0]['date_stop'],'70%','706%','out_%')
# raise Warning(query)
# query = "SELECT ai.partner_id as partner, SUM(ai.amount_untaxed) as ht, SUM(ai.amount_tax) as tax ," \
# "CASE " \
# "WHEN type = 'out_refund' THEN SUM(ai.amount_untaxed) * -1 " \
# "WHEN type = 'out_invoice' THEN SUM(ai.amount_untaxed) " \
# "END ht," \
# "CASE " \
# "WHEN type = 'out_refund' THEN SUM(ai.amount_tax) * -1 " \
# "WHEN type = 'out_invoice' THEN SUM(ai.amount_tax) " \
# "END tax" \
# " FROM account_invoice ai WHERE ai.state IN ('open','paid') AND ai.date_invoice >= '%s' AND ai.date_invoice <= '%s'" \
# " AND ai.type like '%s' GROUP BY partner,ai.type ORDER BY partner" % (dates[0]['date_start'], dates[0]['date_stop'],'out_%')
# query3="SELECT ai.partner_id as partner, SUM(aml.debit) as ht FROM account_invoice ai,"\
# "account_move am,account_move_line aml, account_account aa where ai.state IN ('open','paid') "\
# "AND ai.date_invoice >= '2017-01-01' AND ai.move_id=aml.move_id "\
# "AND ai.move_id=am.id AND aml.account_id=aa.id GROUP BY partner"
res=[]
self.cr.execute(query)
datas = self.cr.dictfetchall()
obj_partner=self.pool.get('res.partner')
ref = ''
tht = ttax = 0.0
for dd in datas:
if dd['ht']==0.0:
continue
query="SELECT ai.partner_id as partner, SUM(aml.credit-aml.debit) as tax FROM account_invoice ai, account_move am,account_move_line aml, account_account aa where ai.state IN ('open','paid') "\
"AND ai.date_invoice >= '%s' AND ai.date_invoice <= '%s' and ai.move_id=aml.move_id "\
"and ai.move_id=am.id and aml.account_id=aa.id and aa.code = '445700' "\
"AND ai.type like '%s' AND ai.partner_id= '%s' GROUP BY partner" % (dates[0]['date_start'], dates[0]['date_stop'],'out_%',dd['partner'])
# raise Warning(query)
self.cr.execute(query)
datas2=self.cr.dictfetchall()
tax=0.0
# raise Warning(query)
for i in datas2:
tax=i['tax']
# raise Warning(query)
ttax+=tax
partner = obj_partner.read(self.cr, self.uid, dd['partner'], [])
ref = partner['name']
if form['reference'] == True:
if partner['ref'] :
ref= '[' + partner['ref'] + '] ' + partner['name']
else:
ref = partner['name']
p1=partner['street'] and partner['street'] or ''
p2=partner['city'] and partner['city'] or ''
rue = p1 +' '+ p2
tht += dd['ht']
nbr += 1
dicts={
'nbr': nbr,
'art' : partner['ai'],
'rc' : partner['rc'],
'nif' : partner['nif'],
'name': ref[0:20],
'rue' : rue[0:27],
'ht' : dd['ht'],
'tax' : tax,
'tht': tht,
'ttax': ttax
}
res.append(dicts)
# if len(data) > 0 :
# for dd in data:
# partner = obj_partner.read(self.cr, self.uid, dd['partner'], [])
# ref = partner['name']
# if form['reference'] == True:
# if partner['ref'] :
# ref= '[' + partner['ref'] + '] ' + partner['name']
# else:
# ref = partner['name']
# p1=partner['street'] and partner['street'] or ''
# p2=partner['city'] and partner['city'] or ''
# rue = p1 +' '+ p2
# tht += dd['ht']
# ttax += dd['tax']
# nbr += 1
# dicts={
# 'nbr': nbr,
# 'art' : partner['ai'],
# 'rc' : partner['rc'],
# 'nif' : partner['nif'],
# 'name': ref[0:20],
# 'rue' : rue[0:27],
# 'ht' : dd['ht'],
# 'tax' : dd['tax'],
# 'tht': tht,
# 'ttax': ttax
# }
# res.append(dicts)
# else:
# dicts={
# 'nbr' : 0,
# 'art' : '',
# 'rc' : '',
# 'nif' : '',
# 'name': '',
# 'rue' : '',
# 'ht' : 0.0,
# 'tax' : 0.0,
# 'tht' : 0.0,
# 'ttax': 0.0
# }
# res.append(dicts)
return res
###############################################################
report_sxw.report_sxw('report.l10n.dz.Etat-104', 'account.move.line', 'addons/l10n_dz_report/report/rmls/etat104.rml', parser=etat104, header=False)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: