diff --git a/addons/.project b/addons/.project deleted file mode 100644 index 8fc3cc934ff..00000000000 --- a/addons/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - pso-newaddons - - - - - - org.python.pydev.PyDevBuilder - - - - - - org.python.pydev.pythonNature - - diff --git a/addons/account/account.py b/addons/account/account.py index 00d2ec3dcba..3f436373ef1 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -281,7 +281,16 @@ class account_account(osv.osv): 'parent_left': fields.integer('Parent Left', select=1), 'parent_right': fields.integer('Parent Right', select=1), - 'check_history': fields.boolean('Display History', help="Check this box if you want to print all entries when printing the General Ledger, otherwise it will only print its balance.") + 'currency_mode': fields.selection([('current','At Date'),('average','Average Rate')], 'Outgoing Currencies Rate', + help= + 'This will select how is computed the current currency rate for outgoing transactions. '\ + 'In most countries the legal method is "average" but only a few softwares are able to '\ + 'manage this. So if you import from another software, you may have to use the rate at date. ' \ + 'Incoming transactions, always use the rate at date.', \ + required=True), + 'check_history': fields.boolean('Display History', + help="Check this box if you want to print all entries when printing the General Ledger, "\ + "otherwise it will only print its balance.") } def _default_company(self, cr, uid, context={}): @@ -296,6 +305,7 @@ class account_account(osv.osv): 'company_id': _default_company, 'active': lambda *a: True, 'check_history': lambda *a: True, + 'currency_mode': lambda *a: 'current' } def _check_recursion(self, cr, uid, ids): @@ -552,6 +562,17 @@ class account_period(osv.osv): if not ids: raise osv.except_osv(_('Error !'), _('No period defined for this date !\nPlease create a fiscal year.')) return ids + + def action_draft(self, cr, uid, ids, *args): + users_roles = self.pool.get('res.users').browse(cr, uid, uid).roles_id + for role in users_roles: + if role.name=='Period': + mode = 'draft' + for id in ids: + cr.execute('update account_journal_period set state=%s where period_id=%d', (mode, id)) + cr.execute('update account_period set state=%s where id=%d', (mode, id)) + return True + account_period() class account_journal_period(osv.osv): @@ -1035,7 +1056,7 @@ class account_tax_code(osv.osv): _rec_name = 'code' _columns = { 'name': fields.char('Tax Case Name', size=64, required=True), - 'code': fields.char('Case Code', size=16), + 'code': fields.char('Case Code', size=64), 'info': fields.text('Description'), 'sum': fields.function(_sum, method=True, string="Year Sum"), 'sum_period': fields.function(_sum_period, method=True, string="Period Sum"), @@ -1685,7 +1706,7 @@ class account_tax_code_template(osv.osv): _rec_name = 'code' _columns = { 'name': fields.char('Tax Case Name', size=64, required=True), - 'code': fields.char('Case Code', size=16), + 'code': fields.char('Case Code', size=64), 'info': fields.text('Description'), 'parent_id': fields.many2one('account.tax.code.template', 'Parent Code', select=True), 'child_ids': fields.one2many('account.tax.code.template', 'parent_id', 'Childs Codes'), @@ -1929,7 +1950,6 @@ class wizard_multi_charts_accounts(osv.osv_memory): code_acc = account_template.code if code_main<=dig and account_template.type != 'view': code_acc=str(code_acc) + (str('0'*(dig-code_main))) - vals={ 'name': (obj_acc_root.id == account_template.id) and obj_multi.company_id.name or account_template.name, #'sign': account_template.sign, @@ -1946,7 +1966,6 @@ class wizard_multi_charts_accounts(osv.osv_memory): } 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 self.pool.get('account.account')._parent_store_compute(cr) diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index 91ee7d094b1..56f4af1401d 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -191,8 +191,14 @@ class account_bank_statement(osv.osv): 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) + 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 @@ -213,7 +219,8 @@ class account_bank_statement(osv.osv): } amount = res_currency_obj.compute(cr, uid, st.currency.id, - company_currency_id, move.amount, context=context) + company_currency_id, move.amount, context=context, + account=acc_cur) if move.account_id and move.account_id.currency_id: val['currency_id'] = move.account_id.currency_id.id @@ -221,7 +228,8 @@ class account_bank_statement(osv.osv): 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) + move.account_id.currency_id.id, amount, context=context, + account=acc_cur) val['amount_currency'] = amount_cur torec.append(account_move_line_obj.create(cr, uid, val , context=context)) @@ -242,11 +250,6 @@ class account_bank_statement(osv.osv): 'period_id': st.period_id.id, }, context=context) - if amount >= 0: - account_id = st.journal_id.default_credit_account_id.id - else: - account_id = st.journal_id.default_debit_account_id.id - # Fill the secondary amount/currency # if currency is not the same than the company amount_currency = False @@ -370,10 +373,16 @@ class account_bank_statement_reconcile(osv.osv): context=context).company_id.currency_id.id currency_id = context.get('currency_id', company_currency_id) + acc_cur = None + if context.get('journal_id', False) and context.get('account_id',False): + st =self.pool.get('account.journal').browse(cursor, user, context['journal_id']) + acc = self.pool.get('account.account').browse(cursor, user, context['account_id']) + acc_cur = (( context.get('amount',0.0)<=0) and st.default_debit_account_id) or acc + for reconcile_id in ids: res[reconcile_id] = res_currency_obj.compute(cursor, user, currency_id, company_currency_id, - context.get('amount', 0.0), context=context) + context.get('amount', 0.0), context=context, account=acc_cur) return res def _default_amount(self, cursor, user, context=None): @@ -386,9 +395,15 @@ class account_bank_statement_reconcile(osv.osv): context=context).company_id.currency_id.id currency_id = context.get('currency_id', company_currency_id) + acc_cur = None + if context.get('journal_id', False) and context.get('account_id',False): + st =self.pool.get('account.journal').browse(cursor, user, context['journal_id']) + acc = self.pool.get('account.account').browse(cursor, user, context['account_id']) + acc_cur = (( context.get('amount',0.0)<=0) and st.default_debit_account_id) or acc + return res_currency_obj.compute(cursor, user, currency_id, company_currency_id, - context.get('amount', 0.0), context=context) + context.get('amount', 0.0), context=context, account=acc_cur) def _total_currency(self, cursor, user, ids, name, attrs, context=None): res = {} @@ -423,25 +438,11 @@ class account_bank_statement_reconcile(osv.osv): def name_get(self, cursor, user, ids, context=None): res= [] - res_currency_obj = self.pool.get('res.currency') - res_users_obj = self.pool.get('res.users') - - company_currency_id = res_users_obj.browse(cursor, user, user, - context=context).company_id.currency_id.id - for o in self.browse(cursor, user, ids, context=context): td = '' - if o.statement_line: - currency_id = o.statement_line[0].statement_id.currency.id - if abs(o.statement_line[0].amount - (o.total_entry - o.total_new))>0.01: - td = 'P ' - else: - currency_id = company_currency_id - res.append((o.id, '%s[%.2f-%.2f]' % (td, - res_currency_obj.compute(cursor, user, company_currency_id, - currency_id, o.total_entry, context=context), - res_currency_obj.compute(cursor, user, company_currency_id, - currency_id, o.total_new, context=context)))) + if o.total_amount: + td = 'P ' + res.append((o.id, '%s[%.2f]' % (td, o.total_amount))) return res _columns = { diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index abade8c579c..60674d5dab3 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -145,7 +145,9 @@ class account_move_line(osv.osv): ref_id = False move = self.pool.get('account.move').browse(cr, uid, move_id, context) + acc1 = False for l in move.line_id: + acc1 = l.account_id partner_id = partner_id or l.partner_id.id ref_id = ref_id or l.ref total += (l.debit or 0.0) - (l.credit or 0.0) @@ -175,6 +177,17 @@ class account_move_line(osv.osv): s = -total data['debit'] = s>0 and s or 0.0 data['credit'] = s<0 and -s or 0.0 + + if account.currency_id: + data['currency_id'] = account.currency_id.id + acc = account + if s>0: + acc = acc1 + v = self.pool.get('res.currency').compute(cr, uid, + account.company_id.currency_id.id, + data['currency_id'], + s, account=acc, account_invert=True) + data['amount_currency'] = v return data def _on_create_write(self, cr, uid, id, context={}): @@ -325,12 +338,19 @@ class account_move_line(osv.osv): context=context) dt = period.date_start return dt + def _get_currency(self, cr, uid, context={}): + if not context.get('journal_id', False): + return False + cur = self.pool.get('account.journal').browse(cr, uid, context['journal_id']).currency + return cur and cur.id or False + _defaults = { 'blocked': lambda *a: False, 'centralisation': lambda *a: 'normal', 'date': _get_date, 'date_created': lambda *a: time.strftime('%Y-%m-%d'), 'state': lambda *a: 'draft', + '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), } @@ -368,6 +388,21 @@ class account_move_line(osv.osv): #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id + def onchange_currency(self, cr, uid, ids, account_id, amount, currency_id, date=False, journal=False): + if (not currency_id) or (not account_id): + return {} + result = {} + acc =self.pool.get('account.account').browse(cr, uid, account_id) + if (amount>0) and journal: + x = self.pool.get('account.journal').browse(cr, uid, journal).default_credit_account_id + if x: acc = x + v = self.pool.get('res.currency').compute(cr, uid, currency_id,acc.company_id.currency_id.id, amount, account=acc) + result['value'] = { + 'debit': v>0 and v or 0.0, + 'credit': v<0 and -v or 0.0 + } + return result + def onchange_partner_id(self, cr, uid, ids, move_id, partner_id, account_id=None, debit=0, credit=0, date=False, journal=False): val = {} val['date_maturity'] = False @@ -603,6 +638,8 @@ class account_move_line(osv.osv): attrs.append('required="1"') else: attrs.append('required="0"') + if field.field in ('amount_currency','currency_id'): + attrs.append('on_change="onchange_currency(account_id,amount_currency,currency_id,date,((\'journal_id\' in context) and context[\'journal_id\']) or {})"') if field.field == 'partner_id': attrs.append('on_change="onchange_partner_id(move_id,partner_id,account_id,debit,credit,((\'journal_id\' in context) and context[\'journal_id\']) or {})"') if field.field in widths: @@ -749,7 +786,9 @@ class account_move_line(osv.osv): ctx = {} if 'date' in vals: ctx['date'] = vals['date'] - vals['amount_currency'] = cur_obj.compute(cr, uid, account.company_id.currency_id.id, account.currency_id.id, vals.get('debit', 0.0)-vals.get('credit', 0.0), context=ctx) + vals['amount_currency'] = cur_obj.compute(cr, uid, account.company_id.currency_id.id, + account.currency_id.id, vals.get('debit', 0.0)-vals.get('credit', 0.0), + context=ctx) if not ok: raise osv.except_osv(_('Bad account !'), _('You can not use this general account in this journal !')) diff --git a/addons/account/account_report.xml b/addons/account/account_report.xml index 1ec5d25aa4f..e4f9ca21b02 100644 --- a/addons/account/account_report.xml +++ b/addons/account/account_report.xml @@ -2,20 +2,20 @@ - - - + + + - + - + + + + account.period.form @@ -74,6 +77,7 @@ +