diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py index 9bbddb1e050..823bb56a7a9 100644 --- a/addons/account/__openerp__.py +++ b/addons/account/__openerp__.py @@ -32,7 +32,7 @@ Customer and Supplier Invoices Bank statements Reconciliation process by partner - Creates a dashboards for accountants that includes: + Creates a dashboard for accountants that includes: * List of uninvoiced quotations * Graph of aged receivables * Graph of aged incomes @@ -49,7 +49,6 @@ module named account_voucher. 'security/ir.model.access.csv', 'account_menuitem.xml', 'account_wizard.xml', - 'wizard/account_statement_from_invoice_view.xml', 'wizard/account_move_bank_reconcile_view.xml', 'wizard/account_use_model_view.xml', 'account_installer.xml', @@ -81,7 +80,6 @@ module named account_voucher. 'wizard/account_report_partner_balance_view.xml', 'wizard/account_report_account_balance_view.xml', 'wizard/account_report_aged_partner_balance_view.xml', - 'wizard/account_compare_account_balance_report_view.xml', 'wizard/account_report_partner_ledger_view.xml', 'wizard/account_reconcile_view.xml', 'wizard/account_reconcile_partner_process_view.xml', diff --git a/addons/account/account.py b/addons/account/account.py index df6a0492ff9..909b1a1203c 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -65,10 +65,10 @@ class account_payment_term(osv.osv): } _order = "name" - def compute(self, cr, uid, id, value, date_ref=False, context={}): + def compute(self, cr, uid, id, value, date_ref=False, context=None): if not date_ref: date_ref = datetime.now().strftime('%Y-%m-%d') - pt = self.browse(cr, uid, id, context) + pt = self.browse(cr, uid, id, context=context) amount = value result = [] for line in pt.line_ids: @@ -125,7 +125,7 @@ class account_payment_term_line(osv.osv): } _order = "sequence" - def _check_percent(self, cr, uid, ids, context={}): + def _check_percent(self, cr, uid, ids, context=None): obj = self.browse(cr, uid, ids[0]) if obj.value == 'procent' and ( obj.value_amount < 0.0 or obj.value_amount > 1.0): return False @@ -156,21 +156,22 @@ class account_account_type(osv.osv): ('expense','Profit & Loss (Expense Accounts)'), ('asset','Balance Sheet (Assets Accounts)'), ('liability','Balance Sheet (Liability Accounts)') - ],'Type Heads', select=True, readonly=False, help="According value related accounts will be display on respective reports (Balance Sheet Profit & Loss Account)"), + ],'Type Heads', select=True, readonly=False, help="According value related accounts will be display on respective reports (Balance Sheet Profit & Loss Account)", required=True), 'note': fields.text('Description'), } _defaults = { 'close_method': 'none', 'sign': 1, + 'report_type': 'none', } _order = "code" account_account_type() -def _code_get(self, cr, uid, context={}): +def _code_get(self, cr, uid, context=None): acc_type_obj = self.pool.get('account.account.type') ids = acc_type_obj.search(cr, uid, []) - res = acc_type_obj.read(cr, uid, ids, ['code', 'name'], context) + res = acc_type_obj.read(cr, uid, ids, ['code', 'name'], context=context) return [(r['code'], r['name']) for r in res] #---------------------------------------------------------- @@ -463,10 +464,10 @@ class account_account(osv.osv): ids = self.search(cr, user, args, context=context, limit=limit) return self.name_get(cr, user, ids, context=context) - def name_get(self, cr, uid, ids, context={}): + def name_get(self, cr, uid, ids, context=None): if not len(ids): return [] - reads = self.read(cr, uid, ids, ['name', 'code'], context) + reads = self.read(cr, uid, ids, ['name', 'code'], context=context) res = [] for record in reads: name = record['name'] @@ -475,7 +476,7 @@ class account_account(osv.osv): res.append((record['id'], name)) return res - def copy(self, cr, uid, id, default={}, context={}, done_list=[], local=False): + def copy(self, cr, uid, id, default={}, context=None, done_list=[], local=False): account = self.browse(cr, uid, id, context=context) new_child_ids = [] if not default: @@ -562,16 +563,17 @@ account_journal_view() class account_journal_column(osv.osv): - def _col_get(self, cr, user, context={}): + + def _col_get(self, cr, user, context=None): result = [] cols = self.pool.get('account.move.line')._columns for col in cols: if col in ('period_id', 'journal_id'): continue - result.append( (col, cols[col].string) ) result.sort() return result + _name = "account.journal.column" _description = "Journal Column" _columns = { @@ -629,7 +631,7 @@ class account_journal(osv.osv): 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_sequence(self, cr, uid, vals, context={}): + def create_sequence(self, cr, uid, vals, context=None): """ Create new entry sequence for every new Joural @param cr: cursor to database @@ -671,12 +673,12 @@ class account_journal(osv.osv): } return seq_pool.create(cr, uid, seq) - def create(self, cr, uid, vals, context={}): + def create(self, cr, uid, vals, context=None): if not 'sequence_id' in vals or not vals['sequence_id']: vals.update({'sequence_id' : self.create_sequence(cr, uid, vals, context)}) return super(account_journal, self).create(cr, uid, vals, context) - def name_get(self, cr, user, ids, context={}): + def name_get(self, cr, user, ids, context=None): """ Returns a list of tupples containing id, name. result format : {[(id, name), (id, name), ...]} @@ -1701,6 +1703,11 @@ class account_tax(osv.osv): ids = self.search(cr, user, args, limit=limit, context=context) return self.name_get(cr, user, ids, context=context) + def write(self, cr, uid, ids, vals, context=None): + if vals.get('type', False) and vals['type'] in ('none', 'code'): + vals.update({'amount': 0.0}) + return super(account_tax, self).write(cr, uid, ids, vals, context=context) + def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False): journal_pool = self.pool.get('account.journal') @@ -1996,32 +2003,34 @@ class account_model(osv.osv): _columns = { 'name': fields.char('Model Name', size=64, required=True, help="This is a model for recurring accounting entries"), 'journal_id': fields.many2one('account.journal', 'Journal', required=True), - 'company_id': fields.many2one('res.company', 'Company', required=True), + 'company_id': fields.related('journal_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True), 'lines_id': fields.one2many('account.model.line', 'model_id', 'Model Entries'), 'legend' :fields.text('Legend', readonly=True, size=100), } _defaults = { 'legend': lambda self, cr, uid, context:_('You can specify year, month and date in the name of the model using the following labels:\n\n%(year)s : To Specify Year \n%(month)s : To Specify Month \n%(date)s : Current Date\n\ne.g. My model on %(date)s'), - 'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id, } - def generate(self, cr, uid, ids, datas={}, context={}): + def generate(self, cr, uid, ids, datas={}, context=None): move_ids = [] entry = {} account_move_obj = self.pool.get('account.move') account_move_line_obj = self.pool.get('account.move.line') pt_obj = self.pool.get('account.payment.term') - if datas.get('date', False): - context.update({'date':datas['date']}) - period_id = self.pool.get('account.period').find(cr, uid, dt=context.get('date', False)) + if context is None: + context = {} + if datas.get('date', False): + context.update({'date': datas['date']}) + + 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] for model in self.browse(cr, uid, ids, context): - entry['name'] = model.name%{'year':time.strftime('%Y'), 'month':time.strftime('%m'), 'date':time.strftime('%d')} + entry['name'] = model.name%{'year':time.strftime('%Y'), 'month':time.strftime('%m'), 'date':time.strftime('%Y-%m')} move_id = account_move_obj.create(cr, uid, { 'ref': entry['name'], 'period_id': period_id, @@ -2069,7 +2078,9 @@ class account_model(osv.osv): c = context.copy() c.update({'journal_id': model.journal_id.id,'period_id': period_id}) account_move_line_obj.create(cr, uid, val, context=c) + return move_ids + account_model() class account_model_line(osv.osv): @@ -2541,6 +2552,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): obj_fiscal_position_template = self.pool.get('account.fiscal.position.template') obj_fiscal_position = self.pool.get('account.fiscal.position') data_pool = self.pool.get('ir.model.data') + analytic_journal_obj = self.pool.get('account.analytic.journal') # Creating Account obj_acc_root = obj_multi.chart_template_id.account_root_id @@ -2666,11 +2678,15 @@ class wizard_multi_charts_accounts(osv.osv_memory): vals_journal['view_id'] = view_id #Sales Journal + analitical_sale_ids = analytic_journal_obj.search(cr,uid,[('type','=','sale')]) + analitical_journal_sale = analitical_sale_ids and analitical_sale_ids[0] or False + vals_journal['name'] = _('Sales Journal') vals_journal['type'] = 'sale' vals_journal['code'] = _('SAJ') vals_journal['sequence_id'] = seq_id_sale vals_journal['company_id'] = company_id + vals_journal['analytic_journal_id'] = analitical_journal_sale if obj_multi.chart_template_id.property_account_receivable: vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_income_categ.id] @@ -2679,12 +2695,16 @@ class wizard_multi_charts_accounts(osv.osv_memory): obj_journal.create(cr,uid,vals_journal) # Purchase Journal + analitical_purchase_ids = analytic_journal_obj.search(cr,uid,[('type','=','purchase')]) + analitical_journal_purchase = analitical_purchase_ids and analitical_purchase_ids[0] or False + vals_journal['name'] = _('Purchase Journal') vals_journal['type'] = 'purchase' vals_journal['code'] = _('EXJ') vals_journal['sequence_id'] = seq_id_purchase vals_journal['view_id'] = view_id vals_journal['company_id'] = company_id + vals_journal['analytic_journal_id'] = analitical_journal_purchase if obj_multi.chart_template_id.property_account_payable: vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_expense_categ.id] @@ -2732,11 +2752,15 @@ class wizard_multi_charts_accounts(osv.osv_memory): seq_id = obj_sequence.create(cr,uid,vals_seq) #create the bank journal + analitical_bank_ids = analytic_journal_obj.search(cr,uid,[('type','=','situation')]) + analitical_journal_bank = analitical_bank_ids and analitical_bank_ids[0] or False + vals_journal['name']= vals['name'] vals_journal['code']= _('BNK') + str(current_num) vals_journal['sequence_id'] = seq_id vals_journal['type'] = 'cash' vals_journal['company_id'] = company_id + vals_journal['analytic_journal_id'] = analitical_journal_bank if line.currency_id: vals_journal['view_id'] = view_id_cur @@ -2745,8 +2769,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): vals_journal['view_id'] = view_id_cash vals_journal['default_credit_account_id'] = acc_cash_id vals_journal['default_debit_account_id'] = acc_cash_id - obj_journal.create(cr,uid,vals_journal) - + obj_journal.create(cr, uid, vals_journal) current_num += 1 #create the properties @@ -2811,14 +2834,6 @@ class wizard_multi_charts_accounts(osv.osv_memory): } obj_ac_fp.create(cr, uid, vals_acc) - #fially inactive the demo chart of accounts - data_id = data_pool.search(cr, uid, [('model','=','account.account'), ('name','=','chart0')]) - if data_id: - data = data_pool.browse(cr, uid, data_id[0]) - account_id = data.res_id - acc_ids = obj_acc._get_children_and_consol(cr, uid, [account_id]) - if acc_ids: - cr.execute("update account_account set active='f' where id in " + str(tuple(acc_ids))) wizard_multi_charts_accounts() class account_bank_accounts_wizard(osv.osv_memory): diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py index 5faec1c63a0..b68083a0bf6 100644 --- a/addons/account/account_analytic_line.py +++ b/addons/account/account_analytic_line.py @@ -71,18 +71,22 @@ class account_analytic_line(osv.osv): # Compute the cost based on the price type define into company # property_valuation_price_type property - def on_change_unit_amount(self, cr, uid, id, prod_id, unit_amount,company_id, + def on_change_unit_amount(self, cr, uid, id, prod_id, quantity, company_id, unit=False, journal_id=False, context=None): if context==None: context={} - uom_obj = self.pool.get('product.uom') + if not journal_id or not prod_id: + return {} product_obj = self.pool.get('product.product') - company_obj=self.pool.get('res.company') - analytic_journal_obj=self.pool.get('account.analytic.journal') - product_price_type_obj = self.pool.get('product.price.type') - if prod_id: - result = 0.0 - prod = product_obj.browse(cr, uid, prod_id) + analytic_journal_obj =self.pool.get('account.analytic.journal') + j_id = analytic_journal_obj.browse(cr, uid, journal_id, context=context) + prod = product_obj.browse(cr, uid, prod_id) + if not company_id: + company_id = j_id.company_id.id + result = 0.0 + is_purchase = False + + if j_id.type == 'purchase': a = prod.product_tmpl_id.property_account_expense.id if not a: a = prod.categ_id.property_account_expense_categ.id @@ -91,8 +95,22 @@ class account_analytic_line(osv.osv): _('There is no expense account defined ' \ 'for this product: "%s" (id:%d)') % \ (prod.name, prod.id,)) - if not company_id: - company_id=company_obj._company_default_get(cr, uid, 'account.analytic.line', context) + amount_unit = prod.price_get('standard_price', context)[prod.id] + is_purchase = True + + else: + a = prod.product_tmpl_id.property_account_income.id + if not a: + a = prod.categ_id.property_account_income_categ.id + if not a: + raise osv.except_osv(_('Error !'), + _('There is no income account defined ' \ + 'for this product: "%s" (id:%d)') % \ + (prod.name, prod_id,)) + amount_unit = prod.price_get('list_price', context)[prod_id] + + if not company_id: + company_id=company_obj._company_default_get(cr, uid, 'account.analytic.line', context) flag = False # Compute based on pricetype product_price_type_ids = product_price_type_obj.search(cr, uid, [('field','=','standard_price')], context) @@ -116,8 +134,8 @@ class account_analytic_line(osv.osv): return {'value': { 'amount': result, 'general_account_id': a, - }} - return {} + } + } def view_header_get(self, cr, user, view_id, view_type, context): if context.get('account_id', False): diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index 3267ae6cecf..647d80e61be 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -71,12 +71,10 @@ class account_bank_statement(osv.osv): journal_pool = self.pool.get('account.journal') journal_type = context.get('journal_type', False) journal_id = False - if journal_type: ids = journal_pool.search(cr, uid, [('type', '=', journal_type)]) if ids: journal_id = ids[0] - return journal_id def _default_balance_start(self, cr, uid, context={}): @@ -152,7 +150,7 @@ class account_bank_statement(osv.osv): 'name': fields.char('Name', size=64, required=True, help='if you give the Name other then /, its created Accounting Entries Move will be with same name as statement name. This allows the statement entries to have the same references than the statement itself', states={'confirm': [('readonly', True)]}), 'date': fields.date('Date', required=True, states={'confirm': [('readonly', True)]}), 'journal_id': fields.many2one('account.journal', 'Journal', required=True, - states={'confirm': [('readonly', True)]}, domain=[('type', '=', 'bank')]), + readonly=True, states={'draft':[('readonly',False)]}), 'period_id': fields.many2one('account.period', 'Period', required=True, states={'confirm':[('readonly', True)]}), 'balance_start': fields.float('Starting Balance', digits_compute=dp.get_precision('Account'), @@ -176,15 +174,15 @@ class account_bank_statement(osv.osv): } _defaults = { - 'name': lambda *a: "/", - 'date': lambda *a: time.strftime('%Y-%m-%d'), - 'state': lambda *a: 'draft', + 'name': "/", + 'date': time.strftime('%Y-%m-%d'), + 'state': 'draft', 'balance_start': _default_balance_start, 'journal_id': _default_journal_id, 'period_id': _get_period, } - def onchange_date(self, cr, user, ids, date, context={}): + def onchange_date(self, cr, user, ids, date, context=None): """ Returns a dict that contains new values and context @param cr: A database cursor @@ -196,6 +194,10 @@ class account_bank_statement(osv.osv): """ res = {} period_pool = self.pool.get('account.period') + + if context is None: + context = {} + pids = period_pool.search(cr, user, [('date_start','<=',date), ('date_stop','>=',date)]) if pids: res.update({ @@ -210,10 +212,8 @@ class account_bank_statement(osv.osv): 'context':context, } - def button_dummy(self, cr, uid, ids, context={}): - self.write(cr, uid, ids, {}, context) - return True - + def button_dummy(self, cr, uid, ids, context=None): + return self.write(cr, uid, ids, {}, context=context) def create_move_from_st_line(self, cr, uid, st_line_id, company_currency_id, st_line_number, context=None): res_currency_obj = self.pool.get('res.currency') @@ -222,10 +222,10 @@ class account_bank_statement(osv.osv): account_move_line_obj = self.pool.get('account.move.line') account_analytic_line_obj = self.pool.get('account.analytic.line') account_bank_statement_line_obj = self.pool.get('account.bank.statement.line') - + st_line = account_bank_statement_line_obj.browse(cr, uid, st_line_id, context) st = st_line.statement_id - + context.update({'date': st_line.date}) move_id = account_move_obj.create(cr, uid, { 'journal_id': st.journal_id.id, @@ -284,7 +284,7 @@ class account_bank_statement(osv.osv): move_line_id = account_move_line_obj.create(cr, uid, val , context=context) torec.append(move_line_id) - + # Fill the secondary amount/currency # if currency is not the same than the company amount_currency = False @@ -323,22 +323,33 @@ class account_bank_statement(osv.osv): def get_next_st_line_number(self, cr, uid, st_number, st_line, context=None): return st_number + ' - ' + str(st_line.sequence) + def balance_check(self, cr, uid, st_id, journal_type='bank', context=None): + st = self.browse(cr, uid, st_id, context) + if not (abs((st.balance_end or 0.0) - st.balance_end_real) < 0.0001): + raise osv.except_osv(_('Error !'), + _('The statement balance is incorrect !\n') + + _('The expected balance (%.2f) is different than the computed one. (%.2f)') % (st.balance_end_real, st.balance_end)) + return True + + def statement_close(self, cr, uid, ids, journal_type='bank', context=None): + return self.write(cr, uid, ids, {'state':'confirm'}, context=context) + + def check_status_condition(self, cr, uid, state, journal_type='bank'): + return state=='draft' + def button_confirm_bank(self, cr, uid, ids, context=None): done = [] obj_seq = self.pool.get('ir.sequence') - if context is None: context = {} for st in self.browse(cr, uid, ids, context): + j_type = st.journal_id.type company_currency_id = st.journal_id.company_id.currency_id.id - if not st.state=='draft': + if not self.check_status_condition(cr, uid, st.state, journal_type=j_type): continue - if not (abs((st.balance_end or 0.0) - st.balance_end_real) < 0.0001): - raise osv.except_osv(_('Error !'), - _('The statement balance is incorrect !\n') + - _('The expected balance (%.2f) is different than the computed one. (%.2f)') % (st.balance_end_real, st.balance_end)) + self.balance_check(cr, uid, st.id, journal_type=j_type, context=context) if (not st.journal_id.default_credit_account_id) \ or (not st.journal_id.default_debit_account_id): raise osv.except_osv(_('Configuration Error !'), @@ -369,11 +380,9 @@ class account_bank_statement(osv.osv): self.write(cr, uid, [st.id], {'name': st_number}, context=context) self.log(cr, uid, st.id, 'Statement %s is confirmed and entries are created.' % st_number) done.append(st.id) + return self.write(cr, uid, ids, {'state':'confirm'}, context=context) - self.write(cr, uid, done, {'state':'confirm'}, context=context) - return True - - def button_cancel(self, cr, uid, ids, context={}): + def button_cancel(self, cr, uid, ids, context=None): done = [] for st in self.browse(cr, uid, ids, context): if st.state=='draft': @@ -383,8 +392,7 @@ class account_bank_statement(osv.osv): ids += [x.id for x in line.move_ids] self.pool.get('account.move').unlink(cr, uid, ids, context) done.append(st.id) - self.write(cr, uid, done, {'state':'draft'}, context=context) - return True + return self.write(cr, uid, done, {'state':'draft'}, context=context) def onchange_journal_id(self, cursor, user, statement_id, journal_id, context=None): account_journal_obj = self.pool.get('account.journal') @@ -404,7 +412,7 @@ class account_bank_statement(osv.osv): if t['state'] in ('draft'): unlink_ids.append(t['id']) else: - raise osv.except_osv(_('Invalid action !'), _('Cannot delete bank statement which are already confirmed !')) + raise osv.except_osv(_('Invalid action !'), _('Cannot delete bank statement(s) which are already confirmed !')) osv.osv.unlink(self, cr, uid, unlink_ids, context=context) return True @@ -415,7 +423,7 @@ class account_bank_statement(osv.osv): context = {} default = default.copy() default['move_line_ids'] = [] - return super(account_bank_statement, self).copy(cr, uid, id, default, context) + return super(account_bank_statement, self).copy(cr, uid, id, default, context=context) account_bank_statement() @@ -487,8 +495,8 @@ class account_bank_statement_line(osv.osv): } _defaults = { 'name': lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'account.bank.statement.line'), - 'date': lambda *a: time.strftime('%Y-%m-%d'), - 'type': lambda *a: 'general', + 'date': time.strftime('%Y-%m-%d'), + 'type': 'general', } account_bank_statement_line() diff --git a/addons/account/account_cash_statement.py b/addons/account/account_cash_statement.py index 2fd80348404..7213cead24a 100644 --- a/addons/account/account_cash_statement.py +++ b/addons/account/account_cash_statement.py @@ -20,9 +20,10 @@ # ############################################################################## -from osv import osv, fields import time from mx import DateTime + +from osv import osv, fields from decimal import Decimal from tools.translate import _ import decimal_precision as dp @@ -204,7 +205,6 @@ class account_cash_statement(osv.osv): return res _columns = { - 'journal_id': fields.many2one('account.journal', 'Journal', required=True, states={'draft': [('readonly', False)]}, readonly=True, domain=[('type', '=', 'cash')]), 'balance_end_real': fields.float('Closing Balance', digits_compute=dp.get_precision('Account'), states={'confirm':[('readonly', True)]}, help="closing balance entered by the cashbox verifier"), 'state': fields.selection( [('draft', 'Draft'), @@ -291,7 +291,10 @@ class account_cash_statement(osv.osv): res = super(account_cash_statement, self).onchange_journal_id(cr, uid, statement_id, journal_id, context=context) return res - def _equal_balance(self, cr, uid, ids, statement, context={}): + def _equal_balance(self, cr, uid, cash_id, context=None): + statement = self.browse(cr, uid, cash_id, context=context) + self.write(cr, uid, [cash_id], {'balance_end_real': statement.balance_end}) + statement.balance_end_real = statement.balance_end if statement.balance_end != statement.balance_end_cash: return False else: @@ -320,26 +323,6 @@ class account_cash_statement(osv.osv): 'name': number }) -# cr.execute("select id from account_bank_statement where journal_id=%s and user_id=%s and state=%s order by id desc limit 1", (statement.journal_id.id, uid, 'confirm')) -# rs = cr.fetchone() -# rs = rs and rs[0] or None -# if rs: -# if len(statement.starting_details_ids) > 0: -# sid = [] -# for line in statement.starting_details_ids: -# sid.append(line.id) -# cash_pool.unlink(cr, uid, sid) -# -# statement = statement_pool.browse(cr, uid, rs) -# balance_start = statement.balance_end_real or 0.0 -# open_ids = cash_pool.search(cr, uid, [('ending_id','=',statement.id)]) -# for sid in open_ids: -# default = { -# 'ending_id': False, -# 'starting_id':ids[0] -# } -# cash_pool.copy(cr, uid, sid, default) - vals.update({ 'date':time.strftime("%Y-%m-%d %H:%M:%S"), 'state':'open', @@ -349,204 +332,31 @@ class account_cash_statement(osv.osv): self.write(cr, uid, ids, vals) return True - def button_confirm_cash(self, cr, uid, ids, context={}): - - """ Check the starting and ending detail of statement - @return: True - """ - done = [] - res_currency_obj = self.pool.get('res.currency') - res_users_obj = self.pool.get('res.users') - account_move_obj = self.pool.get('account.move') - account_move_line_obj = self.pool.get('account.move.line') - account_analytic_line_obj = self.pool.get('account.analytic.line') - account_bank_statement_line_obj = self.pool.get('account.bank.statement.line') - - company_currency_id = res_users_obj.browse(cr, uid, uid, context=context).company_id.currency_id.id - - for st in self.browse(cr, uid, ids, context): - - self.write(cr, uid, [st.id], {'balance_end_real':st.balance_end}) - st.balance_end_real = st.balance_end - - if not st.state == 'open': - continue - - if not self._equal_balance(cr, uid, ids, st, context): - raise osv.except_osv(_('Error !'), _('CashBox Balance is not matching with Calculated Balance !')) - - if (not st.journal_id.default_credit_account_id) \ - or (not st.journal_id.default_debit_account_id): - raise osv.except_osv(_('Configuration Error !'), - _('Please verify that an account is defined in the journal.')) - - for line in st.move_line_ids: - if line.state <> 'valid': - raise osv.except_osv(_('Error !'), - _('The account entries lines are not in valid state.')) - # for bank.statement.lines - # In line we get reconcile_id on bank.ste.rec. - # in bank stat.rec we get line_new_ids on bank.stat.rec.line - for move in st.line_ids: - if move.analytic_account_id: - if not st.journal_id.analytic_journal_id: - raise osv.except_osv(_('No Analytic Journal !'),_("You have to define an analytic journal on the '%s' journal!") % (st.journal_id.name,)) - - context.update({'date':move.date}) - move_id = account_move_obj.create(cr, uid, { - 'journal_id': st.journal_id.id, - 'period_id': st.period_id.id, - 'date': move.date, - }, context=context) - account_bank_statement_line_obj.write(cr, uid, [move.id], { - 'move_ids': [(4,move_id, False)] - }) - if not move.amount: - continue - - torec = [] - if move.amount >= 0: - account_id = st.journal_id.default_credit_account_id.id - else: - account_id = st.journal_id.default_debit_account_id.id - acc_cur = ((move.amount<=0) and st.journal_id.default_debit_account_id) or move.account_id - amount = res_currency_obj.compute(cr, uid, st.currency.id, - company_currency_id, move.amount, context=context, - account=acc_cur) - if move.reconcile_id and move.reconcile_id.line_new_ids: - for newline in move.reconcile_id.line_new_ids: - amount += newline.amount - - val = { - 'name': move.name, - 'date': move.date, - 'ref': move.ref, - 'move_id': move_id, - 'partner_id': ((move.partner_id) and move.partner_id.id) or False, - 'account_id': (move.account_id) and move.account_id.id, - 'credit': ((amount>0) and amount) or 0.0, - 'debit': ((amount<0) and -amount) or 0.0, - 'statement_id': st.id, - 'journal_id': st.journal_id.id, - 'period_id': st.period_id.id, - 'currency_id': st.currency.id, - 'analytic_account_id': move.analytic_account_id and move.analytic_account_id.id or False - } - - amount = res_currency_obj.compute(cr, uid, st.currency.id, - company_currency_id, move.amount, context=context, - account=acc_cur) - if st.currency.id <> company_currency_id: - amount_cur = res_currency_obj.compute(cr, uid, company_currency_id, - st.currency.id, amount, context=context, - account=acc_cur) - val['amount_currency'] = -amount_cur - - if move.account_id and move.account_id.currency_id and move.account_id.currency_id.id <> company_currency_id: - val['currency_id'] = move.account_id.currency_id.id - if company_currency_id==move.account_id.currency_id.id: - amount_cur = move.amount - else: - amount_cur = res_currency_obj.compute(cr, uid, company_currency_id, - move.account_id.currency_id.id, amount, context=context, - account=acc_cur) - val['amount_currency'] = amount_cur - move_line_id = account_move_line_obj.create(cr, uid, val , context=context) - torec.append(move_line_id) - -# if move.analytic_account_id: -# anal_val = {} -# amt = (val['credit'] or 0.0) - (val['debit'] or 0.0) -# anal_val = { -# 'name': val['name'], -# 'ref': val['ref'], -# 'date': val['date'], -# 'amount': amt, -# 'account_id': val['analytic_account_id'], -# 'currency_id': val['currency_id'], -# 'general_account_id': val['account_id'], -# 'journal_id': st.journal_id.analytic_journal_id.id, -# 'period_id': val['period_id'], -# 'user_id': uid, -# 'move_id': move_line_id -# } -# if val.get('amount_currency', False): -# anal_val['amount_currency'] = val['amount_currency'] -# account_analytic_line_obj.create(cr, uid, anal_val, context=context) - - if move.reconcile_id and move.reconcile_id.line_new_ids: - for newline in move.reconcile_id.line_new_ids: - account_move_line_obj.create(cr, uid, { - 'name': newline.name or move.name, - 'date': move.date, - 'ref': move.ref, - 'move_id': move_id, - 'partner_id': ((move.partner_id) and move.partner_id.id) or False, - 'account_id': (newline.account_id) and newline.account_id.id, - 'debit': newline.amount>0 and newline.amount or 0.0, - 'credit': newline.amount<0 and -newline.amount or 0.0, - 'statement_id': st.id, - 'journal_id': st.journal_id.id, - 'period_id': st.period_id.id, - 'analytic_account_id':newline.analytic_id and newline.analytic_id.id or False, - - }, context=context) - - # Fill the secondary amount/currency - # if currency is not the same than the company - amount_currency = False - currency_id = False - if st.currency.id <> company_currency_id: - amount_currency = move.amount - currency_id = st.currency.id - account_move_line_obj.create(cr, uid, { - 'name': move.name, - 'date': move.date, - 'ref': move.ref, - 'move_id': move_id, - 'partner_id': ((move.partner_id) and move.partner_id.id) or False, - 'account_id': account_id, - 'credit': ((amount < 0) and -amount) or 0.0, - 'debit': ((amount > 0) and amount) or 0.0, - 'statement_id': st.id, - 'journal_id': st.journal_id.id, - 'period_id': st.period_id.id, - 'amount_currency': amount_currency, - 'currency_id': currency_id, - }, context=context) - - for line in account_move_line_obj.browse(cr, uid, [x.id for x in - account_move_obj.browse(cr, uid, move_id, - context=context).line_id], - context=context): - if line.state <> 'valid': - raise osv.except_osv(_('Error !'), - _('Journal Item "%s" is not valid') % line.name) - - if move.reconcile_id and move.reconcile_id.line_ids: - torec += map(lambda x: x.id, move.reconcile_id.line_ids) - - if abs(move.reconcile_amount-move.amount)<0.0001: - - writeoff_acc_id = False - #There should only be one write-off account! - for entry in move.reconcile_id.line_new_ids: - writeoff_acc_id = entry.account_id.id - break - - account_move_line_obj.reconcile(cr, uid, torec, 'statement', writeoff_acc_id=writeoff_acc_id, writeoff_period_id=st.period_id.id, writeoff_journal_id=st.journal_id.id, context=context) - else: - account_move_line_obj.reconcile_partial(cr, uid, torec, 'statement', context) - move_name = st.name + ' - ' + str(move.sequence) - account_move_obj.write(cr, uid, [move_id], {'state':'posted', 'name': move_name}) - done.append(st.id) + def balance_check(self, cr, uid, cash_id, journal_type='bank', context=None): + if journal_type == 'bank': + return super(account_cash_statement, self).balance_check(cr, uid, cash_id, journal_type, context) + if not self._equal_balance(cr, uid, cash_id, context): + raise osv.except_osv(_('Error !'), _('CashBox Balance is not matching with Calculated Balance !')) + return True + def statement_close(self, cr, uid, ids, journal_type='bank', context=None): + if journal_type == 'bank': + return super(account_cash_statement, self).statement_close(cr, uid, ids, journal_type, context) vals = { 'state':'confirm', 'closing_date':time.strftime("%Y-%m-%d %H:%M:%S") } - self.write(cr, uid, done, vals, context=context) - return True + return self.write(cr, uid, ids, vals, context=context) + + def check_status_condition(self, cr, uid, state, journal_type='bank'): + if journal_type == 'bank': + return super(account_cash_statement, self).check_status_condition(cr, uid, state, journal_type) + return state=='open' + + def button_confirm_cash(self, cr, uid, ids, context=None): + super(account_cash_statement, self).button_confirm_bank(cr, uid, ids, context=context) + return self.write(cr, uid, ids, {'closing_date':time.strftime("%Y-%m-%d %H:%M:%S")}, context=context) + def button_cancel(self, cr, uid, ids, context={}): done = [] @@ -560,4 +370,3 @@ class account_cash_statement(osv.osv): return True account_cash_statement() - diff --git a/addons/account/account_installer.xml b/addons/account/account_installer.xml index a9de51c3afb..a3570fae79a 100644 --- a/addons/account/account_installer.xml +++ b/addons/account/account_installer.xml @@ -73,7 +73,7 @@ - Add extra Accounting Addons to the ones already installed. Remember you can always install them at a later stage. + Add extra Accounting functionalities to the ones already installed. Configure diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index 53ec4405b9a..2122c879fbb 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -62,7 +62,7 @@ - + @@ -178,7 +178,7 @@ - + @@ -357,7 +357,7 @@ - + diff --git a/addons/account/account_menuitem.xml b/addons/account/account_menuitem.xml index feef0c8fa5e..ecce5df944f 100644 --- a/addons/account/account_menuitem.xml +++ b/addons/account/account_menuitem.xml @@ -8,8 +8,7 @@ - - + @@ -19,11 +18,11 @@ - - - + + + - + 'draft' GROUP BY l.partner_id ) AS s ON (p.id = s.partner_id) + WHERE debit > 0 AND credit > 0 ORDER BY p.last_reconciliation_date LIMIT 1 OFFSET %s""", (offset,) ) return cr.fetchone() @@ -799,8 +800,8 @@ class account_move_line(osv.osv): 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): + partner_id = lines[0].partner_id and lines[0].partner_id.id or False + if partner_id and 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 @@ -946,7 +947,7 @@ class account_move_line(osv.osv): if field in ('amount_currency', 'currency_id'): attrs.append('on_change="onchange_currency(account_id, amount_currency,currency_id, date, journal_id)"') - attrs.append("attrs='{'readonly':[('state','=','valid')]}'") + attrs.append('''attrs="{'readonly':[('state','=','valid')]}"''') if field in widths: attrs.append('width="'+str(widths[field])+'"') diff --git a/addons/account/account_report.xml b/addons/account/account_report.xml index 14efecf350d..b41f90245f5 100644 --- a/addons/account/account_report.xml +++ b/addons/account/account_report.xml @@ -47,14 +47,6 @@ name="Taxes" parent="account.menu_finance_generic_reporting" sequence="3"/> - - - - + + @@ -510,15 +510,12 @@ - + -