[IMP] l10n_fr: Code improved

bzr revid: mra@mra-laptop-20100818045314-kg11zkfizxlnn1bs
This commit is contained in:
Mustufa Rangwala 2010-08-18 10:23:14 +05:30
parent ad32f01bae
commit 18b8ed7835
8 changed files with 59 additions and 52 deletions

View File

@ -29,9 +29,11 @@ class l10n_fr_report(osv.osv):
'name': fields.char('Name', size=128), 'name': fields.char('Name', size=128),
'line_ids': fields.one2many('l10n.fr.line', 'report_id', 'Lines'), 'line_ids': fields.one2many('l10n.fr.line', 'report_id', 'Lines'),
} }
_sql_constraints = [ _sql_constraints = [
('code_uniq', 'unique (code)','The code report must be unique !') ('code_uniq', 'unique (code)','The code report must be unique !')
] ]
l10n_fr_report() l10n_fr_report()
class l10n_fr_line(osv.osv): class l10n_fr_line(osv.osv):
@ -46,6 +48,7 @@ class l10n_fr_line(osv.osv):
_sql_constraints = [ _sql_constraints = [
('code_uniq', 'unique (code)', 'The variable name must be unique !') ('code_uniq', 'unique (code)', 'The variable name must be unique !')
] ]
l10n_fr_line() l10n_fr_line()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -27,10 +27,11 @@
############################################################################## ##############################################################################
import time import time
from report import report_sxw from report import report_sxw
class base_report(report_sxw.rml_parse): class base_report(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context): def __init__(self, cr, uid, name, context=None):
super(base_report, self).__init__(cr, uid, name, context=context) super(base_report, self).__init__(cr, uid, name, context=context)
self.localcontext.update({ self.localcontext.update({
'time': time, 'time': time,
@ -40,48 +41,46 @@ class base_report(report_sxw.rml_parse):
}) })
self.context = context self.context = context
def _load(self,name,form): def _load(self, name, form):
fiscalyear=self.pool.get('account.fiscalyear').browse(self.cr, self.uid, form['fiscalyear']) fiscalyear = self.pool.get('account.fiscalyear').browse(self.cr, self.uid, form['fiscalyear'])
period_query_cond=self.pool.get('account.period').search(self.cr, self.uid, [('fiscalyear_id', '=', form['fiscalyear'])])
period_query_cond=self.pool.get('account.period').search(self.cr, self.uid,[('fiscalyear_id','=',form['fiscalyear'])]) self.cr.execute("SELECT MIN(date_start) AS date_start, MAX(date_stop) AS date_stop FROM account_period WHERE id IN %s", (tuple(period_query_cond),))
dates = self.cr.dictfetchall()
self.cr.execute("SELECT MIN(date_start) AS date_start, MAX(date_stop) AS date_stop FROM account_period WHERE id IN %s",(tuple(period_query_cond),))
dates =self.cr.dictfetchall()
self._set_variable('date_start', dates[0]['date_start']) self._set_variable('date_start', dates[0]['date_start'])
self._set_variable('date_stop', dates[0]['date_stop']) self._set_variable('date_stop', dates[0]['date_stop'])
self.cr.execute("SELECT l10n_fr_line.code,definition FROM l10n_fr_line LEFT JOIN l10n_fr_report ON l10n_fr_report.id=report_id WHERE l10n_fr_report.code=%s",(name,)) self.cr.execute("SELECT l10n_fr_line.code,definition FROM l10n_fr_line LEFT JOIN l10n_fr_report ON l10n_fr_report.id=report_id WHERE l10n_fr_report.code=%s",(name,))
datas =self.cr.dictfetchall() datas = self.cr.dictfetchall()
for line in datas: for line in datas:
self._load_accounts(form,line['code'],eval(line['definition']),fiscalyear,period_query_cond) self._load_accounts(form,line['code'],eval(line['definition']),fiscalyear,period_query_cond)
def _set_variable(self,variable,valeur): def _set_variable(self, variable, valeur):
self.localcontext.update({variable:valeur}) self.localcontext.update({variable: valeur})
def _get_variable(self,variable): def _get_variable(self, variable):
return self.localcontext[variable] return self.localcontext[variable]
def _load_accounts(self,form,code,definition,fiscalyear,period_query_cond): def _load_accounts(self,form,code,definition,fiscalyear,period_query_cond):
accounts={} accounts = {}
for x in definition['load']: for x in definition['load']:
p=x.split(":") p = x.split(":")
accounts[p[1]]=[p[0],p[2]] accounts[p[1]] = [p[0],p[2]]
sum=0.0 sum = 0.0
if fiscalyear.state != 'done' or not code.startswith('bpcheck'):
if fiscalyear.state!='done' or not code.startswith('bpcheck'): query_cond = "("
query_cond="("
for account in accounts: for account in accounts:
query_cond += "aa.code LIKE '"+account+"%' OR " query_cond += "aa.code LIKE '" + account + "%' OR "
query_cond = query_cond[:-4]+")" query_cond = query_cond[:-4]+")"
if len(definition['except'])>0: if len(definition['except']) > 0:
query_cond = query_cond+" and (" query_cond = query_cond+" and ("
for account in definition['except']: for account in definition['except']:
query_cond += "aa.code NOT LIKE '"+account+"%' AND " query_cond += "aa.code NOT LIKE '"+account+"%' AND "
query_cond = query_cond[:-5]+")" query_cond = query_cond[:-5]+")"
closed_cond="" closed_cond = ""
if fiscalyear.state=='done': if fiscalyear.state == 'done':
closed_cond=" AND (aml.move_id NOT IN (SELECT account_move.id as move_id FROM account_move WHERE period_id IN "+str(tuple(period_query_cond))+" AND journal_id=(SELECT res_id FROM ir_model_data WHERE name='closing_journal' AND module='l10n_fr')) OR (aa.type != 'income' AND aa.type !='expense'))" closed_cond=" AND (aml.move_id NOT IN (SELECT account_move.id as move_id FROM account_move WHERE period_id IN "+str(tuple(period_query_cond))+" AND journal_id=(SELECT res_id FROM ir_model_data WHERE name='closing_journal' AND module='l10n_fr')) OR (aa.type != 'income' AND aa.type !='expense'))"
query = "SELECT aa.code AS code, SUM(debit) as debit, SUM(credit) as credit FROM account_move_line aml LEFT JOIN account_account aa ON aa.id=aml.account_id WHERE "+query_cond+closed_cond+" AND aml.state='valid' AND aml.period_id IN "+str(tuple(period_query_cond))+" GROUP BY code" query = "SELECT aa.code AS code, SUM(debit) as debit, SUM(credit) as credit FROM account_move_line aml LEFT JOIN account_account aa ON aa.id=aml.account_id WHERE "+query_cond+closed_cond+" AND aml.state='valid' AND aml.period_id IN "+str(tuple(period_query_cond))+" GROUP BY code"
@ -94,19 +93,19 @@ class base_report(report_sxw.rml_parse):
operator=accounts[account][0] operator=accounts[account][0]
type=accounts[account][1] type=accounts[account][1]
value=0.0 value=0.0
if(type=="S"): if(type == "S"):
value=line["debit"]-line["credit"] value=line["debit"]-line["credit"]
elif(type=="D"): elif(type == "D"):
value=line["debit"]-line["credit"] value=line["debit"]-line["credit"]
if(value<0.001): value=0.0 if(value<0.001): value=0.0
elif(type=="C"): elif(type == "C"):
value=line["credit"]-line["debit"] value=line["credit"]-line["debit"]
if(value<0.001): value=0.0 if(value<0.001): value=0.0
if(operator=='+'): if(operator == '+'):
sum+=value sum += value
else: else:
sum-=value sum -= value
break break
self._set_variable(code, sum) self._set_variable(code, sum)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -32,24 +32,25 @@ class account_bilan_report(osv.osv_memory):
_name = 'account.bilan.report' _name = 'account.bilan.report'
_description = 'Account Bilan Report' _description = 'Account Bilan Report'
def _get_default_fiscalyear(self, cr, uid, context): def _get_default_fiscalyear(self, cr, uid, context=None):
fiscalyear_id = self.pool.get('account.fiscalyear').find(cr, uid) fiscalyear_id = self.pool.get('account.fiscalyear').find(cr, uid)
return fiscalyear_id return fiscalyear_id
_columns = { _columns = {
'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year', required=True), 'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year', required=True),
} }
_defaults = { _defaults = {
'fiscalyear_id':_get_default_fiscalyear 'fiscalyear_id':_get_default_fiscalyear
} }
def print_bilan_report(self, cr, uid, ids, context=None): def print_bilan_report(self, cr, uid, ids, context=None):
active_ids = context.get('active_ids',[]) active_ids = context.get('active_ids', [])
data = {} data = {}
data['form'] = {} data['form'] = {}
data['ids'] = active_ids data['ids'] = active_ids
data['form']['fiscalyear'] = self.browse(cr, uid, ids)[0].fiscalyear_id.id data['form']['fiscalyear'] = self.browse(cr, uid, ids)[0].fiscalyear_id.id
return {'type': 'ir.actions.report.xml', 'report_name': 'l10n.fr.bilan', 'datas': data } return {'type': 'ir.actions.report.xml', 'report_name': 'l10n.fr.bilan', 'datas': data}
account_bilan_report() account_bilan_report()

View File

@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<openerp> <openerp>
<data> <data>
<record id="bilan_report_view" model="ir.ui.view"> <record id="bilan_report_view" model="ir.ui.view">
<field name="name">Bilan Report</field> <field name="name">Bilan Report</field>
<field name="model">account.bilan.report</field> <field name="model">account.bilan.report</field>
<field name="type">form</field> <field name="type">form</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form> <form string="Bilan Report">
<field name="fiscalyear_id"/> <field name="fiscalyear_id"/>
<separator colspan="4"/> <separator colspan="4"/>
<group colspan="4" col="6"> <group colspan="4" col="6">
@ -36,5 +38,6 @@
<field name="key">action</field> <field name="key">action</field>
<field name="model">account.move.line</field> <field name="model">account.move.line</field>
</record> </record>
</data> </data>
</openerp> </openerp>

View File

@ -32,20 +32,20 @@ class account_cdr_report(osv.osv_memory):
_name = 'account.cdr.report' _name = 'account.cdr.report'
_description = 'Account CDR Report' _description = 'Account CDR Report'
def _get_defaults(self, cr, uid, context): def _get_defaults(self, cr, uid, context=None):
fiscalyear_obj = self.pool.get('account.fiscalyear') fiscalyear_id = self.pool.get('account.fiscalyear').find(cr, uid)
fiscalyear_id = fiscalyear_obj.find(cr, uid)
return fiscalyear_id return fiscalyear_id
_columns = { _columns = {
'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year', required=True), 'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year', required=True),
} }
_defaults = { _defaults = {
'fiscalyear_id': _get_defaults 'fiscalyear_id': _get_defaults
} }
def print_cdr_report(self, cr, uid, ids, context=None): def print_cdr_report(self, cr, uid, ids, context=None):
active_ids = context.get('active_ids',[]) active_ids = context.get('active_ids', [])
data = {} data = {}
data['form'] = {} data['form'] = {}
data['ids'] = active_ids data['ids'] = active_ids
@ -55,4 +55,3 @@ class account_cdr_report(osv.osv_memory):
account_cdr_report() account_cdr_report()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<openerp> <openerp>
<data> <data>
<record id="cdr_report_view" model="ir.ui.view"> <record id="cdr_report_view" model="ir.ui.view">
<field name="name">Compte de resultat Report</field> <field name="name">Compte de resultat Report</field>
<field name="model">account.cdr.report</field> <field name="model">account.cdr.report</field>
<field name="type">form</field> <field name="type">form</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form> <form string='Compte de resultant'>
<field name="fiscalyear_id"/> <field name="fiscalyear_id"/>
<separator colspan="4"/> <separator colspan="4"/>
<group colspan="4" col="6"> <group colspan="4" col="6">
@ -36,5 +37,6 @@
<field name="key">action</field> <field name="key">action</field>
<field name="model">account.move.line</field> <field name="model">account.move.line</field>
</record> </record>
</data> </data>
</openerp> </openerp>