[MERGE] merged the branch with account_voucher editable payment_rate
bzr revid: qdp-launchpad@openerp.com-20111021155559-p2gc3njeam5yblem
This commit is contained in:
@@ -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, 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),
|
||||
}
|
||||
_defaults = {
|
||||
'period_id': _get_period,
|
||||
@@ -260,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):
|
||||
@@ -409,6 +418,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,42 +443,32 @@ 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})
|
||||
|
||||
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')
|
||||
|
||||
vals = self.onchange_journal(cr, uid, ids, journal_id, [], False, partner_id, context)
|
||||
vals = vals.get('value')
|
||||
#set default values
|
||||
default = {
|
||||
'value': {'line_ids': [] ,'line_dr_ids': [] ,'line_cr_ids': [] ,'pre_line': False,},
|
||||
}
|
||||
|
||||
#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 or not journal_id:
|
||||
return default
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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 +496,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':
|
||||
@@ -556,23 +582,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')
|
||||
@@ -583,11 +616,19 @@ 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})
|
||||
currency_id = False #journal.company_id.currency_id.id
|
||||
vals['value'].update({'tax_id':tax_id,'amount': amount})
|
||||
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):
|
||||
@@ -631,7 +672,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:
|
||||
@@ -690,9 +730,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
|
||||
@@ -817,10 +857,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,
|
||||
@@ -970,9 +1010,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)
|
||||
|
||||
@@ -1172,17 +1212,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
|
||||
@@ -1203,7 +1236,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):
|
||||
|
||||
@@ -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:
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -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']:
|
||||
|
||||
@@ -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']:
|
||||
|
||||
@@ -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']:
|
||||
|
||||
@@ -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']:
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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']:
|
||||
|
||||
@@ -74,14 +74,14 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Bill Payment">
|
||||
<group col="6" colspan="4">
|
||||
<field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date)" context="{'invoice_currency':currency_id}" string="Supplier"/>
|
||||
<field name="amount" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date)"/>
|
||||
<field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)" context="{'invoice_currency':currency_id}" string="Supplier"/>
|
||||
<field name="amount" on_change="onchange_amount(amount, payment_rate, partner_id, journal_id, currency_id, type, date, context)"/>
|
||||
<field name="journal_id"
|
||||
domain="[('type','in',['bank', 'cash'])]"
|
||||
widget="selection" select="1"
|
||||
on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date)"
|
||||
on_change="onchange_journal(journal_id, line_dr_ids, False, partner_id, date, amount, type, context)"
|
||||
string="Payment Method"/>
|
||||
<field name="date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date)"/>
|
||||
<field name="date" select="1" on_change="onchange_date(date, currency_id, amount, context)"/>
|
||||
<field name="reference" select="1" string="Payment Ref"/>
|
||||
<field name="name" colspan="2"/>
|
||||
<field name="account_id"
|
||||
@@ -92,7 +92,7 @@
|
||||
</group>
|
||||
<notebook colspan="4">
|
||||
<page string="Payment Information">
|
||||
<field name="line_dr_ids" attrs="{'invisible': [('type', '=', 'receipt')]}" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="140" on_change="onchange_line_ids(line_dr_ids, line_cr_ids, amount)">
|
||||
<field name="line_dr_ids" attrs="{'invisible': [('type', '=', 'receipt')]}" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="140" on_change="onchange_line_ids(line_dr_ids, line_cr_ids, amount, context)">
|
||||
<tree string="Open Supplier Journal Entries" editable="bottom">
|
||||
<field name="move_line_id" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
|
||||
on_change="onchange_move_line_id(move_line_id)"
|
||||
@@ -106,7 +106,7 @@
|
||||
<field name="amount" sum="Payment"/>
|
||||
</tree>
|
||||
</field>
|
||||
<field name="line_cr_ids" colspan="4" nolabel="1" attrs="{'invisible': [('type', '=', 'payment')]}" default_get="{'journal_id':journal_id, 'partner_id':partner_id}" on_change="onchange_line_ids(line_dr_ids, line_cr_ids, amount)">
|
||||
<field name="line_cr_ids" colspan="4" nolabel="1" attrs="{'invisible': [('type', '=', 'payment')]}" default_get="{'journal_id':journal_id, 'partner_id':partner_id}" on_change="onchange_line_ids(line_dr_ids, line_cr_ids, amount, context)">
|
||||
<tree string="Open Customer Journal Entries" editable="bottom">
|
||||
<field name="move_line_id"/>
|
||||
<field name="account_id" groups="base.group_extended" domain="[('type','=','receivable')]"/>
|
||||
@@ -122,6 +122,8 @@
|
||||
<group col="2" colspan="1">
|
||||
<separator string="Other Information" colspan="2"/>
|
||||
<field name="currency_id"/>
|
||||
<field name="payment_rate" required="1" on_change="onchange_rate(payment_rate, amount, context)" groups='base.group_extended'/>
|
||||
<field name="paid_amount_in_company_currency" groups='base.group_extended'/>
|
||||
<field name="number"/>
|
||||
</group>
|
||||
</page>
|
||||
@@ -137,15 +139,15 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Bill Payment">
|
||||
<group col="6" colspan="4">
|
||||
<field name="partner_id" domain="[('supplier','=',True)]" required="1" invisible="context.get('line_type', False)" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date)" context="{'invoice_currency':currency_id}" string="Supplier"/>
|
||||
<field name="amount" invisible="context.get('line_type', False)" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date)"/>
|
||||
<field name="partner_id" domain="[('supplier','=',True)]" required="1" invisible="context.get('line_type', False)" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)" context="{'invoice_currency':currency_id}" string="Supplier"/>
|
||||
<field name="amount" invisible="context.get('line_type', False)" on_change="onchange_amount(amount, payment_rate, partner_id, journal_id, currency_id, type, date, context)"/>
|
||||
<field name="journal_id"
|
||||
domain="[('type','in',['bank', 'cash'])]"
|
||||
invisible="context.get('line_type', False)"
|
||||
widget="selection" select="1"
|
||||
on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date)"
|
||||
on_change="onchange_journal(journal_id, line_dr_ids, False, partner_id, date, amount, type, context)"
|
||||
string="Payment Method"/>
|
||||
<field name="date" select="1" invisible="context.get('line_type', False)" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date)"/>
|
||||
<field name="date" select="1" invisible="context.get('line_type', False)" on_change="onchange_date(date, currency_id, amount, context)"/>
|
||||
<field name="reference" select="1" invisible="context.get('line_type', False)" string="Payment Ref"/>
|
||||
<field name="name" colspan="2" invisible="context.get('line_type', False)"/>
|
||||
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
|
||||
@@ -186,12 +188,14 @@
|
||||
<field name="narration" colspan="2" nolabel="1"/>
|
||||
</group>
|
||||
<group col="2" colspan="1">
|
||||
<group col="2" colspan="1">
|
||||
<group col="2" colspan="1" attrs="{'invisible':[('currency_id','=',False)]}">
|
||||
<separator string="Currency Options" colspan="2"/>
|
||||
<field name="exchange_acc_id"
|
||||
attrs="{'invisible':[('currency_id','=',False)]}"
|
||||
domain="[('type','=','other')]"/>
|
||||
<field name="analytic_id"
|
||||
groups="analytic.group_analytic_accounting"/>
|
||||
<field name="payment_rate" required="1" on_change="onchange_rate(payment_rate, amount, context)" groups='base.group_extended'/>
|
||||
<field name="paid_amount_in_company_currency" groups='base.group_extended'/>
|
||||
</group>
|
||||
<group col="2" colspan="1">
|
||||
<separator string="Payment Options" colspan="2"/>
|
||||
<field name="payment_option" required="1"/>
|
||||
<field name="writeoff_amount"
|
||||
@@ -201,12 +205,13 @@
|
||||
domain="[('type','=','other')]"/>
|
||||
<field name="comment"
|
||||
attrs="{'invisible':[('payment_option','!=','with_writeoff')]}"/>
|
||||
|
||||
<field name="analytic_id"
|
||||
groups="analytic.group_analytic_accounting"/>
|
||||
</group>
|
||||
<separator string="Other Information" colspan="2"/>
|
||||
<group col="2" colspan="1">
|
||||
<field name="number"/>
|
||||
<field name="currency_id" invisible="1"/>
|
||||
<group col="4" colspan="2">
|
||||
<separator string="Other Information" colspan="4"/>
|
||||
<field name="number" colspan="4"/>
|
||||
<field name="currency_id" invisible="1" colspan="4"/>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
@@ -279,19 +284,19 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Customer Payment">
|
||||
<group col="6" colspan="4">
|
||||
<field name="partner_id" required="1" invisible="context.get('line_type', False)" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date)" string="Customer"/>
|
||||
<field name="partner_id" required="1" invisible="context.get('line_type', False)" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)" string="Customer"/>
|
||||
<field name="currency_id" invisible="1"/>
|
||||
<field name="amount"
|
||||
invisible="context.get('line_type', False)"
|
||||
string="Paid Amount"
|
||||
on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date)"/>
|
||||
on_change="onchange_amount(amount, payment_rate, partner_id, journal_id, currency_id, type, date, context)"/>
|
||||
<field name="journal_id"
|
||||
domain="[('type','in',['bank', 'cash'])]"
|
||||
invisible="context.get('line_type', False)"
|
||||
widget="selection" select="1"
|
||||
on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date)"
|
||||
on_change="onchange_journal(journal_id, line_cr_ids, False, partner_id, date, amount, type, context)"
|
||||
string="Payment Method"/>
|
||||
<field name="date" select="1" invisible="context.get('line_type', False)" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date)"/>
|
||||
<field name="date" select="1" invisible="context.get('line_type', False)" on_change="onchange_date(date, currency_id, amount, context)"/>
|
||||
<field name="reference" select="1" invisible="context.get('line_type', False)" string="Payment Ref"/>
|
||||
<field name="name" colspan="2" invisible="context.get('line_type', False)"/>
|
||||
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
|
||||
@@ -303,7 +308,7 @@
|
||||
</group>
|
||||
<notebook colspan="4">
|
||||
<page string="Payment Information">
|
||||
<field name="line_cr_ids" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="140" on_change="onchange_line_ids(line_dr_ids, line_cr_ids, amount)">
|
||||
<field name="line_cr_ids" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="140" on_change="onchange_line_ids(line_dr_ids, line_cr_ids, amount, context)">
|
||||
<tree string="Invoices and outstanding transactions" editable="bottom">
|
||||
<field name="move_line_id" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
|
||||
on_change="onchange_move_line_id(move_line_id)"
|
||||
@@ -318,7 +323,7 @@
|
||||
<field name="amount" sum="Payment"/>
|
||||
</tree>
|
||||
</field>
|
||||
<field name="line_dr_ids" colspan="4" nolabel="1" attrs="{'invisible': [('pre_line','=',False)]}" default_get="{'journal_id':journal_id, 'partner_id':partner_id}" on_change="onchange_line_ids(line_dr_ids, line_cr_ids, amount)">
|
||||
<field name="line_dr_ids" colspan="4" nolabel="1" attrs="{'invisible': [('pre_line','=',False)]}" default_get="{'journal_id':journal_id, 'partner_id':partner_id}" on_change="onchange_line_ids(line_dr_ids, line_cr_ids, amount, context)">
|
||||
<tree string="Credits" editable="bottom">
|
||||
<field name="move_line_id"/>
|
||||
<field name="account_id" groups="base.group_extended" domain="[('type','=','receivable')]"/>
|
||||
@@ -332,13 +337,15 @@
|
||||
<field name="narration" colspan="2" nolabel="1"/>
|
||||
</group>
|
||||
<group col="2" colspan="1">
|
||||
<group col="2" colspan="1" attrs="{'invisible':[('currency_id','=',False)]}">
|
||||
<separator string="Currency Options" colspan="2"/>
|
||||
<field name="exchange_acc_id"
|
||||
domain="[('type','=','other')]"/>
|
||||
<field name="payment_rate" required="1" on_change="onchange_rate(payment_rate, amount, context)" groups='base.group_extended'/>
|
||||
<field name="paid_amount_in_company_currency" groups='base.group_extended'/>
|
||||
</group>
|
||||
<group col="2" colspan="1">
|
||||
<separator string="Payment Options" colspan="2"/>
|
||||
<field name="analytic_id"
|
||||
groups="analytic.group_analytic_accounting"/>
|
||||
<field name="exchange_acc_id"
|
||||
attrs="{'invisible':[('currency_id','=',False)]}"
|
||||
domain="[('type','=','other')]"/>
|
||||
<field name="payment_option" required="1"/>
|
||||
<field name="writeoff_amount"
|
||||
attrs="{'invisible':[('payment_option','!=','with_writeoff')]}"/>
|
||||
@@ -347,10 +354,12 @@
|
||||
domain="[('type','=','other')]"/>
|
||||
<field name="comment"
|
||||
attrs="{'invisible':[('payment_option','!=','with_writeoff')]}"/>
|
||||
<field name="analytic_id"
|
||||
groups="analytic.group_analytic_accounting"/>
|
||||
</group>
|
||||
<separator string="Other Information" colspan="2"/>
|
||||
<group col="4" colspan="1">
|
||||
<field name="number"/>
|
||||
<group col="4" colspan="2">
|
||||
<separator string="Other Information" colspan="4"/>
|
||||
<field name="number" colspan="4"/>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
|
||||
@@ -82,9 +82,9 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Sales Receipt">
|
||||
<group col="6" colspan="4">
|
||||
<field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date)" string="Customer"/>
|
||||
<field name="date" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date)"/>
|
||||
<field name="journal_id" domain="[('type','in',['sale','sale_refund'])]" widget="selection" on_change="onchange_journal(journal_id, line_cr_ids, tax_id, partner_id)"/>
|
||||
<field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)" string="Customer"/>
|
||||
<field name="date" on_change="onchange_date(date, currency_id, amount, context)"/>
|
||||
<field name="journal_id" domain="[('type','in',['sale','sale_refund'])]" widget="selection" on_change="onchange_journal(journal_id, line_cr_ids, tax_id, partner_id, date, amount, type, context)"/>
|
||||
<field name="number"/>
|
||||
<field name="name" colspan="2"/>
|
||||
<field name="company_id" select="1" widget="selection" groups="base.group_multi_company"/>
|
||||
@@ -209,9 +209,9 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Supplier Voucher">
|
||||
<group col="6" colspan="4">
|
||||
<field name="partner_id" domain="[('supplier','=',True)]" required="1" string="Supplier" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date)"/>
|
||||
<field name="date" string="Bill Date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date)"/>
|
||||
<field name="journal_id" domain="[('type','in',['purchase','purchase_refund'])]" widget="selection" select="1" on_change="onchange_journal(journal_id, line_dr_ids, tax_id, partner_id)"/>
|
||||
<field name="partner_id" domain="[('supplier','=',True)]" required="1" string="Supplier" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)"/>
|
||||
<field name="date" string="Bill Date" select="1" on_change="onchange_date(date, currency_id, amount, context)"/>
|
||||
<field name="journal_id" domain="[('type','in',['purchase','purchase_refund'])]" widget="selection" select="1" on_change="onchange_journal(journal_id, line_dr_ids, tax_id, partner_id, date, amount, type, context)"/>
|
||||
<field name="number"/>
|
||||
<field name="name" colspan="2"/>
|
||||
<field name="reference" select="1"/>
|
||||
|
||||
Reference in New Issue
Block a user