From c64e10c4fa39f39c84014551e023fddf090b24d2 Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Mon, 2 Nov 2009 09:29:18 +0100 Subject: [PATCH 01/14] [FIX] account_payment when importing payment lines (currency not set correctly) lp bug: https://launchpad.net/bugs/428926 fixed bzr revid: joel.grandguillaume@camptocamp.com-20091102082918-udyj4yyr408myiqq --- addons/account_payment/wizard/wizard_payment_order.py | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/account_payment/wizard/wizard_payment_order.py b/addons/account_payment/wizard/wizard_payment_order.py index 2e84efa5fa8..60dd10010b2 100644 --- a/addons/account_payment/wizard/wizard_payment_order.py +++ b/addons/account_payment/wizard/wizard_payment_order.py @@ -95,6 +95,7 @@ def create_payment(self, cr, uid, data, context): 'partner_id': line.partner_id and line.partner_id.id or False, 'communication': line.ref or '/', 'date': date_to_pay, + 'currency': line.invoice and line.invoice.currency_id.id or False, }, context=context) return {} From 7a2cbc32de5d311dc839d8622ec56ff6cf2c48ff Mon Sep 17 00:00:00 2001 From: rvalyi <> Date: Mon, 2 Nov 2009 09:40:00 +0100 Subject: [PATCH 02/14] [FIX][IMP] Correct write-off date, add analytic account, better interface between all way to reconcile lp bug: https://launchpad.net/bugs/435160 fixed bzr revid: joel.grandguillaume@camptocamp.com-20091102084000-h21k703spch2hqxl --- addons/account/account_move_line.py | 5 ++-- addons/account/wizard/wizard_pay_invoice.py | 14 ++++++---- addons/account/wizard/wizard_reconcile.py | 30 ++++++++++++++------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index d7c098de206..f31fca91a44 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -616,6 +616,7 @@ class account_move_line(osv.osv): 'debit':debit, 'credit':credit, 'account_id':writeoff_acc_id, + 'analytic_account_id': context.get('analytic_id', False), 'date':date, 'partner_id':partner_id }) @@ -624,7 +625,7 @@ class account_move_line(osv.osv): writeoff_move_id = self.pool.get('account.move').create(cr, uid, { 'period_id': writeoff_period_id, 'journal_id': writeoff_journal_id, - + 'date':date, 'state': 'draft', 'line_id': writeoff_lines }) @@ -869,7 +870,7 @@ class account_move_line(osv.osv): 'amount': vals['debit'] or vals['credit'], 'general_account_id': vals['account_id'], 'journal_id': journal.analytic_journal_id.id, - 'ref': vals['ref'], + 'ref': vals.get('ref', False), })] #else: # raise osv.except_osv(_('No analytic journal !'), _('Please set an analytic journal on this financial journal !')) diff --git a/addons/account/wizard/wizard_pay_invoice.py b/addons/account/wizard/wizard_pay_invoice.py index 2baba87e51d..c7781d1b19d 100644 --- a/addons/account/wizard/wizard_pay_invoice.py +++ b/addons/account/wizard/wizard_pay_invoice.py @@ -53,6 +53,7 @@ def _pay_and_reconcile(self, cr, uid, data, context): pool = pooler.get_pool(cr.dbname) cur_obj = pool.get('res.currency') amount = form['amount'] + context['analytic_id'] = form.get('analytic_id', False) invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context) journal = pool.get('account.journal').browse(cr, uid, data['form']['journal_id'], context) @@ -62,9 +63,9 @@ def _pay_and_reconcile(self, cr, uid, data, context): # Take the choosen date if form.has_key('comment'): - context={'date_p':form['date'],'comment':form['comment']} + context.update({'date_p':form['date'],'comment':form['comment']}) else: - context={'date_p':form['date'],'comment':False} + context.update({'date_p':form['date'],'comment':False}) acc_id = journal.default_credit_account_id and journal.default_credit_account_id.id if not acc_id: @@ -90,19 +91,22 @@ def _wo_check(self, cr, uid, data, context): _transaction_add_form = '''
- + + + ''' _transaction_add_fields = { 'writeoff_acc_id': {'string':'Write-Off account', 'type':'many2one', 'relation':'account.account', 'required':True}, 'writeoff_journal_id': {'string': 'Write-Off journal', 'type': 'many2one', 'relation':'account.journal', 'required':True}, - 'comment': {'string': 'Entry Name', 'type':'char', 'size': 64, 'required':True}, + 'comment': {'string': 'Comment', 'type':'char', 'size': 64 , 'required':True}, + 'analytic_id': {'string':'Analytic Account', 'type': 'many2one', 'relation':'account.analytic.account'}, } def _get_value_addendum(self, cr, uid, data, context={}): - return {} + return {'comment': _('Write-Off')} def _get_period(self, cr, uid, data, context={}): pool = pooler.get_pool(cr.dbname) diff --git a/addons/account/wizard/wizard_reconcile.py b/addons/account/wizard/wizard_reconcile.py index d1f98ec191e..de4dbe3c202 100644 --- a/addons/account/wizard/wizard_reconcile.py +++ b/addons/account/wizard/wizard_reconcile.py @@ -25,6 +25,7 @@ import netsvc import time import osv import pooler +from mx import DateTime _transaction_form = '''
@@ -70,8 +71,18 @@ def _trans_rec_reconcile(self, cr, uid, data, context=None): form = data['form'] account_id = form.get('writeoff_acc_id', False) - period_id = form.get('period_id', False) + context['date_p'] = form.get('date_p', False) + date = False + if context['date_p']: + date = DateTime.strptime(context['date_p'], '%Y-%m-%d') + ids = pool.get('account.period').find(cr, uid, dt=date, context=context) + period_id = False + if len(ids): + period_id = ids[0] + journal_id = form.get('journal_id', False) + context['comment'] = form.get('comment', False) + context['analytic_id'] = form.get('analytic_id', False) account_move_line_obj.reconcile(cr, uid, data['ids'], 'manual', account_id, period_id, journal_id, context=context) return {} @@ -85,23 +96,24 @@ _transaction_add_form = ''' - + + + + ''' _transaction_add_fields = { 'journal_id': {'string': 'Write-Off Journal', 'type': 'many2one', 'relation':'account.journal', 'required':True}, - 'period_id': {'string': 'Write-Off Period', 'type': 'many2one', 'relation':'account.period', 'required':True}, 'writeoff_acc_id': {'string':'Write-Off account', 'type':'many2one', 'relation':'account.account', 'required':True}, + 'date_p': {'string':'Date','type':'date'}, + 'comment': {'string':'Comment','type':'char', 'size': 64}, + 'analytic_id': {'string':'Analytic Account', 'type': 'many2one', 'relation':'account.analytic.account'}, } def _trans_rec_addendum(self, cr, uid, data, context={}): - pool = pooler.get_pool(cr.dbname) - ids = pool.get('account.period').find(cr, uid, context=context) - period_id = False - if len(ids): - period_id = ids[0] - return {'period_id':period_id} + date_p = time.strftime('%Y-%m-%d') + return {'date_p':date_p, 'comment': _('Write-Off')} class wiz_reconcile(wizard.interface): From 2d09f1d6391e72b9723729eefe480f7e944f0f6d Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Mon, 2 Nov 2009 09:42:45 +0100 Subject: [PATCH 03/14] [FIX] Residual amount in invoice when currency rating change lp bug: https://launchpad.net/bugs/427869 fixed bzr revid: joel.grandguillaume@camptocamp.com-20091102084245-qatsx72ulgn7ib20 --- addons/account/invoice.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 54e258d791d..3d098bfea2b 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -106,23 +106,29 @@ class account_invoice(osv.osv): cur_obj = self.pool.get('res.currency') for inv in data_inv: debit = credit = 0.0 + context.update({'date':inv.date_invoice}) for lines in inv.move_lines: - if lines.account_id.company_currency_id.id <> inv.currency_id.id: - if lines.debit: - debit += cur_obj.compute(cr, uid, lines.account_id.company_currency_id.id, inv.currency_id.id, lines.debit) - if lines.credit: - credit += cur_obj.compute(cr, uid, lines.account_id.company_currency_id.id, inv.currency_id.id, lines.credit) + # If currency conversion needed + if inv.company_id.currency_id.id <> inv.currency_id.id: + # If invoice paid, compute currency amount according to invoice date + # otherwise, take the line date + if not inv.reconciled: + context.update({'date':lines.date}) + # Compute amount in currency + debit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, lines.debit, round=False,context=context) + credit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, lines.credit, round=False,context=context) else: debit += lines.debit credit += lines.credit - if not inv.amount_total: result = 0.0 elif inv.type in ('out_invoice','in_refund'): - result = inv.amount_total * (1.0 - credit / (debit + inv.amount_total)) + amount = credit-debit + result = inv.amount_total - amount else: - result = inv.amount_total * (1.0 - debit / (credit + inv.amount_total)) - res[inv.id] = round(result,int(config['price_accuracy'])) + amount = debit-credit + result = inv.amount_total - amount + res[inv.id] = result return res def _get_lines(self, cr, uid, ids, name, arg, context=None): From 4ee6427c0b13c8f8ded9e0b7188af3ee0dd25884 Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Mon, 2 Nov 2009 09:52:13 +0100 Subject: [PATCH 04/14] [FIX] Avoid display write-off in pay invoice wizard. Put the right date and currency for conversion lp bug: https://launchpad.net/bugs/453030 fixed bzr revid: joel.grandguillaume@camptocamp.com-20091102085213-d3w0kwk10sj6gyb8 --- addons/account/invoice.py | 14 +++++++++ addons/account/wizard/wizard_pay_invoice.py | 33 ++++++++++++++++----- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 3d098bfea2b..606b42ee926 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -878,6 +878,16 @@ class account_invoice(osv.osv): date=context['date_p'] else: date=time.strftime('%Y-%m-%d') + + # Take the amount in currency and the currency of the payment + if 'amount_currency' in context and context['amount_currency'] and 'currency_id' in context and context['currency_id']: + amount_currency = context['amount_currency'] + currency_id = context['currency_id'] + else: + amount_currency = False + currency_id = False + + # Pay attention to the sign for both debit/credit AND amount_currency l1 = { 'debit': direction * pay_amount>0 and direction * pay_amount, 'credit': direction * pay_amount<0 and - direction * pay_amount, @@ -885,6 +895,8 @@ class account_invoice(osv.osv): 'partner_id': invoice.partner_id.id, 'ref':invoice.number, 'date': date, + 'currency_id':currency_id, + 'amount_currency':amount_currency and direction * amount_currency or 0.0, } l2 = { 'debit': direction * pay_amount<0 and - direction * pay_amount, @@ -893,6 +905,8 @@ class account_invoice(osv.osv): 'partner_id': invoice.partner_id.id, 'ref':invoice.number, 'date': date, + 'currency_id':currency_id, + 'amount_currency':amount_currency and - direction * amount_currency or 0.0, } if not name: diff --git a/addons/account/wizard/wizard_pay_invoice.py b/addons/account/wizard/wizard_pay_invoice.py index c7781d1b19d..c51fe6be54b 100644 --- a/addons/account/wizard/wizard_pay_invoice.py +++ b/addons/account/wizard/wizard_pay_invoice.py @@ -25,6 +25,7 @@ import netsvc import pooler import time from tools.translate import _ +import tools pay_form = '''
@@ -37,7 +38,7 @@ pay_form = '''
''' pay_fields = { - 'amount': {'string': 'Amount paid', 'type':'float', 'required':True}, + 'amount': {'string': 'Amount paid', 'type':'float', 'required':True, 'digits': (16,int(tools.config['price_accuracy']))}, 'name': {'string': 'Entry Name', 'type':'char', 'size': 64, 'required':True}, 'date': {'string': 'Payment date', 'type':'date', 'required':True, 'default':lambda *args: time.strftime('%Y-%m-%d')}, 'journal_id': {'string': 'Journal/Payment Mode', 'type': 'many2one', 'relation':'account.journal', 'required':True, 'domain':[('type','=','cash')]}, @@ -57,10 +58,15 @@ def _pay_and_reconcile(self, cr, uid, data, context): invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context) journal = pool.get('account.journal').browse(cr, uid, data['form']['journal_id'], context) + # Compute the amount in company's currency, with the journal currency (which is equal to payment currency) + # when it is needed : If payment currency (according to selected journal.currency) is <> from company currency if journal.currency and invoice.company_id.currency_id.id<>journal.currency.id: ctx = {'date':data['form']['date']} amount = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, amount, context=ctx) - + currency_id = journal.currency.id + # Put the paid amount in currency, and the currency, in the context if currency is different from company's currency + context.update({'amount_currency':form['amount'],'currency_id':currency_id}) + # Take the choosen date if form.has_key('comment'): context.update({'date_p':form['date'],'comment':form['comment']}) @@ -79,12 +85,23 @@ def _wo_check(self, cr, uid, data, context): pool = pooler.get_pool(cr.dbname) invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context) journal = pool.get('account.journal').browse(cr, uid, data['form']['journal_id'], context) - if invoice.company_id.currency_id.id <> invoice.currency_id.id: - return 'addendum' - if journal.currency and (journal.currency.id <> invoice.currency_id.id): - return 'addendum' - if pool.get('res.currency').is_zero(cr, uid, invoice.currency_id, - (data['form']['amount'] - invoice.amount_total)): + cur_obj = pool.get('res.currency') + # Here we need that: + # The invoice total amount in company's currency <> paid amount in company currency + # (according to the correct day rate, invoicing rate and payment rate are may be different) + # => Ask to a write-off of the difference. This could happen even if both amount are equal, + # because if the currency rate + # Get the amount in company currency for the invoice (according to move lines) + inv_amount_company_currency=invoice.move_id.amount + # Get the amount paid in company currency + if journal.currency and invoice.company_id.currency_id.id<>journal.currency.id: + ctx = {'date':data['form']['date']} + amount_paid = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, data['form']['amount'], round=True, context=ctx) + else: + amount_paid = data['form']['amount'] + # Test if there is a difference according to currency rouding setting + if pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id, + (amount_paid - inv_amount_company_currency)): return 'reconcile' return 'addendum' From 482d6374b929ffd3610679e0c2c6a45534a41acd Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Mon, 2 Nov 2009 10:15:42 +0100 Subject: [PATCH 05/14] [IMP] Add account field into bank statement line lp bug: https://launchpad.net/bugs/351167 fixed bzr revid: joel.grandguillaume@camptocamp.com-20091102091542-qaufnbe3bac03bty --- addons/account/account_view.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 97c50abdea8..91ebe4ba662 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -335,6 +335,7 @@ + @@ -345,6 +346,7 @@
+ From 61e37654f4990a2bba16f03f4a0e9e10a3f8703f Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Mon, 2 Nov 2009 12:24:47 +0100 Subject: [PATCH 06/14] [FIX] Avoid display write-off in pay invoice wizard : take care of partial payment lp bug: https://launchpad.net/bugs/453030 fixed bzr revid: joel.grandguillaume@camptocamp.com-20091102112447-dvhsfwf8lkma5c6v --- addons/account/wizard/wizard_pay_invoice.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/account/wizard/wizard_pay_invoice.py b/addons/account/wizard/wizard_pay_invoice.py index c51fe6be54b..5dd98286339 100644 --- a/addons/account/wizard/wizard_pay_invoice.py +++ b/addons/account/wizard/wizard_pay_invoice.py @@ -93,12 +93,20 @@ def _wo_check(self, cr, uid, data, context): # because if the currency rate # Get the amount in company currency for the invoice (according to move lines) inv_amount_company_currency=invoice.move_id.amount - # Get the amount paid in company currency + # Get the current amount paid in company currency if journal.currency and invoice.company_id.currency_id.id<>journal.currency.id: ctx = {'date':data['form']['date']} amount_paid = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, data['form']['amount'], round=True, context=ctx) else: amount_paid = data['form']['amount'] + # Get the old payment if there are some + if invoice.payment_ids: + debit=credit=0.0 + for payment in invoice.payment_ids: + debit+=payment.debit + credit+=payment.credit + amount_paid+=abs(debit-credit) + # Test if there is a difference according to currency rouding setting if pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id, (amount_paid - inv_amount_company_currency)): From 3a3ded3e6733f98be7615352895f8fcef4f4463d Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Mon, 2 Nov 2009 12:53:09 +0100 Subject: [PATCH 07/14] [IMP] Add support of analytic account into bank statement to be convenient with other method lp bug: https://launchpad.net/bugs/470359 fixed bzr revid: joel.grandguillaume@camptocamp.com-20091102115309-qh4zkiio3chsepcs --- addons/account/account_bank_statement.py | 14 +++++++++++--- addons/account/account_view.xml | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index 56c4ddba96e..1e4022395af 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -170,7 +170,9 @@ class account_bank_statement(osv.osv): 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: move_id = account_move_obj.create(cr, uid, { 'journal_id': st.journal_id.id, @@ -209,7 +211,7 @@ class account_bank_statement(osv.osv): 'period_id': st.period_id.id, 'currency_id': st.currency.id, } - + amount = res_currency_obj.compute(cr, uid, st.currency.id, company_currency_id, move.amount, context=context, account=acc_cur) @@ -245,6 +247,8 @@ class account_bank_statement(osv.osv): 'statement_id': st.id, 'journal_id': st.journal_id.id, 'period_id': st.period_id.id, + # Add analytical account if provided.. + 'analytic_account_id':newline.analytic_id and newline.analytic_id.id or False, }, context=context) # Fill the secondary amount/currency @@ -491,10 +495,14 @@ class account_bank_statement_reconcile_line(osv.osv): _name = "account.bank.statement.reconcile.line" _description = "Statement reconcile line" _columns = { - 'name': fields.char('Description', size=64), + 'name': fields.char('Description', size=64, required=True), 'account_id': fields.many2one('account.account', 'Account', required=True), 'line_id': fields.many2one('account.bank.statement.reconcile', 'Reconcile'), 'amount': fields.float('Amount', required=True), + 'analytic_id': fields.many2one('account.analytic.account',"Analytic Account") + } + _defaults = { + 'name': lambda *a: 'Write-Off', } account_bank_statement_reconcile_line() diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 91ebe4ba662..ff4fca8186c 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -417,6 +417,7 @@ + From aff362e191631adea7624f6289a1acb18c86834c Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Mon, 2 Nov 2009 16:53:05 +0100 Subject: [PATCH 08/14] [FIX] Residual amount into invoice is now correct in every case and avoid rounding trouble even if rating has changed bzr revid: joel.grandguillaume@camptocamp.com-20091102155305-swj8zxhsey8wjhue --- addons/account/invoice.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 606b42ee926..a4cede582f9 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -104,22 +104,34 @@ class account_invoice(osv.osv): res = {} data_inv = self.browse(cr, uid, ids) cur_obj = self.pool.get('res.currency') + import pdb + pdb.set_trace() for inv in data_inv: debit = credit = 0.0 context.update({'date':inv.date_invoice}) + context_unreconciled=context.copy() for lines in inv.move_lines: + debit_tmp = lines.debit + credit_tmp = lines.credit # If currency conversion needed if inv.company_id.currency_id.id <> inv.currency_id.id: # If invoice paid, compute currency amount according to invoice date # otherwise, take the line date if not inv.reconciled: context.update({'date':lines.date}) - # Compute amount in currency - debit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, lines.debit, round=False,context=context) - credit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, lines.credit, round=False,context=context) + context_unreconciled.update({'date':lines.date}) + # If amount currency setted, compute for debit and credit in company currency + if lines.amount_currency < 0: + credit_tmp=abs(cur_obj.compute(cr, uid, lines.currency_id.id, inv.company_id.currency_id.id, lines.amount_currency, round=False,context=context_unreconciled)) + elif lines.amount_currency > 0: + debit_tmp=abs(cur_obj.compute(cr, uid, lines.currency_id.id, inv.company_id.currency_id.id, lines.amount_currency, round=False,context=context_unreconciled)) + # Then, recomput into invoice currency to avoid rounding trouble ! + debit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, debit_tmp, round=False,context=context) + credit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, credit_tmp, round=False,context=context) else: - debit += lines.debit - credit += lines.credit + debit+=debit_tmp + credit+=credit_tmp + if not inv.amount_total: result = 0.0 elif inv.type in ('out_invoice','in_refund'): @@ -128,7 +140,9 @@ class account_invoice(osv.osv): else: amount = debit-credit result = inv.amount_total - amount - res[inv.id] = result + # Use is_zero function to avoid rounding trouble => should be fixed into ORM + res[inv.id] = not self.pool.get('res.currency').is_zero(cr, uid, inv.company_id.currency_id,result) and result or 0.0 + return res def _get_lines(self, cr, uid, ids, name, arg, context=None): From 50071d7df3516510e6f273f904a68c38ea1f4487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Valyi?= Date: Tue, 3 Nov 2009 03:16:13 -0200 Subject: [PATCH 09/14] [FIX] account: removed pdb now that things are claimed fixed (after the commits messages) bzr revid: rvalyi@gmail.com-20091103051613-f2m2n7t20uce8df6 --- addons/account/invoice.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/addons/account/invoice.py b/addons/account/invoice.py index a4cede582f9..ca8b36fbdfe 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -104,8 +104,6 @@ class account_invoice(osv.osv): res = {} data_inv = self.browse(cr, uid, ids) cur_obj = self.pool.get('res.currency') - import pdb - pdb.set_trace() for inv in data_inv: debit = credit = 0.0 context.update({'date':inv.date_invoice}) From 2dabd5f34f4076171797703e2e14e84ca917e735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Valyi?= Date: Tue, 3 Nov 2009 03:17:10 -0200 Subject: [PATCH 10/14] [FIX] account: avoid translate tool missing import on strictier Python 2.6 versions; bare in mind that mx.Datetime should be eraticated from the surface of the earth bzr revid: rvalyi@gmail.com-20091103051710-koeenh3su23yvls2 --- addons/account/wizard/wizard_reconcile.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/account/wizard/wizard_reconcile.py b/addons/account/wizard/wizard_reconcile.py index de4dbe3c202..59c0e062070 100644 --- a/addons/account/wizard/wizard_reconcile.py +++ b/addons/account/wizard/wizard_reconcile.py @@ -25,7 +25,8 @@ import netsvc import time import osv import pooler -from mx import DateTime +from datetime import datetime +from tools.translate import _ _transaction_form = ''' @@ -74,7 +75,7 @@ def _trans_rec_reconcile(self, cr, uid, data, context=None): context['date_p'] = form.get('date_p', False) date = False if context['date_p']: - date = DateTime.strptime(context['date_p'], '%Y-%m-%d') + date = datetime.strptime(context['date_p'], '%Y-%m-%d') ids = pool.get('account.period').find(cr, uid, dt=date, context=context) period_id = False if len(ids): From 2b326eb066002d70092e1a8c9fd96d6b70ecd63a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Valyi?= Date: Tue, 3 Nov 2009 03:19:12 -0200 Subject: [PATCH 11/14] [IMP] account: make comment mandatory. Since it has a default value anyway, it doesn't reall y change anything, but makes the reconciliation UI looks consistent accross the whole OpenERP (eg invoice payment) bzr revid: rvalyi@gmail.com-20091103051912-ead9jx19l3g0d8dm --- addons/account/wizard/wizard_reconcile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/wizard/wizard_reconcile.py b/addons/account/wizard/wizard_reconcile.py index 59c0e062070..2b5385043d6 100644 --- a/addons/account/wizard/wizard_reconcile.py +++ b/addons/account/wizard/wizard_reconcile.py @@ -108,7 +108,7 @@ _transaction_add_fields = { 'journal_id': {'string': 'Write-Off Journal', 'type': 'many2one', 'relation':'account.journal', 'required':True}, 'writeoff_acc_id': {'string':'Write-Off account', 'type':'many2one', 'relation':'account.account', 'required':True}, 'date_p': {'string':'Date','type':'date'}, - 'comment': {'string':'Comment','type':'char', 'size': 64}, + 'comment': {'string':'Comment','type':'char', 'size': 64, 'required':True}, 'analytic_id': {'string':'Analytic Account', 'type': 'many2one', 'relation':'account.analytic.account'}, } From 91efa25bb78859121a7a0887e95c63aa7f7a6bc0 Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Tue, 3 Nov 2009 08:08:58 +0100 Subject: [PATCH 12/14] [FIX] Residual amount into invoice is now correct in every case and avoid rounding trouble even if rating has changed bzr revid: joel.grandguillaume@camptocamp.com-20091103070858-86gtu8tzvztjuyt4 --- addons/account/invoice.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 606b42ee926..ca8b36fbdfe 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -107,19 +107,29 @@ class account_invoice(osv.osv): for inv in data_inv: debit = credit = 0.0 context.update({'date':inv.date_invoice}) + context_unreconciled=context.copy() for lines in inv.move_lines: + debit_tmp = lines.debit + credit_tmp = lines.credit # If currency conversion needed if inv.company_id.currency_id.id <> inv.currency_id.id: # If invoice paid, compute currency amount according to invoice date # otherwise, take the line date if not inv.reconciled: context.update({'date':lines.date}) - # Compute amount in currency - debit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, lines.debit, round=False,context=context) - credit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, lines.credit, round=False,context=context) + context_unreconciled.update({'date':lines.date}) + # If amount currency setted, compute for debit and credit in company currency + if lines.amount_currency < 0: + credit_tmp=abs(cur_obj.compute(cr, uid, lines.currency_id.id, inv.company_id.currency_id.id, lines.amount_currency, round=False,context=context_unreconciled)) + elif lines.amount_currency > 0: + debit_tmp=abs(cur_obj.compute(cr, uid, lines.currency_id.id, inv.company_id.currency_id.id, lines.amount_currency, round=False,context=context_unreconciled)) + # Then, recomput into invoice currency to avoid rounding trouble ! + debit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, debit_tmp, round=False,context=context) + credit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, credit_tmp, round=False,context=context) else: - debit += lines.debit - credit += lines.credit + debit+=debit_tmp + credit+=credit_tmp + if not inv.amount_total: result = 0.0 elif inv.type in ('out_invoice','in_refund'): @@ -128,7 +138,9 @@ class account_invoice(osv.osv): else: amount = debit-credit result = inv.amount_total - amount - res[inv.id] = result + # Use is_zero function to avoid rounding trouble => should be fixed into ORM + res[inv.id] = not self.pool.get('res.currency').is_zero(cr, uid, inv.company_id.currency_id,result) and result or 0.0 + return res def _get_lines(self, cr, uid, ids, name, arg, context=None): From 675d14e54fb5fe674d0e678e5444abe37ba9f2d9 Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Tue, 3 Nov 2009 08:30:04 +0100 Subject: [PATCH 13/14] [FIX] Use price_accuracy to verify balanced entry insteed of fixed '0,0001'. Add price_accuracy on debit and credit move lines lp bug: https://launchpad.net/bugs/452854 fixed bzr revid: joel.grandguillaume@camptocamp.com-20091103073004-7vjpq2t4uqwpgi0j --- addons/account/account.py | 2 +- addons/account/account_move_line.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index ff344b0256b..3ed4ebc600c 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -988,7 +988,7 @@ class account_move(osv.osv): if line.account_id.currency_id.id != line.currency_id.id and (line.account_id.currency_id.id != line.account_id.company_id.currency_id.id or line.currency_id): raise osv.except_osv(_('Error'), _("""Couldn't create move with currency different from the secondary currency of the account "%s - %s". Clear the secondary currency field of the account definition if you want to accept all currencies.""" % (line.account_id.code, line.account_id.name))) - if abs(amount) < 0.0001: + if abs(amount) < config['price_accuracy']: if not len(line_draft_ids): continue self.pool.get('account.move.line').write(cr, uid, line_draft_ids, { diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index f31fca91a44..26d45ab7395 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -341,8 +341,8 @@ class account_move_line(osv.osv): 'quantity': fields.float('Quantity', digits=(16,2), help="The optional quantity expressed by this line, eg: number of product sold. The quantity is not a legal requirement but is very usefull for some reports."), 'product_uom_id': fields.many2one('product.uom', 'UoM'), 'product_id': fields.many2one('product.product', 'Product'), - 'debit': fields.float('Debit', digits=(16,2)), - 'credit': fields.float('Credit', digits=(16,2)), + 'debit': fields.float('Debit', digits=(16,int(tools.config['price_accuracy']))), + 'credit': fields.float('Credit', digits=(16,int(tools.config['price_accuracy']))), 'account_id': fields.many2one('account.account', 'Account', required=True, ondelete="cascade", domain=[('type','<>','view'), ('type', '<>', 'closed')], select=2), 'move_id': fields.many2one('account.move', 'Move', ondelete="cascade", states={'valid':[('readonly',True)]}, help="The move of this entry line.", select=2), @@ -350,7 +350,7 @@ class account_move_line(osv.osv): 'statement_id': fields.many2one('account.bank.statement', 'Statement', help="The bank statement used for bank reconciliation", select=1), 'reconcile_id': fields.many2one('account.move.reconcile', 'Reconcile', readonly=True, ondelete='set null', select=2), 'reconcile_partial_id': fields.many2one('account.move.reconcile', 'Partial Reconcile', readonly=True, ondelete='set null', select=2), - 'amount_currency': fields.float('Amount Currency', help="The amount expressed in an optional other currency if it is a multi-currency entry."), + 'amount_currency': fields.float('Amount Currency', help="The amount expressed in an optional other currency if it is a multi-currency entry.", digits=(16,int(tools.config['price_accuracy']))), 'currency_id': fields.many2one('res.currency', 'Currency', help="The optional other currency if it is a multi-currency entry."), 'period_id': fields.many2one('account.period', 'Period', required=True, select=2), @@ -369,14 +369,14 @@ class account_move_line(osv.osv): 'balance': fields.function(_balance, method=True, string='Balance'), 'state': fields.selection([('draft','Draft'), ('valid','Valid')], 'Status', readonly=True), 'tax_code_id': fields.many2one('account.tax.code', 'Tax Account', help="The Account can either be a base tax code or tax code account."), - 'tax_amount': fields.float('Tax/Base Amount', digits=(16,2), select=True, help="If the Tax account is tax code account, this field will contain the taxed amount.If the tax account is base tax code,\ + 'tax_amount': fields.float('Tax/Base Amount', digits=(16,int(tools.config['price_accuracy'])), select=True, help="If the Tax account is tax code account, this field will contain the taxed amount.If the tax account is base tax code,\ this field will contain the basic amount(without tax)."), 'invoice': fields.function(_invoice, method=True, string='Invoice', type='many2one', relation='account.invoice', fnct_search=_invoice_search), '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=(16,2)), + 'amount_taxed':fields.float("Taxed Amount",digits=(16,int(tools.config['price_accuracy']))), } From ba392d143b96b14da5fcda352b61e03133d5d089 Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Wed, 4 Nov 2009 07:52:26 +0100 Subject: [PATCH 14/14] [FIX] Correct the validate function for balanced move into account.py (after Fabien Warning) lp bug: https://launchpad.net/bugs/452854 fixed bzr revid: joel.grandguillaume@camptocamp.com-20091104065226-sax4u9d6ss4oif62 --- addons/account/account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/account.py b/addons/account/account.py index 3ed4ebc600c..eb7771d8197 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -988,7 +988,7 @@ class account_move(osv.osv): if line.account_id.currency_id.id != line.currency_id.id and (line.account_id.currency_id.id != line.account_id.company_id.currency_id.id or line.currency_id): raise osv.except_osv(_('Error'), _("""Couldn't create move with currency different from the secondary currency of the account "%s - %s". Clear the secondary currency field of the account definition if you want to accept all currencies.""" % (line.account_id.code, line.account_id.name))) - if abs(amount) < config['price_accuracy']: + if abs(amount) < 10**-config['price_accuracy']: if not len(line_draft_ids): continue self.pool.get('account.move.line').write(cr, uid, line_draft_ids, {