[IMP] English Improvement resolved conflicts
[odoo/odoo.git] / addons / account / account.py
index d76b762..0229297 100644 (file)
@@ -1,24 +1,24 @@
-# -*- encoding: utf-8 -*-
+# -*- coding: utf-8 -*-
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
-#    $Id$
+#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
 #
 #    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, either version 3 of the License, or
-#    (at your option) any later version.
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
+#    GNU Affero General Public License for more details.
 #
-#    You should have received a copy of the GNU General Public License
+#    You should have received a copy of the GNU Affero General Public License
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
+
 import time
 import netsvc
 
@@ -30,6 +30,7 @@ import pooler
 import mx.DateTime
 from mx.DateTime import RelativeDateTime, now, DateTime, localtime
 
+from tools import config
 
 class account_payment_term(osv.osv):
     _name = "account.payment.term"
@@ -52,17 +53,17 @@ class account_payment_term(osv.osv):
         amount = value
         result = []
         for line in pt.line_ids:
-            if line.value=='fixed':
-                amt = round(line.value_amount, 2)
-            elif line.value=='procent':
-                amt = round(value * line.value_amount, 2)
-            elif line.value=='balance':
-                amt = round(amount, 2)
+            if line.value == 'fixed':
+                amt = round(line.value_amount, int(config['price_accuracy']))
+            elif line.value == 'procent':
+                amt = round(value * line.value_amount, int(config['price_accuracy']))
+            elif line.value == 'balance':
+                amt = round(amount, int(config['price_accuracy']))
             if amt:
                 next_date = mx.DateTime.strptime(date_ref, '%Y-%m-%d') + RelativeDateTime(days=line.days)
-                if line.days2<0:
+                if line.days2 < 0:
                     next_date += RelativeDateTime(day=line.days2)
-                if line.days2>0:
+                if line.days2 > 0:
                     next_date += RelativeDateTime(day=line.days2, months=1)
                 result.append( (next_date.strftime('%Y-%m-%d'), amt) )
                 amount -= amt
@@ -74,14 +75,17 @@ class account_payment_term_line(osv.osv):
     _name = "account.payment.term.line"
     _description = "Payment Term Line"
     _columns = {
-        'name': fields.char('Line Name', size=32,required=True),
+        'name': fields.char('Line Name', size=32, required=True),
         'sequence': fields.integer('Sequence', required=True, help="The sequence field is used to order the payment term lines from the lowest sequences to the higher ones"),
-        'value': fields.selection([('procent','Percent'),('balance','Balance'),('fixed','Fixed Amount')], 'Value',required=True),
-        'value_amount': fields.float('Value Amount'),
-        'days': fields.integer('Number of Days',required=True, help="Number of days to add before computation of the day of month." \
+        'value': fields.selection([('procent', 'Percent'), ('balance', 'Balance'), ('fixed', 'Fixed Amount')], 'Value', required=True, help="""Example: 14 days 2%, 30 days net
+1. Line 1: percent 0.02 14 days
+2. Line 2: balance 30 days"""),
+
+        'value_amount': fields.float('Value Amount', help="For Value percent enter % ratio between 0-1."),
+        'days': fields.integer('Number of Days', required=True, help="Number of days to add before computation of the day of month." \
             "If Date=15/01, Number of Days=22, Day of Month=-1, then the due date is 28/02."),
-        'days2': fields.integer('Day of the Month',required=True, help="Day of the month, set -1 for the last day of the current month. If it's positive, it gives the day of the next month. Set 0 for net days (otherwise it's based on the beginning of the month)."),
-        'payment_id': fields.many2one('account.payment.term','Payment Term', required=True, select=True),
+        'days2': fields.integer('Day of the Month', required=True, help="Day of the month, set -1 for the last day of the current month. If it's positive, it gives the day of the next month. Set 0 for net days (otherwise it's based on the beginning of the month)."),
+        'payment_id': fields.many2one('account.payment.term', 'Payment Term', required=True, select=True),
     }
     _defaults = {
         'value': lambda *a: 'balance',
@@ -89,6 +93,17 @@ class account_payment_term_line(osv.osv):
         'days2': lambda *a: 0,
     }
     _order = "sequence"
+
+    def _check_percent(self, cr, uid, ids, context={}):
+        obj = self.browse(cr, uid, ids[0])
+        if obj.value == 'procent' and ( obj.value_amount < 0.0 or obj.value_amount > 1.0):
+            return False
+        return True
+
+    _constraints = [
+        (_check_percent, _('Percentages for Payment Term Line must be between 0 and 1, Example: 0.02 for 2% '), ['value_amount']),
+    ]
+
 account_payment_term_line()
 
 
@@ -100,8 +115,8 @@ class account_account_type(osv.osv):
         'code': fields.char('Code', size=32, required=True),
         'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of account types."),
         'partner_account': fields.boolean('Partner account'),
-        'close_method': fields.selection([('none','None'), ('balance','Balance'), ('detail','Detail'),('unreconciled','Unreconciled')], 'Deferral Method', required=True),
-        'sign': fields.selection([(-1, 'Negative'), (1, 'Positive')], 'Sign on Reports', required=True, help='Allows to change the displayed amount of the balance in the reports, in order to see positive results instead of negative ones in expenses accounts.'),
+        'close_method': fields.selection([('none', 'None'), ('balance', 'Balance'), ('detail', 'Detail'), ('unreconciled', 'Unreconciled')], 'Deferral Method', required=True),
+        'sign': fields.selection([(-1, 'Negative'), (1, 'Positive')], 'Sign on Reports', required=True, help='Allows you to change the sign of the balance amount displayed in the reports, so that you can see positive figures instead of negative ones in expenses accounts.'),
     }
     _defaults = {
         'close_method': lambda *a: 'none',
@@ -131,7 +146,6 @@ class account_account(osv.osv):
     _name = "account.account"
     _description = "Account"
     _parent_store = True
-    _parent_order = 'length(code),code'
 
     def search(self, cr, uid, args, offset=0, limit=None, order=None,
             context=None, count=False):
@@ -139,32 +153,32 @@ class account_account(osv.osv):
             context = {}
         pos = 0
 
-        while pos<len(args):
+        while pos < len(args):
 
-            if args[pos][0]=='code' and args[pos][1] in ('like','ilike') and args[pos][2]:
-                args[pos] = ('code', '=like', str(args[pos][2].replace('%',''))+'%')
-            if args[pos][0]=='journal_id':
+            if args[pos][0] == 'code' and args[pos][1] in ('like', 'ilike') and args[pos][2]:
+                args[pos] = ('code', '=like', str(args[pos][2].replace('%', ''))+'%')
+            if args[pos][0] == 'journal_id':
                 if not args[pos][2]:
                     del args[pos]
                     continue
                 jour = self.pool.get('account.journal').browse(cr, uid, args[pos][2])
                 if (not (jour.account_control_ids or jour.type_control_ids)) or not args[pos][2]:
-                    del args[pos]
+                    args[pos] = ('type','not in',('consolidation','view'))
                     continue
-                ids3 = map(lambda x: x.code, jour.type_control_ids)
-                ids1 = super(account_account,self).search(cr, uid, [('type','in',ids3)])
+                ids3 = map(lambda x: x.id, jour.type_control_ids)
+                ids1 = super(account_account, self).search(cr, uid, [('user_type', 'in', ids3)])
                 ids1 += map(lambda x: x.id, jour.account_control_ids)
-                args[pos] = ('id','in',ids1)
-            pos+=1
+                args[pos] = ('id', 'in', ids1)
+            pos += 1
 
         if context and context.has_key('consolidate_childs'): #add consolidated childs of accounts
-            ids = super(account_account,self).search(cr, uid, args, offset, limit,
+            ids = super(account_account, self).search(cr, uid, args, offset, limit,
                 order, context=context, count=count)
             for consolidate_child in self.browse(cr, uid, context['account_id']).child_consol_ids:
                 ids.append(consolidate_child.id)
             return ids
 
-        return super(account_account,self).search(cr, uid, args, offset, limit,
+        return super(account_account, self).search(cr, uid, args, offset, limit,
                 order, context=context, count=count)
 
     def _get_children_and_consol(self, cr, uid, ids, context={}):
@@ -176,7 +190,7 @@ class account_account(osv.osv):
                 ids3.append(child.id)
         if ids3:
             ids3 = self._get_children_and_consol(cr, uid, ids3, context)
-        return ids2+ids3
+        return ids2 + ids3
 
     def __compute(self, cr, uid, ids, field_names, arg, context={}, query=''):
         #compute the balance/debit/credit accordingly to the value of field_name for the given account ids
@@ -237,12 +251,12 @@ class account_account(osv.osv):
         return result
 
     def _get_child_ids(self, cr, uid, ids, field_name, arg, context={}):
-        result={}
+        result = {}
         for record in self.browse(cr, uid, ids, context):
             if record.child_parent_ids:
-                result[record.id]=[x.id for x in record.child_parent_ids]
+                result[record.id] = [x.id for x in record.child_parent_ids]
             else:
-                result[record.id]=[]
+                result[record.id] = []
 
             if record.child_consol_ids:
                 for acc in record.child_consol_ids:
@@ -255,26 +269,26 @@ class account_account(osv.osv):
         'currency_id': fields.many2one('res.currency', 'Secondary Currency', help="Force all moves for this account to have this secondary currency."),
         'code': fields.char('Code', size=64, required=True),
         'type': fields.selection([
-            ('receivable','Receivable'),
-            ('payable','Payable'),
-            ('view','View'),
-            ('consolidation','Consolidation'),
-            ('other','Others'),
-            ('closed','Closed'),
+            ('receivable', 'Receivable'),
+            ('payable', 'Payable'),
+            ('view', 'View'),
+            ('consolidation', 'Consolidation'),
+            ('other', 'Others'),
+            ('closed', 'Closed'),
         ], 'Internal Type', required=True,),
 
         'user_type': fields.many2one('account.account.type', 'Account Type', required=True),
-        'parent_id': fields.many2one('account.account','Parent', ondelete='cascade'),
-        'child_parent_ids':fields.one2many('account.account','parent_id','Children'),
-        'child_consol_ids':fields.many2many('account.account', 'account_account_consol_rel', 'child_id', 'parent_id', 'Consolidated Children'),
-        'child_id': fields.function(_get_child_ids, method=True, type='many2many',relation="account.account",string="Children Accounts"),
-        'balance': fields.function(__compute, digits=(16,2), method=True, string='Balance', multi='balance'),
-        'credit': fields.function(__compute, digits=(16,2), method=True, string='Credit', multi='balance'),
-        'debit': fields.function(__compute, digits=(16,2), method=True, string='Debit', multi='balance'),
-        'reconcile': fields.boolean('Reconcile', help="Check this account if the user can make a reconciliation of the entries in this account."),
+        'parent_id': fields.many2one('account.account', 'Parent', ondelete='cascade'),
+        'child_parent_ids': fields.one2many('account.account','parent_id','Children'),
+        'child_consol_ids': fields.many2many('account.account', 'account_account_consol_rel', 'child_id', 'parent_id', 'Consolidated Children'),
+        'child_id': fields.function(_get_child_ids, method=True, type='many2many', relation="account.account", string="Child Accounts"),
+        'balance': fields.function(__compute, digits=(16, int(config['price_accuracy'])), method=True, string='Balance', multi='balance'),
+        'credit': fields.function(__compute, digits=(16, int(config['price_accuracy'])), method=True, string='Credit', multi='balance'),
+        'debit': fields.function(__compute, digits=(16, int(config['price_accuracy'])), method=True, string='Debit', multi='balance'),
+        'reconcile': fields.boolean('Reconcile', help="Check this if the user is allowed to reconcile entries in this account."),
         'shortcut': fields.char('Shortcut', size=12),
         'tax_ids': fields.many2many('account.tax', 'account_account_tax_default_rel',
-            'account_id','tax_id', 'Default Taxes'),
+            'account_id', 'tax_id', 'Default Taxes'),
         'note': fields.text('Note'),
         'company_currency_id': fields.function(_get_company_currency, method=True, type='many2one', relation='res.currency', string='Company Currency'),
         'company_id': fields.many2one('res.company', 'Company', required=True),
@@ -282,12 +296,12 @@ class account_account(osv.osv):
 
         'parent_left': fields.integer('Parent Left', select=1),
         'parent_right': fields.integer('Parent Right', select=1),
-        'currency_mode': fields.selection([('current','At Date'),('average','Average Rate')], 'Outgoing Currencies Rate',
+        'currency_mode': fields.selection([('current', 'At Date'), ('average', 'Average Rate')], 'Outgoing Currencies Rate',
             help=
-            'This will select how is computed the current currency rate for outgoing transactions. '\
-            'In most countries the legal method is "average" but only a few softwares are able to '\
-            'manage this. So if you import from another software, you may have to use the rate at date. ' \
-            'Incoming transactions, always use the rate at date.', \
+            'This will select how the current currency rate for outgoing transactions is computed. '\
+            'In most countries the legal method is "average" but only a few software systems are able to '\
+            'manage this. So if you import from another software system you may have to use the rate at date. ' \
+            'Incoming transactions always use the rate at date.', \
             required=True),
         'check_history': fields.boolean('Display History',
             help="Check this box if you want to print all entries when printing the General Ledger, "\
@@ -301,7 +315,7 @@ class account_account(osv.osv):
         return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
 
     _defaults = {
-        'type' : lambda *a :'view',
+        'type': lambda *a : 'view',
         'reconcile': lambda *a: False,
         'company_id': _default_company,
         'active': lambda *a: True,
@@ -310,30 +324,33 @@ class account_account(osv.osv):
     }
 
     def _check_recursion(self, cr, uid, ids):
-        obj_self=self.browse(cr,uid,ids[0])
-        p_id=obj_self.parent_id and obj_self.parent_id.id
+        obj_self = self.browse(cr, uid, ids[0])
+        p_id = obj_self.parent_id and obj_self.parent_id.id
         if (obj_self in obj_self.child_consol_ids) or (p_id and (p_id is obj_self.id)):
             return False
         while(ids):
-            cr.execute('select distinct child_id from account_account_consol_rel where parent_id in ('+','.join(map(str,ids))+')')
-            child_ids = filter(None, map(lambda x:x[0], cr.fetchall()))
-            c_ids=child_ids
+            cr.execute('select distinct child_id from account_account_consol_rel where parent_id in ('+','.join(map(str, ids))+')')
+            child_ids = filter(None, map(lambda x: x[0], cr.fetchall()))
+            c_ids = child_ids
             if (p_id and (p_id in c_ids)) or (obj_self.id in c_ids):
                 return False
             while len(c_ids):
-                s_ids=self.search(cr,uid,[('parent_id','in',c_ids)])
+                s_ids = self.search(cr, uid, [('parent_id', 'in', c_ids)])
                 if p_id and (p_id in s_ids):
                     return False
-                c_ids=s_ids
-            ids=child_ids
+                c_ids = s_ids
+            ids = child_ids
         return True
 
     _constraints = [
         (_check_recursion, 'Error ! You can not create recursive accounts.', ['parent_id'])
     ]
+    _sql_constraints = [
+        ('code_company_uniq', 'unique (code,company_id)', 'The code of the account must be unique per company !')
+    ]
     def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80):
         if not args:
-            args=[]
+            args = []
         if not context:
             context = {}
         args = args[:]
@@ -342,20 +359,20 @@ class account_account(osv.osv):
             if name and str(name).startswith('partner:'):
                 part_id = int(name.split(':')[1])
                 part = self.pool.get('res.partner').browse(cr, user, part_id, context)
-                args += [('id','in', (part.property_account_payable.id, part.property_account_receivable.id))]
+                args += [('id', 'in', (part.property_account_payable.id, part.property_account_receivable.id))]
                 name = False
             if name and str(name).startswith('type:'):
                 type = name.split(':')[1]
-                args += [('type','=', type)]
+                args += [('type', '=', type)]
                 name = False
         except:
             pass
         if name:
-            ids = self.search(cr, user, [('code','=like',name+"%")]+ args, limit=limit)
+            ids = self.search(cr, user, [('code', '=like', name+"%")]+args, limit=limit)
             if not ids:
-                ids = self.search(cr, user, [('shortcut','=',name)]+ args, limit=limit)
+                ids = self.search(cr, user, [('shortcut', '=', name)]+ args, limit=limit)
             if not ids:
-                ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit)
+                ids = self.search(cr, user, [('name', operator, name)]+ args, limit=limit)
         else:
             ids = self.search(cr, user, args, context=context, limit=limit)
         return self.name_get(cr, user, ids, context=context)
@@ -363,28 +380,30 @@ class account_account(osv.osv):
     def name_get(self, cr, uid, ids, context={}):
         if not len(ids):
             return []
-        reads = self.read(cr, uid, ids, ['name','code'], context)
+        reads = self.read(cr, uid, ids, ['name', 'code'], context)
         res = []
         for record in reads:
             name = record['name']
             if record['code']:
-                name = record['code']+' '+name
-            res.append((record['id'],name ))
+                name = record['code'] + ' '+name
+            res.append((record['id'], name))
         return res
 
-    def copy(self, cr, uid, id, default={}, context={},done_list=[]):
+    def copy(self, cr, uid, id, default={}, context={}, done_list=[], local=False):
         account = self.browse(cr, uid, id, context=context)
         new_child_ids = []
         if not default:
-            default={}
-        default=default.copy()
-        default['parent_id'] = False
+            default = {}
+        default = default.copy()
+        default['code'] = (account['code'] or '') + '(copy)'
+        if not local:
+            done_list = []
         if account.id in done_list:
             return False
         done_list.append(account.id)
         if account:
             for child in account.child_id:
-                child_ids=self.copy(cr, uid, child.id, default, context=context,done_list=done_list)
+                child_ids = self.copy(cr, uid, child.id, default, context=context, done_list=done_list, local=True)
                 if child_ids:
                     new_child_ids.append(child_ids)
             default['child_parent_ids'] = [(6, 0, new_child_ids)]
@@ -394,12 +413,12 @@ class account_account(osv.osv):
 
     def write(self, cr, uid, ids, vals, context=None):
         if not context:
-            context={}
+            context = {}
         if 'active' in vals and not vals['active']:
             line_obj = self.pool.get('account.move.line')
             account_ids = self.search(cr, uid, [('id', 'child_of', ids)])
             if line_obj.search(cr, uid, [('account_id', 'in', account_ids)]):
-                raise osv.except_osv(_('Error !'), _('You can not deactivate an account that contains account moves.'))
+                raise osv.except_osv(_('Error !'), _('You can not deactivate an account that contains Ledger Postings.'))
         return super(account_account, self).write(cr, uid, ids, vals, context=context)
 account_account()
 
@@ -441,7 +460,7 @@ class account_journal(osv.osv):
     _columns = {
         'name': fields.char('Journal Name', size=64, required=True, translate=True),
         'code': fields.char('Code', size=16),
-        'type': fields.selection([('sale','Sale'), ('purchase','Purchase'), ('cash','Cash'), ('general','General'), ('situation','Situation')], 'Type', size=32, required=True),
+        'type': fields.selection([('sale', 'Sale'), ('purchase', 'Purchase'), ('cash', 'Cash'), ('general', 'General'), ('situation', 'Situation')], 'Type', size=32, required=True),
         'refund_journal': fields.boolean('Refund Journal'),
 
         'type_control_ids': fields.many2many('account.account.type', 'account_journal_type_rel', 'journal_id','type_id', 'Type Controls', domain=[('code','<>','view'), ('code', '<>', 'closed')]),
@@ -451,24 +470,27 @@ class account_journal(osv.osv):
         'view_id': fields.many2one('account.journal.view', 'View', required=True, help="Gives the view used when writing or browsing entries in this journal. The view tell Open ERP which fields should be visible, required or readonly and in which order. You can create your own view for a faster encoding in each journal."),
         'default_credit_account_id': fields.many2one('account.account', 'Default Credit Account', domain="[('type','!=','view')]"),
         'default_debit_account_id': fields.many2one('account.account', 'Default Debit Account', domain="[('type','!=','view')]"),
-        'centralisation': fields.boolean('Centralised counterpart', help="Check this box if you want that each entry doesn't create a counterpart but share the same counterpart for each entry of this journal. This is used in fiscal year closing."),
+        'centralisation': fields.boolean('Centralised counterpart', help="Check this box to determine that each entry of this journal won't create a new counterpart but will share the same counterpart. This is used in fiscal year closing."),
         'update_posted': fields.boolean('Allow Cancelling Entries'),
-        'group_invoice_lines': fields.boolean('Group invoice lines', help="If this box is cheked, the system will try to group the accouting lines when generating them from invoices."),
+        'group_invoice_lines': fields.boolean('Group invoice lines', help="If this box is checked, the system will try to group the accounting lines when generating them from invoices."),
         'sequence_id': fields.many2one('ir.sequence', 'Entry Sequence', help="The sequence gives the display order for a list of journals", required=True),
-        'user_id': fields.many2one('res.users', 'User', help="The responsible user of this journal"),
+        'user_id': fields.many2one('res.users', 'User', help="The user responsible for this journal"),
         'groups_id': fields.many2many('res.groups', 'account_journal_group_rel', 'journal_id', 'group_id', 'Groups'),
         'currency': fields.many2one('res.currency', 'Currency', help='The currency used to enter statement'),
-        'entry_posted': fields.boolean('Skip \'Draft\' State for Created Entries', help='Check this box if you don\'t want that new account moves pass through the \'draft\' state and goes direclty to the \'posted state\' without any manual validation.'),
-        'company_id': fields.related('default_credit_account_id','company_id',type='many2one', relation="res.company", string="Company"),
-        'fy_seq_id': fields.one2many('fiscalyear.seq', 'journal_id', 'Sequences'),
+        'entry_posted': fields.boolean('Skip \'Draft\' State for Created Entries', help='Check this box if you don\'t want new account moves to pass through the \'draft\' state and instead goes directly to the \'posted state\' without any manual validation.'),
+        #'company_id': fields.related('default_credit_account_id','company_id',type='many2one', relation="res.company", string="Company"),
+        'company_id': fields.many2one('res.company', 'Company', required=True,select=1),
+        'invoice_sequence_id': fields.many2one('ir.sequence', 'Invoice Sequence', \
+            help="The sequence used for invoice numbers in this journal."),
     }
 
     _defaults = {
         'active': lambda *a: 1,
         'user_id': lambda self,cr,uid,context: uid,
+        'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
     }
     def create(self, cr, uid, vals, context={}):
-        journal_id = super(osv.osv, self).create(cr, uid, vals, context)
+        journal_id = super(account_journal, self).create(cr, uid, vals, context)
 #       journal_name = self.browse(cr, uid, [journal_id])[0].code
 #       periods = self.pool.get('account.period')
 #       ids = periods.search(cr, uid, [('date_stop','>=',time.strftime('%Y-%m-%d'))])
@@ -479,6 +501,7 @@ class account_journal(osv.osv):
 #               'period_id': period.id
 #           })
         return journal_id
+
     def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80):
         if not args:
             args=[]
@@ -499,15 +522,17 @@ class account_fiscalyear(osv.osv):
         'name': fields.char('Fiscal Year', size=64, required=True),
         'code': fields.char('Code', size=6, required=True),
         'company_id': fields.many2one('res.company', 'Company',
-            help="Keep empty if the fiscal year belongs to several companies."),
-        'date_start': fields.date('Start date', required=True),
-        'date_stop': fields.date('End date', required=True),
+            help="Keep empty if the fiscal year belongs to several companies.", required=True),
+        'date_start': fields.date('Start Date', required=True),
+        'date_stop': fields.date('End Date', required=True),
         'period_ids': fields.one2many('account.period', 'fiscalyear_id', 'Periods'),
-        'state': fields.selection([('draft','Draft'), ('done','Done')], 'Status', redonly=True),
+        'state': fields.selection([('draft','Draft'), ('done','Done')], 'State', readonly=True,
+                                  help='When fiscal year is created. The state is \'Draft\'. At the end of the year it is in \'Done\' state.'),
     }
 
     _defaults = {
         'state': lambda *a: 'draft',
+        'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
     }
     _order = "date_start"
 
@@ -518,7 +543,7 @@ class account_fiscalyear(osv.osv):
         return True
 
     _constraints = [
-        (_check_duration, 'Error ! The date duration of the Fiscal Year is invalid. ', ['date_stop'])
+        (_check_duration, 'Error ! The duration of the Fiscal Year is invalid. ', ['date_stop'])
     ]
 
     def create_period3(self,cr, uid, ids, context={}):
@@ -526,7 +551,6 @@ class account_fiscalyear(osv.osv):
 
     def create_period(self,cr, uid, ids, context={}, interval=1):
         for fy in self.browse(cr, uid, ids, context):
-            dt = fy.date_start
             ds = mx.DateTime.strptime(fy.date_start, '%Y-%m-%d')
             while ds.strftime('%Y-%m-%d')<fy.date_stop:
                 de = ds + RelativeDateTime(months=interval, days=-1)
@@ -564,13 +588,16 @@ class account_period(osv.osv):
         'code': fields.char('Code', size=12),
         'special': fields.boolean('Opening/Closing Period', size=12,
             help="These periods can overlap."),
-        'date_start': fields.date('Start of period', required=True, states={'done':[('readonly',True)]}),
-        'date_stop': fields.date('End of period', required=True, states={'done':[('readonly',True)]}),
+        'date_start': fields.date('Start of Period', required=True, states={'done':[('readonly',True)]}),
+        'date_stop': fields.date('End of Period', required=True, states={'done':[('readonly',True)]}),
         'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year', required=True, states={'done':[('readonly',True)]}, select=True),
-        'state': fields.selection([('draft','Draft'), ('done','Done')], 'Status', readonly=True)
+        'state': fields.selection([('draft','Draft'), ('done','Done')], 'State', readonly=True,
+                                  help='When monthly periods are created. The state is \'Draft\'. At the end of monthly period it is in \'Done\' state.'),
+        'company_id': fields.many2one('res.company', 'Company', required=True)
     }
     _defaults = {
         'state': lambda *a: 'draft',
+        'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
     }
     _order = "date_start"
 
@@ -584,7 +611,11 @@ class account_period(osv.osv):
         for obj_period in self.browse(cr,uid,ids):
             if obj_period.special:
                 continue
-            if obj_period.fiscalyear_id.date_stop < obj_period.date_stop or obj_period.fiscalyear_id.date_stop < obj_period.date_start or obj_period.fiscalyear_id.date_start > obj_period.date_start or obj_period.fiscalyear_id.date_start > obj_period.date_stop:
+
+            if obj_period.fiscalyear_id.date_stop < obj_period.date_stop or \
+               obj_period.fiscalyear_id.date_stop < obj_period.date_start or \
+               obj_period.fiscalyear_id.date_start > obj_period.date_start or \
+               obj_period.fiscalyear_id.date_start > obj_period.date_stop:
                 return False
 
             pids = self.search(cr, uid, [('date_stop','>=',obj_period.date_start),('date_start','<=',obj_period.date_stop),('special','=',False),('id','<>',obj_period.id)])
@@ -594,8 +625,8 @@ class account_period(osv.osv):
         return True
 
     _constraints = [
-        (_check_duration, 'Error ! The date duration of the Period(s) is invalid. ', ['date_stop']),
-        (_check_year_limit, 'Invalid period ! Some periods overlap or the date duration is not in the limit of the fiscal year. ', ['date_stop'])
+        (_check_duration, 'Error ! The duration of the Period(s) is/are invalid. ', ['date_stop']),
+        (_check_year_limit, 'Invalid period ! Some periods overlap or the date period is not in the scope of the fiscal year. ', ['date_stop'])
     ]
 
     def next(self, cr, uid, period, step, context={}):
@@ -643,9 +674,12 @@ class account_journal_period(osv.osv):
         'name': fields.char('Journal-Period Name', size=64, required=True),
         'journal_id': fields.many2one('account.journal', 'Journal', required=True, ondelete="cascade"),
         'period_id': fields.many2one('account.period', 'Period', required=True, ondelete="cascade"),
-        'icon': fields.function(_icon_get, method=True, string='Icon', type='string'),
+        'icon': fields.function(_icon_get, method=True, string='Icon', type='char', size=32),
         'active': fields.boolean('Active', required=True),
-        'state': fields.selection([('draft','Draft'), ('printed','Printed'), ('done','Done')], 'Status', required=True, readonly=True)
+        'state': fields.selection([('draft','Draft'), ('printed','Printed'), ('done','Done')], 'State', required=True, readonly=True,
+                                  help='When journal period is created. The state is \'Draft\'. If a report is printed it comes to \'Printed\' state. When all transactions are done, it comes in \'Done\' state.'),
+        'fiscalyear_id': fields.related('period_id', 'fiscalyear_id', string='Fiscal Year', type='many2one', relation='account.fiscalyear'),
+        'company_id' : fields.many2one('res.company', 'Company')
     }
 
     def _check(self, cr, uid, ids, context={}):
@@ -674,6 +708,7 @@ class account_journal_period(osv.osv):
     _defaults = {
         'state': lambda *a: 'draft',
         'active': lambda *a: True,
+        'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
     }
     _order = "period_id"
 
@@ -718,7 +753,7 @@ class account_move(osv.osv):
 
     def _amount_compute(self, cr, uid, ids, name, args, context, where =''):
         if not ids: return {}
-        cr.execute('select move_id,sum(debit) from account_move_line where move_id in ('+','.join(map(str,ids))+') group by move_id')
+        cr.execute('select move_id,sum(debit) from account_move_line where move_id in ('+','.join(map(str,map(int, ids)))+') group by move_id')
         result = dict(cr.fetchall())
         for id in ids:
             result.setdefault(id, 0.0)
@@ -729,11 +764,12 @@ class account_move(osv.osv):
         'ref': fields.char('Ref', size=64),
         'period_id': fields.many2one('account.period', 'Period', required=True, states={'posted':[('readonly',True)]}),
         'journal_id': fields.many2one('account.journal', 'Journal', required=True, states={'posted':[('readonly',True)]}),
-        'state': fields.selection([('draft','Draft'), ('posted','Posted')], 'Status', required=True, readonly=True),
+        'state': fields.selection([('draft','Draft'), ('posted','Posted')], 'State', required=True, readonly=True,
+                                  help='When new account move is created the state will be \'Draft\'. When all the payments are done it will be in \'Posted\' state.'),
         'line_id': fields.one2many('account.move.line', 'move_id', 'Entries', states={'posted':[('readonly',True)]}),
         'to_check': fields.boolean('To Be Verified'),
         'partner_id': fields.related('line_id', 'partner_id', type="many2one", relation="res.partner", string="Partner"),
-        'amount': fields.function(_amount_compute, method=True, string='Amount', digits=(16,2)),
+        'amount': fields.function(_amount_compute, method=True, string='Amount', digits=(16,int(config['price_accuracy']))),
         'date': fields.date('Date', required=True),
         'type': fields.selection([
             ('pay_voucher','Cash Payment'),
@@ -745,6 +781,7 @@ class account_move(osv.osv):
             ('journal_pur_voucher','Journal Purchase'),
             ('journal_voucher','Journal Voucher'),
         ],'Type', readonly=True, select=True, states={'draft':[('readonly',False)]}),
+        'company_id': fields.many2one('res.company', 'Company', required=True),
     }
     _defaults = {
         'name': lambda *a: '/',
@@ -752,6 +789,7 @@ class account_move(osv.osv):
         'period_id': _get_period,
         'type' : lambda *a : 'journal_voucher',
         'date': lambda *a:time.strftime('%Y-%m-%d'),
+        'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
     }
 
     def _check_centralisation(self, cursor, user, ids):
@@ -776,10 +814,10 @@ class account_move(osv.osv):
 
     _constraints = [
         (_check_centralisation,
-            'You can not create more than one move per period on centralized journal',
+            'You cannot create more than one move per period on centralized journal',
             ['journal_id']),
         (_check_period_journal,
-            'You can not create entries on different period/journal in the same move',
+            'You cannot create entries on different periods/journals in the same move',
             ['line_id']),
     ]
     def post(self, cr, uid, ids, context=None):
@@ -789,15 +827,16 @@ class account_move(osv.osv):
                     new_name = False
                     journal = move.journal_id
                     if journal.sequence_id:
-                        new_name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id)
+                        c = {'fiscalyear_id': move.period_id.fiscalyear_id.id}
+                        new_name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id, context=c)
                     else:
                         raise osv.except_osv(_('Error'), _('No sequence defined in the journal !'))
                     if new_name:
                         self.write(cr, uid, [move.id], {'name':new_name})
 
-            cr.execute('update account_move set state=%s where id in ('+','.join(map(str,ids))+')', ('posted',))
+            cr.execute('update account_move set state=%s where id in ('+','.join(map(str, ids))+')', ('posted',))
         else:
-            raise osv.except_osv(_('Integrity Error !'), _('You can not validate a non balanced entry !'))
+            raise osv.except_osv(_('Integrity Error !'), _('You can not validate a non-balanced entry !'))
         return True
 
     def button_validate(self, cursor, user, ids, context=None):
@@ -806,9 +845,9 @@ class account_move(osv.osv):
     def button_cancel(self, cr, uid, ids, context={}):
         for line in self.browse(cr, uid, ids, context):
             if not line.journal_id.update_posted:
-                raise osv.except_osv(_('Error !'), _('You can not modify a posted entry of this journal !\nYou should mark the journal to allow canceling entries.'))
+                raise osv.except_osv(_('Error !'), _('You can not modify a posted entry of this journal !\nYou should set the journal to allow cancelling entries if you want to do that.'))
         if len(ids):
-            cr.execute('update account_move set state=%s where id in ('+','.join(map(str,ids))+')', ('draft',))
+            cr.execute('update account_move set state=%s where id in ('+','.join(map(str, ids))+')', ('draft',))
         return True
 
     def write(self, cr, uid, ids, vals, context={}):
@@ -860,7 +899,7 @@ class account_move(osv.osv):
     def unlink(self, cr, uid, ids, context={}, check=True):
         toremove = []
         for move in self.browse(cr, uid, ids, context):
-            if move['state'] <> 'draft':
+            if move['state'] != 'draft':
                 raise osv.except_osv(_('UserError'),
                         _('You can not delete posted movement: "%s"!') % \
                                 move['name'])
@@ -933,6 +972,8 @@ class account_move(osv.osv):
     # Validate a balanced move. If it is a centralised journal, create a move.
     #
     def validate(self, cr, uid, ids, context={}):
+        if context and ('__last_update' in context):
+            del context['__last_update']
         ok = True
         for move in self.browse(cr, uid, ids, context):
             #unlink analytic lines on move_lines
@@ -958,7 +999,7 @@ class account_move(osv.osv):
 
                 if line.account_id.currency_id:
                     if line.account_id.currency_id.id != line.currency_id.id and (line.account_id.currency_id.id != line.account_id.company_id.currency_id.id or line.currency_id):
-                            raise osv.except_osv(_('Error'), _("""Couldn't create move with currency different than the secondary currency of the account "%s - %s". Clear the secondary currency field of the account definition if you want to accept all currencies.""" % (line.account_id.code, line.account_id.name)))
+                        raise osv.except_osv(_('Error'), _("""Couldn't create move with currency different from the secondary currency of the account "%s - %s". Clear the secondary currency field of the account definition if you want to accept all currencies.""" % (line.account_id.code, line.account_id.name)))
 
             if abs(amount) < 0.0001:
                 if not len(line_draft_ids):
@@ -975,45 +1016,6 @@ class account_move(osv.osv):
                     continue
 
                 for line in move.line_id:
-                    if move.journal_id.type == 'sale':
-                        if line.debit:
-                            field_base = 'ref_'
-                            key = 'account_paid_id'
-                        else:
-                            field_base = ''
-                            key = 'account_collected_id'
-                    else:
-                        if line.debit:
-                            field_base = ''
-                            key = 'account_collected_id'
-                        else:
-                            field_base = 'ref_'
-                            key = 'account_paid_id'
-                    if line.account_id.tax_ids:
-                        code = amount = False
-                        for tax in line.account_id.tax_ids:
-                            if tax.tax_code_id:
-                                acc = getattr(tax, key).id
-                                account[acc] = (getattr(tax,
-                                    field_base + 'tax_code_id').id,
-                                    getattr(tax, field_base + 'tax_sign'))
-                                account2[(acc,getattr(tax,
-                                    field_base + 'tax_code_id').id)] = (getattr(tax,
-                                        field_base + 'tax_code_id').id,
-                                        getattr(tax, field_base + 'tax_sign'))
-                                code = getattr(tax, field_base + 'base_code_id').id
-                                amount = getattr(tax, field_base+'base_sign') * \
-                                        (line.debit + line.credit)
-                                break
-                        if code and not (line.tax_code_id or line.tax_amount):
-                            self.pool.get('account.move.line').write(cr, uid,
-                                    [line.id], {
-                                'tax_code_id': code,
-                                'tax_amount': amount
-                            }, context=context, check=False)
-                    else:
-                        todo.append(line)
-                for line in todo:
                     code = amount = 0
                     key = (line.account_id.id, line.tax_code_id.id)
                     if key in account2:
@@ -1061,7 +1063,7 @@ class account_move_reconcile(osv.osv):
     _columns = {
         'name': fields.char('Name', size=64, required=True),
         'type': fields.char('Type', size=16, required=True),
-        'line_id': fields.one2many('account.move.line', 'reconcile_id', 'Entry lines'),
+        'line_id': fields.one2many('account.move.line', 'reconcile_id', 'Entry Lines'),
         'line_partial_ids': fields.one2many('account.move.line', 'reconcile_partial_id', 'Partial Entry lines'),
         'create_date': fields.date('Creation date', readonly=True),
     }
@@ -1135,7 +1137,7 @@ class account_tax_code(osv.osv):
                 for rec in record.child_ids:
                     amount += _rec_get(rec) * rec.sign
                 return amount
-            res[record.id] = round(_rec_get(record), 2)
+            res[record.id] = round(_rec_get(record), int(config['price_accuracy']))
         return res
 
     def _sum_year(self, cr, uid, ids, name, args, context):
@@ -1145,9 +1147,9 @@ class account_tax_code(osv.osv):
             fiscalyear_id = self.pool.get('account.fiscalyear').find(cr, uid, exception=False)
         where = ''
         if fiscalyear_id:
-             pids = map(lambda x: str(x.id), self.pool.get('account.fiscalyear').browse(cr, uid, fiscalyear_id).period_ids)
-             if pids:
-                 where = ' and period_id in (' + (','.join(pids))+')'
+            pids = map(lambda x: str(x.id), self.pool.get('account.fiscalyear').browse(cr, uid, fiscalyear_id).period_ids)
+            if pids:
+                where = ' and period_id in (' + (','.join(pids))+')'
         return self._sum(cr, uid, ids, name, args, context,
                 where=where)
 
@@ -1172,11 +1174,11 @@ class account_tax_code(osv.osv):
         'sum': fields.function(_sum_year, method=True, string="Year Sum"),
         'sum_period': fields.function(_sum_period, method=True, string="Period Sum"),
         'parent_id': fields.many2one('account.tax.code', 'Parent Code', select=True),
-        'child_ids': fields.one2many('account.tax.code', 'parent_id', 'Childs Codes'),
+        'child_ids': fields.one2many('account.tax.code', 'parent_id', 'Child Codes'),
         'line_ids': fields.one2many('account.move.line', 'tax_code_id', 'Lines'),
         'company_id': fields.many2one('res.company', 'Company', required=True),
         'sign': fields.float('Sign for parent', required=True),
-        'notprintable':fields.boolean("Not Printable in Invoice", help="Check this box if you don't want that any vat related to this Tax Code appears on invoices"),
+        'notprintable':fields.boolean("Not Printable in Invoice", help="Check this box if you don't want any VAT related to this Tax Code to appear on invoices"),
     }
 
 
@@ -1202,7 +1204,7 @@ class account_tax_code(osv.osv):
     def _check_recursion(self, cr, uid, ids):
         level = 100
         while len(ids):
-            cr.execute('select distinct parent_id from account_tax_code where id in ('+','.join(map(str,ids))+')')
+            cr.execute('select distinct parent_id from account_tax_code where id in ('+','.join(map(str, ids))+')')
             ids = filter(None, map(lambda x:x[0], cr.fetchall()))
             if not level:
                 return False
@@ -1230,24 +1232,24 @@ class account_tax(osv.osv):
     _name = 'account.tax'
     _description = 'Tax'
     _columns = {
-        'name': fields.char('Tax Name', size=64, required=True, translate=True, help="This name will be used to be displayed on reports"),
-        'sequence': fields.integer('Sequence', required=True, help="The sequence field is used to order the taxes lines from the lowest sequences to the higher ones. The order is important if you have a tax that have several tax childs. In this case, the evaluation order is important."),
-        'amount': fields.float('Amount', required=True, digits=(14,4)),
+        'name': fields.char('Tax Name', size=64, required=True, translate=True, help="This name will be displayed on reports"),
+        'sequence': fields.integer('Sequence', required=True, help="The sequence field is used to order the tax lines from the lowest sequences to the higher ones. The order is important if you have a tax with several tax children. In this case, the evaluation order is important."),
+        'amount': fields.float('Amount', required=True, digits=(14,4), help="For Tax Type percent enter % ratio between 0-1."),
         'active': fields.boolean('Active'),
         'type': fields.selection( [('percent','Percent'), ('fixed','Fixed'), ('none','None'), ('code','Python Code'),('balance','Balance')], 'Tax Type', required=True,
             help="The computation method for the tax amount."),
         'applicable_type': fields.selection( [('true','True'), ('code','Python Code')], 'Applicable Type', required=True,
-            help="If not applicable (computed through a Python code), the tax do not appears on the invoice."),
-        'domain':fields.char('Domain', size=32, help="This field is only used if you develop your own module allowing developpers to create specific taxes in a custom domain."),
+            help="If not applicable (computed through a Python code), the tax won't appear on the invoice."),
+        'domain':fields.char('Domain', size=32, help="This field is only used if you develop your own module allowing developers to create specific taxes in a custom domain."),
         'account_collected_id':fields.many2one('account.account', 'Invoice Tax Account'),
         'account_paid_id':fields.many2one('account.account', 'Refund Tax Account'),
         'parent_id':fields.many2one('account.tax', 'Parent Tax Account', select=True),
-        'child_ids':fields.one2many('account.tax', 'parent_id', 'Childs Tax Account'),
-        'child_depend':fields.boolean('Tax on Childs', help="Indicate if the tax computation is based on the value computed for the computation of child taxes or based on the total amount."),
+        'child_ids':fields.one2many('account.tax', 'parent_id', 'Child Tax Accounts'),
+        'child_depend':fields.boolean('Tax on Children', help="Set if the tax computation is based on the computation of child taxes rather than on the total amount."),
         'python_compute':fields.text('Python Code'),
         'python_compute_inv':fields.text('Python Code (reverse)'),
         'python_applicable':fields.text('Python Code'),
-        'tax_group': fields.selection([('vat','VAT'),('other','Other')], 'Tax Group', help="If a default tax if given in the partner it only override taxes from account (or product) of the same group."),
+        'tax_group': fields.selection([('vat','VAT'),('other','Other')], 'Tax Group', help="If a default tax is given in the partner it only overrides taxes from accounts (or products) in the same group."),
 
         #
         # Fields used for the VAT declaration
@@ -1266,8 +1268,18 @@ class account_tax(osv.osv):
         'include_base_amount': fields.boolean('Include in base amount', help="Indicate if the amount of tax must be included in the base amount for the computation of the next taxes"),
         'company_id': fields.many2one('res.company', 'Company', required=True),
         'description': fields.char('Tax Code',size=32),
-        'price_include': fields.boolean('Tax Included in Price', help="Check this is the price you use on the product and invoices is including this tax.")
+        'price_include': fields.boolean('Tax Included in Price', help="Check this if the price you use on the product and invoices includes this tax."),
+        'type_tax_use': fields.selection([('sale','Sale'),('purchase','Purchase'),('all','All')], 'Tax Application', required=True)
+
     }
+    def search(self, cr, uid, args, offset=0, limit=None, order=None,
+            context=None, count=False):
+        if context and context.has_key('type'):
+            if context['type'] in ('out_invoice','out_refund'):
+                args.append(('type_tax_use','in',['sale','all']))
+            elif context['type'] in ('in_invoice','in_refund'):
+                args.append(('type_tax_use','in',['purchase','all']))
+        return super(account_tax, self).search(cr, uid, args, offset, limit, order, context, count)
 
     def name_get(self, cr, uid, ids, context={}):
         if not len(ids):
@@ -1291,6 +1303,7 @@ class account_tax(osv.osv):
         'amount': lambda *a: 0,
         'price_include': lambda *a: 0,
         'active': lambda *a: 1,
+        'type_tax_use': lambda *a: 'all',
         'sequence': lambda *a: 1,
         'tax_group': lambda *a: 'vat',
         'ref_tax_sign': lambda *a: 1,
@@ -1314,7 +1327,7 @@ class account_tax(osv.osv):
                 res.append(tax)
         return res
 
-    def _unit_compute(self, cr, uid, taxes, price_unit, address_id=None, product=None, partner=None):
+    def _unit_compute(self, cr, uid, taxes, price_unit, address_id=None, product=None, partner=None, quantity=0):
         taxes = self._applicable(cr, uid, taxes, price_unit, address_id, product, partner)
 
         res = []
@@ -1323,7 +1336,7 @@ class account_tax(osv.osv):
             # we compute the amount for the current tax object and append it to the result
 
             data = {'id':tax.id,
-                            'name':tax.name,
+                            'name':tax.description and tax.description + " - " + tax.name or tax.name,
                             'account_collected_id':tax.account_collected_id.id,
                             'account_paid_id':tax.account_paid_id.id,
                             'base_code_id': tax.base_code_id.id,
@@ -1344,6 +1357,8 @@ class account_tax(osv.osv):
 
             elif tax.type=='fixed':
                 data['amount'] = tax.amount
+                data['tax_amount']=quantity
+               # data['amount'] = quantity
             elif tax.type=='code':
                 address = address_id and self.pool.get('res.partner.address').browse(cr, uid, address_id) or None
                 localdict = {'price_unit':cur_price_unit, 'address':address, 'product':product, 'partner':partner}
@@ -1359,7 +1374,7 @@ class account_tax(osv.osv):
                 if tax.child_depend:
                     latest = res.pop()
                 amount = amount2
-                child_tax = self._unit_compute(cr, uid, tax.child_ids, amount, address_id, product, partner)
+                child_tax = self._unit_compute(cr, uid, tax.child_ids, amount, address_id, product, partner, quantity)
                 res.extend(child_tax)
                 if tax.child_depend:
                     for r in res:
@@ -1389,13 +1404,13 @@ class account_tax(osv.osv):
             tax = {'name':'', 'amount':0.0, 'account_collected_id':1, 'account_paid_id':2}
             one tax for each tax id in IDS and their childs
         """
-        res = self._unit_compute(cr, uid, taxes, price_unit, address_id, product, partner)
+        res = self._unit_compute(cr, uid, taxes, price_unit, address_id, product, partner, quantity)
         total = 0.0
         for r in res:
             if r.get('balance',False):
-                r['amount'] = round(r['balance'] * quantity, 2) - total
+                r['amount'] = round(r['balance'] * quantity, int(config['price_accuracy'])) - total
             else:
-                r['amount'] = round(r['amount'] * quantity, 2)
+                r['amount'] = round(r['amount'] * quantity, int(config['price_accuracy']))
                 total += r['amount']
 
         return res
@@ -1405,12 +1420,16 @@ class account_tax(osv.osv):
 
         res = []
         taxes.reverse()
-        cur_price_unit=price_unit
+        cur_price_unit = price_unit
 
         tax_parent_tot = 0.0
         for tax in taxes:
             if (tax.type=='percent') and not tax.include_base_amount:
-                tax_parent_tot+=tax.amount
+                tax_parent_tot += tax.amount
+
+        for tax in taxes:
+            if (tax.type=='fixed') and not tax.include_base_amount:
+                cur_price_unit -= tax.amount
 
         for tax in taxes:
             if tax.type=='percent':
@@ -1486,9 +1505,9 @@ class account_tax(osv.osv):
         total = 0.0
         for r in res:
             if r.get('balance',False):
-                r['amount'] = round(r['balance'] * quantity, 2) - total
+                r['amount'] = round(r['balance'] * quantity, int(config['price_accuracy'])) - total
             else:
-                r['amount'] = round(r['amount'] * quantity, 2)
+                r['amount'] = round(r['amount'] * quantity, int(config['price_accuracy']))
                 total += r['amount']
         return res
 account_tax()
@@ -1510,9 +1529,42 @@ class account_model(osv.osv):
 
     _defaults = {
         'legend': lambda self, cr, uid, context:_('You can specify year, month and date in the name of the model using the following labels:\n\n%(year)s : To Specify Year \n%(month)s : To Specify Month \n%(date)s : Current Date\n\ne.g. My model on %(date)s'),
-
     }
-
+    def generate(self, cr, uid, ids, datas={}, context={}):
+        move_ids = []
+        for model in self.browse(cr, uid, ids, context):
+            period_id = self.pool.get('account.period').find(cr,uid, context=context)
+            if not period_id:
+                raise osv.except_osv(_('No period found !'), _('Unable to find a valid period !'))
+            period_id = period_id[0]
+            move_id = self.pool.get('account.move').create(cr, uid, {
+                'ref': model.ref,
+                'period_id': period_id,
+                'journal_id': model.journal_id.id,
+            })
+            move_ids.append(move_id)
+            for line in model.lines_id:
+                val = {
+                    'move_id': move_id,
+                    'journal_id': model.journal_id.id,
+                    'period_id': period_id
+                }
+                val.update({
+                    'name': line.name,
+                    'quantity': line.quantity,
+                    'debit': line.debit,
+                    'credit': line.credit,
+                    'account_id': line.account_id.id,
+                    'move_id': move_id,
+                    'ref': line.ref,
+                    'partner_id': line.partner_id.id,
+                    'date': time.strftime('%Y-%m-%d'),
+                    'date_maturity': time.strftime('%Y-%m-%d')
+                })
+                c = context.copy()
+                c.update({'journal_id': model.journal_id.id,'period_id': period_id})
+                self.pool.get('account.move.line').create(cr, uid, val, context=c)
+        return move_ids
 account_model()
 
 class account_model_line(osv.osv):
@@ -1520,10 +1572,10 @@ class account_model_line(osv.osv):
     _description = "Account Model Entries"
     _columns = {
         'name': fields.char('Name', size=64, required=True),
-        'sequence': fields.integer('Sequence', required=True, help="The sequence field is used to order the resources from the lowest sequences to the higher ones"),
-        'quantity': fields.float('Quantity', digits=(16,2), help="The optionnal quantity on entries"),
-        'debit': fields.float('Debit', digits=(16,2)),
-        'credit': fields.float('Credit', digits=(16,2)),
+        'sequence': fields.integer('Sequence', required=True, help="The sequence field is used to order the resources from lower sequences to higher ones"),
+        'quantity': fields.float('Quantity', digits=(16, int(config['price_accuracy'])), help="The optional quantity on entries"),
+        'debit': fields.float('Debit', digits=(16, int(config['price_accuracy']))),
+        'credit': fields.float('Credit', digits=(16, int(config['price_accuracy']))),
 
         'account_id': fields.many2one('account.account', 'Account', required=True, ondelete="cascade"),
 
@@ -1531,7 +1583,7 @@ class account_model_line(osv.osv):
 
         'ref': fields.char('Ref.', size=16),
 
-        'amount_currency': fields.float('Amount Currency', help="The amount expressed in an optionnal other currency."),
+        'amount_currency': fields.float('Amount Currency', help="The amount expressed in an optional other currency."),
         'currency_id': fields.many2one('res.currency', 'Currency'),
 
         'partner_id': fields.many2one('res.partner', 'Partner Ref.'),
@@ -1558,14 +1610,14 @@ class account_subscription(osv.osv):
     _description = "Account Subscription"
     _columns = {
         'name': fields.char('Name', size=64, required=True),
-        'ref': fields.char('Ref.', size=16),
+        'ref': fields.char('Ref', size=16),
         'model_id': fields.many2one('account.model', 'Model', required=True),
 
-        'date_start': fields.date('Starting date', required=True),
-        'period_total': fields.integer('Number of period', required=True),
+        'date_start': fields.date('Start Date', required=True),
+        'period_total': fields.integer('Number of Periods', required=True),
         'period_nbr': fields.integer('Period', required=True),
         'period_type': fields.selection([('day','days'),('month','month'),('year','year')], 'Period Type', required=True),
-        'state': fields.selection([('draft','Draft'),('running','Running'),('done','Done')], 'Status', required=True, readonly=True),
+        'state': fields.selection([('draft','Draft'),('running','Running'),('done','Done')], 'State', required=True, readonly=True),
 
         'lines_id': fields.one2many('account.subscription.line', 'subscription_id', 'Subscription Lines')
     }
@@ -1663,8 +1715,8 @@ class account_config_wizard(osv.osv_memory):
     _columns = {
         'name':fields.char('Name', required=True, size=64, help="Name of the fiscal year as displayed on screens."),
         'code':fields.char('Code', required=True, size=64, help="Name of the fiscal year as displayed in reports."),
-        'date1': fields.date('Starting Date', required=True),
-        'date2': fields.date('Ending Date', required=True),
+        'date1': fields.date('Start Date', required=True),
+        'date2': fields.date('End Date', required=True),
         'period':fields.selection([('month','Month'),('3months','3 Months')], 'Periods', required=True),
         'charts' : fields.selection(_get_charts, 'Charts of Account',required=True)
     }
@@ -1749,9 +1801,14 @@ class account_account_template(osv.osv):
             ('consolidation','Consolidation'),
             ('other','Others'),
             ('closed','Closed'),
-            ], 'Internal Type', required=True,),
-        'user_type': fields.many2one('account.account.type', 'Account Type', required=True),
-        'reconcile': fields.boolean('Allow Reconciliation', help="Check this option if the user can make a reconciliation of the entries in this account."),
+            ], 'Internal Type', required=True,help="This type is used to differenciate types with "\
+            "special effects in Open ERP: view can not have entries, consolidation are accounts that "\
+            "can have children accounts for multi-company consolidations, payable/receivable are for "\
+            "partners accounts (for debit/credit computations), closed for deprecated accounts."),
+        'user_type': fields.many2one('account.account.type', 'Account Type', required=True,
+            help="These types are defined according to your country. The type contain more information "\
+            "about the account and it's specificities."),
+        'reconcile': fields.boolean('Allow Reconciliation', help="Check this option if you want the user to reconcile entries in this account."),
         'shortcut': fields.char('Shortcut', size=12),
         'note': fields.text('Note'),
         'parent_id': fields.many2one('account.account.template','Parent Account Template', ondelete='cascade'),
@@ -1767,7 +1824,7 @@ class account_account_template(osv.osv):
     def _check_recursion(self, cr, uid, ids):
         level = 100
         while len(ids):
-            cr.execute('select parent_id from account_account_template where id in ('+','.join(map(str,ids))+')')
+            cr.execute('select parent_id from account_account_template where id in ('+','.join(map(str, ids))+')')
             ids = filter(None, map(lambda x:x[0], cr.fetchall()))
             if not level:
                 return False
@@ -1804,9 +1861,9 @@ class account_tax_code_template(osv.osv):
         'code': fields.char('Case Code', size=64),
         'info': fields.text('Description'),
         'parent_id': fields.many2one('account.tax.code.template', 'Parent Code', select=True),
-        'child_ids': fields.one2many('account.tax.code.template', 'parent_id', 'Childs Codes'),
+        'child_ids': fields.one2many('account.tax.code.template', 'parent_id', 'Child Codes'),
         'sign': fields.float('Sign for parent', required=True),
-        'notprintable':fields.boolean("Not Printable in Invoice", help="Check this box if you don't want that any vat related to this Tax Code appears on invoices"),
+        'notprintable':fields.boolean("Not Printable in Invoice", help="Check this box if you don't want any VAT related to this Tax Code to appear on invoices"),
     }
 
     _defaults = {
@@ -1826,7 +1883,7 @@ class account_tax_code_template(osv.osv):
     def _check_recursion(self, cr, uid, ids):
         level = 100
         while len(ids):
-            cr.execute('select distinct parent_id from account_tax_code_template where id in ('+','.join(map(str,ids))+')')
+            cr.execute('select distinct parent_id from account_tax_code_template where id in ('+','.join(map(str, ids))+')')
             ids = filter(None, map(lambda x:x[0], cr.fetchall()))
             if not level:
                 return False
@@ -1868,7 +1925,7 @@ class account_tax_template(osv.osv):
     _columns = {
         'chart_template_id': fields.many2one('account.chart.template', 'Chart Template', required=True),
         'name': fields.char('Tax Name', size=64, required=True),
-        'sequence': fields.integer('Sequence', required=True, help="The sequence field is used to order the taxes lines from the lowest sequences to the higher ones. The order is important if you have a tax that have several tax children. In this case, the evaluation order is important."),
+        'sequence': fields.integer('Sequence', required=True, help="The sequence field is used to order the taxes lines from lower sequences to higher ones. The order is important if you have a tax that has several tax children. In this case, the evaluation order is important."),
         'amount': fields.float('Amount', required=True, digits=(14,4)),
         'type': fields.selection( [('percent','Percent'), ('fixed','Fixed'), ('none','None'), ('code','Python Code')], 'Tax Type', required=True),
         'applicable_type': fields.selection( [('true','True'), ('code','Python Code')], 'Applicable Type', required=True),
@@ -1876,7 +1933,7 @@ class account_tax_template(osv.osv):
         'account_collected_id':fields.many2one('account.account.template', 'Invoice Tax Account'),
         'account_paid_id':fields.many2one('account.account.template', 'Refund Tax Account'),
         'parent_id':fields.many2one('account.tax.template', 'Parent Tax Account', select=True),
-        'child_depend':fields.boolean('Tax on Childs', help="Indicate if the tax computation is based on the value computed for the computation of child taxes or based on the total amount."),
+        'child_depend':fields.boolean('Tax on Children', help="Indicate if the tax computation is based on the value computed for the computation of child taxes or based on the total amount."),
         'python_compute':fields.text('Python Code'),
         'python_compute_inv':fields.text('Python Code (reverse)'),
         'python_applicable':fields.text('Python Code'),
@@ -1896,8 +1953,9 @@ class account_tax_template(osv.osv):
         'ref_tax_code_id': fields.many2one('account.tax.code.template', 'Refund Tax Code', help="Use this code for the VAT declaration."),
         'ref_base_sign': fields.float('Base Code Sign', help="Usually 1 or -1."),
         'ref_tax_sign': fields.float('Tax Code Sign', help="Usually 1 or -1."),
-        'include_base_amount': fields.boolean('Include in base amount', help="Indicate if the amount of tax must be included in the base amount for the computation of the next taxes."),
+        'include_base_amount': fields.boolean('Include in Base Amount', help="Set if the amount of tax must be included in the base amount before computing the next taxes."),
         'description': fields.char('Internal Name', size=32),
+        'type_tax_use': fields.selection([('sale','Sale'),('purchase','Purchase'),('all','All')], 'Tax Use In', required=True,)
     }
 
     def name_get(self, cr, uid, ids, context={}):
@@ -1928,6 +1986,7 @@ class account_tax_template(osv.osv):
         'tax_sign': lambda *a: 1,
         'base_sign': lambda *a: 1,
         'include_base_amount': lambda *a: False,
+        'type_tax_use': lambda *a: 'all',
     }
     _order = 'sequence'
 
@@ -1943,15 +2002,15 @@ class account_fiscal_position_template(osv.osv):
     _columns = {
         'name': fields.char('Fiscal Position Template', size=64, translate=True, required=True),
         'chart_template_id': fields.many2one('account.chart.template', 'Chart Template', required=True),
-        'account_ids': fields.one2many('account.fiscal.position.account.template', 'position_id', 'Accounts Mapping'),
-        'tax_ids': fields.one2many('account.fiscal.position.tax.template', 'position_id', 'Taxes Mapping')
+        'account_ids': fields.one2many('account.fiscal.position.account.template', 'position_id', 'Account Mapping'),
+        'tax_ids': fields.one2many('account.fiscal.position.tax.template', 'position_id', 'Tax Mapping')
     }
 
 account_fiscal_position_template()
 
 class account_fiscal_position_tax_template(osv.osv):
     _name = 'account.fiscal.position.tax.template'
-    _description = 'Fiscal Position Template Taxes Mapping'
+    _description = 'Fiscal Position Template Tax Mapping'
     _rec_name = 'position_id'
 
     _columns = {
@@ -1964,7 +2023,7 @@ account_fiscal_position_tax_template()
 
 class account_fiscal_position_account_template(osv.osv):
     _name = 'account.fiscal.position.account.template'
-    _description = 'Fiscal Position Template Accounts Mapping'
+    _description = 'Fiscal Position Template Account Mapping'
     _rec_name = 'position_id'
     _columns = {
         'position_id': fields.many2one('account.fiscal.position.template', 'Fiscal Position', required=True, ondelete='cascade'),
@@ -1979,15 +2038,15 @@ account_fiscal_position_account_template()
 class wizard_multi_charts_accounts(osv.osv_memory):
     """
     Create a new account chart for a company.
-    Wizards ask:
+    Wizards ask for:
         * a company
         * an account chart template
         * a number of digits for formatting code of non-view accounts
-        * a list of bank account owned by the company
+        * a list of bank accounts owned by the company
     Then, the wizard:
-        * generates all accounts from the template and assign them to the right company
+        * generates all accounts from the template and assigns them to the right company
         * generates all taxes and tax codes, changing account assignations
-        * generates all accounting properties and assign correctly
+        * generates all accounting properties and assigns them correctly
     """
     _name='wizard.multi.charts.accounts'
 
@@ -2073,6 +2132,7 @@ class wizard_multi_charts_accounts(osv.osv_memory):
                 'include_base_amount': tax.include_base_amount,
                 'description':tax.description,
                 'company_id': company_id,
+                'type_tax_use': tax.type_tax_use
             }
             new_tax = obj_acc_tax.create(cr,uid,vals_tax)
             #as the accounts have not been created yet, we have to wait before filling these fields
@@ -2120,7 +2180,7 @@ class wizard_multi_charts_accounts(osv.osv_memory):
 
         for key,value in todo_dict.items():
             if value['account_collected_id'] or value['account_paid_id']:
-                obj_acc_tax.write(cr, uid, [key], vals={
+                obj_acc_tax.write(cr, uid, [key], {
                     'account_collected_id': acc_template_ref[value['account_collected_id']],
                     'account_paid_id': acc_template_ref[value['account_paid_id']],
                 })
@@ -2129,7 +2189,7 @@ class wizard_multi_charts_accounts(osv.osv_memory):
         vals_journal={}
         view_id = self.pool.get('account.journal.view').search(cr,uid,[('name','=','Journal View')])[0]
         seq_id = obj_sequence.search(cr,uid,[('name','=','Account Journal')])[0]
-        
+
         if obj_multi.seq_journal:
             seq_id_sale = obj_sequence.search(cr,uid,[('name','=','Sale Journal')])[0]
             seq_id_purchase = obj_sequence.search(cr,uid,[('name','=','Purchase Journal')])[0]
@@ -2173,10 +2233,15 @@ class wizard_multi_charts_accounts(osv.osv_memory):
             #create the account_account for this bank journal
             tmp = self.pool.get('res.partner.bank').name_get(cr, uid, [line.acc_no.id])[0][1]
             dig = obj_multi.code_digits
+            if ref_acc_bank.code:
+                try:
+                    new_code = str(int(ref_acc_bank.code.ljust(dig,'0')) + current_num)
+                except Exception,e:
+                    new_code = str(ref_acc_bank.code.ljust(dig-len(str(current_num)),'0')) + str(current_num)
             vals = {
                 'name': line.acc_no.bank and line.acc_no.bank.name+' '+tmp or tmp,
                 'currency_id': line.currency_id and line.currency_id.id or False,
-                'code': str(ref_acc_bank.code.ljust(dig,'0') + str(current_num)),
+                'code': new_code,
                 'type': 'other',
                 'user_type': account_template.user_type and account_template.user_type.id or False,
                 'reconcile': True,
@@ -2255,7 +2320,7 @@ class wizard_multi_charts_accounts(osv.osv_memory):
                 for tax in position.tax_ids:
                     vals_tax = {
                                 'tax_src_id' : tax_template_ref[tax.tax_src_id.id],
-                                'tax_dest_id' : tax_template_ref[tax.tax_dest_id.id],
+                                'tax_dest_id' : tax.tax_dest_id and tax_template_ref[tax.tax_dest_id.id] or False,
                                 'position_id' : new_fp,
                                 }
                     obj_tax_fp.create(cr, uid, vals_tax)