diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py index 8e48ca91683..b91de72dff6 100644 --- a/addons/account/__openerp__.py +++ b/addons/account/__openerp__.py @@ -41,9 +41,9 @@ The processes like maintaining of general ledger is done through the defined fin grouping is maintained through journal) for a particular financial year and for preparation of vouchers there is a module named account_vouchers """, - "depends" : ["product", "analytic", "process","board"], 'website': 'http://www.openerp.com', 'init_xml': [], + "depends" : ["product", "analytic", "process","board"], 'update_xml': [ #'test/test_parent_structure.yml', 'security/account_security.xml', @@ -55,6 +55,7 @@ module named account_vouchers 'wizard/account_use_model_view.xml', 'account_view.xml', 'account_report.xml', + 'wizard/account_report_common_view.xml', 'wizard/account_invoice_refund_view.xml', 'wizard/account_period_close_view.xml', 'wizard/account_fiscalyear_close_state.xml', @@ -64,9 +65,9 @@ module named account_vouchers 'wizard/account_open_closed_fiscalyear_view.xml', 'wizard/account_move_line_unreconcile_select_view.xml', 'wizard/account_vat_view.xml', - 'wizard/account_print_journal_view.xml', - 'wizard/account_general_journal_view.xml', - 'wizard/account_central_journal_view.xml', + 'wizard/account_report_print_journal_view.xml', + 'wizard/account_report_general_journal_view.xml', + 'wizard/account_report_central_journal_view.xml', 'wizard/account_subscription_generate_view.xml', 'wizard/account_fiscalyear_close_view.xml', 'wizard/account_state_open_view.xml', @@ -75,14 +76,14 @@ module named account_vouchers 'wizard/account_validate_move_view.xml', 'wizard/account_pay_invoice_view.xml', 'wizard/account_unreconcile_view.xml', - 'wizard/account_general_ledger_report_view.xml', + 'wizard/account_report_general_ledger_view.xml', 'wizard/account_invoice_state_view.xml', - 'wizard/account_partner_balance_report_view.xml', - 'wizard/account_balance_report_view.xml', + 'wizard/account_report_partner_balance_view.xml', + 'wizard/account_report_account_balance_view.xml', # 'wizard/account_move_line_select_view.xml', - 'wizard/account_aged_trial_balance_view.xml', + 'wizard/account_report_aged_partner_balance_view.xml', 'wizard/account_compare_account_balance_report_view.xml', - 'wizard/account_third_party_ledger.xml', + 'wizard/account_report_partner_ledger_view.xml', 'wizard/account_reconcile_view.xml', 'wizard/account_reconcile_partner_process_view.xml', 'wizard/account_automatic_reconcile_view.xml', @@ -113,12 +114,15 @@ module named account_vouchers 'report/account_invoice_report_view.xml', 'report/account_entries_report_view.xml', 'report/account_report_view.xml', + 'report/account_analytic_report_view.xml', + 'report/account_account_report_view.xml', 'report/account_analytic_entries_report_view.xml', 'board_account_view.xml', - "wizard/account_pl_report_view.xml", - "wizard/account_bs_report_view.xml" + "wizard/account_report_profit_loss_view.xml", + "wizard/account_report_balance_sheet_view.xml" ], 'demo_xml': [ + #'demo/price_accuracy00.yml', 'account_demo.xml', 'project/project_demo.xml', 'project/analytic_account_demo.xml', @@ -133,7 +137,7 @@ module named account_vouchers 'test/chart_of_account.yml', 'test/account_period_close.yml', 'test/account_fiscalyear_close_state.yml', - 'test/account_invoice_state.yml', + #'test/account_invoice_state.yml', 'test/account_use_model.yml', 'test/account_validate_account_move.yml', 'test/account_fiscalyear_close.yml', diff --git a/addons/account/account.py b/addons/account/account.py index 67abf8b4520..aa0a27ad76d 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -81,7 +81,7 @@ class account_payment_term(osv.osv): if amt: next_date = datetime.strptime(date_ref, '%Y-%m-%d') + relativedelta(days=line.days) if line.days2 < 0: - next_date += relativedelta(day=31) + next_date += relativedelta(day=line.days2) if line.days2 > 0: next_date += relativedelta(day=line.days2, months=1) result.append( (next_date.strftime('%Y-%m-%d'), amt) ) @@ -629,8 +629,8 @@ class account_journal(osv.osv): '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, 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."), + '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'), } @@ -695,13 +695,13 @@ class account_journal(osv.osv): 'sequence_id':seq_id }) -# if journal.type in journal_type and not journal.invoice_sequence_id: -# res_ids = date_pool.search(cr, uid, [('model','=','ir.sequence'), ('name','=',journal_seq.get(journal.type, 'sale'))]) -# inv_seq_id = date_pool.browse(cr, uid, res_ids[0]).res_id -# inv_seq_id -# res.update({ -# 'invoice_sequence_id':inv_seq_id -# }) + if journal.type in journal_type and not journal.invoice_sequence_id: + res_ids = date_pool.search(cr, uid, [('model','=','ir.sequence'), ('name','=',journal_seq.get(journal.type, 'sale'))]) + inv_seq_id = date_pool.browse(cr, uid, res_ids[0]).res_id + inv_seq_id + res.update({ + 'invoice_sequence_id':inv_seq_id + }) result = self.write(cr, uid, [journal.id], res) @@ -860,7 +860,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.related('fiscalyear_id', 'company_id', type='many2one', relation='res.company', string='Company'), + 'company_id': fields.related('fiscalyear_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True) } _defaults = { 'state': lambda *a: 'draft', @@ -1236,7 +1236,7 @@ class account_move(osv.osv): return amount def _centralise(self, cr, uid, move, mode, context=None): - assert mode in ('debit', 'credit'), 'Invalid Mode' #to prevent sql injection + assert(mode in ('debit', 'credit'), 'Invalid Mode') #to prevent sql injection if context is None: context = {} @@ -1292,11 +1292,10 @@ class account_move(osv.osv): # # Validate a balanced move. If it is a centralised journal, create a move. # - def validate(self, cr, uid, ids, context={}): if context and ('__last_update' in context): del context['__last_update'] - + valid_moves = [] #Maintains a list of moves which can be responsible to create analytic entries for move in self.browse(cr, uid, ids, context): @@ -1332,7 +1331,7 @@ class account_move(osv.osv): valid_moves.append(move) # Check whether the move lines are confirmed - + if not len(line_draft_ids): continue # Update the move lines (set them as valid) @@ -1345,7 +1344,7 @@ class account_move(osv.osv): account = {} account2 = {} - + if journal.type in ('purchase','sale'): for line in move.line_id: code = amount = 0 @@ -1602,8 +1601,8 @@ class account_tax(osv.osv): # # Fields used for the VAT declaration # - 'base_code_id': fields.many2one('account.tax.code', 'Base Code', help="Use this code for the VAT declaration."), - 'tax_code_id': fields.many2one('account.tax.code', 'Tax Code', help="Use this code for the VAT declaration."), + 'base_code_id': fields.many2one('account.tax.code', 'Account Base Code', help="Use this code for the VAT declaration."), + 'tax_code_id': fields.many2one('account.tax.code', 'Account Tax Code', help="Use this code for the VAT declaration."), 'base_sign': fields.float('Base Code Sign', help="Usually 1 or -1."), 'tax_sign': fields.float('Tax Code Sign', help="Usually 1 or -1."), @@ -1620,13 +1619,44 @@ class account_tax(osv.osv): 'type_tax_use': fields.selection([('sale','Sale'),('purchase','Purchase'),('all','All')], 'Tax Application', required=True) } - def search(self, cr, uid, args, offset=0, limit=None, order=None, - context=None, count=False): + + def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80): + """ + Returns a list of tupples containing id, name, as internally it is called {def name_get} + result format : {[(id, name), (id, name), ...]} + + @param cr: A database cursor + @param user: ID of the user currently logged in + @param name: name to search + @param args: other arguments + @param operator: default operator is 'ilike', it can be changed + @param context: context arguments, like lang, time zone + @param limit: Returns first 'n' ids of complete result, default is 80. + + @return: Returns a list of tupples containing id and name + """ + if not args: + args=[] + if not context: + context={} + ids = [] + ids = self.search(cr, user, args, limit=limit, context=context) + return self.name_get(cr, user, ids, 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') + if context and context.has_key('type'): - if context['type'] in ('out_invoice','out_refund'): - args.append(('type_tax_use','in',['sale','all'])) - elif context['type'] in ('in_invoice','in_refund'): - args.append(('type_tax_use','in',['purchase','all'])) + if context.get('type') in ('out_invoice','out_refund'): + args += [('type_tax_use','in',['sale','all'])] + elif context.get('type') in ('in_invoice','in_refund'): + args += [('type_tax_use','in',['purchase','all'])] + + if context and context.has_key('journal_id'): + journal = journal_pool.browse(cr, uid, context.get('journal_id')) + if journal.type in ('sale', 'purchase'): + args += [('type_tax_use','in',[journal.type,'all'])] + return super(account_tax, self).search(cr, uid, args, offset, limit, order, context, count) def name_get(self, cr, uid, ids, context={}): @@ -1643,6 +1673,7 @@ class account_tax(osv.osv): if user.company_id: return user.company_id.id return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0] + _defaults = { 'python_compute': lambda *a: '''# price_unit\n# address : res.partner.address object or False\n# product : product.product object or None\n# partner : res.partner object or None\n\nresult = price_unit * 0.10''', 'python_compute_inv': lambda *a: '''# price_unit\n# address : res.partner.address object or False\n# product : product.product object or False\n\nresult = price_unit * 0.10''', @@ -2164,6 +2195,7 @@ class account_add_tmpl_wizard(osv.osv_memory): def _get_def_cparent(self, cr, uid, context): 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']) if not tids or not tids[0]['parent_id']: return False @@ -2205,6 +2237,7 @@ class account_add_tmpl_wizard(osv.osv_memory): # 'tax_ids': [(6,0,tax_ids)], todo!! 'company_id': company_id, } + # print "Creating:", vals new_account = acc_obj.create(cr, uid, vals) return {'type':'state', 'state': 'end' } @@ -2225,7 +2258,7 @@ class account_tax_code_template(osv.osv): 'info': fields.text('Description'), 'parent_id': fields.many2one('account.tax.code.template', 'Parent Code', select=True), 'child_ids': fields.one2many('account.tax.code.template', 'parent_id', 'Child Codes'), - 'sign': fields.float('Sign for parent', required=True, help="Choose 1.00 to add the total to the parent account or -1.00 to subtract it"), + 'sign': fields.float('Sign for parent', required=True), 'notprintable':fields.boolean("Not Printable in Invoice", help="Check this box if you don't want any VAT related to this Tax Code to appear on invoices"), } @@ -2257,7 +2290,7 @@ class account_chart_template(osv.osv): _columns={ 'name': fields.char('Name', size=64, required=True), - 'account_root_id': fields.many2one('account.account.template','Root Account',required=True,domain=[('parent_id','=',False)], help=""), + 'account_root_id': fields.many2one('account.account.template','Root Account',required=True,domain=[('parent_id','=',False)]), 'tax_code_root_id': fields.many2one('account.tax.code.template','Root Tax Code',required=True,domain=[('parent_id','=',False)]), 'tax_template_ids': fields.one2many('account.tax.template', 'chart_template_id', 'Tax Template List', help='List of all the taxes that have to be installed by the wizard'), 'bank_account_view_id': fields.many2one('account.account.template','Bank Account',required=True), diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py index 2cd1b4d17bd..c1c6e3f854b 100644 --- a/addons/account/account_analytic_line.py +++ b/addons/account/account_analytic_line.py @@ -96,7 +96,7 @@ class account_analytic_line(osv.osv): # Take the company currency as the reference one 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 + amount = amount_unit*unit_amount or 1.0 return {'value': { 'amount': - round(amount, 2), 'general_account_id': a, diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index e5581f3f05d..45736c2948f 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -49,9 +49,16 @@ class account_bank_statement(osv.osv): } def _default_journal_id(self, cr, uid, context={}): - if context.get('journal_id', False): - return context['journal_id'] - return False + 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={}): cr.execute('select id from account_bank_statement where journal_id=%s order by date desc limit 1', (1,)) @@ -119,7 +126,7 @@ class account_bank_statement(osv.osv): currency_id = res[statement_id] res[statement_id] = (currency_id, currency_names[currency_id]) return res - + _order = "date desc" _name = "account.bank.statement" _description = "Bank Statement" @@ -128,7 +135,7 @@ class account_bank_statement(osv.osv): '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', '=', 'cash')]), + states={'confirm': [('readonly', True)]}, domain=[('type', '=', 'bank')]), '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'), @@ -151,8 +158,7 @@ class account_bank_statement(osv.osv): } _defaults = { - 'name': lambda self, cr, uid, context=None: \ - self.pool.get('ir.sequence').get(cr, uid, 'account.bank.statement'), + 'name': lambda *a: "/", 'date': lambda *a: time.strftime('%Y-%m-%d'), 'state': lambda *a: 'draft', 'balance_start': _default_balance_start, @@ -185,7 +191,7 @@ class account_bank_statement(osv.osv): 'value':res, 'context':context, } - + def button_confirm_bank(self, cr, uid, ids, context={}): done = [] res_currency_obj = self.pool.get('res.currency') @@ -361,8 +367,13 @@ class account_bank_statement(osv.osv): if st.journal_id.entry_posted: account_move_obj.write(cr, uid, [move_id], {'state':'posted'}) + self.log(cr, uid, st.id, 'Statement %s is confirmed and entries are created.' % st.name) done.append(st.id) + + next_number = self.pool.get('ir.sequence').get(cr, uid, 'account.bank.statement') + self.write(cr, uid, [st.id], {'name':next_number}, context) + self.write(cr, uid, done, {'state':'confirm'}, context=context) return True @@ -425,7 +436,6 @@ class account_bank_statement(osv.osv): account_bank_statement() - class account_bank_statement_reconcile(osv.osv): _name = "account.bank.statement.reconcile" _description = "Statement Reconcile" diff --git a/addons/account/account_cash_statement.py b/addons/account/account_cash_statement.py index af92d59b89b..815f3531c57 100644 --- a/addons/account/account_cash_statement.py +++ b/addons/account/account_cash_statement.py @@ -118,18 +118,18 @@ class account_cash_statement(osv.osv): res2[statement.id]=encoding_total return res2 - def _default_journal_id(self, cr, uid, context={}): +# def _default_journal_id(self, cr, uid, context={}): - """ To get default journal for the object" - @param name: Names of fields. - @return: journal - """ - company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.id - journal = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'cash'), ('company_id', '=', company_id)]) - if journal: - return journal[0] - else: - return False +# """ To get default journal for the object" +# @param name: Names of fields. +# @return: journal +# """ +# company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.id +# journal = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'cash'), ('company_id', '=', company_id)]) +# if journal: +# return journal[0] +# else: +# return False def _end_balance(self, cursor, user, ids, name, attr, context=None): res_currency_obj = self.pool.get('res.currency') @@ -174,7 +174,7 @@ class account_cash_statement(osv.osv): return company_id - def _get_cash_box_lines(self, cr, uid, ids, context={}): + def _get_cash_open_box_lines(self, cr, uid, ids, context={}): res = [] curr = [1, 2, 5, 10, 20, 50, 100, 500] for rs in curr: @@ -182,12 +182,23 @@ class account_cash_statement(osv.osv): 'pieces':rs, 'number':0 } - res.append((0,0,dct)) + res.append(dct) return res - + + def _get_cash_close_box_lines(self, cr, uid, ids, context={}): + res = [] + curr = [1, 2, 5, 10, 20, 50, 100, 500] + for rs in curr: + dct = { + 'pieces':rs, + 'number':0 + } + res.append((0, 0, dct)) + return res + _columns = { 'company_id':fields.many2one('res.company', 'Company', required=False), - 'journal_id': fields.many2one('account.journal', 'Journal', required=True), + 'journal_id': fields.many2one('account.journal', 'Journal', required=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'), @@ -204,13 +215,11 @@ class account_cash_statement(osv.osv): } _defaults = { 'state': lambda *a: 'draft', - 'name': lambda *a: '/', 'date': lambda *a:time.strftime("%Y-%m-%d %H:%M:%S"), - 'journal_id': _default_journal_id, 'user_id': lambda self, cr, uid, context=None: uid, 'company_id': _get_company, - 'starting_details_ids':_get_cash_box_lines, - 'ending_details_ids':_get_cash_box_lines + 'starting_details_ids':_get_cash_open_box_lines, + 'ending_details_ids':_get_cash_open_box_lines } def create(self, cr, uid, vals, context=None): @@ -224,7 +233,19 @@ class account_cash_statement(osv.osv): open_jrnl = self.search(cr, uid, sql) if open_jrnl: raise osv.except_osv('Error', _('You can not have two open register for the same journal')) + + if self.pool.get('account.journal').browse(cr, uid, vals['journal_id']).type == 'cash': + lines = end_lines = self._get_cash_close_box_lines(cr, uid, [], context) + vals.update({ + 'ending_details_ids':lines + }) + else: + vals.update({ + 'ending_details_ids':False, + 'starting_details_ids':False + }) res_id = super(account_cash_statement, self).create(cr, uid, vals, context=context) + self.write(cr, uid, [res_id], {}) return res_id def write(self, cr, uid, ids, vals, context=None): @@ -288,11 +309,16 @@ class account_cash_statement(osv.osv): statement_pool = self.pool.get('account.bank.statement') statement = statement_pool.browse(cr, uid, ids[0]) + vals = {} if not self._user_allow(cr, uid, ids, statement, context={}): raise osv.except_osv(_('Error !'), _('User %s does not have rights to access %s journal !' % (statement.user_id.name, statement.journal_id.name))) - number = self.pool.get('ir.sequence').get(cr, uid, statement.journal_id.sequence_id.code) + if statement.name and statement.name == '/': + number = self.pool.get('ir.sequence').get(cr, uid, 'account.cash.statement') + vals.update({ + 'name':number + }) # if len(statement.starting_details_ids) > 0: # sid = [] @@ -314,11 +340,11 @@ class account_cash_statement(osv.osv): # } # cash_pool.copy(cr, uid, sid, default) # - vals = { + vals.update({ 'date':time.strftime("%Y-%m-%d %H:%M:%S"), 'state':'open', - 'name':number - } + + }) self.write(cr, uid, ids, vals) return True diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index ac82fc1b6cc..22df9059305 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -138,7 +138,7 @@