From 9ecff1245aedd5d7a3d6d565389d35d9920acf59 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 20 Oct 2011 16:42:17 +0200 Subject: [PATCH 1/5] [IMP] account_voucher: onchange_partner_id small refactoring + improved the splitting of the amount by existing voucher lines bzr revid: qdp-launchpad@openerp.com-20111020144217-t4owndjuntdeuts9 --- addons/account_voucher/account_voucher.py | 91 ++++++++++--------- addons/account_voucher/invoice.py | 5 +- .../voucher_payment_receipt_view.xml | 30 +++--- 3 files changed, 68 insertions(+), 58 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 38af59009d8..d2f9d230fbd 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -427,36 +427,31 @@ class account_voucher(osv.osv): if date: context_multi_currency.update({'date': date}) - line_pool = self.pool.get('account.voucher.line') - line_ids = ids and line_pool.search(cr, uid, [('voucher_id', '=', ids[0])]) or False - if line_ids: - line_pool.unlink(cr, uid, line_ids) - currency_pool = self.pool.get('res.currency') move_line_pool = self.pool.get('account.move.line') partner_pool = self.pool.get('res.partner') journal_pool = self.pool.get('account.journal') + line_pool = self.pool.get('account.voucher.line') + #get default values vals = self.onchange_journal(cr, uid, ids, journal_id, [], False, partner_id, context) vals = vals.get('value') - - journal = journal_pool.browse(cr, uid, journal_id, context=context) currency_id = vals.get('currency_id', currency_id) default = { 'value':{'line_ids':[], 'line_dr_ids':[], 'line_cr_ids':[], 'pre_line': False, 'currency_id':currency_id}, } - currency_id = currency_id or journal.company_id.currency_id.id + + #drop existing lines + line_ids = ids and line_pool.search(cr, uid, [('voucher_id', '=', ids[0])]) or False + if line_ids: + line_pool.unlink(cr, uid, line_ids) if not partner_id: return default - if not partner_id and ids: - line_ids = line_pool.search(cr, uid, [('voucher_id', '=', ids[0])]) - if line_ids: - line_pool.unlink(cr, uid, line_ids) - return default - + journal = journal_pool.browse(cr, uid, journal_id, context=context) partner = partner_pool.browse(cr, uid, partner_id, context=context) + currency_id = currency_id or journal.company_id.currency_id.id account_id = False if journal.type in ('sale','sale_refund'): account_id = partner.property_account_receivable.id @@ -484,64 +479,78 @@ class account_voucher(osv.osv): ids = move_line_pool.search(cr, uid, [('state','=','valid'), ('account_id.type', '=', account_type), ('reconcile_id', '=', False), ('partner_id', '=', partner_id)], context=context) else: ids = context['move_line_ids'] + invoice_id = context.get('invoice_id', False) + company_currency = journal.company_id.currency_id.id + move_line_found = False + + #order the lines by most old first ids.reverse() moves = move_line_pool.browse(cr, uid, ids, context=context) - #company_currency = journal.company_id.currency_id.id - #if company_currency != currency_id and ttype == 'payment': - # total_debit = currency_pool.compute(cr, uid, currency_id, company_currency, total_debit, context=context_multi_currency) - #elif company_currency != currency_id and ttype == 'receipt': - # total_credit = currency_pool.compute(cr, uid, currency_id, company_currency, total_credit, context=context_multi_currency) - - company_currency = journal.company_id.currency_id.id for line in moves: if line.credit and line.reconcile_partial_id and ttype == 'receipt': continue if line.debit and line.reconcile_partial_id and ttype == 'payment': continue + if invoice_id: + if line.invoice.id == invoice_id: + #if the invoice linked to the voucher line is equal to the invoice_id in context + #then we assign the amount on that line, whatever the other voucher lines + move_line_found = line.id + break + elif currency_id == company_currency: + #otherwise treatments is the same but with other field names + if line.amount_residual == price: + #if the amount residual is equal the amount voucher, we assign it to that voucher + #line, whatever the other voucher lines + move_line_found = line.id + break + #otherwise we will split the voucher amount on each line (by most old first) + total_credit += line.credit or 0.0 + total_debit += line.debit or 0.0 + elif currency_id == line.currency_id.id: + if line.amount_residual_currency == price: + move_line_found = line.id + break + total_credit += line.credit and line.amount_currency or 0.0 + total_debit += line.debit and line.amount_currency or 0.0 - if line.currency_id and currency_id==line.currency_id.id: - total_credit += line.amount_currency <0 and -line.amount_currency or 0.0 - total_debit += line.amount_currency >0 and line.amount_currency or 0.0 - else: - total_credit += currency_pool.compute(cr, uid, company_currency, currency_id, line.credit or 0.0) - total_debit += currency_pool.compute(cr, uid, company_currency, currency_id, line.debit or 0.0) - + #voucher line creation for line in moves: if line.credit and line.reconcile_partial_id and ttype == 'receipt': continue if line.debit and line.reconcile_partial_id and ttype == 'payment': continue - if line.currency_id and currency_id==line.currency_id.id: amount_original = abs(line.amount_currency) amount_unreconciled = abs(line.amount_residual_currency) else: amount_original = currency_pool.compute(cr, uid, company_currency, currency_id, line.credit or line.debit or 0.0) amount_unreconciled = currency_pool.compute(cr, uid, company_currency, currency_id, abs(line.amount_residual)) - - #original_amount = line.credit or line.debit or 0.0 - #amount_unreconciled = currency_pool.compute(cr, uid, line.currency_id and line.currency_id.id or company_currency, currency_id, abs(line.amount_residual_currency), context=context_multi_currency) rs = { 'name':line.move_id.name, 'type': line.credit and 'dr' or 'cr', 'move_line_id':line.id, 'account_id':line.account_id.id, 'amount_original': amount_original, + 'amount': (move_line_found == line.id) and min(price, amount_unreconciled) or 0.0, 'date_original':line.date, 'date_due':line.date_maturity, 'amount_unreconciled': amount_unreconciled, - } - if line.credit: - amount = min(amount_unreconciled, total_debit) - rs['amount'] = amount - total_debit -= amount - else: - amount = min(amount_unreconciled, total_credit) - rs['amount'] = amount - total_credit -= amount + #split voucher amount by most old first, but only for lines in the same currency + if not move_line_found: + line_currency_id = line.currency_id and line.currency_id.id or company_currency + if currency_id == line_currency_id: + if line.credit: + amount = min(amount_unreconciled, abs(total_debit)) + rs['amount'] = amount + total_debit -= amount + else: + amount = min(amount_unreconciled, abs(total_credit)) + rs['amount'] = amount + total_credit -= amount default['value']['line_ids'].append(rs) if rs['type'] == 'cr': diff --git a/addons/account_voucher/invoice.py b/addons/account_voucher/invoice.py index 0230cac1009..b108bc14fe3 100644 --- a/addons/account_voucher/invoice.py +++ b/addons/account_voucher/invoice.py @@ -45,10 +45,11 @@ class invoice(osv.osv): 'close_after_process': True, 'invoice_type':inv.type, 'invoice_id':inv.id, - 'default_type': inv.type in ('out_invoice','out_refund') and 'receipt' or 'payment' + 'default_type': inv.type in ('out_invoice','out_refund') and 'receipt' or 'payment', + 'type': inv.type in ('out_invoice','out_refund') and 'receipt' or 'payment' } } invoice() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account_voucher/voucher_payment_receipt_view.xml b/addons/account_voucher/voucher_payment_receipt_view.xml index 9c8bdffb35d..0ddc868cb45 100644 --- a/addons/account_voucher/voucher_payment_receipt_view.xml +++ b/addons/account_voucher/voucher_payment_receipt_view.xml @@ -74,14 +74,14 @@
- - + + - + - + - + @@ -137,15 +137,15 @@ - + - + @@ -279,19 +279,19 @@ - + + on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)"/> - + @@ -303,7 +303,7 @@ - + - + From 7f8fb0804af0e928214c568e210bcd92eab59b30 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Fri, 21 Oct 2011 15:52:40 +0200 Subject: [PATCH 2/5] [IMP] account_voucher: added payment_rate field on the voucher, if you don't want to use the rate encoded in openerp for this payment + made some order in the views bzr revid: qdp-launchpad@openerp.com-20111021135240-0qjjs9p7y92ed1nr --- addons/account_voucher/account_voucher.py | 88 ++++++++++++------- .../voucher_payment_receipt_view.xml | 59 +++++++------ 2 files changed, 88 insertions(+), 59 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index d2f9d230fbd..6d30820d54c 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -39,8 +39,6 @@ class account_voucher(osv.osv): res[voucher.id] = ok return res - - def _get_type(self, cr, uid, context=None): if context is None: context = {} @@ -98,7 +96,6 @@ class account_voucher(osv.osv): journal_id = context.get('journal_id', False) if journal_id: journal = journal_pool.browse(cr, uid, journal_id, context=context) -# currency_id = journal.company_id.currency_id.id if journal.currency: return journal.currency.id return False @@ -182,6 +179,14 @@ class account_voucher(osv.osv): res[voucher.id] = abs(voucher.amount - abs(credit - debit)) return res + def _paid_amount_in_company_currency(self, cr, uid, ids, name, args, context=None): + if not ids: return {} + res = {} + debit = credit = 0.0 + for voucher in self.browse(cr, uid, ids, context=context): + res[voucher.id] = voucher.amount / voucher.payment_rate + return res + _name = 'account.voucher' _description = 'Accounting Voucher' _order = "date desc, id desc" @@ -242,6 +247,9 @@ class account_voucher(osv.osv): 'comment': fields.char('Counterpart Comment', size=64, required=True, readonly=True, states={'draft': [('readonly', False)]}), 'analytic_id': fields.many2one('account.analytic.account','Write-Off Analytic Account', readonly=True, states={'draft': [('readonly', False)]}), 'writeoff_amount': fields.function(_get_writeoff_amount, string='Reconcile Amount', type='float', readonly=True), + 'payment_rate': fields.float('Payment Rate', digits=(12,6), required=True, + help='The rate between the journal currency and the company currency for this particular payment.'), + 'paid_amount_in_company_currency': fields.function(_paid_amount_in_company_currency, string='Paid Amount in Company Currency', type='float', readonly=True), } _defaults = { 'period_id': _get_period, @@ -409,6 +417,19 @@ class account_voucher(osv.osv): return default + def onchange_rate(self, cr, uid, ids, rate, amount, context=None): + res = {'value': {'paid_amount_in_company_currency': 0.0}} + if rate and amount: + res['value']['paid_amount_in_company_currency'] = amount / rate + return res + + def onchange_amount(self, cr, uid, ids, amount, rate, partner_id, journal_id, currency_id, ttype, date, context=None): + res = self.onchange_partner_id(cr, uid, ids, partner_id, journal_id, amount, currency_id, ttype, date, context=context) + vals = self.onchange_rate(cr, uid, ids, rate, amount, context=context) + for key in vals.keys(): + res[key].update(vals[key]) + return res + def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=None): """ Returns a dict that contains new values and context @@ -421,8 +442,6 @@ class account_voucher(osv.osv): """ if context is None: context = {} - if not journal_id: - return {} context_multi_currency = context.copy() if date: context_multi_currency.update({'date': date}) @@ -433,12 +452,9 @@ class account_voucher(osv.osv): journal_pool = self.pool.get('account.journal') line_pool = self.pool.get('account.voucher.line') - #get default values - vals = self.onchange_journal(cr, uid, ids, journal_id, [], False, partner_id, context) - vals = vals.get('value') - currency_id = vals.get('currency_id', currency_id) + #set default values default = { - 'value':{'line_ids':[], 'line_dr_ids':[], 'line_cr_ids':[], 'pre_line': False, 'currency_id':currency_id}, + 'value': {'line_ids': [] ,'line_dr_ids': [] ,'line_cr_ids': [] ,'pre_line': False,}, } #drop existing lines @@ -446,7 +462,7 @@ class account_voucher(osv.osv): if line_ids: line_pool.unlink(cr, uid, line_ids) - if not partner_id: + if not partner_id or not journal_id: return default journal = journal_pool.browse(cr, uid, journal_id, context=context) @@ -565,23 +581,30 @@ class account_voucher(osv.osv): default['value']['writeoff_amount'] = self._compute_writeoff_amount(cr, uid, default['value']['line_dr_ids'], default['value']['line_cr_ids'], price) return default - def onchange_date(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=None): + def onchange_date(self, cr, uid, ids, date, currency_id, amount, context=None): """ @param date: latest value from user input for field date @param args: other arguments @param context: context arguments, like lang, time zone @return: Returns a dict which contains new values, and context """ + res = {'value': {}} + #set the period of the voucher period_pool = self.pool.get('account.period') - res = self.onchange_partner_id(cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=context) pids = period_pool.search(cr, uid, [('date_start', '<=', date), ('date_stop', '>=', date)]) if pids: - if not 'value' in res: - res['value'] = {} res['value'].update({'period_id':pids[0]}) + #set the default payment rate of the voucher and compute the paid amount in company currency + payment_rate = 1.0 + if currency_id: + payment_rate = self.pool.get('res.currency').browse(cr, uid, currency_id, context={'date': date}).rate + res['value'].update({'payment_rate': payment_rate}) + vals = self.onchange_rate(cr, uid, ids, payment_rate, amount, context=context) + for key in vals.keys(): + res[key].update(vals[key]) return res - def onchange_journal(self, cr, uid, ids, journal_id, line_ids, tax_id, partner_id, context=None): + def onchange_journal(self, cr, uid, ids, journal_id, line_ids, tax_id, partner_id, date, amount, ttype, context=None): if not journal_id: return False journal_pool = self.pool.get('account.journal') @@ -593,10 +616,18 @@ class account_voucher(osv.osv): vals = self.onchange_price(cr, uid, ids, line_ids, tax_id, partner_id, context) vals['value'].update({'tax_id':tax_id}) - currency_id = False #journal.company_id.currency_id.id + currency_id = False if journal.currency: currency_id = journal.currency.id - vals['value'].update({'currency_id':currency_id}) + payment_rate = self.pool.get('res.currency').browse(cr, uid, currency_id, context={'date': date}).rate + vals['value'].update({'payment_rate': payment_rate}) + res = self.onchange_rate(cr, uid, ids, payment_rate, amount, context=context) + for key in res.keys(): + vals[key].update(res[key]) + vals['value'].update({'currency_id': currency_id}) + res = self.onchange_partner_id(cr, uid, ids, partner_id, journal_id, amount, currency_id, ttype, date, context) + for key in res.keys(): + vals[key].update(res[key]) return vals def proforma_voucher(self, cr, uid, ids, context=None): @@ -640,7 +671,6 @@ class account_voucher(osv.osv): raise osv.except_osv(_('Invalid action !'), _('Cannot delete Voucher(s) which are already opened or paid !')) return super(account_voucher, self).unlink(cr, uid, ids, context=context) - # TODO: may be we can remove this method if not used anyware def onchange_payment(self, cr, uid, ids, pay_now, journal_id, partner_id, ttype='sale'): res = {} if not partner_id: @@ -699,9 +729,9 @@ class account_voucher(osv.osv): # TODO: Make this logic available. # -for sale, purchase we have but for the payment and receipt we do not have as based on the bank/cash journal we can not know its payment or receipt if voucher_brw.type in ('purchase', 'payment'): - credit = currency_obj.compute(cr, uid, current_currency, company_currency, voucher_brw.amount, context=context) + credit = voucher_brw.amount / voucher_brw.payment_rate elif voucher_brw.type in ('sale', 'receipt'): - debit = currency_obj.compute(cr, uid, current_currency, company_currency, voucher_brw.amount, context=context) + debit = voucher_brw.amount / voucher_brw.payment_rate if debit < 0: credit = -debit; debit = 0.0 if credit < 0: debit = -credit; credit = 0.0 sign = debit - credit < 0 and -1 or 1 @@ -826,10 +856,10 @@ class account_voucher(osv.osv): continue #we check if the voucher line is fully paid or not and create a move line to balance the payment and initial invoice if needed if line.amount == line.amount_unreconciled: - amount = currency_obj.compute(cr, uid, current_currency, company_currency, line.untax_amount or line.amount, context=context) + amount = (line.untax_amount or line.amount) / voucher_brw.payment_rate amount_residual = line.move_line_id.amount_residual - amount #residual amount in company currency else: - amount = currency_obj.compute(cr, uid, current_currency, company_currency, line.untax_amount or line.amount, context=context) + amount = (line.untax_amount or line.amount) / voucher_brw.payment_rate amount_residual = 0.0 move_line = { 'journal_id': voucher_brw.journal_id.id, @@ -979,9 +1009,9 @@ class account_voucher(osv.osv): line_total = move_line_brw.debit - move_line_brw.credit rec_list_ids = [] if voucher.type == 'sale': - line_total = line_total - currency_pool.compute(cr, uid, current_currency, company_currency, voucher.tax_amount, context=context) + line_total = line_total - (voucher.tax_amount / voucher.payment_rate) elif voucher.type == 'purchase': - line_total = line_total + currency_pool.compute(cr, uid, current_currency, company_currency, voucher.tax_amount, context=context) + line_total = line_total + (voucher.tax_amount / voucher.payment_rate) #create one move line per voucher line where amount is not 0.0 line_total, rec_list_ids = self.voucher_move_line_create(cr, uid, voucher.id, line_total, move_id, company_currency, current_currency, context) @@ -1181,17 +1211,10 @@ class account_bank_statement_line(osv.osv): def _amount_reconciled(self, cursor, user, ids, name, args, context=None): if not ids: return {} - res = {} -# company_currency_id = False for line in self.browse(cursor, user, ids, context=context): -# if not company_currency_id: -# company_currency_id = line.company_id.id if line.voucher_id: res[line.id] = line.voucher_id.amount# -# res_currency_obj.compute(cursor, user, -# company_currency_id, line.statement_id.currency.id, -# line.voucher_id.amount, context=context) else: res[line.id] = 0.0 return res @@ -1212,7 +1235,6 @@ class account_bank_statement_line(osv.osv): 'amount_reconciled': fields.function(_amount_reconciled, string='Amount reconciled', type='float'), 'voucher_id': fields.many2one('account.voucher', 'Payment'), - } def unlink(self, cr, uid, ids, context=None): diff --git a/addons/account_voucher/voucher_payment_receipt_view.xml b/addons/account_voucher/voucher_payment_receipt_view.xml index 0ddc868cb45..c1c7f076c9f 100644 --- a/addons/account_voucher/voucher_payment_receipt_view.xml +++ b/addons/account_voucher/voucher_payment_receipt_view.xml @@ -75,13 +75,13 @@ - + - + - + - + @@ -186,12 +186,14 @@ - + + - + + + + - + - - - - + + + + @@ -284,14 +287,14 @@ + on_change="onchange_amount(amount, payment_rate, partner_id, journal_id, currency_id, type, date, context)"/> - + @@ -332,13 +335,15 @@ + + + + + + - - @@ -347,10 +352,12 @@ domain="[('type','=','other')]"/> + - - - + + + From 5414fc79690c95c6ebe4bdb12104ae9b6a1cbfa0 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Fri, 21 Oct 2011 17:32:58 +0200 Subject: [PATCH 3/5] [IMP] account_voucher: changed the views for sale and purchase of the voucher in order to make them work with the new signature of the onchanges (included in previous revision) + corrected yaml tests to trigger the onchanges bzr revid: qdp-launchpad@openerp.com-20111021153258-nw6rxt77yon5dudl --- addons/account_voucher/account_voucher.py | 1 + addons/account_voucher/test/case1_usd_usd.yml | 6 ++++-- addons/account_voucher/test/case2_suppl_usd_eur.yml | 3 ++- .../test/case2_usd_eur_debtor_in_eur.yml | 10 ++++++---- .../test/case2_usd_eur_debtor_in_usd.yml | 7 ++++--- addons/account_voucher/test/case3_eur_eur.yml | 4 ++-- addons/account_voucher/test/case4_cad_chf.yml | 5 +++-- .../account_voucher/voucher_sales_purchase_view.xml | 12 ++++++------ 8 files changed, 28 insertions(+), 20 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 6d30820d54c..20eb552c074 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -268,6 +268,7 @@ class account_voucher(osv.osv): 'tax_id': _get_tax, 'payment_option': 'without_writeoff', 'comment': _('Write-Off'), + 'payment_rate': 1.0, } def compute_tax(self, cr, uid, ids, context=None): diff --git a/addons/account_voucher/test/case1_usd_usd.yml b/addons/account_voucher/test/case1_usd_usd.yml index eabcec2a08c..6685e64f298 100644 --- a/addons/account_voucher/test/case1_usd_usd.yml +++ b/addons/account_voucher/test/case1_usd_usd.yml @@ -149,12 +149,13 @@ 'partner_id': ref('res_partner_strauss0'), 'period_id': ref('account.period_3'), 'type': 'receipt', - 'date': time.strftime("%Y-03-01"), + 'date': time.strftime("%Y-%m-%d"), 'payment_option': 'with_writeoff', 'writeoff_acc_id': ref('account.a_expense'), 'comment': 'Write Off', 'name': 'First payment', } + vals.update(self.onchange_date(cr, uid, [], time.strftime('%Y-03-01'), ref('base.USD'), 240)['value']) if not res['value']['line_cr_ids']: res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}] for item in res['value']['line_cr_ids']: @@ -247,12 +248,13 @@ 'partner_id': ref('res_partner_strauss0'), 'period_id': ref('account.period_3'), 'type': 'receipt', - 'date': time.strftime("%Y-04-01"), + 'date': time.strftime("%Y-%m-%d"), 'payment_option': 'with_writeoff', 'writeoff_acc_id': ref('account.a_expense'), 'comment': 'Write Off', 'name': 'Second payment', } + vals.update(self.onchange_date(cr, uid, [], time.strftime('%Y-04-01'), ref('base.USD'), 45.0)['value']) if not res['value']['line_cr_ids']: res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}] for item in res['value']['line_cr_ids']: diff --git a/addons/account_voucher/test/case2_suppl_usd_eur.yml b/addons/account_voucher/test/case2_suppl_usd_eur.yml index 31e756d5355..424783d8a7b 100644 --- a/addons/account_voucher/test/case2_suppl_usd_eur.yml +++ b/addons/account_voucher/test/case2_suppl_usd_eur.yml @@ -239,12 +239,13 @@ 'partner_id': ref('res_partner_clements0'), 'period_id': ref('account.period_3'), 'type': 'payment', - 'date': time.strftime("%Y-04-01"), + 'date': time.strftime("%Y-%m-%d"), 'payment_option': 'with_writeoff', 'writeoff_acc_id': ref('account.a_expense'), 'comment': 'Write Off', 'name': 'Second payment', } + vals.update(self.onchange_date(cr, uid, [], time.strftime('%Y-04-01'), ref('base.USD'), 45.0)['value']) if not res['value']['line_dr_ids']: res['value']['line_dr_ids'] = [{'type': 'dr', 'account_id': ref('account.a_pay'),}] for item in res['value']['line_dr_ids']: diff --git a/addons/account_voucher/test/case2_usd_eur_debtor_in_eur.yml b/addons/account_voucher/test/case2_usd_eur_debtor_in_eur.yml index b872a54561d..e1cc87f427e 100644 --- a/addons/account_voucher/test/case2_usd_eur_debtor_in_eur.yml +++ b/addons/account_voucher/test/case2_usd_eur_debtor_in_eur.yml @@ -155,12 +155,12 @@ !python {model: account.voucher}: | import netsvc, time vals = {} - res = self.onchange_partner_id(cr, uid, [], ref("res_partner_michael0"), ref('bank_journal_EUR'), 240.0, 2, ttype='receipt', date=False) + res = self.onchange_partner_id(cr, uid, [], ref("res_partner_michael0"), ref('bank_journal_EUR'), 240.0, False, ttype='receipt', date=False) vals = { 'account_id': ref('account.cash'), 'amount': 200.0, 'company_id': ref('base.main_company'), - 'currency_id': ref('base.EUR'), + 'currency_id': False, 'journal_id': ref('bank_journal_EUR'), 'partner_id': ref('res_partner_michael0'), 'period_id': ref('account.period_3'), @@ -220,8 +220,9 @@ move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) + print move_line.amount_residual, move_line.amount_residual_currency assert (move_line.amount_residual_currency == 55.56 and move_line.amount_residual == 20) , "Residual amount is not correct for first Invoice" -- toto +- I check the residual amuont of Invoice2, should be 22.22 in residual currency and 10 in amount_residual - !python {model: account.invoice}: | @@ -247,13 +248,14 @@ 'partner_id': ref('res_partner_michael0'), 'period_id': ref('account.period_3'), 'type': 'receipt', - 'date': time.strftime("%Y-04-01"), + 'date': time.strftime("%Y-%m-%d"), 'payment_option': 'with_writeoff', 'writeoff_acc_id': ref('account.a_expense'), 'exchange_acc_id': ref('account.o_expense'), 'comment': 'Write Off', 'name': 'Second payment', } + vals.update(self.onchange_date(cr, uid, [], time.strftime('%Y-04-01'), ref('base.USD'), 80.0)['value']) if not res['value']['line_cr_ids']: res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}] for item in res['value']['line_cr_ids']: diff --git a/addons/account_voucher/test/case2_usd_eur_debtor_in_usd.yml b/addons/account_voucher/test/case2_usd_eur_debtor_in_usd.yml index 8fc495d79c8..355098dc7d6 100644 --- a/addons/account_voucher/test/case2_usd_eur_debtor_in_usd.yml +++ b/addons/account_voucher/test/case2_usd_eur_debtor_in_usd.yml @@ -155,7 +155,7 @@ !python {model: account.voucher}: | import netsvc, time vals = {} - res = self.onchange_partner_id(cr, uid, [], ref("res_partner_michal1"), ref('bank_journal_EUR'), 200.0, 2, ttype='receipt', date=False) + res = self.onchange_partner_id(cr, uid, [], ref("res_partner_michal1"), ref('bank_journal_EUR'), 200.0, False, ttype='receipt', date=False) vals = { 'account_id': ref('account.cash'), 'amount': 200.0, @@ -240,7 +240,7 @@ !python {model: account.voucher}: | import netsvc, time vals = {} - res = self.onchange_partner_id(cr, uid, [], ref("res_partner_michal1"), ref('bank_journal_USD'), 80.0, 2, ttype='receipt', date=False) + res = self.onchange_partner_id(cr, uid, [], ref("res_partner_michal1"), ref('bank_journal_USD'), 80.0, ref('base.USD'), ttype='receipt', date=False) vals = { 'account_id': ref('account.cash'), 'amount': 80.0, @@ -250,13 +250,14 @@ 'partner_id': ref('res_partner_michal1'), 'period_id': ref('account.period_3'), 'type': 'receipt', - 'date': time.strftime("%Y-04-01"), + 'date': time.strftime("%Y-%m-%d"), 'payment_option': 'with_writeoff', 'writeoff_acc_id': ref('account.a_expense'), 'exchange_acc_id': ref('account.o_expense'), 'comment': 'Write Off', 'name': 'Second payment', } + vals.update(self.onchange_date(cr, uid, [], time.strftime('%Y-04-01'), ref('base.USD'), 80.0)['value']) if not res['value']['line_cr_ids']: res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}] for item in res['value']['line_cr_ids']: diff --git a/addons/account_voucher/test/case3_eur_eur.yml b/addons/account_voucher/test/case3_eur_eur.yml index 374f40607bd..9ed498442fb 100644 --- a/addons/account_voucher/test/case3_eur_eur.yml +++ b/addons/account_voucher/test/case3_eur_eur.yml @@ -118,7 +118,7 @@ !python {model: account.voucher}: | import netsvc, time vals = {} - res = self.onchange_partner_id(cr, uid, [], ref("res_partner_peter0"), ref('bank_journal_EUR'), 120.00, 2, ttype='receipt', date=False) + res = self.onchange_partner_id(cr, uid, [], ref("res_partner_peter0"), ref('bank_journal_EUR'), 120.00, False, ttype='receipt', date=False) vals = { 'account_id': ref('account.cash'), 'amount': 120.00, @@ -210,7 +210,7 @@ !python {model: account.voucher}: | import netsvc, time vals = {} - res = self.onchange_partner_id(cr, uid, [], ref("res_partner_peter0"), ref('bank_journal_EUR'), 120.00, 2, ttype='receipt', date=False) + res = self.onchange_partner_id(cr, uid, [], ref("res_partner_peter0"), ref('bank_journal_EUR'), 120.00, False, ttype='receipt', date=False) vals = { 'account_id': ref('account.cash'), 'amount': 120.00, diff --git a/addons/account_voucher/test/case4_cad_chf.yml b/addons/account_voucher/test/case4_cad_chf.yml index deaf341d1c0..557e20dec1a 100644 --- a/addons/account_voucher/test/case4_cad_chf.yml +++ b/addons/account_voucher/test/case4_cad_chf.yml @@ -97,7 +97,7 @@ !python {model: account.voucher}: | import netsvc, time vals = {} - res = self.onchange_partner_id(cr, uid, [], ref("res_partner_john0"), ref('bank_journal_CHF'), 200.00, 2, ttype='receipt', date=False) + res = self.onchange_partner_id(cr, uid, [], ref("res_partner_john0"), ref('bank_journal_CHF'), 200.00, ref('base.CHF'), ttype='receipt', date=False) vals = { 'account_id': ref('account.cash'), 'amount': 200.00, @@ -107,13 +107,14 @@ 'partner_id': ref('res_partner_john0'), 'period_id': ref('account.period_3'), 'type': 'receipt', - 'date': time.strftime("%Y-03-01"), + 'date': time.strftime("%Y-%m-%d"), 'payment_option': 'with_writeoff', 'writeoff_acc_id': ref('account.a_expense'), 'exchange_acc_id': ref('account.o_expense'), 'comment': 'Write Off', 'name': 'First payment', } + vals.update(self.onchange_date(cr, uid, [], time.strftime('%Y-03-01'), ref('base.CHF'), 200.0)['value']) if not res['value']['line_cr_ids']: res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}] for item in res['value']['line_cr_ids']: diff --git a/addons/account_voucher/voucher_sales_purchase_view.xml b/addons/account_voucher/voucher_sales_purchase_view.xml index 170f8fbcfe0..db21b4ce86a 100644 --- a/addons/account_voucher/voucher_sales_purchase_view.xml +++ b/addons/account_voucher/voucher_sales_purchase_view.xml @@ -82,9 +82,9 @@ - - - + + + @@ -209,9 +209,9 @@ - - - + + + From cd8641a2284f2207ea404e3c9e50145c08316f8d Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Fri, 21 Oct 2011 17:47:04 +0200 Subject: [PATCH 4/5] [FIX] account_voucher: do not let the field payment_rate editable if the voucher is posted + [FIX] onchange_journal do not reset the amount to 0 anymore bzr revid: qdp-launchpad@openerp.com-20111021154704-r7bi9a7iqpxaccem --- addons/account_voucher/account_voucher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 20eb552c074..03b3a75144c 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -247,7 +247,7 @@ class account_voucher(osv.osv): 'comment': fields.char('Counterpart Comment', size=64, required=True, readonly=True, states={'draft': [('readonly', False)]}), 'analytic_id': fields.many2one('account.analytic.account','Write-Off Analytic Account', readonly=True, states={'draft': [('readonly', False)]}), 'writeoff_amount': fields.function(_get_writeoff_amount, string='Reconcile Amount', type='float', readonly=True), - 'payment_rate': fields.float('Payment Rate', digits=(12,6), required=True, + 'payment_rate': fields.float('Payment Rate', digits=(12,6), required=True, readonly=True, states={'draft': [('readonly', False)]}, help='The rate between the journal currency and the company currency for this particular payment.'), 'paid_amount_in_company_currency': fields.function(_paid_amount_in_company_currency, string='Paid Amount in Company Currency', type='float', readonly=True), } @@ -616,7 +616,7 @@ class account_voucher(osv.osv): tax_id = account_id.tax_ids[0].id vals = self.onchange_price(cr, uid, ids, line_ids, tax_id, partner_id, context) - vals['value'].update({'tax_id':tax_id}) + vals['value'].update({'tax_id':tax_id,'amount': amount}) currency_id = False if journal.currency: currency_id = journal.currency.id From 5385588ea4d1638e1a4865690256850459d7c319 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Fri, 21 Oct 2011 17:55:08 +0200 Subject: [PATCH 5/5] [IMP] account_voucher: added base.group_extended on the new fields payment_rate and paid_amount_in_company_currency bzr revid: qdp-launchpad@openerp.com-20111021155508-6la9ybpuspwsvdsz --- .../account_voucher/voucher_payment_receipt_view.xml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/account_voucher/voucher_payment_receipt_view.xml b/addons/account_voucher/voucher_payment_receipt_view.xml index c1c7f076c9f..2c9b2edee6e 100644 --- a/addons/account_voucher/voucher_payment_receipt_view.xml +++ b/addons/account_voucher/voucher_payment_receipt_view.xml @@ -122,6 +122,8 @@ + + @@ -190,8 +192,8 @@ - - + + @@ -339,8 +341,8 @@ - - + +