[IMP] account_voucher:-improvements on the basis of base_module_quality

bzr revid: mtr@mtr-20101011124925-d9bc3ldvzi9hbdgg
This commit is contained in:
mtr 2010-10-11 18:19:25 +05:30
parent affab14974
commit ed8aaa066e
7 changed files with 54 additions and 62 deletions

View File

@ -115,7 +115,7 @@ class account_voucher(osv.osv):
return [(r['id'], (str("%.2f" % r['amount']) or '')) for r in self.read(cr, uid, ids, ['amount'], context, load='_classic_write')]
def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
if not view_id and context.get('invoice_type',False):
if not view_id and context.get('invoice_type', False):
mod_obj = self.pool.get('ir.model.data')
if context.get('invoice_type') in ('out_invoice', 'out_refund'):
result = mod_obj._get_id(cr, uid, 'account_voucher', 'view_vendor_receipt_form')
@ -123,7 +123,7 @@ class account_voucher(osv.osv):
result = mod_obj._get_id(cr, uid, 'account_voucher', 'view_vendor_payment_form')
result = mod_obj.read(cr, uid, [result], ['res_id'], context=context)[0]['res_id']
view_id = result
res = super(account_voucher,self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
res = super(account_voucher, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
doc = etree.XML(res['arch'])
nodes = doc.xpath("//field[@name='partner_id']")
if context.get('type', 'sale') in ('purchase', 'payment'):
@ -226,7 +226,7 @@ class account_voucher(osv.osv):
total_tax = 0.0
if not tax[0].price_include:
for tax_line in tax_pool.compute_all(cr, uid, tax, voucher_amount, 1).get('taxes',[]):
for tax_line in tax_pool.compute_all(cr, uid, tax, voucher_amount, 1).get('taxes', []):
total_tax += tax_line.get('amount', 0.0)
total += total_tax
else:
@ -234,7 +234,7 @@ class account_voucher(osv.osv):
line_total = 0.0
line_tax = 0.0
for tax_line in tax_pool.compute_all(cr, uid, tax, line.untax_amount or line.amount, 1).get('taxes',[]):
for tax_line in tax_pool.compute_all(cr, uid, tax, line.untax_amount or line.amount, 1).get('taxes', []):
line_tax += tax_line.get('amount', 0.0)
line_total += tax_line.get('price_unit')
total_tax += line_tax
@ -249,8 +249,8 @@ class account_voucher(osv.osv):
partner_pool = self.pool.get('res.partner')
position_pool = self.pool.get('account.fiscal.position')
res = {
'tax_amount':False,
'amount':False,
'tax_amount': False,
'amount': False,
}
voucher_total = 0.0
voucher_line_ids = []
@ -274,7 +274,7 @@ class account_voucher(osv.osv):
tax = tax_pool.browse(cr, uid, taxes)
if not tax[0].price_include:
for tax_line in tax_pool.compute_all(cr, uid, tax, voucher_total, 1).get('taxes',[]):
for tax_line in tax_pool.compute_all(cr, uid, tax, voucher_total, 1).get('taxes', []):
total_tax += tax_line.get('amount')
total += total_tax
@ -374,7 +374,7 @@ class account_voucher(osv.osv):
return default
if not partner_id and ids:
line_ids = line_pool.search(cr, uid, [('voucher_id','=',ids[0])])
line_ids = line_pool.search(cr, uid, [('voucher_id', '=', ids[0])])
if line_ids:
line_pool.unlink(cr, uid, line_ids)
return default
@ -405,7 +405,7 @@ class account_voucher(osv.osv):
account_type = 'receivable'
if not context.get('move_line_ids', False):
ids = move_line_pool.search(cr, uid, [('account_id.type','=', account_type), ('reconcile_id','=', False), ('partner_id','=',partner_id)], context=context)
ids = move_line_pool.search(cr, uid, [('account_id.type', '=', account_type), ('reconcile_id', '=', False), ('partner_id', '=', partner_id)], context=context)
else:
ids = context['move_line_ids']
ids.reverse()
@ -472,7 +472,7 @@ class account_voucher(osv.osv):
@return: Returns a dict which contains new values, and context
"""
period_pool = self.pool.get('account.period')
pids = period_pool.search(cr, user, [('date_start','<=',date), ('date_stop','>=',date)])
pids = period_pool.search(cr, user, [('date_start', '<=', date), ('date_stop', '>=', date)])
if not pids:
return {}
return {
@ -688,13 +688,13 @@ class account_voucher(osv.osv):
if not self.pool.get('res.currency').is_zero(cr, uid, inv.currency_id, line_total):
diff = line_total
move_line = {
'name':name,
'account_id':False,
'move_id':move_id ,
'partner_id':inv.partner_id.id,
'date':inv.date,
'credit':diff>0 and diff or 0.0,
'debit':diff<0 and -diff or 0.0,
'name': name,
'account_id': False,
'move_id': move_id ,
'partner_id': inv.partner_id.id,
'date': inv.date,
'credit': diff > 0 and diff or 0.0,
'debit': diff < 0 and -diff or 0.0,
}
account_id = False
if inv.type in ('sale', 'receipt'):
@ -795,10 +795,10 @@ class account_voucher_line(osv.osv):
if move_line_id:
move_line = move_line_pool.browse(cr, user, move_line_id, context=context)
if move_line.credit:
ttype='dr'
ttype = 'dr'
amount = move_line.credit
else:
ttype='cr'
ttype = 'cr'
account_id = move_line.account_id.id
res.update({
'account_id':account_id,
@ -912,4 +912,4 @@ class account_bank_statement_line(osv.osv):
self.pool.get('account.voucher').unlink(cr, uid, unlink_ids, context=context)
return super(account_bank_statement_line, self).unlink(cr, uid, ids, context=context)
account_bank_statement_line()
account_bank_statement_line()

View File

@ -19,8 +19,7 @@
#
##############################################################################
import netsvc
from osv import fields, osv
from osv import osv
from tools.translate import _
class invoice(osv.osv):

View File

@ -36,7 +36,7 @@ class report_voucher(report_sxw.rml_parse):
})
def convert(self, amount, cur):
amt_en = amount_to_text_en.amount_to_text(amount, 'en', cur);
amt_en = amount_to_text_en.amount_to_text(amount, 'en', cur)
return amt_en
def get_title(self, type):
@ -48,17 +48,17 @@ class report_voucher(report_sxw.rml_parse):
def debit(self, move_ids):
debit = 0.0
for move in move_ids:
debit +=move.debit
debit += move.debit
return debit
def credit(self, move_ids):
credit = 0.0
for move in move_ids:
credit +=move.credit
credit += move.credit
return credit
def _get_ref(self, voucher_id, move_ids):
voucher_line = self.pool.get('account.voucher.line').search(self.cr, self.uid, [('partner_id','=',move_ids.partner_id.id), ('voucher_id','=',voucher_id)])
voucher_line = self.pool.get('account.voucher.line').search(self.cr, self.uid, [('partner_id', '=', move_ids.partner_id.id), ('voucher_id', '=', voucher_id)])
if voucher_line:
voucher = self.pool.get('account.voucher.line').browse(self.cr, self.uid, voucher_line)[0]
return voucher.name
@ -69,4 +69,4 @@ report_sxw.report_sxw(
'account.voucher',
'addons/account_voucher/report/account_voucher.rml',
parser=report_voucher,header="external"
)
)

View File

@ -35,10 +35,10 @@ class report_voucher_print(report_sxw.rml_parse):
})
def convert(self, amount, cur):
amt_en = amount_to_text_en.amount_to_text(amount, 'en', cur);
amt_en = amount_to_text_en.amount_to_text(amount, 'en', cur)
return amt_en
def get_lines(self,voucher):
def get_lines(self, voucher):
result = []
if voucher.type in ('payment','receipt'):
type = voucher.line_ids and voucher.line_ids[0].type or False

View File

@ -20,15 +20,9 @@
##############################################################################
from report import report_sxw
import xml.dom.minidom
import os, time
import osv
import re
import tools
import pooler
import re
import sys
from datetime import datetime
import re
class rml_parse(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
@ -40,7 +34,7 @@ class rml_parse(report_sxw.rml_parse):
'explode_name' : self._explode_name,
})
def comma_me(self,amount):
def comma_me(self, amount):
if not amount:
amount = 0.0
if type(amount) is float :
@ -48,7 +42,7 @@ class rml_parse(report_sxw.rml_parse):
else :
amount = str(amount)
if (amount == '0'):
return ' '
return ' '
orig = amount
new = re.sub("^(-?\d+)(\d{3})", "\g<1>'\g<2>", amount)
if orig == new:
@ -60,19 +54,19 @@ class rml_parse(report_sxw.rml_parse):
ellipsis = ellipsis or ''
try:
return string[:maxlen - len(ellipsis) ] + (ellipsis, '')[len(string) < maxlen]
except Exception, e:
except:
return False
def _strip_name(self, name, maxlen=50):
return self._ellipsis(name, maxlen, '...')
def _get_and_change_date_format_for_swiss (self,date_to_format):
date_formatted=''
def _get_and_change_date_format_for_swiss (self, date_to_format):
date_formatted = ''
if date_to_format:
date_formatted = strptime (date_to_format,'%Y-%m-%d').strftime('%d.%m.%Y')
date_formatted = datetime.strptime(date_to_format,'%Y-%m-%d').strftime('%d.%m.%Y')
return date_formatted
def _explode_name(self,chaine,length):
def _explode_name(self, chaine, length):
# We will test if the size is less then account
full_string = ''
if (len(str(chaine)) <= length):
@ -92,7 +86,7 @@ class rml_parse(report_sxw.rml_parse):
return full_string
def makeAscii(self,str):
def makeAscii(self, str):
try:
Stringer = str.encode("utf-8")
except UnicodeDecodeError:
@ -106,7 +100,7 @@ class rml_parse(report_sxw.rml_parse):
return Stringer
return Stringer
def explode_this(self,chaine,length):
def explode_this(self, chaine, length):
chaine = rstrip(chaine)
ast = list(chaine)
i = length
@ -116,7 +110,7 @@ class rml_parse(report_sxw.rml_parse):
chaine = str("".join(ast))
return chaine
def repair_string(self,chaine):
def repair_string(self, chaine):
ast = list(chaine)
UnicodeAst = []
_previouslyfound = False
@ -135,7 +129,7 @@ class rml_parse(report_sxw.rml_parse):
i += i + 1
return "".join(UnicodeAst)
def ReencodeAscii(self,str):
def ReencodeAscii(self, str):
try:
Stringer = str.decode("ascii")
except UnicodeEncodeError:
@ -146,7 +140,7 @@ class rml_parse(report_sxw.rml_parse):
return Stringer
def _add_header(self, node, header=1):
if header==2:
if header == 2:
rml_head = self.rml_header2
else:
rml_head = self.rml_header

View File

@ -86,7 +86,7 @@ class account_statement_from_invoice_lines(osv.osv_memory):
'period_id':statement.period_id.id}
voucher_id = voucher_obj.create(cr, uid, voucher_res, context=context)
voucher_line_dict = False
voucher_line_dict = {}
if result['value']['line_ids']:
for line_dict in result['value']['line_ids']:
move_line = line_obj.browse(cr, uid, line_dict['move_line_id'], context)
@ -94,7 +94,7 @@ class account_statement_from_invoice_lines(osv.osv_memory):
voucher_line_dict = line_dict
if voucher_line_dict:
voucher_line_dict.update({'voucher_id':voucher_id})
voucher_line_dict.update({'voucher_id': voucher_id})
voucher_line_obj.create(cr, uid, voucher_line_dict, context=context)
if line.journal_id.type == 'sale':
type = 'customer'
@ -147,11 +147,11 @@ class account_statement_from_invoice(osv.osv_memory):
# Creating a group that is unique for importing move lines(move lines, once imported into statement lines, should not appear again)
for st_line in statement.line_ids:
args_move_line = []
args_move_line.append(('name','=', st_line.name))
args_move_line.append(('ref','=',st_line.ref))
args_move_line.append(('name', '=', st_line.name))
args_move_line.append(('ref', '=', st_line.ref))
if st_line.partner_id:
args_move_line.append(('partner_id','=',st_line.partner_id.id))
args_move_line.append(('account_id','=',st_line.account_id.id))
args_move_line.append(('partner_id', '=', st_line.partner_id.id))
args_move_line.append(('account_id', '=', st_line.account_id.id))
move_line_id = line_obj.search(cr, uid, args_move_line, context=context)
if move_line_id:
@ -159,7 +159,7 @@ class account_statement_from_invoice(osv.osv_memory):
journal_ids = data['journal_ids']
if journal_ids == []:
journal_ids = journal_obj.search(cr, uid, [('type', 'in', ('sale','cash','purchase'))], context=context)
journal_ids = journal_obj.search(cr, uid, [('type', 'in', ('sale', 'cash', 'purchase'))], context=context)
args = [
('reconcile_id', '=', False),
@ -167,12 +167,12 @@ class account_statement_from_invoice(osv.osv_memory):
('account_id.reconcile', '=', True)]
if repeated_move_line_ids:
args.append(('id','not in',repeated_move_line_ids))
args.append(('id', 'not in', repeated_move_line_ids))
line_ids = line_obj.search(cr, uid, args,
context=context)
model_data_ids = mod_obj.search(cr,uid,[('model','=','ir.ui.view'),('name','=','view_account_statement_from_invoice_lines')], context=context)
model_data_ids = mod_obj.search(cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'view_account_statement_from_invoice_lines')], context=context)
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
return {
'domain': "[('id','in', ["+','.join([str(x) for x in line_ids])+"])]",
@ -187,4 +187,4 @@ class account_statement_from_invoice(osv.osv_memory):
}
account_statement_from_invoice()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -19,7 +19,6 @@
#
##############################################################################
import netsvc
from osv import osv
from osv import fields
@ -32,11 +31,11 @@ class account_voucher_unreconcile(osv.osv_memory):
}
_defaults = {
'remove': lambda *a: True,
'remove': True,
}
def trans_unrec(self, cr, uid, ids, context=None):
res = self.browse(cr, uid, ids[0])
# res = self.browse(cr, uid, ids[0])
if context is None:
context = {}
voucher_pool = self.pool.get('account.voucher')