diff --git a/addons/account/__init__.py b/addons/account/__init__.py index 8e83d9aa7a7..da397978bd2 100644 --- a/addons/account/__init__.py +++ b/addons/account/__init__.py @@ -33,5 +33,4 @@ import product import sequence import company -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py index 51724f47d33..39e40555f39 100644 --- a/addons/account/__openerp__.py +++ b/addons/account/__openerp__.py @@ -23,7 +23,7 @@ { "name" : "Accounting and Financial Management", "version" : "1.1", - "depends" : ["product", "analytic", "process"], + "depends" : ["product", "analytic", "process","board"], "author" : "Tiny", "category": 'Generic Modules/Accounting', "description": """Financial and accounting module that covers: @@ -34,10 +34,15 @@ Budgets Customer and Supplier Invoices Bank statements + Reconciliation process by partner + Creates a dashboards for accountants that includes: + * List of uninvoiced quotations + * Graph of aged receivables + * Graph of aged incomes The processes like maintaining of general ledger is done through the defined financial Journals (entry move line or grouping is maintained through journal) for a particular financial year and for preparation of vouchers there is a -module named account_voucherss +module named account_vouchers """, 'website': 'http://www.openerp.com', 'init_xml': [], @@ -81,6 +86,7 @@ module named account_voucherss 'wizard/account_compare_account_balance_report_view.xml', 'wizard/account_third_party_ledger.xml', 'wizard/account_reconcile_view.xml', + 'wizard/account_reconcile_partner_process_view.xml', 'wizard/account_automatic_reconcile_view.xml', 'project/wizard/project_account_analytic_line_view.xml', 'account_end_fy.xml', @@ -111,7 +117,8 @@ module named account_voucherss 'report/account_report_view.xml', 'report/account_analytic_report_view.xml', 'report/account_account_report_view.xml', - 'report/account_analytic_entries_report_view.xml' + 'report/account_analytic_entries_report_view.xml', + 'board_account_view.xml', ], 'demo_xml': [ #'demo/price_accuracy00.yml', @@ -120,10 +127,19 @@ module named account_voucherss 'project/analytic_account_demo.xml', 'demo/account_minimal.xml', 'account_unit_test.xml', + 'board_account_demo.xml', ], 'test': [ 'test/account_customer_invoice.yml', 'test/account_supplier_invoice.yml', + 'test/account_change_currency.yml', + 'test/chart_of_account.yml', + 'test/account_period_close.yml', + 'test/account_fiscalyear_close_state.yml', + 'test/account_invoice_state.yml', + 'test/account_use_model.yml', + 'test/account_validate_account_move.yml', +# 'test/account_fiscalyear_close.yml', ], 'installable': True, 'active': False, diff --git a/addons/account/account.py b/addons/account/account.py index e30912aa187..06060f59e28 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -18,21 +18,38 @@ # along with this program. If not, see . # ############################################################################## - import time -import netsvc - -from osv import fields, osv -import decimal_precision as dp - -from tools.misc import currency -from tools.translate import _ -import pooler from datetime import datetime from dateutil.relativedelta import relativedelta +from operator import itemgetter +import netsvc +import pooler +from osv import fields, osv +import decimal_precision as dp +from tools.misc import currency +from tools.translate import _ from tools import config +def check_cycle(self, cr, uid, ids): + """ climbs the ``self._table.parent_id`` chains for 100 levels or + until it can't find any more parent(s) + + Returns true if it runs out of parents (no cycle), false if + it can recurse 100 times without ending all chains + """ + level = 100 + while len(ids): + cr.execute('SELECT DISTINCT parent_id '\ + 'FROM '+self._table+' '\ + 'WHERE id IN %s '\ + 'AND parent_id IS NOT NULL',(tuple(ids),)) + ids = map(itemgetter(0), cr.fetchall()) + if not level: + return False + level -= 1 + return True + class account_payment_term(osv.osv): _name = "account.payment.term" _description = "Payment Term" @@ -62,7 +79,7 @@ class account_payment_term(osv.osv): elif line.value == 'balance': amt = round(amount, prec) if amt: - next_date = datetime.strptime(date_ref, '%y-%m-%d') + relativedelta(days=line.days) + next_date = datetime.strptime(date_ref, '%Y-%m-%d') + relativedelta(days=line.days) if line.days2 < 0: next_date += relativedelta(day=line.days2) if line.days2 > 0: @@ -170,6 +187,7 @@ class account_account(osv.osv): _name = "account.account" _description = "Account" _parent_store = True + logger = netsvc.Logger() def _get_children_and_consol(self, cr, uid, ids, context={}): ids2=[] @@ -229,65 +247,87 @@ class account_account(osv.osv): ids3 = self._get_children_and_consol(cr, uid, ids3, context) 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 - mapping = { - 'balance': "COALESCE(SUM(l.debit),0) - COALESCE(SUM(l.credit), 0) as balance ", - 'debit': "COALESCE(SUM(l.debit), 0) as debit ", - 'credit': "COALESCE(SUM(l.credit), 0) as credit " - } - #get all the necessary accounts - ids2 = self._get_children_and_consol(cr, uid, ids, context) - #compute for each account the balance/debit/credit from the move lines - accounts = {} - if ids2: - aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context) + def __compute(self, cr, uid, ids, field_names, arg=None, context=None, + query='', query_params=()): + """ compute the balance, debit and/or credit for the provided + account ids + Arguments: + `ids`: account ids + `field_names`: the fields to compute (a list of any of + 'balance', 'debit' and 'credit') + `arg`: unused fields.function stuff + `query`: additional query filter (as a string) + `query_params`: parameters for the provided query string + (__compute will handle their escaping) as a + tuple + """ + mapping = { + 'balance': "COALESCE(SUM(l.debit),0) " \ + "- COALESCE(SUM(l.credit), 0) as balance", + 'debit': "COALESCE(SUM(l.debit), 0) as debit", + 'credit': "COALESCE(SUM(l.credit), 0) as credit" + } + #get all the necessary accounts + children_and_consolidated = self._get_children_and_consol(cr, uid, ids, context=context) + #compute for each account the balance/debit/credit from the move lines + accounts = {} + if children_and_consolidated: + aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context) - wheres = [""] - if query.strip(): - wheres.append(query.strip()) - if aml_query.strip(): - wheres.append(aml_query.strip()) - query = " AND ".join(wheres) + wheres = [""] + if query.strip(): + wheres.append(query.strip()) + if aml_query.strip(): + wheres.append(aml_query.strip()) + filters = " AND ".join(wheres) + self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG, + 'Filters: %s'%filters) + # IN might not work ideally in case there are too many + # children_and_consolidated, in that case join on a + # values() e.g.: + # SELECT l.account_id as id FROM account_move_line l + # INNER JOIN (VALUES (id1), (id2), (id3), ...) AS tmp (id) + # ON l.account_id = tmp.id + # or make _get_children_and_consol return a query and join on that + request = ("SELECT l.account_id as id, " +\ + ' , '.join(map(mapping.__getitem__, field_names)) + + " FROM account_move_line l" \ + " WHERE l.account_id IN %s " \ + + filters + + " GROUP BY l.account_id") + params = (tuple(children_and_consolidated),) + query_params + cr.execute(request, params) + self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG, + 'Status: %s'%cr.statusmessage) - cr.execute("SELECT l.account_id as id, " +\ - ' , '.join(map(lambda x: mapping[x], field_names)) + - "FROM " \ - "account_move_line l " \ - "WHERE " \ - "l.account_id =ANY(%s) " \ - + query + - " GROUP BY l.account_id",(ids2,)) + for res in cr.dictfetchall(): + accounts[res['id']] = res - for res in cr.dictfetchall(): - accounts[res['id']] = res - - - # consolidate accounts with direct children - ids2.reverse() - brs = list(self.browse(cr, uid, ids2, context=context)) - sums = {} - while brs: - current = brs[0] - can_compute = True - for child in current.child_id: - if child.id not in sums: - can_compute = False - try: - brs.insert(0, brs.pop(brs.index(child))) - except ValueError: - brs.insert(0, child) - if can_compute: - brs.pop(0) - for fn in field_names: - sums.setdefault(current.id, {})[fn] = accounts.get(current.id, {}).get(fn, 0.0) - if current.child_id: - sums[current.id][fn] += sum(sums[child.id][fn] for child in current.child_id) - res = {} - null_result = dict((fn, 0.0) for fn in field_names) - for id in ids: - res[id] = sums.get(id, null_result) - return res + # consolidate accounts with direct children + children_and_consolidated.reverse() + brs = list(self.browse(cr, uid, children_and_consolidated, context=context)) + sums = {} + while brs: + current = brs[0] + can_compute = True + for child in current.child_id: + if child.id not in sums: + can_compute = False + try: + brs.insert(0, brs.pop(brs.index(child))) + except ValueError: + brs.insert(0, child) + if can_compute: + brs.pop(0) + for fn in field_names: + sums.setdefault(current.id, {})[fn] = accounts.get(current.id, {}).get(fn, 0.0) + if current.child_id: + sums[current.id][fn] += sum(sums[child.id][fn] for child in current.child_id) + res = {} + null_result = dict((fn, 0.0) for fn in field_names) + for id in ids: + res[id] = sums.get(id, null_result) + return res def _get_company_currency(self, cr, uid, ids, field_name, arg, context={}): result = {} @@ -392,8 +432,10 @@ class account_account(osv.osv): 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 =ANY(%s)',(ids,)) - child_ids = filter(None, map(lambda x: x[0], cr.fetchall())) + cr.execute('SELECT DISTINCT child_id '\ + 'FROM account_account_consol_rel '\ + 'WHERE parent_id IN %s', (tuple(ids),)) + child_ids = map(itemgetter(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 @@ -509,8 +551,13 @@ class account_account(osv.osv): def write(self, cr, uid, ids, vals, context=None): if context is None: context = {} + + if 'company_id' in vals: + move_lines = self.pool.get('account.move.line').search(cr, uid, [('account_id', 'in', ids)]) + if move_lines: + raise osv.except_osv(_('Warning !'), _('You cannot modify Company of account as its related record exist in Entry Lines')) if 'active' in vals and not vals['active']: - self._check_moves(cr, uid, ids, "write", context) + self._check_moves(cr, uid, ids, "write", context=context) if 'type' in vals.keys(): self._check_allow_type_change(cr, uid, ids, vals['type'], context=context) return super(account_account, self).write(cr, uid, ids, vals, context=context) @@ -557,42 +604,46 @@ class account_journal(osv.osv): _name = "account.journal" _description = "Journal" _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'), ('expense', 'Expense'), ('cash', 'Cash'), ('bank', 'Bank'), ('general', 'General'), ('situation', 'Situation')], 'Type', size=32, required=True, + 'name': fields.char('Journal Name', size=64, required=True, translate=True,help="Name of the journal"), + 'code': fields.char('Code', size=16,required=True,help="Code of the journal"), + 'type': fields.selection([('sale', 'Sale'),('sale_refund','Sale Refund'), ('purchase', 'Purchase'), ('purchase_refund','Purchase Refund'),('expense', 'Expense'), ('cash', 'Cash'), ('bank', 'Bank'), ('general', 'General'), ('situation', 'Situation')], 'Type', size=32, required=True, help="Select 'Sale' for Sale journal to be used at the time of making invoice."\ " Select 'Purchase' for Purchase Journal to be used at the time of approving purchase order."\ " Select 'Cash' to be used at the time of making payment."\ " Select 'General' to be used at the time of stock input/output."\ " Select 'Situation' to be used at the time of making vouchers."), 'refund_journal': fields.boolean('Refund Journal', help='Fill this if the journal is to be used for refunds of invoices.'), - 'type_control_ids': fields.many2many('account.account.type', 'account_journal_type_rel', 'journal_id','type_id', 'Type Controls', domain=[('code','<>','view'), ('code', '<>', 'closed')]), 'account_control_ids': fields.many2many('account.account', 'account_account_type_rel', 'journal_id','account_id', 'Account', domain=[('type','<>','view'), ('type', '<>', 'closed')]), - - 'active': fields.boolean('Active', help="If the active field is set to true, it will allow you to hide the journal without removing it."), - '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 tells 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')]"), + 'view_id': fields.many2one('account.journal.view', 'Display Mode', required=True, help="Gives the view used when writing or browsing entries in this journal. The view tells 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')]", help="It acts as a default account for credit amount"), + 'default_debit_account_id': fields.many2one('account.account', 'Default Debit Account', domain="[('type','!=','view')]", help="It acts as a default account for debit amount"), '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'), + 'update_posted': fields.boolean('Allow Cancelling Entries', help="Check this box if you want to allow the cancellation the entries related to this journal or of the invoice related to this journal"), '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 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 new account moves to pass through the \'draft\' state and instead goes directly to the \'posted state\' without any manual validation.'), - 'company_id': fields.many2one('res.company', 'Company', required=True,select=1), + 'company_id': fields.many2one('res.company', 'Company', required=True, select=1, help="Company related to this journal"), 'invoice_sequence_id': fields.many2one('ir.sequence', 'Invoice Sequence', \ help="The sequence used for invoice numbers in this journal."), 'allow_date':fields.boolean('Check Date not in the Period', help= 'If set to True then do not accept the entry if the entry date is not into the period dates'), } _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 write(self, cr, uid, ids, vals, context=None): + obj=[] + if 'company_id' in vals: + move_lines = self.pool.get('account.move.line').search(cr, uid, [('journal_id', 'in', ids)]) + if move_lines: + raise osv.except_osv(_('Warning !'), _('You cannot modify company of this journal as its related record exist in Entry Lines')) + return super(account_journal, self).write(cr, uid, ids, vals, context=context) + def create(self, 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 @@ -618,6 +669,15 @@ class account_journal(osv.osv): ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit, context=context) return self.name_get(cr, user, ids, context=context) + def onchange_type(self, cr, uid, ids, type): + res={} + for line in self.browse(cr, uid, ids): + if type == 'situation': + res= {'value':{'centralisation': True}} + else: + res= {'value':{'centralisation': False}} + return res + account_journal() class account_fiscalyear(osv.osv): @@ -711,7 +771,7 @@ class account_period(osv.osv): 'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year', required=True, states={'done':[('readonly',True)]}, select=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) + 'company_id': fields.related('fiscalyear_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True) } _defaults = { 'state': lambda *a: 'draft', @@ -784,6 +844,14 @@ class account_period(osv.osv): ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit) return self.name_get(cr, user, ids, context=context) + def write(self, cr, uid, ids, vals, context=None): + obj=[] + if 'company_id' in vals: + move_lines = self.pool.get('account.move.line').search(cr, uid, [('period_id', 'in', ids)]) + if move_lines: + raise osv.except_osv(_('Warning !'), _('You cannot modify company of this period as its related record exist in Entry Lines')) + return super(account_period, self).write(cr, uid, ids, vals, context=context) + account_period() class account_journal_period(osv.osv): @@ -809,7 +877,7 @@ class account_journal_period(osv.osv): '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') + 'company_id': fields.related('journal_id', 'company_id', type='many2one', relation='res.company', string='Company') } def _check(self, cr, uid, ids, context={}): @@ -883,7 +951,10 @@ 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 =ANY(%s) group by move_id',(ids,)) + cr.execute( 'SELECT move_id, SUM(debit) '\ + 'FROM account_move_line '\ + 'WHERE move_id IN %s '\ + 'GROUP BY move_id', (tuple(ids),)) result = dict(cr.fetchall()) for id in ids: result.setdefault(id, 0.0) @@ -982,7 +1053,10 @@ class account_move(osv.osv): if new_name: self.write(cr, uid, [move.id], {'name':new_name}) - cr.execute('update account_move set state=%s where id =ANY(%s) ',('posted',ids,)) + cr.execute('UPDATE account_move '\ + 'SET state=%s '\ + 'WHERE id IN %s', + ('posted', tuple(ids),)) else: raise osv.except_osv(_('Integrity Error !'), _('You can not validate a non-balanced entry !\nMake sure you have configured Payment Term properly !\nIt should contain atleast one Payment Term Line with type "Balance" !')) return True @@ -995,7 +1069,9 @@ class account_move(osv.osv): if not line.journal_id.update_posted: 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 =ANY(%s)',('draft',ids,)) + cr.execute('UPDATE account_move '\ + 'SET state=%s '\ + 'WHERE id IN %s', ('draft', tuple(ids),)) return True def write(self, cr, uid, ids, vals, context={}): @@ -1114,7 +1190,10 @@ class account_move(osv.osv): else: line_id2 = 0 - cr.execute('select sum('+mode+') from account_move_line where move_id=%s and id<>%s', (move.id, line_id2)) + cr.execute('SELECT SUM(%s) '\ + 'FROM account_move_line '\ + 'WHERE move_id=%s AND id<>%s', + (mode, move.id, line_id2)) result = cr.fetchone()[0] or 0.0 cr.execute('update account_move_line set '+mode2+'=%s where id=%s', (result, line_id)) return True @@ -1268,24 +1347,26 @@ class account_tax_code(osv.osv): This code is used for some tax declarations. """ - def _sum(self, cr, uid, ids, name, args, context, where =''): - ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) + def _sum(self, cr, uid, ids, name, args, context,where ='', where_params=()): + parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)])) if context.get('based_on', 'invoices') == 'payments': cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \ FROM account_move_line AS line, \ account_move AS move \ LEFT JOIN account_invoice invoice ON \ (invoice.move_id = move.id) \ - WHERE line.tax_code_id =ANY(%s) '+where+' \ + WHERE line.tax_code_id IN %s '+where+' \ AND move.id = line.move_id \ AND ((invoice.state = \'paid\') \ OR (invoice.id IS NULL)) \ - GROUP BY line.tax_code_id',(ids2,)) + GROUP BY line.tax_code_id', + (parent_ids,)+where_params) else: cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \ FROM account_move_line AS line \ - WHERE line.tax_code_id =ANY(%s) '+where+' \ - GROUP BY line.tax_code_id',(ids2,)) + WHERE line.tax_code_id IN %s '+where+' \ + GROUP BY line.tax_code_id', + (parent_ids,)+where_params) res=dict(cr.fetchall()) for record in self.browse(cr, uid, ids, context): def _rec_get(record): @@ -1302,12 +1383,14 @@ class account_tax_code(osv.osv): else: fiscalyear_id = self.pool.get('account.fiscalyear').find(cr, uid, exception=False) where = '' + where_params = () 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))+')' + where = ' and period_id IN %s' + where_params = (tuple(pids),) return self._sum(cr, uid, ids, name, args, context, - where=where) + where=where, where_params=where_params) def _sum_period(self, cr, uid, ids, name, args, context): if 'period_id' in context and context['period_id']: @@ -1318,7 +1401,7 @@ class account_tax_code(osv.osv): return dict.fromkeys(ids, 0.0) period_id = period_id[0] return self._sum(cr, uid, ids, name, args, context, - where=' and line.period_id='+str(period_id)) + where=' and line.period_id=%s', where_params=(period_id,)) _name = 'account.tax.code' _description = 'Tax Code' @@ -1366,16 +1449,6 @@ class account_tax_code(osv.osv): 'sign': lambda *args: 1.0, 'notprintable': lambda *a: False, } - def _check_recursion(self, cr, uid, ids): - level = 100 - while len(ids): - cr.execute('select distinct parent_id from account_tax_code where id =ANY(%s)',(ids,)) - ids = filter(None, map(lambda x:x[0], cr.fetchall())) - if not level: - return False - level -= 1 - return True - def copy(self, cr, uid, id, default=None, context=None): if default is None: @@ -1384,6 +1457,7 @@ class account_tax_code(osv.osv): default.update({'line_ids': []}) return super(account_tax_code, self).copy(cr, uid, id, default, context) + _check_recursion = check_cycle _constraints = [ (_check_recursion, 'Error ! You can not create recursive accounts.', ['parent_id']) ] @@ -1731,7 +1805,7 @@ class account_model(osv.osv): 'ref': fields.char('Reference', size=64), 'journal_id': fields.many2one('account.journal', 'Journal', required=True), 'lines_id': fields.one2many('account.model.line', 'model_id', 'Model Entries'), - 'legend' :fields.text('Legend',readonly=True,size=100), + 'legend' :fields.text('Legend', readonly=True, size=100), } _defaults = { @@ -1741,7 +1815,7 @@ class account_model(osv.osv): move_ids = [] for model in self.browse(cr, uid, ids, context): context.update({'date':datas['date']}) - period_id = self.pool.get('account.period').find(cr, uid, dt=context.get('date',False)) + period_id = self.pool.get('account.period').find(cr, uid, dt=context.get('date', False)) if not period_id: raise osv.except_osv(_('No period found !'), _('Unable to find a valid period !')) period_id = period_id[0] @@ -1943,9 +2017,9 @@ class account_account_template(osv.osv): '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'), - 'child_parent_ids':fields.one2many('account.account.template','parent_id','Children'), - 'tax_ids': fields.many2many('account.tax.template', 'account_account_template_tax_rel','account_id','tax_id', 'Default Taxes'), + 'parent_id': fields.many2one('account.account.template', 'Parent Account Template', ondelete='cascade'), + 'child_parent_ids':fields.one2many('account.account.template', 'parent_id', 'Children'), + 'tax_ids': fields.many2many('account.tax.template', 'account_account_template_tax_rel', 'account_id', 'tax_id', 'Default Taxes'), 'nocreate': fields.boolean('Optional create', help="If checked, the new chart of accounts will not contain this by default."), } @@ -1955,16 +2029,7 @@ class account_account_template(osv.osv): 'nocreate': lambda *a: False, } - def _check_recursion(self, cr, uid, ids): - level = 100 - while len(ids): - cr.execute('select parent_id from account_account_template where id =ANY(%s)',(ids,)) - ids = filter(None, map(lambda x:x[0], cr.fetchall())) - if not level: - return False - level -= 1 - return True - + _check_recursion = check_cycle _constraints = [ (_check_recursion, 'Error ! You can not create recursive account templates.', ['parent_id']) ] @@ -1994,14 +2059,14 @@ class account_add_tmpl_wizard(osv.osv_memory): acc_obj=self.pool.get('account.account') tmpl_obj=self.pool.get('account.account.template') #print "Searching for ",context - tids=tmpl_obj.read(cr, uid, [context['tmpl_ids']],['parent_id']) + tids=tmpl_obj.read(cr, uid, [context['tmpl_ids']], ['parent_id']) if not tids or not tids[0]['parent_id']: return False - ptids = tmpl_obj.read(cr, uid, [tids[0]['parent_id'][0]],['code']) + ptids = tmpl_obj.read(cr, uid, [tids[0]['parent_id'][0]], ['code']) res = None if not ptids or not ptids[0]['code']: raise osv.except_osv(_('Error !'), _('Cannot locate parent code for template account!')) - res = acc_obj.search(cr,uid,[('code','=',ptids[0]['code'])]) + res = acc_obj.search(cr, uid, [('code','=',ptids[0]['code'])]) return res and res[0] or False @@ -2015,9 +2080,9 @@ class account_add_tmpl_wizard(osv.osv_memory): def action_create(self,cr,uid,ids,context=None): acc_obj=self.pool.get('account.account') tmpl_obj=self.pool.get('account.account.template') - data= self.read(cr,uid,ids) - company_id = acc_obj.read(cr,uid,[data[0]['cparent_id']],['company_id'])[0]['company_id'][0] - account_template = tmpl_obj.browse(cr,uid,context['tmpl_ids']) + data= self.read(cr, uid, ids) + company_id = acc_obj.read(cr, uid, [data[0]['cparent_id']], ['company_id'])[0]['company_id'][0] + account_template = tmpl_obj.browse(cr, uid, context['tmpl_ids']) #tax_ids = [] #for tax in account_template.tax_ids: # tax_ids.append(tax_template_ref[tax.id]) @@ -2036,10 +2101,10 @@ class account_add_tmpl_wizard(osv.osv_memory): 'company_id': company_id, } # print "Creating:", vals - new_account = acc_obj.create(cr,uid,vals) + new_account = acc_obj.create(cr, uid, vals) return {'type':'state', 'state': 'end' } - def action_cancel(self,cr,uid,ids,context=None): + def action_cancel(self, cr, uid, ids, context=None): return { 'type': 'state', 'state': 'end' } account_add_tmpl_wizard() @@ -2074,16 +2139,7 @@ class account_tax_code_template(osv.osv): return [(x['id'], (x['code'] and x['code'] + ' - ' or '') + x['name']) \ for x in reads] - 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 =ANY(%s)',(ids,)) - ids = filter(None, map(lambda x:x[0], cr.fetchall())) - if not level: - return False - level -= 1 - return True - + _check_recursion = check_cycle _constraints = [ (_check_recursion, 'Error ! You can not create recursive Tax Codes.', ['parent_id']) ] @@ -2246,11 +2302,11 @@ class wizard_multi_charts_accounts(osv.osv_memory): _inherit = 'res.config' _columns = { - 'company_id':fields.many2one('res.company','Company',required=True), - 'chart_template_id': fields.many2one('account.chart.template','Chart Template',required=True), - 'bank_accounts_id': fields.one2many('account.bank.accounts.wizard', 'bank_account_id', 'Bank Accounts',required=True), - 'code_digits':fields.integer('# of Digits',required=True,help="No. of Digits to use for account code"), - 'seq_journal':fields.boolean('Separated Journal Sequences',help="Check this box if you want to use a different sequence for each created journal. Otherwise, all will use the same sequence."), + 'company_id':fields.many2one('res.company', 'Company', required=True), + 'chart_template_id': fields.many2one('account.chart.template', 'Chart Template', required=True), + 'bank_accounts_id': fields.one2many('account.bank.accounts.wizard', 'bank_account_id', 'Bank Accounts', required=True), + 'code_digits':fields.integer('# of Digits', required=True, help="No. of Digits to use for account code"), + 'seq_journal':fields.boolean('Separated Journal Sequences', help="Check this box if you want to use a different sequence for each created journal. Otherwise, all will use the same sequence."), } def _get_chart(self, cr, uid, context={}): @@ -2259,14 +2315,14 @@ class wizard_multi_charts_accounts(osv.osv_memory): return ids[0] return False _defaults = { - 'company_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr,uid,[uid],c)[0].company_id.id, + 'company_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr, uid, [uid], c)[0].company_id.id, 'chart_template_id': _get_chart, 'code_digits': lambda *a:6, 'seq_journal': True } def execute(self, cr, uid, ids, context=None): - obj_multi = self.browse(cr,uid,ids[0]) + obj_multi = self.browse(cr, uid, ids[0]) obj_acc = self.pool.get('account.account') obj_acc_tax = self.pool.get('account.tax') obj_journal = self.pool.get('account.journal') @@ -2298,7 +2354,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): 'company_id': company_id, 'sign': tax_code_template.sign, } - new_tax_code = self.pool.get('account.tax.code').create(cr,uid,vals) + new_tax_code = self.pool.get('account.tax.code').create(cr, uid, vals) #recording the new tax code to do the mapping tax_code_template_ref[tax_code_template.id] = new_tax_code @@ -2331,7 +2387,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): 'company_id': company_id, 'type_tax_use': tax.type_tax_use } - new_tax = obj_acc_tax.create(cr,uid,vals_tax) + 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 todo_dict[new_tax] = { 'account_collected_id': tax.account_collected_id and tax.account_collected_id.id or False, @@ -2369,7 +2425,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): 'tax_ids': [(6,0,tax_ids)], 'company_id': company_id, } - new_account = obj_acc.create(cr,uid,vals) + new_account = obj_acc.create(cr, uid, vals) acc_template_ref[account_template.id] = new_account #reactivate the parent_store functionnality on account_account self.pool._init = False @@ -2385,11 +2441,11 @@ class wizard_multi_charts_accounts(osv.osv_memory): # Creating Journals 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] + 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] + seq_id_sale = obj_sequence.search(cr, uid, [('name','=','Sale Journal')])[0] + seq_id_purchase = obj_sequence.search(cr, uid, [('name','=','Purchase Journal')])[0] else: seq_id_sale = seq_id seq_id_purchase = seq_id @@ -2421,8 +2477,8 @@ class wizard_multi_charts_accounts(osv.osv_memory): obj_journal.create(cr,uid,vals_journal) # Bank Journals - view_id_cash = self.pool.get('account.journal.view').search(cr,uid,[('name','=','Cash Journal View')])[0] - view_id_cur = self.pool.get('account.journal.view').search(cr,uid,[('name','=','Multi-Currency Cash Journal View')])[0] + view_id_cash = self.pool.get('account.journal.view').search(cr, uid, [('name','=','Cash Journal View')])[0] + view_id_cur = self.pool.get('account.journal.view').search(cr, uid, [('name','=','Multi-Currency Cash Journal View')])[0] ref_acc_bank = obj_multi.chart_template_id.bank_account_view_id current_num = 1 @@ -2500,7 +2556,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): #create the property property_obj.create(cr, uid, vals) - fp_ids = obj_fiscal_position_template.search(cr, uid,[('chart_template_id', '=', obj_multi.chart_template_id.id)]) + fp_ids = obj_fiscal_position_template.search(cr, uid, [('chart_template_id', '=', obj_multi.chart_template_id.id)]) if fp_ids: for position in obj_fiscal_position_template.browse(cr, uid, fp_ids): diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py index d02dec33af0..2cd1b4d17bd 100644 --- a/addons/account/account_analytic_line.py +++ b/addons/account/account_analytic_line.py @@ -92,9 +92,9 @@ class account_analytic_line(osv.osv): company_id=company_obj._company_default_get(cr, uid, 'account.analytic.line', context) # Compute based on pricetype - pricetype=self.pool.get('product.price.type').browse(cr,uid,company_obj.browse(cr,uid,company_id).property_valuation_price_type.id) + pricetype=self.pool.get('product.price.type').browse(cr, uid, company_obj.browse(cr,uid,company_id).property_valuation_price_type.id) # Take the company currency as the reference one - context['currency_id']=company_obj.browse(cr,uid,company_id).currency_id.id + context['currency_id']=company_obj.browse(cr, uid, company_id).currency_id.id amount_unit=prod.price_get(pricetype.field, context)[prod.id] amount=amount_unit*unit_amount or 1.0 return {'value': { diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index 81b6e3157a1..6de3dabaa28 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -32,7 +32,7 @@ class account_bank_statement(osv.osv): mod_obj = self.pool.get('ir.model.data') if context is None: context = {} - model_data_ids = mod_obj.search(cr,uid,[('model','=','ir.ui.view'),('name','=','view_account_statement_from_invoice')], context=context) + model_data_ids = mod_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_account_statement_from_invoice')], context=context) resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] context.update({'statement_id': ids[0]}) return { diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index 2421c4c044d..bceb1b3c857 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -53,7 +53,7 @@ - + @@ -220,7 +220,8 @@ - + + @@ -404,7 +405,7 @@ - + Customer Invoices @@ -427,10 +428,10 @@ - + - Supplier Invoices + Vendor Invoices account.invoice form tree,form,calendar,graph @@ -439,7 +440,7 @@ {'type':'in_invoice'} - + Customer Refunds @@ -465,10 +466,10 @@ - + - Supplier Refunds + Vendor Refunds account.invoice form tree,form,calendar,graph @@ -477,7 +478,7 @@ {'type':'in_refund'} - + diff --git a/addons/account/account_menuitem.xml b/addons/account/account_menuitem.xml index 4cdcb7787b6..7394b15f0be 100644 --- a/addons/account/account_menuitem.xml +++ b/addons/account/account_menuitem.xml @@ -2,27 +2,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - + - - + + + + - + diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 7350596c4e3..b8719f26242 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -18,13 +18,12 @@ # along with this program. If not, see . # ############################################################################## - import time +from datetime import datetime + import netsvc from osv import fields, osv from tools.translate import _ - -from datetime import datetime import decimal_precision as dp import tools @@ -66,9 +65,9 @@ class account_move_line(osv.osv): #the query have to be build with no reference to periods but thanks to the creation date if context.get('periods',False): #if one or more period are given, use them - fiscalperiod_ids = fiscalperiod_obj.search(cr,uid,[('id','in',context['periods'])]) + fiscalperiod_ids = fiscalperiod_obj.search(cr, uid, [('id','in',context['periods'])]) else: - fiscalperiod_ids = self.pool.get('account.period').search(cr,uid,[('fiscalyear_id','in',fiscalyear_ids)]) + fiscalperiod_ids = self.pool.get('account.period').search(cr, uid, [('fiscalyear_id','in',fiscalyear_ids)]) @@ -87,7 +86,7 @@ class account_move_line(osv.osv): #add to 'res' a new clause containing the creation date criterion count = 1 res += " AND (" - periods = self.pool.get('account.period').read(cr,uid,p_ids,['date_start','date_stop']) + periods = self.pool.get('account.period').read(cr, uid, p_ids, ['date_start','date_stop']) for period in periods: if count != 1: res += " OR " @@ -150,7 +149,7 @@ class account_move_line(osv.osv): for item in i[2]: data[item]=i[2][item] if context['journal']: - journal_obj=self.pool.get('account.journal').browse(cr,uid,context['journal']) + journal_obj=self.pool.get('account.journal').browse(cr, uid, context['journal']) if journal_obj.type == 'purchase': if total_new>0: account = journal_obj.default_credit_account_id @@ -298,9 +297,10 @@ class account_move_line(osv.osv): for line_id in ids: res[line_id] = False cursor.execute('SELECT l.id, i.id ' \ - 'FROM account_move_line l, account_invoice i ' \ - 'WHERE l.move_id = i.move_id ' \ - 'AND l.id =ANY(%s)',(ids,)) + 'FROM account_move_line l, account_invoice i ' \ + 'WHERE l.move_id = i.move_id ' \ + 'AND l.id IN %s', + (tuple(ids),)) invoice_ids = [] for line_id, invoice_id in cursor.fetchall(): res[line_id] = invoice_id @@ -333,7 +333,7 @@ class account_move_line(osv.osv): return [] where = ' and '.join(map(lambda x: '(abs(sum(debit-credit))'+x[1]+str(x[2])+')',args)) cursor.execute('select id, sum(debit-credit) from account_move_line \ - group by id,debit,credit having '+where) + group by id, debit, credit having '+where) res = cursor.fetchall() if not len(res): return [('id', '=', '0')] @@ -433,8 +433,8 @@ class account_move_line(osv.osv): 'account_tax_id':fields.many2one('account.tax', 'Tax'), 'analytic_account_id' : fields.many2one('account.analytic.account', 'Analytic Account'), #TODO: remove this - 'amount_taxed':fields.float("Taxed Amount",digits_compute=dp.get_precision('Account')), - 'company_id': fields.related('account_id','company_id',type='many2one',relation='res.company',string='Company',store=True) + 'amount_taxed':fields.float("Taxed Amount", digits_compute=dp.get_precision('Account')), + 'company_id': fields.related('account_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True) } @@ -469,7 +469,7 @@ class account_move_line(osv.osv): 'currency_id': _get_currency, 'journal_id': lambda self, cr, uid, c: c.get('journal_id', False), 'period_id': lambda self, cr, uid, c: c.get('period_id', False), - 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.move.line', context=c) + 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.move.line', context=c) } _order = "date desc,id desc" _sql_constraints = [ @@ -498,9 +498,17 @@ class account_move_line(osv.osv): return False return True + def _check_company_id(self, cr, uid, ids): + lines = self.browse(cr, uid, ids) + for l in lines: + if l.company_id != l.account_id.company_id or l.company_id != l.period_id.company_id: + return False + return True + _constraints = [ (_check_no_view, 'You can not create move line on view account.', ['account_id']), (_check_no_closed, 'You can not create move line on closed account.', ['account_id']), + (_check_company_id,'Company must be same for its related account and period.',['company_id'] ), ] #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id @@ -569,11 +577,54 @@ class account_move_line(osv.osv): # writeoff; entry generated for the difference between the lines # - def reconcile_partial(self, cr, uid, ids, type='auto', context={}): + def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False): + if context is None: + context = {} + if context and context.get('next_partner_only', False): + if not context.get('partner_id', False): + partner = self.get_next_partner_only(cr, uid, offset, context) + else: + partner = context.get('partner_id', False) + if not partner: + return [] + args.append(('partner_id', '=', partner[0])) + return super(account_move_line, self).search(cr, uid, args, offset, limit, order, context, count) + + def get_next_partner_only(self, cr, uid, offset=0, context=None): + cr.execute( + """ + SELECT p.id + FROM res_partner p + RIGHT JOIN ( + SELECT l.partner_id as partner_id, SUM(l.debit) as debit, SUM(l.credit) as credit + FROM account_move_line l + LEFT JOIN account_account a ON (a.id = l.account_id) + LEFT JOIN res_partner p ON (l.partner_id = p.id) + WHERE a.reconcile IS TRUE + AND l.reconcile_id IS NULL + AND (p.last_reconciliation_date IS NULL OR l.date > p.last_reconciliation_date) + AND l.state <> 'draft' + GROUP BY l.partner_id + ) AS s ON (p.id = s.partner_id) + ORDER BY p.last_reconciliation_date LIMIT 1 OFFSET %s""", (offset,) + ) + return cr.fetchone() + + def reconcile_partial(self, cr, uid, ids, type='auto', context=None): merges = [] unmerge = [] total = 0.0 merges_rec = [] + + company_list = [] + if context is None: + context = {} + + for line in self.browse(cr, uid, ids, context=context): + if company_list and not line.company_id.id in company_list: + raise osv.except_osv(_('Warning !'), _('To reconcile the entries company should be the same for all entries')) + company_list.append(line.company_id.id) + for line in self.browse(cr, uid, ids, context): if line.reconcile_id: raise osv.except_osv(_('Warning'), _('Already Reconciled!')) @@ -587,6 +638,7 @@ class account_move_line(osv.osv): else: unmerge.append(line.id) total += (line.debit or 0.0) - (line.credit or 0.0) + if not total: res = self.reconcile(cr, uid, merges+unmerge, context=context) return res @@ -597,13 +649,22 @@ class account_move_line(osv.osv): self.pool.get('account.move.reconcile').reconcile_partial_check(cr, uid, [r_id] + merges_rec, context=context) return True - def reconcile(self, cr, uid, ids, type='auto', writeoff_acc_id=False, writeoff_period_id=False, writeoff_journal_id=False, context={}): + def reconcile(self, cr, uid, ids, type='auto', writeoff_acc_id=False, writeoff_period_id=False, writeoff_journal_id=False, context=None): lines = self.browse(cr, uid, ids, context=context) unrec_lines = filter(lambda x: not x['reconcile_id'], lines) credit = debit = 0.0 currency = 0.0 account_id = False partner_id = False + if context is None: + context = {} + + company_list = [] + for line in self.browse(cr, uid, ids, context=context): + if company_list and not line.company_id.id in company_list: + raise osv.except_osv(_('Warning !'), _('To reconcile the entries company should be the same for all entries')) + company_list.append(line.company_id.id) + for line in unrec_lines: if line.state <> 'valid': raise osv.except_osv(_('Error'), @@ -620,10 +681,11 @@ class account_move_line(osv.osv): else: date = time.strftime('%Y-%m-%d') - cr.execute('SELECT account_id, reconcile_id \ - FROM account_move_line \ - WHERE id =ANY(%s) \ - GROUP BY account_id,reconcile_id',(ids,)) + cr.execute('SELECT account_id, reconcile_id '\ + 'FROM account_move_line '\ + 'WHERE id IN %s '\ + 'GROUP BY account_id,reconcile_id', + (tuple(ids),)) r = cr.fetchall() #TODO: move this check to a constraint in the account_move_reconcile object if (len(r) != 1) and not context.get('fy_closing', False): @@ -701,6 +763,11 @@ class account_move_line(osv.osv): # because of the way the line_id are defined: (4, x, False) for id in ids: wf_service.trg_trigger(uid, 'account.move.line', id, cr) + + if lines and lines[0]: + partner_id = lines[0].partner_id.id + if context and context.get('stop_reconcile', False): + self.pool.get('res.partner').write(cr, uid, [partner_id], {'last_reconciliation_date': time.strftime('%Y-%m-%d %H:%M:%S')}) return r_id def view_header_get(self, cr, user, view_id, view_type, context): @@ -809,13 +876,14 @@ class account_move_line(osv.osv): journal_id = m.journal_id.id period_id = m.period_id.id else: - journal_id = context['journal_id'] - period_id = context['period_id'] - journal = self.pool.get('account.journal').browse(cr,uid,[journal_id])[0] - if journal.allow_date: - period = self.pool.get('account.period').browse(cr,uid,[period_id])[0] - if not time.strptime(vals['date'],'%Y-%m-%d')>=time.strptime(period.date_start,'%Y-%m-%d') or not time.strptime(vals['date'],'%Y-%m-%d')<=time.strptime(period.date_stop,'%Y-%m-%d'): - raise osv.except_osv(_('Error'),_('The date of your Ledger Posting is not in the defined period !')) + journal_id = context.get('journal_id',False) + period_id = context.get('period_id',False) + if journal_id: + journal = self.pool.get('account.journal').browse(cr, uid, [journal_id])[0] + if journal.allow_date and period_id: + period = self.pool.get('account.period').browse(cr, uid, [period_id])[0] + if not time.strptime(vals['date'],'%Y-%m-%d')>=time.strptime(period.date_start,'%Y-%m-%d') or not time.strptime(vals['date'],'%Y-%m-%d')<=time.strptime(period.date_stop,'%Y-%m-%d'): + raise osv.except_osv(_('Error'),_('The date of your Ledger Posting is not in the defined period !')) else: return True @@ -836,7 +904,7 @@ class account_move_line(osv.osv): if vals.get('date', False): todo_date = vals['date'] del vals['date'] - + for line in self.browse(cr, uid, ids,context=context): ctx = context.copy() if ('journal_id' not in ctx): @@ -848,8 +916,8 @@ class account_move_line(osv.osv): if line.move_id: ctx['period_id'] = line.move_id.period_id.id else: - ctx['period_id'] = line.period_id.id - #Check for centralisation + ctx['period_id'] = line.period_id.id + #Check for centralisation journal = self.pool.get('account.journal').browse(cr, uid, ctx['journal_id'], context=ctx) if journal.centralisation: self._check_moves(cr, uid, context=ctx) diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index ab28fa3925c..a93179e3f98 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -163,13 +163,13 @@ - List of Accounts + Accounts account.account form tree,form,graph - + @@ -197,7 +197,7 @@ [('parent_id','=',False)] - + @@ -609,7 +610,7 @@ - + - + + parent="periodical_processing_reconciliation" groups="group_account_user" /> + + + + - Models Definition + Define Models account.model form tree,form - + Running Subscriptions @@ -1525,8 +1598,18 @@ + + @@ -1577,7 +1660,7 @@ - + @@ -1622,7 +1705,7 @@ tree,form - + @@ -1698,7 +1781,7 @@ tree,form - + @@ -1736,7 +1819,7 @@ form tree,form - + @@ -1783,7 +1866,6 @@ - diff --git a/addons/account/account_wizard.xml b/addons/account/account_wizard.xml index 8b093fb2310..260876a98eb 100644 --- a/addons/account/account_wizard.xml +++ b/addons/account/account_wizard.xml @@ -33,7 +33,7 @@ --> - + @@ -52,18 +52,15 @@ - + + - + + - + + res.partner.form.reconcile + res.partner + + + + + + + + diff --git a/addons/account/process/customer_invoice_process.xml b/addons/account/process/customer_invoice_process.xml index b9710276509..fd1b65708b2 100644 --- a/addons/account/process/customer_invoice_process.xml +++ b/addons/account/process/customer_invoice_process.xml @@ -39,7 +39,7 @@ - + diff --git a/addons/account/process/supplier_invoice_process.xml b/addons/account/process/supplier_invoice_process.xml index 26e1e9862e7..080cc5cb984 100644 --- a/addons/account/process/supplier_invoice_process.xml +++ b/addons/account/process/supplier_invoice_process.xml @@ -39,7 +39,7 @@ - + diff --git a/addons/account/product.py b/addons/account/product.py index b2963a34fec..ce91b9b0743 100644 --- a/addons/account/product.py +++ b/addons/account/product.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# along with this program. If not, see . # ############################################################################## diff --git a/addons/account/project/project.py b/addons/account/project/project.py index a844d6dec2e..7db18c4458c 100644 --- a/addons/account/project/project.py +++ b/addons/account/project/project.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# along with this program. If not, see . # ############################################################################## @@ -46,7 +46,7 @@ class account_journal(osv.osv): _inherit="account.journal" _columns = { - 'analytic_journal_id':fields.many2one('account.analytic.journal','Analytic Journal'), + 'analytic_journal_id':fields.many2one('account.analytic.journal','Analytic Journal',help="Journal for analytic entries"), } account_journal() diff --git a/addons/account/project/project_view.xml b/addons/account/project/project_view.xml index 363eeec138b..067fbd38ab1 100644 --- a/addons/account/project/project_view.xml +++ b/addons/account/project/project_view.xml @@ -101,7 +101,7 @@ - + Accounts to Renew @@ -114,7 +114,7 @@ - Analytic Chart of Accounts + Chart of Analytic Accounts ir.actions.act_window account.analytic.account [('parent_id','=',False)] @@ -122,10 +122,10 @@ form,graph - + + + + + - + + + + Analytic Entries @@ -293,31 +293,49 @@ - Analytic Journal Definition + Analytic Journals account.analytic.journal form tree,form - + # # Open journal entries # - Entries of Open Analytic Journals + Analytic Journal Items account.analytic.line form tree,form [('journal_id','=',active_id)] - - - - Open Analytic Journal - - - + + + + + + + + + + + + + # # Reporting @@ -331,13 +349,13 @@ - - Analytic Entries by Journal - account.analytic.journal - tree - - - + + + + + + + # # Statistics diff --git a/addons/account/project/report/analytic_balance.py b/addons/account/project/report/analytic_balance.py index f7b909ae452..8815369375e 100644 --- a/addons/account/project/report/analytic_balance.py +++ b/addons/account/project/report/analytic_balance.py @@ -32,15 +32,9 @@ class account_analytic_balance(report_sxw.rml_parse): 'get_objects': self._get_objects, 'lines_g': self._lines_g, 'move_sum': self._move_sum, -# 'move_sum_debit': self._move_sum_debit, -# 'move_sum_credit': self._move_sum_credit, 'sum_all': self._sum_all, -# 'sum_debit': self._sum_debit, -# 'sum_credit': self._sum_credit, 'sum_balance': self._sum_balance, -# 'sum_quantity': self._sum_quantity, 'move_sum_balance': self._move_sum_balance, -# 'move_sum_quantity': self._move_sum_quantity, }) self.acc_ids = [] self.read_data = [] @@ -81,10 +75,10 @@ class account_analytic_balance(report_sxw.rml_parse): sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity \ FROM account_analytic_line AS aal, account_account AS aa \ WHERE (aal.general_account_id=aa.id) \ - AND (aal.account_id in (" + ','.join(map(str, ids)) + "))\ + AND (aal.account_id IN aal.account_id IN %s)\ AND (date>=%s) AND (date<=%s) AND aa.active \ GROUP BY aal.general_account_id, aa.name, aa.code, aal.code \ - ORDER BY aal.code", (date1, date2)) + ORDER BY aal.code", (tuple(ids), date1, date2)) res = self.cr.dictfetchall() for r in res: @@ -107,62 +101,26 @@ class account_analytic_balance(report_sxw.rml_parse): self.acc_data_dict[account_id] = ids else: ids = self.acc_data_dict[account_id] - + + query_params = (tuple(ids), date1, date2) if option == "credit" : self.cr.execute("SELECT -sum(amount) FROM account_analytic_line \ - WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0", - (ids,date1, date2)) + WHERE account_id IN %s AND date>=%s AND date<=%s AND amount<0",query_params) elif option == "debit" : self.cr.execute("SELECT sum(amount) FROM account_analytic_line \ - WHERE account_id =ANY(%s)\ - AND date>=%s AND date<=%s AND amount>0", - (ids,date1, date2)) + WHERE account_id IN %s\ + AND date>=%s AND date<=%s AND amount>0",query_params) elif option == "quantity" : self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line \ - WHERE account_id =ANY(%s)\ - AND date>=%s AND date<=%s", - (ids,date1, date2)) + WHERE account_id IN %s\ + AND date>=%s AND date<=%s",query_params) return self.cr.fetchone()[0] or 0.0 - -# def _move_sum_debit(self, account_id, date1, date2): -# account_analytic_obj = self.pool.get('account.analytic.account') -# ids = account_analytic_obj.search(self.cr, self.uid, -# [('parent_id', 'child_of', [account_id])]) -# self.cr.execute("SELECT sum(amount) \ -# FROM account_analytic_line \ -# WHERE account_id in ("+ ','.join(map(str, ids)) +") \ -# AND date>=%s AND date<=%s AND amount>0", -# (date1, date2)) -# return self.cr.fetchone()[0] or 0.0 -# -# def _move_sum_credit(self, account_id, date1, date2): -# account_analytic_obj = self.pool.get('account.analytic.account') -# ids = account_analytic_obj.search(self.cr, self.uid, -# [('parent_id', 'child_of', [account_id])]) -# self.cr.execute("SELECT -sum(amount) \ -# FROM account_analytic_line \ -# WHERE account_id in ("+ ','.join(map(str, ids)) +") \ -# AND date>=%s AND date<=%s AND amount<0", -# (date1, date2)) -# return self.cr.fetchone()[0] or 0.0 -# def _move_sum_balance(self, account_id, date1, date2): debit = self._move_sum(account_id, date1, date2, 'debit') credit = self._move_sum(account_id, date1, date2, 'credit') return (debit-credit) -# def _move_sum_quantity(self, account_id, date1, date2): -# account_analytic_obj = self.pool.get('account.analytic.account') -# ids = account_analytic_obj.search(self.cr, self.uid, -# [('parent_id', 'child_of', [account_id])]) -# self.cr.execute("SELECT sum(unit_amount) \ -# FROM account_analytic_line \ -# WHERE account_id in ("+ ','.join(map(str, ids)) +") \ -# AND date>=%s AND date<=%s", -# (date1, date2)) -# return self.cr.fetchone()[0] or 0.0 - def _sum_all(self, accounts, date1, date2, option): ids = map(lambda x: x['id'], accounts) if not len(ids): @@ -174,68 +132,25 @@ class account_analytic_balance(report_sxw.rml_parse): self.acc_sum_list = ids2 else: ids2 = self.acc_sum_list + query_params = (tuple(ids2), date1, date2) if option == "debit" : self.cr.execute("SELECT sum(amount) FROM account_analytic_line \ - WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount>0", - (ids,date1, date2,)) + WHERE account_id IN %s AND date>=%s AND date<=%s AND amount>0",query_params) elif option == "credit" : self.cr.execute("SELECT -sum(amount) FROM account_analytic_line \ - WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0", - (ids,date1, date2,)) + WHERE account_id IN %s AND date>=%s AND date<=%s AND amount<0",query_params) elif option == "quantity" : self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line \ - WHERE account_id =ANY(%s)AND date>=%s AND date<=%s", - (ids,date1, date2,)) + WHERE account_id IN %s AND date>=%s AND date<=%s",query_params) return self.cr.fetchone()[0] or 0.0 -# def _sum_debit(self, accounts, date1, date2): -# ids = map(lambda x: x['id'], accounts) -# if not len(ids): -# return 0.0 -# account_analytic_obj = self.pool.get('account.analytic.account') -# ids2 = account_analytic_obj.search(self.cr, self.uid, -# [('parent_id', 'child_of', ids)]) -# self.cr.execute("SELECT sum(amount) \ -# FROM account_analytic_line \ -# WHERE account_id IN ("+','.join(map(str, ids2))+") \ -# AND date>=%s AND date<=%s AND amount>0", -# (date1, date2)) -# return self.cr.fetchone()[0] or 0.0 -# -# def _sum_credit(self, accounts, date1, date2): -# ids = map(lambda x: x['id'], accounts) -# if not len(ids): -# return 0.0 -# ids = map(lambda x: x['id'], accounts) -# account_analytic_obj = self.pool.get('account.analytic.account') -# ids2 = account_analytic_obj.search(self.cr, self.uid, -# [('parent_id', 'child_of', ids)]) -# self.cr.execute("SELECT -sum(amount) \ -# FROM account_analytic_line \ -# WHERE account_id IN ("+','.join(map(str, ids2))+") \ -# AND date>=%s AND date<=%s AND amount<0", -# (date1, date2)) -# return self.cr.fetchone()[0] or 0.0 def _sum_balance(self, accounts, date1, date2): debit = self._sum_all(accounts, date1, date2, 'debit') or 0.0 credit = self._sum_all(accounts, date1, date2, 'credit') or 0.0 return (debit-credit) -# def _sum_quantity(self, accounts, date1, date2): -# ids = map(lambda x: x['id'], accounts) -# if not len(ids): -# return 0.0 -# account_analytic_obj = self.pool.get('account.analytic.account') -# ids2 = account_analytic_obj.search(self.cr, self.uid, -# [('parent_id', 'child_of', ids)]) -# self.cr.execute("SELECT sum(unit_amount) \ -# FROM account_analytic_line \ -# WHERE account_id IN ("+','.join(map(str, ids2))+") \ -# AND date>=%s AND date<=%s", -# (date1, date2)) -# return self.cr.fetchone()[0] or 0.0 report_sxw.report_sxw('report.account.analytic.account.balance', 'account.analytic.account', 'addons/account/project/report/analytic_balance.rml', diff --git a/addons/account/project/report/analytic_check.py b/addons/account/project/report/analytic_check.py index 458827d8bf3..3075a7821bb 100644 --- a/addons/account/project/report/analytic_check.py +++ b/addons/account/project/report/analytic_check.py @@ -77,41 +77,6 @@ class account_analytic_analytic_check(report_sxw.rml_parse): return res -# def _lines_p(self, date1, date2): -# res = [] -# acc_obj = self.pool.get('account.account') -# for a in acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code','sign']): -# self.cr.execute("SELECT sum(debit), sum(credit) \ -# FROM account_move_line \ -# WHERE date>=%s AND date<=%s AND state<>'draft' AND account_id = %s", (date1, date2, a['id'])) -# (gd, gc) = self.cr.fetchone() -# gd = gd or 0.0 -# gc = gc or 0.0 -# -# self.cr.execute("SELECT abs(sum(amount)) AS balance \ -# FROM account_analytic_line \ -# WHERE date>=%s AND date<=%s AND amount*%s>0 AND general_account_id = %s", (date1, date2, a['sign'], a['id'])) -# (ad,) = self.cr.fetchone() -# ad = ad or 0.0 -# self.cr.execute("SELECT abs(sum(amount)) AS balance \ -# FROM account_analytic_line \ -# WHERE date>=%s AND date<=%s AND amount*%s<0 AND general_account_id = %s", (date1, date2, a['sign'], a['id'])) -# (ac,) = self.cr.fetchone() -# ac = ac or 0.0 -# -# res.append({'code': a['code'], 'name': a['name'], -# 'gen_debit': gd, -# 'gen_credit': gc, -# 'ana_debit': ad, -# 'ana_credit': ac, -# 'delta_debit': gd - ad, -# 'delta_credit': gc - ac,}) -# self.sum_gen_deb += gd -# self.sum_gen_cred += gc -# self.sum_ana_deb += ad -# self.sum_ana_cred += ac -# return res - def _gen_deb(self, date1, date2): return self.sum_gen_deb diff --git a/addons/account/project/report/cost_ledger.py b/addons/account/project/report/cost_ledger.py index 9163cd8e0d4..4317831998c 100644 --- a/addons/account/project/report/cost_ledger.py +++ b/addons/account/project/report/cost_ledger.py @@ -93,15 +93,14 @@ class account_analytic_cost_ledger(report_sxw.rml_parse): ids = map(lambda x: x.id, accounts) if not len(ids): return 0.0 - self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount>0", (ids, date1, date2,)) + self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id IN %s AND date>=%s AND date<=%s AND amount>0", (tuple(ids), date1, date2,)) return self.cr.fetchone()[0] or 0.0 def _sum_credit(self, accounts, date1, date2): ids = map(lambda x: x.id, accounts) if not len(ids): return 0.0 - ids = map(lambda x: x.id, accounts) - self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0", (ids,date1, date2,)) + self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id IN %s AND date>=%s AND date<=%s AND amount<0", (tuple(ids),date1, date2,)) return self.cr.fetchone()[0] or 0.0 def _sum_balance(self, accounts, date1, date2): diff --git a/addons/account/project/report/inverted_analytic_balance.py b/addons/account/project/report/inverted_analytic_balance.py index 37f469d4ef8..f313a9c55db 100644 --- a/addons/account/project/report/inverted_analytic_balance.py +++ b/addons/account/project/report/inverted_analytic_balance.py @@ -38,12 +38,17 @@ class account_inverted_analytic_balance(report_sxw.rml_parse): def _lines_g(self, accounts, date1, date2): ids = map(lambda x: x.id, accounts) - self.cr.execute("SELECT aa.name AS name, aa.code AS code, sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity, aa.id AS id \ + self.cr.execute("SELECT aa.name AS name, aa.code AS code, " + "sum(aal.amount) AS balance, " + "sum(aal.unit_amount) AS quantity, aa.id AS id \ FROM account_analytic_line AS aal, account_account AS aa \ - WHERE (aal.general_account_id=aa.id) AND (aal.account_id =ANY(%s)) AND (date>=%s) AND (date<=%s) AND aa.active \ - GROUP BY aal.general_account_id, aa.name, aa.code, aal.code, aa.id ORDER BY aal.code", (ids,date1,date2,)) + WHERE (aal.general_account_id=aa.id) " + "AND (aal.account_id IN %s) " + "AND (date>=%s) AND (date<=%s) AND aa.active \ + GROUP BY aal.general_account_id, aa.name, aa.code, aal.code, aa.id " + "ORDER BY aal.code", + (tuple(ids), date1, date2)) res = self.cr.dictfetchall() - for r in res: if r['balance'] > 0: r['debit'] = r['balance'] @@ -58,10 +63,17 @@ class account_inverted_analytic_balance(report_sxw.rml_parse): def _lines_a(self, accounts, general_account_id, date1, date2): ids = map(lambda x: x.id, accounts) - self.cr.execute("SELECT sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity, aaa.code AS code, aaa.name AS name, account_id \ - FROM account_analytic_line AS aal, account_analytic_account AS aaa \ - WHERE aal.account_id=aaa.id AND aal.account_id =ANY(%s) AND aal.general_account_id=%s AND aal.date>=%s AND aal.date<=%s \ - GROUP BY aal.account_id, general_account_id, aaa.code, aaa.name ORDER BY aal.account_id", (ids,general_account_id, date1, date2,)) + self.cr.execute("SELECT sum(aal.amount) AS balance, " + "sum(aal.unit_amount) AS quantity, " + "aaa.code AS code, aaa.name AS name, account_id \ + FROM account_analytic_line AS aal, " + "account_analytic_account AS aaa \ + WHERE aal.account_id=aaa.id AND aal.account_id IN %s " + "AND aal.general_account_id=%s AND aal.date>=%s " + "AND aal.date<=%s \ + GROUP BY aal.account_id, general_account_id, aaa.code, aaa.name " + "ORDER BY aal.account_id", + (tuple(ids), general_account_id, date1, date2)) res = self.cr.dictfetchall() aaa_obj = self.pool.get('account.analytic.account') @@ -86,14 +98,14 @@ class account_inverted_analytic_balance(report_sxw.rml_parse): ids = map(lambda x: x.id, accounts) self.cr.execute("SELECT sum(amount) \ FROM account_analytic_line \ - WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount>0", (ids,date1, date2,)) + WHERE account_id IN %s AND date>=%s AND date<=%s AND amount>0", (tuple(ids),date1, date2,)) return self.cr.fetchone()[0] or 0.0 def _sum_credit(self, accounts, date1, date2): ids = map(lambda x: x.id, accounts) self.cr.execute("SELECT -sum(amount) \ FROM account_analytic_line \ - WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0", (ids,date1, date2,)) + WHERE account_id IN %s AND date>=%s AND date<=%s AND amount<0", (tuple(ids),date1, date2,)) return self.cr.fetchone()[0] or 0.0 def _sum_balance(self, accounts, date1, date2): @@ -105,7 +117,7 @@ class account_inverted_analytic_balance(report_sxw.rml_parse): ids = map(lambda x: x.id, accounts) self.cr.execute("SELECT sum(unit_amount) \ FROM account_analytic_line \ - WHERE account_id =ANY(%s) AND date>=%s AND date<=%s", (ids,date1, date2,)) + WHERE account_id IN %s AND date>=%s AND date<=%s", (tuple(ids),date1, date2,)) return self.cr.fetchone()[0] or 0.0 report_sxw.report_sxw('report.account.analytic.account.inverted.balance', 'account.analytic.account', 'addons/account/project/report/inverted_analytic_balance.rml',parser=account_inverted_analytic_balance, header=False) diff --git a/addons/account/project/report/quantity_cost_ledger.py b/addons/account/project/report/quantity_cost_ledger.py index 12bea390eba..37b09827c51 100644 --- a/addons/account/project/report/quantity_cost_ledger.py +++ b/addons/account/project/report/quantity_cost_ledger.py @@ -52,9 +52,9 @@ class account_analytic_quantity_cost_ledger(report_sxw.rml_parse): WHERE (aal.account_id=%s) AND (aal.date>=%s) \ AND (aal.date<=%s) AND (aal.general_account_id=aa.id) \ AND aa.active \ - AND (aal.journal_id =ANY(%s) ) \ + AND (aal.journal_id IN %s ) \ GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code", - (account_id, date1, date2,journal_ids)) + (account_id, date1, date2, tuple(journal_ids))) res = self.cr.dictfetchall() return res @@ -79,9 +79,9 @@ class account_analytic_quantity_cost_ledger(report_sxw.rml_parse): account_analytic_journal AS aaj \ WHERE (aal.general_account_id=%s) AND (aal.account_id=%s) \ AND (aal.date>=%s) AND (aal.date<=%s) \ - AND (aal.journal_id=aaj.id) AND (aaj.id =ANY(%s)) \ + AND (aal.journal_id=aaj.id) AND (aaj.id IN %s) \ ORDER BY aal.date, aaj.code, aal.code", - (general_account_id, account_id, date1, date2,journal_ids,)) + (general_account_id, account_id, date1, date2,tuple(journal_ids))) res = self.cr.dictfetchall() return res @@ -96,8 +96,8 @@ class account_analytic_quantity_cost_ledger(report_sxw.rml_parse): self.cr.execute("SELECT sum(unit_amount) \ FROM account_analytic_line \ WHERE account_id = %s AND date >= %s AND date <= %s \ - AND journal_id =ANY(%s)", - (account_id, date1, date2,journal_ids,)) + AND journal_id IN %s", + (account_id, date1, date2, tuple(journal_ids),)) return self.cr.fetchone()[0] or 0.0 def _sum_quantity(self, accounts, date1, date2, journals): @@ -107,14 +107,14 @@ class account_analytic_quantity_cost_ledger(report_sxw.rml_parse): if not journals: self.cr.execute("SELECT sum(unit_amount) \ FROM account_analytic_line \ - WHERE account_id =ANY(%s) AND date>=%s AND date<=%s", - (ids, date1, date2,)) + WHERE account_id IN %s AND date>=%s AND date<=%s", + (tuple(ids), date1, date2,)) else: journal_ids = journals self.cr.execute("SELECT sum(unit_amount) \ FROM account_analytic_line \ - WHERE account_id =ANY(%s) AND date >= %s AND date <= %s \ - AND journal_id =ANY(%s)",(ids, date1, date2, journal_ids)) + WHERE account_id IN %s AND date >= %s AND date <= %s \ + AND journal_id IN %s",(tuple(ids), date1, date2, tuple(journal_ids))) return self.cr.fetchone()[0] or 0.0 report_sxw.report_sxw('report.account.analytic.account.quantity_cost_ledger', diff --git a/addons/account/project/wizard/account_analytic_cost_ledger_for_journal_report.py b/addons/account/project/wizard/account_analytic_cost_ledger_for_journal_report.py index 73dd38533c4..6074fee3f08 100644 --- a/addons/account/project/wizard/account_analytic_cost_ledger_for_journal_report.py +++ b/addons/account/project/wizard/account_analytic_cost_ledger_for_journal_report.py @@ -29,7 +29,7 @@ class account_analytic_cost_ledger_journal_report(osv.osv_memory): _columns = { 'date1': fields.date('Start of period', required=True), 'date2': fields.date('End of period', required=True), - 'journal': fields.many2many('account.analytic.journal', 'ledger_journal_rel','ledger_id', 'Journal_id','Journals'), + 'journal': fields.many2many('account.analytic.journal', 'ledger_journal_rel', 'ledger_id', 'Journal_id', 'Journals'), } _defaults = { @@ -55,51 +55,3 @@ class account_analytic_cost_ledger_journal_report(osv.osv_memory): account_analytic_cost_ledger_journal_report() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - -#import time -#import wizard -# -#_form = ''' -#
-# -# -# -# -# -#''' -# -#_fields = { -# 'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')}, -# 'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')}, -# 'journal': {'string':'Journals','type':'many2many', 'relation':'account.analytic.journal'}, -#} -# -# -#class wizard_report(wizard.interface): -# states = { -# 'init': { -# 'actions': [], -# 'result': { -# 'type': 'form', -# 'arch': _form, -# 'fields': _fields, -# 'state': [ -# ('end','Cancel'), -# ('report','Print') -# ] -# } -# }, -# 'report': { -# 'actions': [], -# 'result': { -# 'type': 'print', -# 'report': 'account.analytic.account.quantity_cost_ledger', -# 'state': 'end' -# } -# }, -# } -# -#wizard_report('account.analytic.account.quantity_cost_ledger.report') -# -## vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/addons/account/project/wizard/project_account_analytic_line.py b/addons/account/project/wizard/project_account_analytic_line.py index d84c199ff40..dbe3df3c819 100644 --- a/addons/account/project/wizard/project_account_analytic_line.py +++ b/addons/account/project/wizard/project_account_analytic_line.py @@ -32,26 +32,26 @@ class project_account_analytic_line(osv.osv_memory): def action_open_window(self, cr, uid, ids, context={}): mod_obj =self.pool.get('ir.model.data') domain = [] - for data in self.read(cr, uid, ids, context=context): - from_date = data['from_date'] - to_date = data['to_date'] - if from_date and to_date: - domain = [('date','>=',from_date), ('date','<=',to_date)] - elif from_date: - domain = [('date','>=',from_date)] - elif to_date: - domain = [('date','<=',to_date)] - result = mod_obj._get_id(cr, uid, 'account', 'view_account_analytic_line_filter') - id = mod_obj.read(cr, uid, result, ['res_id'], context=context) - return { - 'name': _('Analytic Entries by line'), - 'view_type': 'form', - "view_mode": 'tree,form', - 'res_model': 'account.analytic.line', - 'type': 'ir.actions.act_window', - 'domain': domain, - 'search_view_id': id['res_id'], - } + data = self.read(cr, uid, ids, [])[0] + from_date = data['from_date'] + to_date = data['to_date'] + if from_date and to_date: + domain = [('date','>=',from_date), ('date','<=',to_date)] + elif from_date: + domain = [('date','>=',from_date)] + elif to_date: + domain = [('date','<=',to_date)] + result = mod_obj._get_id(cr, uid, 'account', 'view_account_analytic_line_filter') + id = mod_obj.read(cr, uid, result, ['res_id'], context=context) + return { + 'name': _('Analytic Entries by line'), + 'view_type': 'form', + "view_mode": 'tree,form', + 'res_model': 'account.analytic.line', + 'type': 'ir.actions.act_window', + 'domain': domain, + 'search_view_id': id['res_id'], + } project_account_analytic_line() diff --git a/addons/account/report/account_account_report.py b/addons/account/report/account_account_report.py index 55e5d7030c7..b396521e45c 100644 --- a/addons/account/report/account_account_report.py +++ b/addons/account/report/account_account_report.py @@ -38,8 +38,8 @@ class account_account_report(osv.osv): ('closed', 'Closed'), ], 'Internal Type', readonly=True), 'company_id': fields.many2one('res.company', 'Company', required=True), - 'currency_mode': fields.selection([('current', 'At Date'), ('average', 'Average Rate')], 'Outgoing Currencies Rate',readonly=True), - 'user_type': fields.many2one('account.account.type', 'Account Type',readonly=True), + 'currency_mode': fields.selection([('current', 'At Date'), ('average', 'Average Rate')], 'Outgoing Currencies Rate', readonly=True), + 'user_type': fields.many2one('account.account.type', 'Account Type', readonly=True), 'quantity': fields.float('Quantity', readonly=True), 'amount_total': fields.float('Total Amount', readonly=True), 'credit': fields.float('Credit', readonly=True), diff --git a/addons/account/report/account_analytic_report.py b/addons/account/report/account_analytic_report.py index 87912b4a3ef..a740076ad09 100644 --- a/addons/account/report/account_analytic_report.py +++ b/addons/account/report/account_analytic_report.py @@ -28,21 +28,21 @@ class analytic_report(osv.osv): _auto = False _columns = { 'date_start': fields.date('Date Start', readonly=True), - 'date_end': fields.date('Date End',readonly=True), + 'date_end': fields.date('Date End', readonly=True), 'name' : fields.char('Analytic Account', size=128, readonly=True), - 'partner_id' : fields.many2one('res.partner', 'Associated Partner',readonly=True), + 'partner_id' : fields.many2one('res.partner', 'Associated Partner', readonly=True), 'journal_id' : fields.many2one('account.analytic.journal', 'Analytic Journal', readonly=True), 'parent_id': fields.many2one('account.analytic.account', 'Parent Analytic Account', readonly=True), - 'user_id' : fields.many2one('res.users', 'Account Manager',readonly=True), - 'product_id' : fields.many2one('product.product', 'Product',readonly=True), - 'total_quantity': fields.float('# Total Quantity',readonly=True), - 'debit' : fields.float('Debit',readonly=True), - 'credit' : fields.float('Credit',readonly=True), - 'balance' : fields.float('Balance',readonly=True), + 'user_id' : fields.many2one('res.users', 'Account Manager', readonly=True), + 'product_id' : fields.many2one('product.product', 'Product', readonly=True), + 'total_quantity': fields.float('# Total Quantity', readonly=True), + 'debit' : fields.float('Debit', readonly=True), + 'credit' : fields.float('Credit', readonly=True), + 'balance' : fields.float('Balance', readonly=True), 'year': fields.char('Year', size=4, readonly=True), 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'), - ('10','October'), ('11','November'), ('12','December')], 'Month',readonly=True), + ('10','October'), ('11','November'), ('12','December')], 'Month', readonly=True), 'day': fields.char('Day', size=128, readonly=True), 'nbr':fields.integer('# of Lines', readonly=True), 'company_id': fields.many2one('res.company', 'Company', readonly=True), diff --git a/addons/account/report/account_balance.py b/addons/account/report/account_balance.py index 78683b5120b..93a09db9edf 100644 --- a/addons/account/report/account_balance.py +++ b/addons/account/report/account_balance.py @@ -68,14 +68,14 @@ class account_balance(report_sxw.rml_parse): result='' if form.has_key('periods') and form['periods']: period_ids = form['periods'] - per_ids = self.pool.get('account.period').browse(self.cr,self.uid,form['periods']) + per_ids = self.pool.get('account.period').browse(self.cr, self.uid, form['periods']) for r in per_ids: if r == per_ids[len(per_ids)-1]: result+=r.name+". " else: result+=r.name+", " else: - fy_obj = self.pool.get('account.fiscalyear').browse(self.cr,self.uid,form['fiscalyear']) + fy_obj = self.pool.get('account.fiscalyear').browse(self.cr, self.uid, form['fiscalyear']) res = fy_obj.period_ids len_res = len(res) for r in res: @@ -118,7 +118,7 @@ class account_balance(report_sxw.rml_parse): child_ids = self.pool.get('account.account')._get_children_and_consol(self.cr, self.uid, ids, ctx) if child_ids: ids = child_ids - accounts = self.pool.get('account.account').read(self.cr, self.uid, ids,['type','code','name','debit','credit','balance','parent_id'], ctx) + accounts = self.pool.get('account.account').read(self.cr, self.uid, ids, ['type','code','name','debit','credit','balance','parent_id'], ctx) for account in accounts: if account['id'] in done: continue diff --git a/addons/account/report/account_balance_landscape.py b/addons/account/report/account_balance_landscape.py index a2677e46c27..02d69ba8b19 100644 --- a/addons/account/report/account_balance_landscape.py +++ b/addons/account/report/account_balance_landscape.py @@ -351,7 +351,7 @@ class account_balance_landscape(rml_parse.rml_parse): if perc==1: if form['select_account']!=False: - ref_ac=self.pool.get('account.account').browse(self.cr, self.uid,form['select_account'],ctx.copy()) + ref_ac=self.pool.get('account.account').browse(self.cr, self.uid, form['select_account'], ctx.copy()) if ref_ac.balance<>0.00: ref_bal=ref_ac.balance else: @@ -365,7 +365,7 @@ class account_balance_landscape(rml_parse.rml_parse): total_for_perc=[] # if perc==1: self.done_total=1 - self.total_for_perc=self.linesForTotal(form,ids={},doneAccount={},level=1) + self.total_for_perc=self.linesForTotal(form, ids={}, doneAccount={}, level=1) self.done_total=0 for t1 in range(0,len(form['fiscalyear'])): @@ -376,13 +376,13 @@ class account_balance_landscape(rml_parse.rml_parse): # self.result_total = {} for temp in range(0,len(form['fiscalyear'])): - fy=self.pool.get('account.fiscalyear').name_get(self.cr,self.uid,form['fiscalyear'][temp]) + fy=self.pool.get('account.fiscalyear').name_get(self.cr, self.uid, form['fiscalyear'][temp]) years["year"+str(temp)]=fy[0][1][12:16] return [years] - def linesForTotal(self,form,ids={},doneAccount={},level=1): + def linesForTotal(self, form, ids={}, doneAccount={}, level=1): if self.done_total==1: self.done_total==1 else: @@ -443,7 +443,7 @@ class account_balance_landscape(rml_parse.rml_parse): ids2 = [(x.code,x.id) for x in entry[0].child_id] ids2.sort() - result_total_parent = self.linesForTotal(form, [x[1] for x in ids2],doneAccount,level+1) + result_total_parent = self.linesForTotal(form, [x[1] for x in ids2], doneAccount, level+1) return [self.result_total] @@ -462,7 +462,7 @@ class account_balance_landscape(rml_parse.rml_parse): ctx['periods'] = form['periods'] ctx['period_manner']=form['period_manner'] ctx['state'] = form['context'].get('state','all') - tmp1 = self.pool.get('account.account').browse(self.cr, self.uid, ids,ctx.copy()) + tmp1 = self.pool.get('account.account').browse(self.cr, self.uid, ids, ctx.copy()) if len(tmp1): accounts.append(tmp1) @@ -598,12 +598,12 @@ class account_balance_landscape(rml_parse.rml_parse): return result - def get_years(self,form): + def get_years(self, form): result =[] res={} - for temp in range(0,len(form['fiscalyear'])): + for temp in range(0, len(form['fiscalyear'])): res={} - fy=self.pool.get('account.fiscalyear').name_get(self.cr,self.uid,form['fiscalyear'][temp]) + fy=self.pool.get('account.fiscalyear').name_get(self.cr, self.uid, form['fiscalyear'][temp]) res['year']=fy[0][1] res['last_str']=temp @@ -611,7 +611,7 @@ class account_balance_landscape(rml_parse.rml_parse): self.linesForYear(form) return result - def get_lines(self,year_dict,form): + def get_lines(self, year_dict, form): final_result = [] line_l =[] res = {} @@ -643,7 +643,7 @@ class account_balance_landscape(rml_parse.rml_parse): final_result.append(res) return final_result - def cal_total(self,year_dict): + def cal_total(self, year_dict): total_l = self.result_total if total_l: for k,v in total_l.items(): diff --git a/addons/account/report/account_entries_report.py b/addons/account/report/account_entries_report.py index 85ba8a058f7..2c22db01e53 100644 --- a/addons/account/report/account_entries_report.py +++ b/addons/account/report/account_entries_report.py @@ -33,18 +33,18 @@ class account_entries_report(osv.osv): 'date_maturity': fields.date('Date Maturity', readonly=True), 'nbr':fields.integer('# of Entries', readonly=True), 'nbl':fields.integer('# of Lines', readonly=True), - 'amount': fields.float('Amount',readonly=True), + 'amount': fields.float('Amount', readonly=True), 'year': fields.char('Year', size=4, readonly=True), 'day': fields.char('Day', size=128, readonly=True), 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'), - ('10','October'), ('11','November'), ('12','December')], 'Month',readonly=True), - 'ref': fields.char('Reference', size=64,readonly=True), + ('10','October'), ('11','November'), ('12','December')], 'Month', readonly=True), + 'ref': fields.char('Reference', size=64, readonly=True), 'period_id': fields.many2one('account.period', 'Period', readonly=True), 'account_id': fields.many2one('account.account', 'Account', readonly=True), 'journal_id': fields.many2one('account.journal', 'Journal', readonly=True), 'product_id': fields.many2one('product.product', 'Product', readonly=True), - 'state': fields.selection([('draft','Draft'), ('posted','Posted')], 'State',readonly=True, + 'state': fields.selection([('draft','Draft'), ('posted','Posted')], 'State', 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.'), 'state_2': fields.selection([('draft','Draft'), ('valid','Valid')], 'State of Move Line', readonly=True, help='When new move line is created the state will be \'Draft\'.\n* When all the payments are done it will be in \'Valid\' state.'), diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py index 1fb90a86bec..43c8344f110 100644 --- a/addons/account/report/account_invoice_report.py +++ b/addons/account/report/account_invoice_report.py @@ -33,16 +33,16 @@ class account_invoice_report(osv.osv): 'day': fields.char('Day', size=128, readonly=True), 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'), - ('10','October'), ('11','November'), ('12','December')], 'Month',readonly=True), + ('10','October'), ('11','November'), ('12','December')], 'Month', readonly=True), 'product_id':fields.many2one('product.product', 'Product', readonly=True), 'product_qty':fields.float('Qty', readonly=True), 'uom_name': fields.char('Default UoM', size=128, readonly=True), - 'payment_term': fields.many2one('account.payment.term', 'Payment Term',readonly=True), - 'period_id': fields.many2one('account.period', 'Force Period', domain=[('state','<>','done')],readonly=True), - 'fiscal_position': fields.many2one('account.fiscal.position', 'Fiscal Position',readonly=True), + 'payment_term': fields.many2one('account.payment.term', 'Payment Term', readonly=True), + 'period_id': fields.many2one('account.period', 'Force Period', domain=[('state','<>','done')], readonly=True), + 'fiscal_position': fields.many2one('account.fiscal.position', 'Fiscal Position', readonly=True), 'currency_id': fields.many2one('res.currency', 'Currency', readonly=True), 'categ_id': fields.many2one('product.category','Category of Product', readonly=True), - 'journal_id': fields.many2one('account.journal', 'Journal',readonly=True), + 'journal_id': fields.many2one('account.journal', 'Journal', readonly=True), 'partner_id':fields.many2one('res.partner', 'Partner', readonly=True), 'company_id':fields.many2one('res.company', 'Company', readonly=True), 'user_id':fields.many2one('res.users', 'Salesman', readonly=True), diff --git a/addons/account/report/account_report.py b/addons/account/report/account_report.py index e2c05616c3f..5a62c1ea337 100644 --- a/addons/account/report/account_report.py +++ b/addons/account/report/account_report.py @@ -207,15 +207,15 @@ class report_account_type_sales(osv.osv): _description = "Report of the Sales by Account Type" _auto = False _columns = { - 'name': fields.char('Year',size=64,required=False, readonly=True), - 'period_id': fields.many2one('account.period', 'Force Period',readonly=True), - 'product_id': fields.many2one('product.product', 'Product',readonly=True), + 'name': fields.char('Year', size=64, required=False, readonly=True), + 'period_id': fields.many2one('account.period', 'Force Period', readonly=True), + 'product_id': fields.many2one('product.product', 'Product', readonly=True), 'quantity': fields.float('Quantity', readonly=True), 'user_type': fields.many2one('account.account.type', 'Account Type', readonly=True), 'amount_total': fields.float('Total', readonly=True), 'currency_id': fields.many2one('res.currency', 'Currency', readonly=True), 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'), - ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True), + ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')], 'Month', readonly=True), } _order = 'name desc,amount_total desc' @@ -249,15 +249,15 @@ class report_account_sales(osv.osv): _description = "Report of the Sales by Account" _auto = False _columns = { - 'name': fields.char('Year',size=64,required=False, readonly=True), - 'period_id': fields.many2one('account.period', 'Force Period',readonly=True), - 'product_id': fields.many2one('product.product', 'Product',readonly=True), + 'name': fields.char('Year', size=64, required=False, readonly=True), + 'period_id': fields.many2one('account.period', 'Force Period', readonly=True), + 'product_id': fields.many2one('product.product', 'Product', readonly=True), 'quantity': fields.float('Quantity', readonly=True), 'account_id': fields.many2one('account.account', 'Account', readonly=True), 'amount_total': fields.float('Total', readonly=True), 'currency_id': fields.many2one('res.currency', 'Currency', readonly=True), 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'), - ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True), + ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')], 'Month', readonly=True), } _order = 'name desc,amount_total desc' diff --git a/addons/account/report/aged_trial_balance.py b/addons/account/report/aged_trial_balance.py index 26e24031c3a..43db65f25c9 100644 --- a/addons/account/report/aged_trial_balance.py +++ b/addons/account/report/aged_trial_balance.py @@ -80,13 +80,13 @@ class aged_trial_report(rml_parse.rml_parse): self.cr.execute("""SELECT partner_id, SUM(debit-credit) FROM account_move_line AS line, account_account WHERE (line.account_id = account_account.id) - AND (account_account.type =ANY(%s)) - AND (partner_id =ANY (%s)) + AND (account_account.type IN %s) + AND (partner_id IN %s) AND ((reconcile_id IS NULL) OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) AND (account_account.company_id = %s) AND account_account.active - GROUP BY partner_id""" , (self.ACCOUNT_TYPE, partner_ids,form['date1'],form['company_id'],)) + GROUP BY partner_id""" , (tuple(self.ACCOUNT_TYPE), tuple(partner_ids),form['date1'],form['company_id'],)) t = self.cr.fetchall() for i in t: totals[i[0]] = i[1] @@ -97,14 +97,14 @@ class aged_trial_report(rml_parse.rml_parse): self.cr.execute("""SELECT partner_id, SUM(debit-credit) FROM account_move_line AS line, account_account WHERE (line.account_id=account_account.id) - AND (account_account.type =ANY (%s)) + AND (account_account.type IN %s) AND (COALESCE(date_maturity,date) < %s) - AND (partner_id =ANY (%s)) + AND (partner_id IN %s) AND ((reconcile_id IS NULL) OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) AND (account_account.company_id = %s) AND account_account.active - GROUP BY partner_id""", (self.ACCOUNT_TYPE, form['date1'], partner_ids,form['date1'], form['company_id'],)) + GROUP BY partner_id""", (tuple(self.ACCOUNT_TYPE), form['date1'], tuple(partner_ids),form['date1'], form['company_id'],)) t = self.cr.fetchall() for i in t: future_past[i[0]] = i[1] @@ -112,14 +112,14 @@ class aged_trial_report(rml_parse.rml_parse): self.cr.execute("""SELECT partner_id, SUM(debit-credit) FROM account_move_line AS line, account_account WHERE (line.account_id=account_account.id) - AND (account_account.type =ANY (%s)) + AND (account_account.type IN %s) AND (COALESCE(date_maturity,date) > %s) - AND (partner_id =ANY (%s)) + AND (partner_id IN %s) AND ((reconcile_id IS NULL) OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) AND (account_account.company_id = %s) AND account_account.active - GROUP BY partner_id""" , (self.ACCOUNT_TYPE, form['date1'], partner_ids, form['date1'], form['company_id'],)) + GROUP BY partner_id""" , (tuple(self.ACCOUNT_TYPE), form['date1'], tuple(partner_ids), form['date1'], form['company_id'],)) t = self.cr.fetchall() for i in t: future_past[i[0]] = i[1] @@ -131,14 +131,14 @@ class aged_trial_report(rml_parse.rml_parse): self.cr.execute("""SELECT partner_id, SUM(debit-credit) FROM account_move_line AS line, account_account WHERE (line.account_id=account_account.id) - AND (account_account.type =ANY (%s)) + AND (account_account.type IN %s) AND (COALESCE(date_maturity,date) BETWEEN %s AND %s) - AND (partner_id =ANY (%s)) + AND (partner_id IN %s) AND ((reconcile_id IS NULL) OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) AND (account_account.company_id = %s) AND account_account.active - GROUP BY partner_id""" , (self.ACCOUNT_TYPE, form[str(i)]['start'], form[str(i)]['stop'],partner_ids ,form['date1'] ,form['company_id'],)) + GROUP BY partner_id""" , (tuple(self.ACCOUNT_TYPE), form[str(i)]['start'], form[str(i)]['stop'], tuple(partner_ids) ,form['date1'] ,form['company_id'],)) t = self.cr.fetchall() d = {} diff --git a/addons/account/report/central_journal.py b/addons/account/report/central_journal.py index 36c61b877ff..d76f6ccf07b 100644 --- a/addons/account/report/central_journal.py +++ b/addons/account/report/central_journal.py @@ -40,7 +40,7 @@ class journal_print(report_sxw.rml_parse): ids_final = [] for journal in journal_id: for period in period_id: - ids_journal_period = self.pool.get('account.journal.period').search(self.cr,self.uid, [('journal_id','=',journal),('period_id','=',period)]) + ids_journal_period = self.pool.get('account.journal.period').search(self.cr, self.uid, [('journal_id','=',journal),('period_id','=',period)]) if ids_journal_period: self.cr.execute('select a.code, a.name, sum(debit) as debit, sum(credit) as credit from account_move_line l left join account_account a on (l.account_id=a.id) where l.period_id=%s and l.journal_id=%s and l.state<>\'draft\' group by a.id, a.code, a.name, l.journal_id, l.period_id', (period, journal)) res = self.cr.dictfetchall() diff --git a/addons/account/report/compare_account_balance.py b/addons/account/report/compare_account_balance.py index 28054377834..13fb90fdb5f 100644 --- a/addons/account/report/compare_account_balance.py +++ b/addons/account/report/compare_account_balance.py @@ -320,7 +320,7 @@ class account_balance(report_sxw.rml_parse): # return super(account_balance,self).repeatIn(lst, name, nodes_parent=False) #end - def linesForYear(self,form): + def linesForYear(self, form): temp=0 years={} @@ -351,7 +351,7 @@ class account_balance(report_sxw.rml_parse): if perc==1: if form['select_account']!=False: - ref_ac=self.pool.get('account.account').browse(self.cr, self.uid,form['select_account'],ctx.copy()) + ref_ac=self.pool.get('account.account').browse(self.cr, self.uid, form['select_account'], ctx.copy()) if ref_ac.balance<>0.00: ref_bal=ref_ac.balance else: @@ -365,7 +365,7 @@ class account_balance(report_sxw.rml_parse): total_for_perc=[] # if perc==1: self.done_total=1 - self.total_for_perc=self.linesForTotal(form,ids={},doneAccount={},level=1) + self.total_for_perc=self.linesForTotal(form, ids={}, doneAccount={}, level=1) self.done_total=0 for t1 in range(0,len(form['fiscalyear'])): @@ -376,13 +376,13 @@ class account_balance(report_sxw.rml_parse): # self.result_total = {} for temp in range(0,len(form['fiscalyear'])): - fy=self.pool.get('account.fiscalyear').name_get(self.cr,self.uid,form['fiscalyear'][temp]) + fy=self.pool.get('account.fiscalyear').name_get(self.cr, self.uid, form['fiscalyear'][temp]) years["year"+str(temp)]=fy[0][1][12:16] return [years] - def linesForTotal(self,form,ids={},doneAccount={},level=1): + def linesForTotal(self, form, ids={}, doneAccount={}, level=1): if self.done_total==1: self.done_total==1 else: @@ -440,7 +440,7 @@ class account_balance(report_sxw.rml_parse): ids2 = [(x.code,x.id) for x in entry[0].child_id] ids2.sort() - result_total_parent = self.linesForTotal(form, [x[1] for x in ids2],doneAccount,level+1) + result_total_parent = self.linesForTotal(form, [x[1] for x in ids2], doneAccount, level+1) return [self.result_total] @@ -459,7 +459,7 @@ class account_balance(report_sxw.rml_parse): ctx['periods'] = form['periods'] ctx['period_manner']=form['period_manner'] ctx['state'] = form['context'].get('state','all') - tmp1 = self.pool.get('account.account').browse(self.cr, self.uid, ids,ctx.copy()) + tmp1 = self.pool.get('account.account').browse(self.cr, self.uid, ids, ctx.copy()) if len(tmp1): accounts.append(tmp1) @@ -594,12 +594,12 @@ class account_balance(report_sxw.rml_parse): return result - def get_years(self,form): + def get_years(self, form): result =[] res={} for temp in range(0,len(form['fiscalyear'])): res={} - fy=self.pool.get('account.fiscalyear').name_get(self.cr,self.uid,form['fiscalyear'][temp]) + fy=self.pool.get('account.fiscalyear').name_get(self.cr, self.uid, form['fiscalyear'][temp]) res['year']=fy[0][1] res['last_str']=temp @@ -607,7 +607,7 @@ class account_balance(report_sxw.rml_parse): self.linesForYear(form) return result - def get_lines(self,year_dict,form): + def get_lines(self, year_dict, form): final_result = [] line_l =[] res = {} @@ -639,7 +639,7 @@ class account_balance(report_sxw.rml_parse): final_result.append(res) return final_result - def cal_total(self,year_dict): + def cal_total(self, year_dict): total_l = self.result_total if total_l: for k,v in total_l.items(): diff --git a/addons/account/report/general_journal.py b/addons/account/report/general_journal.py index 112ce970694..631930ce3a7 100644 --- a/addons/account/report/general_journal.py +++ b/addons/account/report/general_journal.py @@ -18,7 +18,7 @@ # along with this program. If not, see . # ############################################################################## - +from operator import itemgetter import pooler import time from report import report_sxw @@ -41,10 +41,12 @@ class journal_print(report_sxw.rml_parse): def set_context(self, objects, data, ids, report_type = None): super(journal_print, self).set_context(objects, data, ids, report_type) - self.cr.execute('select period_id, journal_id from account_journal_period where id =ANY(%s)',(ids,)) + self.cr.execute('SELECT period_id, journal_id ' + 'FROM account_journal_period ' + 'WHERE id IN %s', + (tuple(ids),)) res = self.cr.fetchall() - self.period_ids = map(lambda x:x[0],res) - self.journal_ids = map(lambda x:x[1],res) + self.period_ids, self.journal_ids = zip(*res) # returns a list of period objs def periods(self, journal_period_objs): @@ -63,7 +65,7 @@ class journal_print(report_sxw.rml_parse): ids_final = [] for journal in journal_id: for period in period_id: - ids_journal_period = self.pool.get('account.journal.period').search(self.cr,self.uid, [('journal_id','=',journal),('period_id','=',period)]) + ids_journal_period = self.pool.get('account.journal.period').search(self.cr, self.uid, [('journal_id','=',journal),('period_id','=',period)]) if ids_journal_period: ids_final.append(ids_journal_period[0]) data_jour_period = self.pool.get('account.journal.period').browse(self.cr, self.uid, ids_final) @@ -74,7 +76,14 @@ class journal_print(report_sxw.rml_parse): periods.append(data.period_id.id) for period in periods: period_data = self.pool.get('account.period').browse(self.cr, self.uid, period) - self.cr.execute('select j.code, j.name, sum(l.debit) as debit, sum(l.credit) as credit from account_move_line l left join account_journal j on (l.journal_id=j.id) where period_id=%s and journal_id =ANY(%s) and l.state<>\'draft\' group by j.id, j.code, j.name', (period,journal_id,)) + self.cr.execute( + 'SELECT j.code, j.name, ' + 'SUM(l.debit) AS debit, SUM(l.credit) AS credit ' + 'FROM account_move_line l ' + 'LEFT JOIN account_journal j ON (l.journal_id=j.id) ' + 'WHERE period_id=%s AND journal_id IN %s ' + 'AND l.state<>\'draft\' ' + 'GROUP BY j.id, j.code, j.name', (period, tuple(journal_id))) res = self.cr.dictfetchall() res[0].update({'period_name':period_data.name}) res[0].update({'pid':period}) @@ -82,45 +91,60 @@ class journal_print(report_sxw.rml_parse): return lines_data if not self.journal_ids: return [] - self.cr.execute('select j.code, j.name, sum(l.debit) as debit, sum(l.credit) as credit from account_move_line l left join account_journal j on (l.journal_id=j.id) where period_id=%s and journal_id =ANY(%s) and l.state<>\'draft\' group by j.id, j.code, j.name', (period_id,self.journal_ids,)) + + self.cr.execute('SELECT j.code, j.name, ' + 'SUM(l.debit) AS debit, SUM(l.credit) AS credit ' + 'FROM account_move_line l ' + 'LEFT JOIN account_journal j ON (l.journal_id=j.id) ' + 'WHERE period_id=%s AND journal_id IN %s ' + 'AND l.state<>\'draft\' ' + 'GROUP BY j.id, j.code, j.name', + (period_id, tuple(self.journal_ids))) res = self.cr.dictfetchall() return res - def _sum_debit_period(self, period_id,journal_id=None): - if type(journal_id)==type([]): - self.cr.execute('select sum(debit) from account_move_line where period_id=%s and journal_id =ANY(%s) and state<>\'draft\'', (period_id,journal_id,)) - return self.cr.fetchone()[0] or 0.0 - if not self.journal_ids: + def _sum_debit_period(self, period_id, journal_id=None): + journals = journal_id or self.journal_ids + if not journals: return 0.0 - self.cr.execute('select sum(debit) from account_move_line where period_id=%s and journal_id =ANY(%s) and state<>\'draft\'', (period_id,self.journal_ids,)) - + self.cr.execute('SELECT SUM(debit) FROM account_move_line ' + 'WHERE period_id=%s AND journal_id IN %s ' + 'AND state<>\'draft\'', + (period_id, tuple(journals))) return self.cr.fetchone()[0] or 0.0 - def _sum_credit_period(self, period_id,journal_id=None): - if type(journal_id)==type([]): - self.cr.execute('select sum(credit) from account_move_line where period_id=%s and journal_id =ANY(%s) and state<>\'draft\'', (period_id,journal_id,)) - return self.cr.fetchone()[0] or 0.0 - if not self.journal_ids: + def _sum_credit_period(self, period_id, journal_id=None): + journals = journal_id or self.journal_ids + if not journals: return 0.0 - self.cr.execute('select sum(credit) from account_move_line where period_id=%s and journal_id =ANY(%s) and state<>\'draft\'', (period_id,self.journal_ids,)) + self.cr.execute('SELECT SUM(credit) FROM account_move_line ' + 'WHERE period_id=%s AND journal_id IN %s ' + 'AND state<>\'draft\'', + (period_id, tuple(journals))) return self.cr.fetchone()[0] or 0.0 - def _sum_debit(self,period_id=None,journal_id=None): - if type(period_id)==type([]): - self.cr.execute('select sum(debit) from account_move_line where period_id =ANY(%s) and journal_id =ANY(%s) and state<>\'draft\'',(period_id,journal_id,)) - return self.cr.fetchone()[0] or 0.0 - if not self.journal_ids or not self.period_ids: + def _sum_debit(self, period_id=None, journal_id=None): + journals = journal_id or self.journal_ids + periods = period_id or self.period_ids + if not (journals and periods): return 0.0 - self.cr.execute('select sum(debit) from account_move_line where period_id =ANY(%s) and journal_id =ANY(%s) and state<>\'draft\'',(self.period_ids,self.journal_ids,)) + self.cr.execute('SELECT SUM(debit) FROM account_move_line ' + 'WHERE period_id IN %s ' + 'AND journal_id IN %s ' + 'AND state<>\'draft\'', + (tuple(periods), tuple(journals))) return self.cr.fetchone()[0] or 0.0 - def _sum_credit(self,period_id=None,journal_id=None): - if type(period_id)==type([]): - self.cr.execute('select sum(credit) from account_move_line where period_id =ANY(%s) and journal_id =ANY(%s) and state<>\'draft\'',(period_id,journal_id,)) - return self.cr.fetchone()[0] or 0.0 - if not self.journal_ids or not self.period_ids: + def _sum_credit(self, period_id=None, journal_id=None): + periods = period_id or self.period_ids + journals = journal_id or self.journal_ids + if not (periods and journals): return 0.0 - self.cr.execute('select sum(credit) from account_move_line where period_id =ANY(%s) and journal_id =ANY(%s) and state<>\'draft\'',(self.period_ids,self.journal_ids,)) + self.cr.execute('SELECT SUM(credit) FROM account_move_line ' + 'WHERE period_id IN %s ' + 'AND journal_id IN %s ' + 'AND state<>\'draft\'', + (tuple(periods), tuple(journals))) return self.cr.fetchone()[0] or 0.0 report_sxw.report_sxw('report.account.general.journal', 'account.journal.period', 'addons/account/report/general_journal.rml', parser=journal_print) report_sxw.report_sxw('report.account.general.journal.wiz', 'account.journal.period', 'addons/account/report/wizard_general_journal.rml', parser=journal_print, header=False) diff --git a/addons/account/report/general_ledger.py b/addons/account/report/general_ledger.py index e2c24fe96d2..32186c269f9 100644 --- a/addons/account/report/general_ledger.py +++ b/addons/account/report/general_ledger.py @@ -70,7 +70,7 @@ class general_ledger(rml_parse.rml_parse): }) self.context = context - def get_min_date(self,form): + def get_min_date(self, form): ## Get max born from account_fiscal year # @@ -87,14 +87,15 @@ class general_ledger(rml_parse.rml_parse): #periods = form['periods'][0][2] if not periods: sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """ + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = %s """ + sqlargs = (form['fiscalyear'],) else: - periods_id = ','.join(map(str, periods)) sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in ( """ + periods_id + """) + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in %s """ - self.cr.execute(sql) + sqlargs = (tuple(periods),) + self.cr.execute(sql, sqlargs) res = self.cr.dictfetchall() borne_min = res[0]['start_date'] borne_max = res[0]['stop_date'] @@ -105,15 +106,22 @@ class general_ledger(rml_parse.rml_parse): periods = form['periods'] #periods = form['periods'][0][2] if not periods: - sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """ - """ + sql = """ + SELECT MIN(p.date_start) AS start_date, + MAX(p.date_stop) AS stop_date + FROM account_period AS p + WHERE p.fiscalyear_id = %s + """ + sqlargs = (form['fiscalyear'],) else: - periods_id = ','.join(map(str, periods)) sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in ( """ + periods_id + """) + SELECT MIN(p.date_start) AS start_date, + MAX(p.date_stop) AS stop_date + FROM account_period AS p + WHERE p.id IN %s """ - self.cr.execute(sql) + sqlargs = (tuple(periods),) + self.cr.execute(sql, sqlargs) res = self.cr.dictfetchall() period_min = res[0]['start_date'] period_max = res[0]['stop_date'] @@ -150,7 +158,7 @@ class general_ledger(rml_parse.rml_parse): ## We will make the test for period or date ## We will now make the test # - ctx['state'] = form['context'].get('state','all') + ctx['state'] = form['context'].get('state', 'all') if form.has_key('fiscalyear'): ctx['fiscalyear'] = form['fiscalyear'] ctx['periods'] = form['periods'] @@ -165,10 +173,10 @@ class general_ledger(rml_parse.rml_parse): if account and account.child_consol_ids: # add ids of consolidated childs also of selected account ctx['consolidate_childs'] = True ctx['account_id'] = account.id - ids_acc = self.pool.get('account.account').search(self.cr, self.uid,[('parent_id', 'child_of', [account.id])], context=ctx) + ids_acc = self.pool.get('account.account').search(self.cr, self.uid, [('parent_id', 'child_of', [account.id])], context=ctx) for child_id in ids_acc: child_account = self.pool.get('account.account').browse(self.cr, self.uid, child_id) - sold_account = self._sum_solde_account(child_account,form) + sold_account = self._sum_solde_account(child_account, form) self.sold_accounts[child_account.id] = sold_account if form['display_account'] == 'bal_mouvement': if child_account.type != 'view' \ @@ -196,8 +204,12 @@ class general_ledger(rml_parse.rml_parse): else: ## We will now compute solde initiaux for move in res: - SOLDEINIT = "SELECT sum(l.debit) AS sum_debit, sum(l.credit) AS sum_credit FROM account_move_line l WHERE l.account_id = " + str(move.id) + " AND l.date < '" + self.borne_date['max_date'] + "'" + " AND l.date > '" + self.borne_date['min_date'] + "'" - self.cr.execute(SOLDEINIT) + SOLDEINIT = "SELECT SUM(l.debit) AS sum_debit,"\ + " SUM(l.credit) AS sum_credit "\ + "FROM account_move_line l "\ + "WHERE l.account_id = %s "\ + "AND l.date < %s AND l.date > %s" + self.cr.execute(SOLDEINIT, (move.id, self.borne_date['max_date'], self.borne_date['min_date'])) resultat = self.cr.dictfetchall() if resultat[0] : if resultat[0]['sum_debit'] == None: @@ -263,7 +275,7 @@ class general_ledger(rml_parse.rml_parse): for l in res: l['move']=l['move_name'] if l['invoice_id']: - l['ref'] = '%s: %s'%(inv_types[l['invoice_type']],l['invoice_number']) + l['ref'] = '%s: %s'%(inv_types[l['invoice_type']], l['invoice_number']) l['partner'] = l['partner_name'] or '' account_sum = l['debit'] - l ['credit'] #c = time.strptime(l['date'],"%Y-%m-%d") @@ -296,7 +308,7 @@ class general_ledger(rml_parse.rml_parse): self.cr.execute("SELECT sum(credit) "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s "%(account.id,self.query)) + "WHERE l.account_id = %s AND %s "%(account.id, self.query)) ## Add solde init to the result # sum_credit = self.cr.fetchone()[0] or 0.0 @@ -310,7 +322,7 @@ class general_ledger(rml_parse.rml_parse): def _sum_solde_account(self, account, form): self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s"%(account.id,self.query)) + "WHERE l.account_id = %s AND %s"%(account.id, self.query)) sum_solde = self.cr.fetchone()[0] or 0.0 if form.get('soldeinit', False): sum_solde += account.init_debit - account.init_credit @@ -322,7 +334,8 @@ class general_ledger(rml_parse.rml_parse): return 0.0 self.cr.execute("SELECT sum(debit) "\ "FROM account_move_line l "\ - "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query) + "WHERE l.account_id IN %s AND "+self.query, + (tuple(self.child_ids),)) sum_debit = self.cr.fetchone()[0] or 0.0 return sum_debit @@ -331,7 +344,8 @@ class general_ledger(rml_parse.rml_parse): return 0.0 self.cr.execute("SELECT sum(credit) "\ "FROM account_move_line l "\ - "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query) + "WHERE l.account_id IN %s AND "+self.query, + (tuple(self.child_ids),)) ## Add solde init to the result # sum_credit = self.cr.fetchone()[0] or 0.0 @@ -342,7 +356,8 @@ class general_ledger(rml_parse.rml_parse): return 0.0 self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\ "FROM account_move_line l "\ - "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query) + "WHERE l.account_id IN %s AND "+self.query, + (tuple(self.child_ids),)) sum_solde = self.cr.fetchone()[0] or 0.0 return sum_solde diff --git a/addons/account/report/overdue.py b/addons/account/report/overdue.py index d25432bde24..b7ffaf8816f 100644 --- a/addons/account/report/overdue.py +++ b/addons/account/report/overdue.py @@ -51,7 +51,7 @@ class Overdue(report_sxw.rml_parse): 'country_id' : False, } if adr_id: - result = res_partner_address.read(self.cr, self.uid, [adr_id],context=self.context.copy()) + result = res_partner_address.read(self.cr, self.uid, [adr_id], context=self.context.copy()) result[0]['country_id'] = result[0]['country_id'] and result[0]['country_id'][1] or False return result diff --git a/addons/account/report/partner_balance.py b/addons/account/report/partner_balance.py index f296475cb3f..142375aedb5 100644 --- a/addons/account/report/partner_balance.py +++ b/addons/account/report/partner_balance.py @@ -29,7 +29,6 @@ class partner_balance(report_sxw.rml_parse): def __init__(self, cr, uid, name, context): super(partner_balance, self).__init__(cr, uid, name, context=context) self.date_lst = [] - self.date_lst_string = '' self.account_ids = '' self.localcontext.update( { 'time': time, @@ -49,7 +48,7 @@ class partner_balance(report_sxw.rml_parse): # # Date Management # - def date_range(self,start,end): + def date_range(self, start, end): if not start or not end: return [] start = datetime.date.fromtimestamp(time.mktime(time.strptime(start,"%Y-%m-%d"))) @@ -63,7 +62,7 @@ class partner_balance(report_sxw.rml_parse): full_str_date.append(str(date)) return full_str_date - def transform_period_into_date_array(self,data): + def transform_period_into_date_array(self, data): ## Get All Period Date # # If we have no period we will take all perdio in the FiscalYear. @@ -74,17 +73,17 @@ class partner_balance(report_sxw.rml_parse): date_array = [] for period_id in periods_id: period_obj = self.pool.get('account.period').browse(self.cr, self.uid, period_id) - date_array = date_array + self.date_range(period_obj.date_start,period_obj.date_stop) + date_array = date_array + self.date_range(period_obj.date_start, period_obj.date_stop) self.date_lst = date_array self.date_lst.sort() - def transform_date_into_date_array(self,data): - return_array = self.date_range(data['form']['date1'],data['form']['date2']) + def transform_date_into_date_array(self, data): + return_array = self.date_range(data['form']['date1'], data['form']['date2']) self.date_lst = return_array self.date_lst.sort() - def transform_both_into_date_array(self,data): + def transform_both_into_date_array(self, data): final_date_array = [] date_start_date = data['form']['date1'] date_stop_date = data['form']['date2'] @@ -96,7 +95,7 @@ class partner_balance(report_sxw.rml_parse): if periods_id: for period_id in periods_id: period_obj = self.pool.get('account.period').browse(self.cr, self.uid, period_id) - date_array = date_array + self.date_range(period_obj.date_start,period_obj.date_stop) + date_array = date_array + self.date_range(period_obj.date_start, period_obj.date_stop) period_start_date = date_array[0] period_stop_date = date_array[-1] @@ -110,15 +109,15 @@ class partner_balance(report_sxw.rml_parse): else : stop_date = date_stop_date - final_date_array = final_date_array + self.date_range(start_date,stop_date) + final_date_array = final_date_array + self.date_range(start_date, stop_date) self.date_lst = final_date_array self.date_lst.sort() else : - final_date_array = final_date_array + self.date_range(date_start_date,date_stop_date) + final_date_array = final_date_array + self.date_range(date_start_date, date_stop_date) self.date_lst = final_date_array self.date_lst.sort() - def transform_none_into_date_array(self,data): + def transform_none_into_date_array(self, data): sql = "SELECT min(date) as start_date from account_move_line" self.cr.execute(sql) @@ -130,12 +129,12 @@ class partner_balance(report_sxw.rml_parse): array = [] - array = array + self.date_range(start_date,stop_date) + array = array + self.date_range(start_date, stop_date) self.date_lst = array self.date_lst.sort() - def comma_me(self,amount): + def comma_me(self, amount): if type(amount) is float : amount = str('%.2f'%amount) else : @@ -166,28 +165,24 @@ class partner_balance(report_sxw.rml_parse): self.transform_both_into_date_array(data) - ## - self.date_lst_string ='' - if self.date_lst: - self.date_lst_string = '\'' + '\',\''.join(map(str, self.date_lst)) + '\'' ## Compute Code account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') # if (data['form']['result_selection'] == 'customer' ): - self.ACCOUNT_TYPE = ['receivable'] + self.ACCOUNT_TYPE = ('receivable',) elif (data['form']['result_selection'] == 'supplier'): - self.ACCOUNT_TYPE = ['payable'] + self.ACCOUNT_TYPE = ('payable',) else: - self.ACCOUNT_TYPE = ['payable','receivable'] + self.ACCOUNT_TYPE = ('payable','receivable') # self.cr.execute("SELECT a.id " \ "FROM account_account a " \ "LEFT JOIN account_account_type t " \ "ON (a.type = t.code) " \ "WHERE a.company_id = %s " \ - "AND a.type =ANY(%s) "\ - "AND a.active", (data['form']['company_id'],self.ACCOUNT_TYPE,)) + "AND a.type IN %s " \ + "AND a.active", (data['form']['company_id'], self.ACCOUNT_TYPE)) self.account_ids = [a for (a,) in self.cr.fetchall()] super(partner_balance, self).set_context(objects, data, ids, report_type) @@ -197,7 +192,7 @@ class partner_balance(report_sxw.rml_parse): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') full_account = [] result_tmp = 0.0 - if self.date_lst_string: + if self.date_lst: self.cr.execute( "SELECT p.ref,l.account_id,ac.name as account_name,ac.code as code ,p.name, sum(debit) as debit, sum(credit) as credit, " \ "CASE WHEN sum(debit) > sum(credit) " \ @@ -211,16 +206,17 @@ class partner_balance(report_sxw.rml_parse): "(SELECT sum(debit-credit) " \ "FROM account_move_line l " \ "WHERE partner_id = p.id " \ - "AND l.date IN (" + self.date_lst_string + ") " \ + "AND l.date IN %s " \ "AND blocked = TRUE " \ ") AS enlitige " \ "FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \ "JOIN account_account ac ON (l.account_id = ac.id)" \ - "WHERE ac.type =ANY(%s) " - "AND l.date IN (" + self.date_lst_string + ") " \ - "AND ac.company_id = %s" \ + "WHERE ac.type IN %s " \ + "AND l.date IN %s " \ + "AND ac.company_id = %s " \ "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \ - "ORDER BY l.account_id,p.name",(self.ACCOUNT_TYPE,data['form']['company_id'],)) + "ORDER BY l.account_id,p.name", + (tuple(self.date_lst), self.ACCOUNT_TYPE, tuple(self.date_lst), data['form']['company_id'])) res = self.cr.dictfetchall() for r in res: full_account.append(r) @@ -228,7 +224,7 @@ class partner_balance(report_sxw.rml_parse): ## We will now compute Total return self._add_subtotal(full_account) - def _add_subtotal(self,cleanarray): + def _add_subtotal(self, cleanarray): i=0 completearray = [] tot_debit = 0.0 @@ -347,75 +343,79 @@ class partner_balance(report_sxw.rml_parse): return completearray - def _sum_debit(self,data): + def _sum_debit(self, data): if not self.ids: return 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') result_tmp = 0.0 temp_res = 0.0 - if self.date_lst_string: + if self.date_lst: self.cr.execute( "SELECT sum(debit) " \ "FROM account_move_line AS l " \ - "WHERE l.account_id =ANY(%s)" \ - "AND l.date IN (" + self.date_lst_string + ")" ,(self.account_ids,)) + "WHERE l.account_id IN %s" \ + "AND l.date IN %s", + (tuple(self.account_ids), tuple(self.date_lst))) temp_res = float(self.cr.fetchone()[0] or 0.0) result_tmp = result_tmp + temp_res return result_tmp - def _sum_credit(self,data): + def _sum_credit(self, data): if not self.ids: return 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') result_tmp = 0.0 temp_res = 0.0 - if self.date_lst_string: + if self.date_lst: self.cr.execute( "SELECT sum(credit) " \ "FROM account_move_line AS l " \ - "WHERE l.account_id =ANY(%s)" \ - "AND l.date IN (" + self.date_lst_string + ")" ,(self.account_ids,)) + "WHERE l.account_id IN %s" \ + "AND l.date IN %s", + (tuple(self.account_ids), tuple(self.date_lst),)) temp_res = float(self.cr.fetchone()[0] or 0.0) result_tmp = result_tmp + temp_res return result_tmp - def _sum_litige(self,data): + def _sum_litige(self, data): if not self.ids: return 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') result_tmp = 0.0 temp_res = 0.0 - if self.date_lst_string: + if self.date_lst: self.cr.execute( "SELECT sum(debit-credit) " \ "FROM account_move_line AS l " \ - "WHERE l.account_id =ANY(%s)" \ - "AND l.date IN (" + self.date_lst_string + ")"\ - "AND l.blocked=TRUE " ,(self.account_ids,)) + "WHERE l.account_id IN %s" \ + "AND l.date IN %s " \ + "AND l.blocked=TRUE ", + (tuple(self.account_ids), tuple(self.date_lst),)) temp_res = float(self.cr.fetchone()[0] or 0.0) result_tmp = result_tmp + temp_res return result_tmp - def _sum_sdebit(self,data): + def _sum_sdebit(self, data): if not self.ids: return 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') result_tmp = 0.0 a = 0.0 - if self.date_lst_string: + if self.date_lst: self.cr.execute( "SELECT CASE WHEN sum(debit) > sum(credit) " \ "THEN sum(debit) - sum(credit) " \ "ELSE 0 " \ "END " \ "FROM account_move_line AS l " \ - "WHERE l.account_id =ANY(%s)" \ - "AND l.date IN (" + self.date_lst_string + ")" \ - "GROUP BY l.partner_id",(self.account_ids,)) + "WHERE l.account_id IN %s" \ + "AND l.date IN %s " \ + "GROUP BY l.partner_id", + (tuple(self.account_ids), tuple(self.date_lst),)) a = self.cr.fetchone()[0] if self.cr.fetchone() != None: @@ -425,7 +425,7 @@ class partner_balance(report_sxw.rml_parse): return result_tmp - def _sum_scredit(self,data): + def _sum_scredit(self, data): if not self.ids: return 0.0 @@ -433,16 +433,17 @@ class partner_balance(report_sxw.rml_parse): result_tmp = 0.0 a = 0.0 - if self.date_lst_string: + if self.date_lst: self.cr.execute( "SELECT CASE WHEN sum(debit) < sum(credit) " \ "THEN sum(credit) - sum(debit) " \ "ELSE 0 " \ "END " \ "FROM account_move_line AS l " \ - "WHERE l.account_id =ANY(%s)" \ - "AND l.date IN (" + self.date_lst_string + ")" \ - "GROUP BY l.partner_id",(self.account_ids,)) + "WHERE l.account_id IN %s" \ + "AND l.date IN %s " \ + "GROUP BY l.partner_id", + (tuple(self.account_ids), tuple(self.date_lst),)) a = self.cr.fetchone()[0] or 0.0 if self.cr.fetchone() != None: @@ -453,11 +454,11 @@ class partner_balance(report_sxw.rml_parse): return result_tmp - def _solde_balance_debit(self,data): + def _solde_balance_debit(self, data): debit, credit = self._sum_debit(data), self._sum_credit(data) return debit > credit and debit - credit - def _solde_balance_credit(self,data): + def _solde_balance_credit(self, data): debit, credit = self._sum_debit(data), self._sum_credit(data) return credit > debit and credit - debit diff --git a/addons/account/report/tax_report.py b/addons/account/report/tax_report.py index daa010a0453..2075b1f139b 100644 --- a/addons/account/report/tax_report.py +++ b/addons/account/report/tax_report.py @@ -28,7 +28,6 @@ from report import report_sxw class tax_report(rml_parse.rml_parse): _name = 'report.account.vat.declaration' def __init__(self, cr, uid, name, context={}): - print "tax______init", name, context super(tax_report, self).__init__(cr, uid, name, context=context) self.localcontext.update({ 'time': time, @@ -86,9 +85,10 @@ class tax_report(rml_parse.rml_parse): def _get_period(self, period_id, context={}): return self.pool.get('account.period').browse(self.cr, self.uid, period_id, context=context).name - def _get_general(self, tax_code_id,period_list ,company_id, based_on, context={}): + def _get_general(self, tax_code_id, period_list ,company_id, based_on, context={}): res=[] obj_account = self.pool.get('account.account') + periods_ids = tuple(period_list) if based_on == 'payments': self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \ SUM(line.debit) AS debit, \ @@ -107,11 +107,11 @@ class tax_report(rml_parse.rml_parse): AND line.account_id = account.id \ AND account.company_id = %s \ AND move.id = line.move_id \ - AND line.period_id =ANY(%s) \ + AND line.period_id IN %s \ AND ((invoice.state = %s) \ OR (invoice.id IS NULL)) \ GROUP BY account.id,account.name,account.code', ('draft', tax_code_id, - company_id, period_list, 'paid',)) + company_id, periods_ids, 'paid',)) else : self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \ @@ -127,10 +127,10 @@ class tax_report(rml_parse.rml_parse): AND line.tax_code_id = %s \ AND line.account_id = account.id \ AND account.company_id = %s \ - AND line.period_id =ANY(%s)\ + AND line.period_id IN %s\ AND account.active \ GROUP BY account.id,account.name,account.code', ('draft', tax_code_id, - company_id, period_list,)) + company_id, periods_ids,)) res = self.cr.dictfetchall() #AND line.period_id IN ('+ period_sql_list +') \ diff --git a/addons/account/report/third_party_ledger.py b/addons/account/report/third_party_ledger.py index c10fcb33313..07e3dc39b18 100644 --- a/addons/account/report/third_party_ledger.py +++ b/addons/account/report/third_party_ledger.py @@ -42,7 +42,7 @@ class third_party_ledger(rml_parse.rml_parse): 'get_currency': self._get_currency, 'comma_me' : self.comma_me, }) - def date_range(self,start,end): + def date_range(self, start, end): if not start or not end: return [] start = datetime.date.fromtimestamp(time.mktime(time.strptime(start,"%Y-%m-%d"))) @@ -57,7 +57,7 @@ class third_party_ledger(rml_parse.rml_parse): return full_str_date # - def transform_period_into_date_array(self,data): + def transform_period_into_date_array(self, data): ## Get All Period Date if not data['form']['periods']: periods_id = self.pool.get('account.period').search(self.cr, self.uid, [('fiscalyear_id','=',data['form']['fiscalyear'])]) @@ -66,12 +66,12 @@ class third_party_ledger(rml_parse.rml_parse): date_array = [] for period_id in periods_id: period_obj = self.pool.get('account.period').browse(self.cr, self.uid, period_id) - date_array = date_array + self.date_range(period_obj.date_start,period_obj.date_stop) + date_array = date_array + self.date_range(period_obj.date_start, period_obj.date_stop) self.date_lst = date_array self.date_lst.sort() def transform_date_into_date_array(self,data): - return_array = self.date_range(data['form']['date1'],data['form']['date2']) + return_array = self.date_range(data['form']['date1'], data['form']['date2']) self.date_lst = return_array self.date_lst.sort() @@ -84,7 +84,7 @@ class third_party_ledger(rml_parse.rml_parse): date_array = [] for period_id in periods_id: period_obj = self.pool.get('account.period').browse(self.cr, self.uid, period_id) - date_array = date_array + self.date_range(period_obj.date_start,period_obj.date_stop) + date_array = date_array + self.date_range(period_obj.date_start, period_obj.date_stop) period_start_date = date_array[0] date_start_date = data['form']['date1'] @@ -105,7 +105,7 @@ class third_party_ledger(rml_parse.rml_parse): self.date_lst = final_date_array self.date_lst.sort() - def transform_none_into_date_array(self,data): + def transform_none_into_date_array(self, data): sql = "SELECT min(date) as start_date from account_move_line" self.cr.execute(sql) start_date = self.cr.fetchone()[0] @@ -118,7 +118,7 @@ class third_party_ledger(rml_parse.rml_parse): self.date_lst.sort() - def comma_me(self,amount): + def comma_me(self, amount): if type(amount) is float : amount = str('%.2f'%amount) else : @@ -143,7 +143,7 @@ class third_party_ledger(rml_parse.rml_parse): ## Si on imprime depuis les partenaires if ids: #PARTNER_REQUEST = "AND line.partner_id IN (" + ','.join(map(str, ids)) + ")" - PARTNER_REQUEST = "AND line.partner_id =ANY(%s)" %ids + PARTNER_REQUEST = "AND line.partner_id IN %s",(tuple(ids),) # Transformation des date # # @@ -179,8 +179,8 @@ class third_party_ledger(rml_parse.rml_parse): "LEFT JOIN account_account_type t " \ "ON (a.type=t.code) " \ "WHERE a.company_id = %s " \ - 'AND a.type =ANY(%s)' \ - "AND a.active", (data['form']['company_id'],self.ACCOUNT_TYPE,)) + 'AND a.type IN %s' \ + "AND a.active", (data['form']['company_id'],tuple(self.ACCOUNT_TYPE))) self.account_ids = [a for (a,) in self.cr.fetchall()] account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') @@ -196,11 +196,11 @@ class third_party_ledger(rml_parse.rml_parse): "AND line.date >= %s " \ "AND line.date <= %s " \ "AND line.reconcile_id IS NULL " \ - "AND line.account_id =ANY(%s)" \ + "AND line.account_id IN %s" \ " " + PARTNER_REQUEST + " " \ "AND account.company_id = %s " \ "AND account.active " , - (self.date_lst[0],self.date_lst[len(self.date_lst)-1],self.account_ids,data['form']['company_id'],)) + (self.date_lst[0],self.date_lst[len(self.date_lst)-1],tuple(self.account_ids),data['form']['company_id'],)) # else: # # self.cr.execute( @@ -261,11 +261,11 @@ class third_party_ledger(rml_parse.rml_parse): "LEFT JOIN account_journal j " \ "ON (l.journal_id = j.id) " \ "WHERE l.partner_id = %s " \ - "AND l.account_id =ANY(%s)"\ + "AND l.account_id IN %s"\ "AND l.date IN (" + self.date_lst_string + ")" " " + RECONCILE_TAG + " "\ "ORDER BY l.id", - (partner.id,self.account_ids,)) + (partner.id, tuple(self.account_ids),)) res = self.cr.dictfetchall() sum = 0.0 for r in res: @@ -275,7 +275,7 @@ class third_party_ledger(rml_parse.rml_parse): return full_account - def _sum_debit_partner(self, partner,data): + def _sum_debit_partner(self, partner, data): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') result_tmp = 0.0 @@ -288,10 +288,10 @@ class third_party_ledger(rml_parse.rml_parse): "SELECT sum(debit) " \ "FROM account_move_line " \ "WHERE partner_id = %s " \ - "AND account_id =ANY(%s)" \ + "AND account_id IN %s" \ "AND reconcile_id IS NULL " \ "AND date < %s " , - (partner.id, self.account_ids,self.date_lst[0],)) + (partner.id, tuple(self.account_ids), self.date_lst[0],)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 @@ -303,10 +303,10 @@ class third_party_ledger(rml_parse.rml_parse): "SELECT sum(debit) " \ "FROM account_move_line " \ "WHERE partner_id = %s " \ - "AND account_id =ANY(%s)" \ + "AND account_id IN %s" \ " " + RECONCILE_TAG + " " \ "AND date IN (" + self.date_lst_string + ")" , - (partner.id,self.account_ids,)) + (partner.id,tuple(self.account_ids),)) contemp = self.cr.fetchone() if contemp != None: @@ -315,7 +315,7 @@ class third_party_ledger(rml_parse.rml_parse): result_tmp = result_tmp + 0.0 return result_tmp - def _sum_credit_partner(self, partner,data): + def _sum_credit_partner(self, partner, data): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') result_tmp = 0.0 if data['form']['reconcil'] : @@ -327,10 +327,10 @@ class third_party_ledger(rml_parse.rml_parse): "SELECT sum(credit) " \ "FROM account_move_line " \ "WHERE partner_id=%s " \ - "AND account_id =ANY(%s)" \ + "AND account_id IN %s" \ "AND reconcile_id IS NULL " \ "AND date < %s " , - (partner.id,self.account_ids,self.date_lst[0],)) + (partner.id, tuple(self.account_ids), self.date_lst[0],)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 @@ -342,10 +342,10 @@ class third_party_ledger(rml_parse.rml_parse): "SELECT sum(credit) " \ "FROM account_move_line " \ "WHERE partner_id=%s " \ - "AND account_id =ANY(%s)" \ + "AND account_id IN %s" \ " " + RECONCILE_TAG + " " \ "AND date IN (" + self.date_lst_string + ")", - (partner.id,self.account_ids,)) + (partner.id, tuple(self.account_ids),)) contemp = self.cr.fetchone() if contemp != None: @@ -354,7 +354,7 @@ class third_party_ledger(rml_parse.rml_parse): result_tmp = result_tmp + 0.0 return result_tmp - def _sum_debit(self,data): + def _sum_debit(self, data): if not self.ids: return 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') @@ -367,11 +367,11 @@ class third_party_ledger(rml_parse.rml_parse): self.cr.execute( "SELECT sum(debit) " \ "FROM account_move_line " \ - "WHERE partner_id =ANY(%s)" \ - "AND account_id =ANY(%s)" \ + "WHERE partner_id IN %s" \ + "AND account_id IN %s" \ "AND reconcile_id IS NULL " \ "AND date < %s " , - (self.partner_ids,self.account_ids,self.date_lst[0],)) + (tuple(self.partner_ids), tuple(self.account_ids), self.date_lst[0],)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 @@ -382,10 +382,10 @@ class third_party_ledger(rml_parse.rml_parse): self.cr.execute( "SELECT sum(debit) " \ "FROM account_move_line " \ - "WHERE partner_id =ANY(%s)" \ - "AND account_id =ANY(%s)" \ + "WHERE partner_id IN %s" \ + "AND account_id IN %s" \ " " + RECONCILE_TAG + " " \ - "AND date IN (" + self.date_lst_string + ")",(self.partner_ids,self.account_ids,)) + "AND date IN (" + self.date_lst_string + ")",(tuple(self.partner_ids), tuple(self.account_ids),)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 @@ -395,7 +395,7 @@ class third_party_ledger(rml_parse.rml_parse): return result_tmp - def _sum_credit(self,data): + def _sum_credit(self, data): if not self.ids: return 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') @@ -408,11 +408,11 @@ class third_party_ledger(rml_parse.rml_parse): self.cr.execute( "SELECT sum(credit) " \ "FROM account_move_line " \ - "WHERE partner_id =ANY(%s)" \ - "AND account_id =ANY(%s)" \ + "WHERE partner_id IN %s" \ + "AND account_id IN %s" \ "AND reconcile_id IS NULL " \ "AND date < %s " , - (self.partner_ids,self.account_ids,self.date_lst[0],)) + (tuple(self.partner_ids), tuple(self.account_ids), self.date_lst[0],)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 @@ -423,10 +423,10 @@ class third_party_ledger(rml_parse.rml_parse): self.cr.execute( "SELECT sum(credit) " \ "FROM account_move_line " \ - "WHERE partner_id =ANY(%s)" \ - "AND account_id =ANY(%s)" \ + "WHERE partner_id IN %s" \ + "AND account_id IN %s" \ " " + RECONCILE_TAG + " " \ - "AND date IN (" + self.date_lst_string + ")",(self.partner_ids,self.account_ids,)) + "AND date IN (" + self.date_lst_string + ")",(tuple(self.partner_ids), tuple(self.account_ids),)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 diff --git a/addons/account/report/voucher_print.py b/addons/account/report/voucher_print.py index 1eefd995df7..829f0f7e397 100755 --- a/addons/account/report/voucher_print.py +++ b/addons/account/report/voucher_print.py @@ -36,10 +36,10 @@ class report_voucher_move(report_sxw.rml_parse): }) self.user=uid - def convert(self,amount): - user_id = self.pool.get('res.users').browse(self.cr, self.user,[self.user])[0] + def convert(self, amount): + user_id = self.pool.get('res.users').browse(self.cr, self.user, [self.user])[0] cur = user_id.company_id.currency_id.name - 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 debit(self, move_ids): diff --git a/addons/account/security/account_security.xml b/addons/account/security/account_security.xml index a572f6ca425..67f3bf65f61 100644 --- a/addons/account/security/account_security.xml +++ b/addons/account/security/account_security.xml @@ -24,7 +24,11 @@ - + + + + + diff --git a/addons/account/sequence.py b/addons/account/sequence.py index e23ec1e3def..c90e9ef93c7 100644 --- a/addons/account/sequence.py +++ b/addons/account/sequence.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (). # @@ -15,11 +15,10 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# along with this program. If not, see . # ############################################################################## - from osv import fields,osv class ir_sequence_fiscalyear(osv.osv): diff --git a/addons/account/test/account_change_currency.yml b/addons/account/test/account_change_currency.yml new file mode 100644 index 00000000000..d99c9002870 --- /dev/null +++ b/addons/account/test/account_change_currency.yml @@ -0,0 +1,84 @@ +- + In order to test change currency wizard I create an invoice with currency "EUR" and change it to "USD" using the wizard +- + !record {model: account.invoice, id: account_invoice_currency}: + account_id: account.a_recv + address_contact_id: base.res_partner_address_3000 + address_invoice_id: base.res_partner_address_3000 + company_id: base.main_company + currency_id: base.EUR + invoice_line: + - account_id: account.a_sale + name: '[PC1] Basic PC' + price_unit: 450.0 + quantity: 1.0 + product_id: product.product_product_pc1 + uos_id: product.product_uom_unit + journal_id: account.sales_journal + partner_id: base.res_partner_desertic_hispafuentes + reference_type: none + +- + I check that Initially customer invoice is in the draft state +- + !assert {model: account.invoice, id: account_invoice_currency, string: Customer Invoice is in Draft state}: + - state == 'draft' +- + I change the state of invoice to proforma2 by clicking PRO-FORMA button +- + !workflow {model: account.invoice, action: invoice_proforma2, ref: account_invoice_currency} +- + I check that now customer invoice is in the "proforma2" state +- + !assert {model: account.invoice, id: account_invoice_currency}: + - state == 'proforma2' +- + Now I select USD as new currency +- + !record {model: account.change.currency, id: account_change_currency_0}: + currency_id: base.USD +- + I clicked on Change Currency button to change the currency +- + !python {model: account.change.currency}: | + try: + self.view_init(cr, uid, [ref("account_change_currency_0")], {"lang": 'en_US', + "active_model": "account.invoice", "tz": False, "record_id": 4, "active_ids": + [ref("account_invoice_currency")], "type": "out_invoice", "active_id": ref("account_invoice_currency"), + }) + self.change_currency(cr, uid, [ref("account_change_currency_0")], {"lang": 'en_US', + "active_model": "account.invoice", "tz": False, "record_id": 4, "active_ids": + [ref("account_invoice_currency")], "type": "out_invoice", "active_id": ref("account_invoice_currency"), + }) + except: + print "You can not change currency for Open Invoice !" +- + I can't change the currency of invoice when it is not in draft state so i change the state to cancel +- + !workflow {model: account.invoice, action: invoice_cancel, ref: account_invoice_currency} +- + I change the state to "Draft" +- + !python {model: account.invoice}: | + self.action_cancel_draft(cr, uid, [ref("account_invoice_currency")], {"lang": 'en_US', + "tz": False, "active_model": "ir.ui.menu", "active_ids": [ref("account.menu_action_invoice_tree1")], + "type": "out_invoice", "active_id": ref("account.menu_action_invoice_tree1"), + }) +- + I change the currency. +- + !record {model: account.change.currency, id: account_change_currency_0}: + currency_id: base.USD +- + I clicked on Change Currency button to change the currency +- + !python {model: account.change.currency}: | + self.change_currency(cr, uid, [ref("account_change_currency_0")], {"lang": 'en_US', + "active_model": "account.invoice", "tz": False, "record_id": 4, "active_ids": + [ref("account_invoice_currency")], "type": "out_invoice", "active_id": ref("account_invoice_currency"), + }) +- + I check that the currency is changed successfully +- + !assert {model: account.invoice, id: account_invoice_currency, string: Currency changed from EUR to USD}: + - currency_id.id == ref("base.USD") diff --git a/addons/account/test/account_customer_invoice.yml b/addons/account/test/account_customer_invoice.yml index 1700f08b470..0cbcc0f944d 100644 --- a/addons/account/test/account_customer_invoice.yml +++ b/addons/account/test/account_customer_invoice.yml @@ -1,9 +1,7 @@ - - In order to test account invoice i create a new customer invoice + In order to test account invoice I create a new customer invoice - - Creating a account.invoice record -- - !record {model: account.invoice, id: account_invoice_0}: + !record {model: account.invoice, id: account_invoice_customer0}: account_id: account.a_recv address_contact_id: base.res_partner_address_zen address_invoice_id: base.res_partner_address_zen @@ -21,36 +19,30 @@ partner_id: base.res_partner_3 reference_type: none - - I check that Initially customer invoice is in the draft state + I check that Initially customer invoice is in the "Draft" state - - !assert {model: account.invoice, id: account_invoice_0}: + !assert {model: account.invoice, id: account_invoice_customer0}: - state == 'draft' - - I change the state of invoice to proforma2 by clicking PRO-FORMA button + I change the state of invoice to "Proforma2" by clicking PRO-FORMA button - - Performing a workflow action invoice_proforma2 on module account.invoice + !workflow {model: account.invoice, action: invoice_proforma2, ref: account_invoice_customer0} - - !workflow {model: account.invoice, action: invoice_proforma2, ref: account_invoice_0} + I check that the invoice state is now "Proforma2" - - I check that the invoice state is now proforma2 -- - !assert {model: account.invoice, id: account_invoice_0}: + !assert {model: account.invoice, id: account_invoice_customer0}: - state == 'proforma2' - I create invoice by clicking on Create button - - Performing a workflow action invoice_open on module account.invoice + !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_customer0} - - !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_0} + I check that the invoice state is "Open" - - I check that the invoice state is now open -- - !assert {model: account.invoice, id: account_invoice_0}: + !assert {model: account.invoice, id: account_invoice_customer0}: - state == 'open' - - I make a partial payment of 1000 by clicking on Pay Invoice button -- - Creating a account.invoice.pay record + I create a record for partial payment of 1000 EUR. - !record {model: account.invoice.pay, id: account_invoice_pay_first0}: amount: 1000.0 @@ -58,25 +50,21 @@ journal_id: account.sales_journal name: First payment for [PC3] Medium PC to Distrib PC period_id: account.period_5 - - - - Performing an osv_memory action pay_and_reconcile on module account.invoice.pay + I make partial payment by clicking on Partial Payment button - !python {model: account.invoice.pay}: | self.pay_and_reconcile(cr, uid, [ref("account_invoice_pay_first0")], {"lang": 'en_US', "active_model": "account.invoice", "tz": False, "record_id": 3, "active_ids": - [ref("account_invoice_0")], "type": "out_invoice", "active_id": ref("account_invoice_0"), + [ref("account_invoice_customer0")], "type": "out_invoice", "active_id": ref("account_invoice_customer0"), }) - I check that the invoice state is still open - - !assert {model: account.invoice, id: account_invoice_0}: + !assert {model: account.invoice, id: account_invoice_customer0}: - state == 'open' - - I make second partial payment of 6000 by clicking on Pay Invoice button -- - Creating a account.invoice.pay record + I make second partial payment of 6000 EUR. - !record {model: account.invoice.pay, id: account_invoice_pay_second0}: amount: 6000.0 @@ -84,19 +72,17 @@ journal_id: account.sales_journal name: Second payment for [PC3] Medium PC to Distrib PC period_id: account.period_5 - - - Performing an osv_memory action pay_and_reconcile on module account.invoice.pay + I make partial payment by clicking on Partial Payment button + - !python {model: account.invoice.pay}: | self.pay_and_reconcile(cr, uid, [ref("account_invoice_pay_second0")], {"lang": 'en_US', "active_model": "account.invoice", "tz": False, "record_id": 3, "active_ids": - [ref("account_invoice_0")], "type": "out_invoice", "active_id": ref("account_invoice_0"), + [ref("account_invoice_customer0")], "type": "out_invoice", "active_id": ref("account_invoice_customer0"), }) - - I make final partial payment of 2000 by clicking on Pay Invoice button -- - Creating a account.invoice.pay record + I make final partial payment of 2000 EUR - !record {model: account.invoice.pay, id: account_invoice_pay_final0}: amount: 2000.0 @@ -105,39 +91,39 @@ name: Final payment for [PC3] Medium PC to Distrib PC period_id: account.period_5 - - - Performing an osv_memory action pay_and_reconcile on module account.invoice.pay + I make partial payment by clicking on Partial Payment button + - !python {model: account.invoice.pay}: | self.pay_and_reconcile(cr, uid, [ref("account_invoice_pay_final0")], {"lang": 'en_US', "active_model": "account.invoice", "tz": False, "record_id": 3, "active_ids": - [ref("account_invoice_0")], "type": "out_invoice", "active_id": ref("account_invoice_0"), + [ref("account_invoice_customer0")], "type": "out_invoice", "active_id": ref("account_invoice_customer0"), }) - I check that the invoice state is now Done - - !assert {model: account.invoice, id: account_invoice_0}: + !assert {model: account.invoice, id: account_invoice_customer0}: - state == 'paid' - I check that an payment entry gets created in the account.move.line - !python {model: account.invoice}: | - acc_id=self.browse(cr, uid, ref("account_invoice_0")) + acc_id=self.browse(cr, uid, ref("account_invoice_customer0")) assert(acc_id.move_id) -#- -# I refund the invoice -#- -# Creating a account.invoice.refund record -#- -# !record {model: account.invoice.refund, id: account_invoice_refund_0}: -# description: Refund -# -#- -# Performing an osv_memory action invoice_refund on module account.invoice.refund -#- -# !python {model: account.invoice.refund}: | -# self.invoice_refund(cr, uid, [ref("account_invoice_refund_0")], {"lang": 'en_US', "tz": False, "active_model": "account.invoice", "active_ids": [ref("account.account_invoice_0")], "type": "out_invoice", "active_id": ref("account.account_invoice_0"), }) -# return self.compute_refund(cr, uid, [ref("account_invoice_refund_0")], "refund" {"lang": 'en_US',"tz": False, "active_model": "account.invoice", "active_ids": [ref("account.account_invoice_0")], "type": "out_invoice", "active_id": ref("account.account_invoice_0"), }) +- + I refund the invoice Using Credit Note +- + !record {model: account.invoice.refund, id: account_invoice_refund_0}: + description: Refund To China Export + period: account.period_5 +- + I clicked on refund button +- + !python {model: account.invoice.refund}: | + self.invoice_refund(cr, uid, [ref("account_invoice_refund_0")], {"lang": 'en_US', "tz": False, "active_model": "account.invoice", "active_ids": [ref("account.account_invoice_customer0")], "type": "out_invoice", "active_id": ref("account.account_invoice_customer0"), }) +- + I checked that a new entry with state "Draft" created in account move line + diff --git a/addons/account/test/account_fiscalyear_close.yml b/addons/account/test/account_fiscalyear_close.yml new file mode 100644 index 00000000000..6a619a8df5c --- /dev/null +++ b/addons/account/test/account_fiscalyear_close.yml @@ -0,0 +1,91 @@ +- + In order to test Generate Fiscalyear Opening Entries wizard of OpenERP I first create a fiscalyear "Fiscal Year 2011" to which the entries will move +- + !record {model: account.fiscalyear, id: account_fiscalyear_fiscalyear0}: + code: FY2011 + company_id: base.main_company + date_start: '2011-01-01' + date_stop: '2011-12-31' + name: Fiscal Year 2011 +- + I create a period "Jan2011" for the new fiscalyear +- + !record {model: account.period, id: account_period_jan11}: + company_id: base.main_company + date_start: '2011-01-01' + date_stop: '2011-12-31' + fiscalyear_id: account_fiscalyear_fiscalyear0 + name: Jan2011 + special: 1 + +- + I made modification in journal so it can move entries +- + !record {model: account.journal, id: account.sales_journal}: + centralisation: 1 + +- + I called the Generate Fiscalyear Opening Entries wizard +- + !record {model: account.fiscalyear.close, id: account_fiscalyear_close_0}: + fy2_id: account_fiscalyear_fiscalyear0 + fy_id: account.data_fiscalyear + journal_id: account.sales_journal + period_id: account_period_jan11 + report_name: End of Fiscal Year Entry + sure: 1 +- + I clicked on create Button + +- + !python {model: account.fiscalyear.close}: | + self.data_save(cr, uid, [ref("account_fiscalyear_close_0")], {"lang": 'en_US', + "active_model": "ir.ui.menu", "active_ids": [ref("account.menu_wizard_fy_close")], + "tz": False, "active_id": ref("account.menu_wizard_fy_close"), }) + +- + I check the opening entries By using "Entries by Line wizard" +- + !record {model: account.move.journal, id: account_move_journal_0}: + journal_id: account.sales_journal + period_id: account_period_jan11 +- + I clicked on Open Journal Button to check the entries + +- + !python {model: account.move.journal}: | + self.action_open_window(cr, uid, [ref("account_move_journal_0")], {"lang": 'en_US', + "active_model": "ir.ui.menu", "active_ids": [ref("account.menu_action_move_journal_line_form")], + "tz": False, "active_id": ref("account.menu_action_move_journal_line_form"), + }) + +- + In order to test Cancel Opening Entries I cancelled the opening entries created for "Fiscal Year 2011" +- + !record {model: account.open.closed.fiscalyear, id: account_open_closed_fiscalyear_1}: + fyear_id: account.data_fiscalyear +- + I clicked on Open button +- + !python {model: account.open.closed.fiscalyear}: | + self.remove_entries(cr, uid, [ref("account_open_closed_fiscalyear_1")], {"lang": + 'en_US', "active_model": "ir.ui.menu", "active_ids": [ref("account.menu_wizard_open_closed_fy")], + "tz": False, "active_id": ref("account.menu_wizard_open_closed_fy"), }) +- + I check the opening entries By using "Entries by Line wizard" +- + !record {model: account.move.journal, id: account_move_journal_2}: + journal_id: account.sales_journal + period_id: account_period_jan11 + +- + I checked the Opening entries are cancelled successfully +- + !python {model: account.move.journal}: | + self.action_open_window(cr, uid, [ref("account_move_journal_2")], {"lang": 'en_US', + "active_model": "ir.ui.menu", "active_ids": [ref("account.menu_action_move_journal_line_form")], + "tz": False, "active_id": ref("account.menu_action_move_journal_line_form"), + }) + + + diff --git a/addons/account/test/account_fiscalyear_close_state.yml b/addons/account/test/account_fiscalyear_close_state.yml new file mode 100644 index 00000000000..988ba5593d5 --- /dev/null +++ b/addons/account/test/account_fiscalyear_close_state.yml @@ -0,0 +1,46 @@ + +- + In order to check the Close a Fiscal Year wizard in OpenERP I first create a Fiscalyear +- + !record {model: account.fiscalyear, id: account_fiscalyear_fiscalyear0}: + code: FY2011 + company_id: base.main_company + date_start: '2011-01-01' + date_stop: '2011-12-31' + name: Fiscal Year 2011 +- + I create monthly Periods for this fiscalyear +- + !python {model: account.fiscalyear}: | + self.create_period(cr, uid, [ref("account_fiscalyear_fiscalyear0")], {"lang": + 'en_US', "active_model": "ir.ui.menu", "active_ids": [ref("account.menu_action_account_fiscalyear_form")], + "tz": False, "active_id": ref("account.menu_action_account_fiscalyear_form"), + }) +- + I check that the fiscalyear state is "Draft" +- + !assert {model: account.fiscalyear, id: account_fiscalyear_fiscalyear0, string: Fiscal Year is in Draft state}: + - state == 'draft' +- + I run the Close a Fiscalyear wizard to close this fiscalyear +- + !record {model: account.fiscalyear.close.state, id: account_fiscalyear_close_state_0}: + fy_id: account_fiscalyear_fiscalyear0 + sure: 1 +- + I clicked on Close States Button to close fiscalyear + +- + !python {model: account.fiscalyear.close.state}: | + self.data_save(cr, uid, [ref("account_fiscalyear_close_state_0")], {"lang": 'en_US', + "active_model": "ir.ui.menu", "active_ids": [ref("account.menu_wizard_fy_close_state")], + "tz": False, "active_id": ref("account.menu_wizard_fy_close_state"), }) +- + I check that the fiscalyear state is now "Done" +- + !assert {model: account.fiscalyear, id: account_fiscalyear_fiscalyear0, string: Fiscal Year is in Done state}: + - state == 'done' + + + + diff --git a/addons/account/test/account_invoice_state.yml b/addons/account/test/account_invoice_state.yml new file mode 100644 index 00000000000..b9818b71d2f --- /dev/null +++ b/addons/account/test/account_invoice_state.yml @@ -0,0 +1,68 @@ +- + In order to test Confirm Draft Invoice wizard I create an invoice and confirm it with this wizard +- + !record {model: account.invoice, id: account_invoice_state}: + account_id: account.a_recv + address_contact_id: base.res_partner_address_3000 + address_invoice_id: base.res_partner_address_3000 + company_id: base.main_company + currency_id: base.EUR + invoice_line: + - account_id: account.a_sale + name: '[PC1] Basic PC' + price_unit: 450.0 + quantity: 1.0 + product_id: product.product_product_pc1 + uos_id: product.product_uom_unit + journal_id: account.bank_journal + partner_id: base.res_partner_desertic_hispafuentes + reference_type: none +- + I check that Initially customer invoice state is "Draft" +- + !assert {model: account.invoice, id: account_invoice_state}: + - state == 'draft' +- + I called the "Confirm Draft Invoices" wizard +- + !record {model: account.invoice.confirm, id: account_invoice_confirm_0}: + {} +- + I clicked on Confirm Invoices Button +- + !python {model: account.invoice.confirm}: | + self.invoice_confirm(cr, uid, [ref("account_invoice_confirm_0")], {"lang": 'en_US', + "tz": False, "active_model": "account.invoice", "active_ids": [ref("account_invoice_state")], + "type": "out_invoice", "active_id": ref("account_invoice_state"), }) +- + I check that customer invoice state is "Open" +- + !assert {model: account.invoice, id: account_invoice_state}: + - state == 'open' +- + I Modified the journal record so it can cancel invoice +- + !record {model: account.journal, id: account.bank_journal}: + update_posted: 1 + + +- + In order to check the "Cancel Selected Invoices" wizard in openerp I cancelled this open invoice using this wizard +- + !record {model: account.invoice.cancel, id: account_invoice_cancel_0}: + {} + +- + I clicked on Cancel Invoices Button +- + !python {model: account.invoice.cancel}: | + self.invoice_cancel(cr, uid, [ref("account_invoice_cancel_0")], {"lang": 'en_US', + "tz": False, "active_model": "account.invoice", "active_ids": [ref("account_invoice_state")], + "type": "out_invoice", "active_id": ref("account_invoice_state"), }) + +- + I check that customer invoice is in the cancel state +- + !assert {model: account.invoice, id: account_invoice_state}: + - state == 'cancel' + diff --git a/addons/account/test/account_period_close.yml b/addons/account/test/account_period_close.yml new file mode 100644 index 00000000000..af180050b1b --- /dev/null +++ b/addons/account/test/account_period_close.yml @@ -0,0 +1,35 @@ + +- + In order to test close period wizard I create a period then close it and checked it's state +- + !record {model: account.period, id: account_period_jan0}: + company_id: base.main_company + date_start: '2010-01-01' + date_stop: '2010-01-31' + fiscalyear_id: account.data_fiscalyear + name: Jan-2010 + special: 1 + +- + I check that the period state is "Draft" +- + !assert {model: account.period, id: account_period_jan0, string: Period is in Draft state}: + - state == 'draft' +- + I use "Close a Period" wizard to close period Jan-2010 +- + !record {model: account.period.close, id: account_period_close_0}: + sure: 1 +- + I clicked on Close Period Button to close Period + +- + !python {model: account.period.close}: | + self.data_save(cr, uid, [ref("account_period_close_0")], {"lang": 'en_US', "active_model": + "account.period", "active_ids": [ref("account_period_jan0")], "tz": False, "active_id": + ref("account_period_jan0"), }) +- + I check that the period state is "Done" +- + !assert {model: account.period, id: account_period_jan0, string: Period is in Done state}: + - state == 'done' diff --git a/addons/account/test/account_supplier_invoice.yml b/addons/account/test/account_supplier_invoice.yml index a577fa8330b..c5ed0087a92 100644 --- a/addons/account/test/account_supplier_invoice.yml +++ b/addons/account/test/account_supplier_invoice.yml @@ -1,9 +1,7 @@ - - In order to test account invoice i create a new supplier invoice + In order to test account invoice I create a new supplier invoice - - Creating a account.invoice record -- - !record {model: account.invoice, id: account_invoice_1}: + !record {model: account.invoice, id: account_invoice_supplier0}: account_id: account.a_pay address_contact_id: base.res_partner_address_3000 address_invoice_id: base.res_partner_address_3000 @@ -22,25 +20,21 @@ reference_type: none type: in_invoice - - I check that Initially supplier invoice is in the draft state + I check that Initially supplier invoice state is "Draft" - - !assert {model: account.invoice, id: account_invoice_1}: + !assert {model: account.invoice, id: account_invoice_supplier0}: - state == 'draft' - I change the state of invoice to open by clicking Validate button - - Performing a workflow action invoice_open on module account.invoice + !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_supplier0} - - !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_1} + I check that the invoice state is now "Open" - - I check that the invoice state is now open -- - !assert {model: account.invoice, id: account_invoice_1}: + !assert {model: account.invoice, id: account_invoice_supplier0}: - state == 'open' - - I make a partial payment of 2000 by clicking on Pay Invoice button -- - Creating a account.invoice.pay record + I make a partial payment of 2000 EUR - !record {model: account.invoice.pay, id: account_invoice_pay_firstpaymenttoaxelorforbasicpc0}: amount: 2000.0 @@ -48,24 +42,21 @@ journal_id: account.sales_journal name: First Payment to Axelor for Basic PC period_id: account.period_5 - - - Performing an osv_memory action pay_and_reconcile on module account.invoice.pay + I make partial payment by clicking on Partial Payment button - !python {model: account.invoice.pay}: | self.pay_and_reconcile(cr, uid, [ref("account_invoice_pay_firstpaymenttoaxelorforbasicpc0")], {"lang": 'en_US', "active_model": "account.invoice", "tz": False, "record_id": - 25, "active_ids": [ref("account_invoice_1")], "type": "in_invoice", "active_id": - ref("account_invoice_1"), }) + 25, "active_ids": [ref("account_invoice_supplier0")], "type": "in_invoice", "active_id": + ref("account_invoice_supplier0"), }) - - I check that the invoice state is still open + I check that the invoice state is still "Open" - - !assert {model: account.invoice, id: account_invoice_1}: + !assert {model: account.invoice, id: account_invoice_supplier0}: - state == 'open' - - I make final partial payment of 1000 by clicking on Pay Invoice button -- - Creating a account.invoice.pay record + I make final partial payment of 1000 EUR - !record {model: account.invoice.pay, id: account_invoice_pay_finalpaymenttoaxelorforbasicpc0}: amount: 1000.0 @@ -73,45 +64,23 @@ journal_id: account.sales_journal name: Final Payment to Axelor for Basic PC period_id: account.period_5 - - - - Performing an osv_memory action pay_and_reconcile on module account.invoice.pay + I make partial payment by clicking on Partial Payment button - !python {model: account.invoice.pay}: | self.pay_and_reconcile(cr, uid, [ref("account_invoice_pay_finalpaymenttoaxelorforbasicpc0")], {"lang": 'en_US', "active_model": "account.invoice", "tz": False, "record_id": - 25, "active_ids": [ref("account_invoice_1")], "type": "in_invoice", "active_id": - ref("account_invoice_1"), }) + 25, "active_ids": [ref("account_invoice_supplier0")], "type": "in_invoice", "active_id": + ref("account_invoice_supplier0"), }) - - I check that the invoice state is now Done + I check that the invoice state is now "Done" - - !assert {model: account.invoice, id: account_invoice_1}: + !assert {model: account.invoice, id: account_invoice_supplier0}: - state == 'paid' - - I check that an payment entry gets created in the account.move.line + I check that an payment entry gets created in the account move line - !python {model: account.invoice}: | - acc_id=self.browse(cr, uid, ref("account_invoice_1")) + acc_id=self.browse(cr, uid, ref("account_invoice_supplier0")) assert(acc_id.move_id) -#- -# I refund the invoice -#- -# Creating a account.invoice.refund record -#- -# !record {model: account.invoice.refund, id: account_invoice_refund_0}: -# date: '2010-06-22' -# description: 'Refund By Axelor ' -# -# -#- -# Performing an osv_memory action invoice_refund on module account.invoice.refund -#- -# !python {model: account.invoice.refund}: | -# self.invoice_refund(cr, uid, [ref("account_invoice_refund_0")], {"lang": 'en_US', -# "tz": False, "active_model": "account.invoice", "active_ids": [ref("account_invoice_1")], -# "type": "in_invoice", "active_id": ref("account_invoice_1"), }) - - - diff --git a/addons/account/test/account_use_model.yml b/addons/account/test/account_use_model.yml new file mode 100644 index 00000000000..7de88cff94e --- /dev/null +++ b/addons/account/test/account_use_model.yml @@ -0,0 +1,44 @@ +- + In order to test account use models wizard in OpenERP I create an account model record +- + !record {model: account.model, id: account_model_mymodelonyears0}: + journal_id: account.expenses_journal + lines_id: + - account_id: account.a_recv + credit: 0.0 + debit: 0.0 + name: test1 + sequence: 0.0 + date: today + quantity: 0.0 + name: My Model on %(year)s + +- + I create an account use model record + +- + !record {model: account.use.model, id: account_use_model_0}: + {} + +- + I create entries. +- + !python {model: account.use.model}: | + self.create_entries(cr, uid, [ref("account_use_model_0")], {"lang": 'en_US', "active_model": + "account.model", "active_ids": [ref("account_model_mymodelonyears0")], "tz": + False, "active_id": ref("account_model_mymodelonyears0"), }) +- + I create an account use model record +- + !record {model: account.use.model, id: account_use_model_1}: + {} + +- + I checked that Moves are created successfully + +- + !python {model: account.use.model}: | + self.open_moves(cr, uid, [ref("account_use_model_1")], {"lang": 'en_US', "move_ids": + [], "tz": False, "active_model": "account.model", "active_ids": [ref("account_model_mymodelonyears0")], + "active_id": ref("account_model_mymodelonyears0"), }) + diff --git a/addons/account/test/account_validate_account_move.yml b/addons/account/test/account_validate_account_move.yml new file mode 100644 index 00000000000..5157467800b --- /dev/null +++ b/addons/account/test/account_validate_account_move.yml @@ -0,0 +1,60 @@ +- + In order to test Validate Ledger Postings wizard in OpenERP I created a account move + +- + !record {model: account.move, id: account_move_0}: + date: '2010-06-07' + journal_id: account.bank_journal + line_id: + - account_id: account.cash + amount_currency: 0.0 + credit: 2000.0 + date: '2010-06-07' + debit: 0.0 + journal_id: account.bank_journal + name: Basic Computer + partner_id: base.res_partner_desertic_hispafuentes + period_id: account.period_6 + ref: '2010010' + tax_amount: 0.0 + - journal_id: account.bank_journal + period_id: account.period_6 + ref: '2010010' + tax_amount: 0.0 + account_id: account.a_recv + amount_currency: 0.0 + credit: 0.0 + date: '2010-06-07' + debit: 2000.0 + name: Basic Computer + partner_id: base.res_partner_desertic_hispafuentes + quantity: 0.0 + name: / + period_id: account.period_6 + ref: '2010010' + state: draft + +- + I check that Initially account move state is "Draft" +- + !assert {model: account.move, id: account_move_0}: + - state == 'draft' +- + I validate this account move by using Validate Ledger Postings +- + !record {model: validate.account.move, id: validate_account_move_0}: + journal_id: account.bank_journal + period_id: account.period_6 +- + I clicked on validate Button +- + !python {model: validate.account.move}: | + self.validate_move(cr, uid, [ref("validate_account_move_0")], {"lang": "en_US", + "active_model": "ir.ui.menu", "active_ids": [ref("account.menu_validate_account_moves")], + "tz": False, "active_id": ref("account.menu_validate_account_moves"), }) + +- + I check that the invoice state is now "Posted" +- + !assert {model: account.move, id: account_move_0}: + - state == 'posted' diff --git a/addons/account/test/chart_of_account.yml b/addons/account/test/chart_of_account.yml new file mode 100644 index 00000000000..39d7428ea73 --- /dev/null +++ b/addons/account/test/chart_of_account.yml @@ -0,0 +1,75 @@ +- + In order to check the Chart of Accounts wizard I run the wizard with target move set as all + +- + !record {model: account.chart, id: account_chart_0}: + target_move: all +- + I clicked on Open chart Button to open the chart +- + !python {model: account.chart}: | + self.account_chart_open_window(cr, uid, [ref("account_chart_0")], {"lang": 'en_US', + "active_model": "ir.ui.menu", "active_ids": [ref("account.menu_action_account_tree2")], + "tz": False, "active_id": ref("account.menu_action_account_tree2"), }) + +- + I create chart of account with target move set as posted +- + !record {model: account.chart, id: account_chart_0}: + target_move: posted +- + I clicked on Open chart Button to open the chart +- + !python {model: account.chart}: | + self.account_chart_open_window(cr, uid, [ref("account_chart_0")], {"lang": 'en_US', + "active_model": "ir.ui.menu", "active_ids": [ref("account.menu_action_account_tree2")], + "tz": False, "active_id": ref("account.menu_action_account_tree2"), }) + +- + In order to test Account Move Line Wizard I check the move line entries using this wizard +- + !record {model: account.move.line.select, id: account_move_line_select_0}: + {} +- + I clicked on Button to open the account move lines +- + !python {model: account.move.line.select}: | + self.open_window(cr, uid, [ref("account_move_line_select_0")], {"lang": 'en_US', + "state": "all", "tz": False, "active_model": "account.account", "active_ids": + [ref("account.a_recv")], "fiscalyear": 1, "active_id": ref("account.a_recv"), + }) + + +- + In order to test the Analytic Charts of Account wizard I will generate chart + +- + !record {model: account.analytic.chart, id: account_analytic_chart_0}: + from_date: '2010-01-01' + to_date: '2010-06-30' +- + I clicked on Open chart Button to open the charts + +- + !python {model: account.analytic.chart}: | + self.analytic_account_chart_open_window(cr, uid, [ref("account_analytic_chart_0")], + {"lang": 'en_US', "active_model": "ir.ui.menu", "active_ids": [ref("account.menu_action_analytic_account_tree2")], + "tz": False, "active_id": ref("account.menu_action_analytic_account_tree2"), + }) + +- + In order to test Account Journal Select wizard I open journal entries using this wizard +- + !record {model: account.journal.select, id: account_journal_select_0}: + {} +- + I clicked on Open Journal Button to open the entries + +- + !python {model: account.journal.select}: | + self.action_open_window(cr, uid, [ref("account_journal_select_0")], {"lang": + 'en_US', "active_model": "account.journal.period", "active_ids": [ref("account.a_recv")], + "tz": False, "active_id": ref("account.a_recv"), }) +- + I check that the entries open successfully + diff --git a/addons/account/wizard/__init__.py b/addons/account/wizard/__init__.py index 39971f5c11a..c56c6c2e764 100644 --- a/addons/account/wizard/__init__.py +++ b/addons/account/wizard/__init__.py @@ -22,6 +22,7 @@ import account_automatic_reconcile import account_move_line_reconcile_select import account_move_line_unreconcile_select +import account_reconcile_partner_process import account_reconcile import account_unreconcile import account_invoice_refund diff --git a/addons/account/wizard/account_automatic_reconcile.py b/addons/account/wizard/account_automatic_reconcile.py index a1798ae9cbf..3fb921696f4 100644 --- a/addons/account/wizard/account_automatic_reconcile.py +++ b/addons/account/wizard/account_automatic_reconcile.py @@ -31,15 +31,16 @@ class account_automatic_reconcile(osv.osv_memory): _columns = { 'account_ids': fields.many2many('account.account', 'reconcile_account_rel', 'reconcile_id', 'account_id', 'Account to reconcile', domain = [('reconcile','=',1)], \ help = 'If no account is specified, the reconciliation will be made using every accounts that can be reconcilied'), - 'writeoff_acc_id': fields.many2one('account.account', 'Account', required=True), - 'journal_id': fields.many2one('account.journal', 'Journal', required=True), - 'period_id': fields.many2one('account.period', 'Period', required=True), + 'writeoff_acc_id': fields.many2one('account.account', 'Account'), + 'journal_id': fields.many2one('account.journal', 'Journal'), + 'period_id': fields.many2one('account.period', 'Period'), 'max_amount': fields.float('Maximum write-off amount'), - 'power': fields.selection([(p, str(p)) for p in range(2, 10)], 'Power', required=True), + 'power': fields.selection([(p, str(p)) for p in range(2, 10)], 'Power', required=True, help='Number of partial amounts that can be combined to find a balance point can be chosen as the power of the automatic reconciliation'), 'date1': fields.date('Start of period', required=True), 'date2': fields.date('End of period', required=True), 'reconciled': fields.integer('Reconciled transactions', readonly=True), 'unreconciled': fields.integer('Not reconciled transactions', readonly=True), + 'allow_write_off': fields.boolean('Allow write off') } def _get_reconciled(self, cr, uid, context={}): @@ -145,16 +146,18 @@ class account_automatic_reconcile(osv.osv_memory): if not form['account_ids']: raise osv.except_osv(_('UserError'), _('You must select accounts to reconcile')) for account_id in form['account_ids']: + if not context.get('allow_write_off', False): + query = "SELECT partner_id FROM account_move_line WHERE account_id=%s AND reconcile_id IS NULL \ + AND state <> 'draft' GROUP BY partner_id \ + HAVING ABS(SUM(debit-credit)) <> %s AND count(*)>0"%(account_id, 0.0) +# query="SELECT partner_id FROM account_move_line WHERE account_id=%s AND reconcile_id IS NULL \ +# AND state <> 'draft' GROUP BY partner_id AND debit = credi"%(account_id) + else: + query = "SELECT partner_id FROM account_move_line WHERE account_id=%s AND reconcile_id IS NULL \ + AND state <> 'draft' GROUP BY partner_id \ + HAVING ABS(SUM(debit-credit)) <= %s AND count(*)>0"%(account_id, max_amount or 0.0) # reconcile automatically all transactions from partners whose balance is 0 - cr.execute( - "SELECT partner_id " \ - "FROM account_move_line " \ - "WHERE account_id=%s " \ - "AND reconcile_id IS NULL " \ - "AND state <> 'draft' " \ - "GROUP BY partner_id " \ - "HAVING ABS(SUM(debit-credit)) < %s AND count(*)>0", - (account_id, max_amount or 0.0)) + cr.execute(query) partner_ids = [id for (id,) in cr.fetchall()] for partner_id in partner_ids: cr.execute( @@ -167,63 +170,67 @@ class account_automatic_reconcile(osv.osv_memory): (account_id, partner_id)) line_ids = [id for (id,) in cr.fetchall()] if len(line_ids): - move_line_obj.reconcile(cr, uid, line_ids, 'auto', form['writeoff_acc_id'], form['period_id'], form['journal_id'], context) reconciled += len(line_ids) + if not context.get('allow_write_off', False): + move_line_obj.reconcile_partial(cr, uid, line_ids, 'manual', context={}) + else: + move_line_obj.reconcile(cr, uid, line_ids, 'auto', form['writeoff_acc_id'], form['period_id'], form['journal_id'], context) - # get the list of partners who have more than one unreconciled transaction - cr.execute( - "SELECT partner_id " \ - "FROM account_move_line " \ - "WHERE account_id=%s " \ - "AND reconcile_id IS NULL " \ - "AND state <> 'draft' " \ - "AND partner_id IS NOT NULL " \ - "GROUP BY partner_id " \ - "HAVING count(*)>1", - (account_id,)) - partner_ids = [id for (id,) in cr.fetchall()] - #filter? - for partner_id in partner_ids: - # get the list of unreconciled 'debit transactions' for this partner - cr.execute( - "SELECT id, debit " \ - "FROM account_move_line " \ - "WHERE account_id=%s " \ - "AND partner_id=%s " \ - "AND reconcile_id IS NULL " \ - "AND state <> 'draft' " \ - "AND debit > 0", - (account_id, partner_id)) - debits = cr.fetchall() + # get the list of partners who have more than one unreconciled transaction + cr.execute( + "SELECT partner_id " \ + "FROM account_move_line " \ + "WHERE account_id=%s " \ + "AND reconcile_id IS NULL " \ + "AND state <> 'draft' " \ + "AND partner_id IS NOT NULL " \ + "GROUP BY partner_id " \ + "HAVING count(*)>1", + (account_id,)) + partner_ids = [id for (id,) in cr.fetchall()] + #filter? + for partner_id in partner_ids: + # get the list of unreconciled 'debit transactions' for this partner + cr.execute( + "SELECT id, debit " \ + "FROM account_move_line " \ + "WHERE account_id=%s " \ + "AND partner_id=%s " \ + "AND reconcile_id IS NULL " \ + "AND state <> 'draft' " \ + "AND debit > 0", + (account_id, partner_id)) + debits = cr.fetchall() - # get the list of unreconciled 'credit transactions' for this partner - cr.execute( - "SELECT id, credit " \ - "FROM account_move_line " \ - "WHERE account_id=%s " \ - "AND partner_id=%s " \ - "AND reconcile_id IS NULL " \ - "AND state <> 'draft' " \ - "AND credit > 0", - (account_id, partner_id)) - credits = cr.fetchall() + # get the list of unreconciled 'credit transactions' for this partner + cr.execute( + "SELECT id, credit " \ + "FROM account_move_line " \ + "WHERE account_id=%s " \ + "AND partner_id=%s " \ + "AND reconcile_id IS NULL " \ + "AND state <> 'draft' " \ + "AND credit > 0", + (account_id, partner_id)) + credits = cr.fetchall() - (rec, unrec) = self.do_reconcile(cr, uid, credits, debits, max_amount, power, form['writeoff_acc_id'], form['period_id'], form['journal_id'], context) - reconciled += rec - unreconciled += unrec + (rec, unrec) = self.do_reconcile(cr, uid, credits, debits, max_amount, power, form['writeoff_acc_id'], form['period_id'], form['journal_id'], context) + reconciled += rec + unreconciled += unrec - # add the number of transactions for partners who have only one - # unreconciled transactions to the unreconciled count - partner_filter = partner_ids and 'AND partner_id not in (%s)' % ','.join(map(str, filter(None, partner_ids))) or '' - cr.execute( - "SELECT count(*) " \ - "FROM account_move_line " \ - "WHERE account_id=%s " \ - "AND reconcile_id IS NULL " \ - "AND state <> 'draft' " + partner_filter, - (account_id,)) - additional_unrec = cr.fetchone()[0] - context.update({'reconciled': reconciled, 'unreconciled': unreconciled + additional_unrec}) + # add the number of transactions for partners who have only one + # unreconciled transactions to the unreconciled count + partner_filter = partner_ids and 'AND partner_id not in (%s)' % ','.join(map(str, filter(None, partner_ids))) or '' + cr.execute( + "SELECT count(*) " \ + "FROM account_move_line " \ + "WHERE account_id=%s " \ + "AND reconcile_id IS NULL " \ + "AND state <> 'draft' " + partner_filter, + (account_id,)) + additional_unrec = cr.fetchone()[0] + unreconciled = unreconciled + additional_unrec + context.update({'reconciled': reconciled, 'unreconciled': unreconciled}) model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','account_automatic_reconcile_view1')]) resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'])[0]['res_id'] return { @@ -239,4 +246,4 @@ class account_automatic_reconcile(osv.osv_memory): account_automatic_reconcile() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/account/wizard/account_automatic_reconcile_view.xml b/addons/account/wizard/account_automatic_reconcile_view.xml index 02fbb5a7376..f48fa010ad8 100644 --- a/addons/account/wizard/account_automatic_reconcile_view.xml +++ b/addons/account/wizard/account_automatic_reconcile_view.xml @@ -8,21 +8,29 @@ form
+ + - - - - - + + + + + + + + + +