diff --git a/addons/account_voucher/voucher.py b/addons/account_voucher/voucher.py
index 3cb62011a4e..00d12f8063b 100644
--- a/addons/account_voucher/voucher.py
+++ b/addons/account_voucher/voucher.py
@@ -103,7 +103,7 @@ class account_voucher(osv.osv):
_name = 'account.voucher'
_description = 'Accounting Voucher'
- _order = "date desc"
+ _order = "id desc"
_columns = {
'name':fields.char('Name', size=256, required=True, readonly=True, states={'draft':[('readonly',False)]}),
'type': fields.selection([
@@ -211,7 +211,11 @@ class account_voucher(osv.osv):
self.action_move_line_create(cr, uid, ids)
self.write(cr, uid, ids, {'state':'posted'})
return True
-
+
+ def action_cancel_draft(self, cr, uid, ids, *args):
+ self.write(cr, uid, ids, {'state':'draft'})
+ return True
+
def cancel_voucher(self, cr, uid, ids, context={}):
move_pool = self.pool.get('account.move')
@@ -228,10 +232,6 @@ class account_voucher(osv.osv):
self.write(cr, uid, ids, res)
return True
- def action_cancel_draft(self, cr, uid, ids, *args):
- self.write(cr, uid, ids, {'state':'draft'})
- return True
-
def unlink(self, cr, uid, ids, context=None):
vouchers = self.read(cr, uid, ids, ['state'])
unlink_ids = []
@@ -417,176 +417,52 @@ class account_voucher_line(osv.osv):
'type': lambda *a: 'cr'
}
- def move_line_get(self, cr, uid, voucher_id, context={}):
- res = []
-
- cur_obj = self.pool.get('res.currency')
- inv = self.pool.get('account.voucher').browse(cr, uid, voucher_id)
- company_currency = inv.company_id.currency_id.id
- cur = inv.currency_id
-
- for line in inv.payment_ids:
- res.append(self.move_line_get_item(cr, uid, line, context))
- return res
-
def onchange_partner(self, cr, uid, ids, partner_id, ttype ,type1):
+ vals = {}
+
if not partner_id:
- return {'value' : {'account_id' : False, 'type' : False ,'amount':False}}
- obj = self.pool.get('res.partner')
+ vals.update({
+ 'account_id': False,
+ 'type': False ,
+ 'amount': False
+ })
+ return {
+ 'value' : vals
+ }
+
+ partner_pool = self.pool.get('res.partner')
account_id = False
+
+ partner = partner_pool.browse(cr, uid, partner_id)
+
if type1 in ('rec_voucher','bank_rec_voucher', 'journal_voucher'):
- account_id = obj.browse(cr, uid, partner_id).property_account_receivable
- balance = obj.browse(cr,uid,partner_id).credit
+ account_id = partner.property_account_receivable.id
+ balance = partner.credit
ttype = 'cr'
+
elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') :
- account_id = obj.browse(cr, uid, partner_id).property_account_payable
- balance = obj.browse(cr,uid,partner_id).debit
+ account_id = partner.property_account_payable.id
+ balance = partner.debit
ttype = 'dr'
+
elif type1 in ('journal_sale_vou') :
- account_id = obj.browse(cr, uid, partner_id).property_account_receivable
- balance = obj.browse(cr,uid,partner_id).credit
+ account_id = partner.property_account_receivable.id
+ balance = partner.credit
ttype = 'dr'
+
elif type1 in ('journal_pur_voucher') :
- account_id = obj.browse(cr, uid, partner_id).property_account_payable
- balance = obj.browse(cr,uid,partner_id).debit
+ account_id = partner.property_account_payable.id
+ balance = partner.debit
ttype = 'cr'
-
+
+ vals.update({
+ 'account_id': account_id,
+ 'type': ttype,
+ 'amount':balance
+ })
+
return {
- 'value' : {'account_id' : account_id.id, 'type' : ttype, 'amount':balance}
+ 'value' : vals
}
-
- def onchange_amount(self, cr, uid, ids, partner_id, amount, type, type1):
- if not amount:
- return {'value' : {}}
- if partner_id:
- obj = self.pool.get('res.partner')
- if type1 in ('rec_voucher', 'bank_rec_voucher', 'journal_voucher'):
- if amount < 0 :
- account_id = obj.browse(cr, uid, partner_id).property_account_payable
- type = 'dr'
- else:
- account_id = obj.browse(cr, uid, partner_id).property_account_receivable
- type = 'cr'
-
- elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') :
- if amount < 0 :
- account_id = obj.browse(cr, uid, partner_id).property_account_receivable
- type = 'cr'
- else:
- account_id = obj.browse(cr, uid, partner_id).property_account_payable
- type = 'dr'
-
- elif type1 in ('journal_sale_vou') :
- if amount < 0 :
- account_id = obj.browse(cr, uid, partner_id).property_account_payable
- type = 'cr'
- else:
- account_id = obj.browse(cr, uid, partner_id).property_account_receivable
- type = 'dr'
-
- elif type1 in ('journal_pur_voucher') :
- if amount< 0 :
- account_id = obj.browse(cr, uid, partner_id).property_account_receivable
- type = 'dr'
- else:
- account_id = obj.browse(cr, uid, partner_id).property_account_payable
- type = 'cr'
- else:
- if type1 in ('rec_voucher', 'bank_rec_voucher', 'journal_voucher'):
- if amount < 0 :
- type = 'dr'
- else:
- type = 'cr'
- elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') :
- if amount < 0 :
- type = 'cr'
- else:
- type = 'dr'
- elif type1 in ('journal_sale_vou') :
- if amount < 0 :
- type = 'cr'
- else:
- type = 'dr'
- elif type1 in ('journal_pur_voucher') :
- if amount< 0 :
- type = 'dr'
- else:
- type = 'cr'
-
- return {
- 'value' : { 'type' : type , 'amount':amount}
- }
-
- def onchange_type(self, cr, uid, ids, partner_id, amount, type, type1):
- if partner_id:
- obj = self.pool.get('res.partner')
- if type1 in ('rec_voucher','bank_rec_voucher', 'journal_voucher'):
- if type == 'dr' :
- account_id = obj.browse(cr, uid, partner_id).property_account_payable
- total=amount*(-1)
- else:
- account_id = obj.browse(cr, uid, partner_id).property_account_receivable
- total=amount*(-1)
-
- elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') :
- if type == 'cr' :
- account_id = obj.browse(cr, uid, partner_id).property_account_receivable
- total=amount*(-1)
- else:
- account_id = obj.browse(cr, uid, partner_id).property_account_payable
- total=amount*(-1)
-
- elif type1 in ('journal_sale_vou') :
- if type == 'cr' :
- account_id = obj.browse(cr, uid, partner_id).property_account_payable
- total=amount*(-1)
- else:
- account_id = obj.browse(cr, uid, partner_id).property_account_receivable
- total=amount*(-1)
- elif type1 in ('journal_pur_voucher') :
- if type == 'dr' :
- account_id = obj.browse(cr, uid, partner_id).property_account_receivable
- total=amount*(-1)
- else:
- account_id = obj.browse(cr, uid, partner_id).property_account_payable
- total=amount*(-1)
- else:
- if type1 in ('rec_voucher','bank_rec_voucher', 'journal_voucher'):
- if type == 'dr' :
- total=amount*(-1)
- else:
- total=amount*(-1)
-
- elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') :
- if type == 'cr' :
- total=amount*(-1)
- else:
- total=amount*(-1)
-
- elif type1 in ('journal_sale_vou') :
- if type == 'cr' :
- total=amount*(-1)
- else:
- total=amount*(-1)
- elif type1 in ('journal_pur_voucher') :
- if type == 'dr' :
- total=amount*(-1)
- else:
- total=amount*(-1)
-
- return {
- 'value' : {'type' : type , 'amount':total}
- }
-
- def move_line_get_item(self, cr, uid, line, context={}):
- return {
- 'type':'src',
- 'name': line.name[:64],
- 'amount':line.amount,
- 'account_id':line.account_id.id,
- 'partner_id':line.partner_id.id or False ,
- 'account_analytic_id':line.account_analytic_id.id or False,
- 'ref' : line.ref
- }
-
+
account_voucher_line()
diff --git a/addons/account_voucher/voucher_view.xml b/addons/account_voucher/voucher_view.xml
index 296d7882b1a..9f9ce13276c 100644
--- a/addons/account_voucher/voucher_view.xml
+++ b/addons/account_voucher/voucher_view.xml
@@ -35,7 +35,7 @@
-
+
@@ -48,15 +48,6 @@
-
-
-
-
-
-
-
-
-
@@ -67,6 +58,15 @@
+
+
+
+
+
+
+
+
+
diff --git a/addons/account_voucher_payment/account_voucher_payment.py b/addons/account_voucher_payment/account_voucher_payment.py
index efe0c41619d..a34a0859bfa 100755
--- a/addons/account_voucher_payment/account_voucher_payment.py
+++ b/addons/account_voucher_payment/account_voucher_payment.py
@@ -38,170 +38,127 @@ class account_voucher(osv.osv):
def action_move_line_create(self, cr, uid, ids, *args):
+ journal_pool = self.pool.get('account.journal')
+ sequence_pool = self.pool.get('ir.sequence')
+ move_pool = self.pool.get('account.move')
+ move_line_pool = self.pool.get('account.move.line')
+ analytic_pool = self.pool.get('account.analytic.line')
+ currency_pool = self.pool.get('res.currency')
+ invoice_pool = self.pool.get('account.invoice')
+
for inv in self.browse(cr, uid, ids):
+
if inv.move_id:
continue
+
company_currency = inv.company_id.currency_id.id
-
- line_ids = self.read(cr, uid, [inv.id], ['payment_ids'])[0]['payment_ids']
- ils = self.pool.get('account.voucher.line').read(cr, uid, line_ids)
-
- iml = self._get_analytic_lines(cr, uid, inv.id)
-
diff_currency_p = inv.currency_id.id <> company_currency
-
- total = 0
- if inv.type in ('pay_voucher', 'journal_voucher', 'rec_voucher','cont_voucher','bank_pay_voucher','bank_rec_voucher','journal_sale_voucher','journal_pur_voucher'):
- ref = inv.reference
- else:
- ref = self._convert_ref(cr, uid, inv.number)
-
- date = inv.date
- total_currency = 0
- for i in iml:
- partner_id=i['partner_id']
- acc_id = i['account_id']
- if inv.currency_id.id != company_currency:
- i['currency_id'] = inv.currency_id.id
- i['amount_currency'] = i['amount']
- else:
- i['amount_currency'] = False
- i['currency_id'] = False
- if inv.type in ('rec_voucher','bank_rec_voucher','journal_pur_voucher','journal_voucher'):
- total += i['amount']
- total_currency += i['amount_currency'] or i['amount']
- i['amount'] = - i['amount']
- else:
- total -= i['amount']
- total_currency -= i['amount_currency'] or i['amount']
-
- name = inv['name'] or '/'
- totlines = False
-
- iml.append({
- 'type': 'dest',
- 'name': name,
- 'amount': total or False,
- 'account_id': acc_id,
- 'amount_currency': diff_currency_p \
- and total_currency or False,
- 'currency_id': diff_currency_p \
- and inv.currency_id.id or False,
- 'ref': ref,
- 'partner_id':partner_id or False,
- })
-
- date = inv.date
- inv.amount=total
-
- line = map(lambda x:(0,0,self.line_get_convert(cr, uid, x,date, context={})) ,iml)
- an_journal_id=inv.journal_id.analytic_journal_id.id
- journal_id = inv.journal_id.id
-
- journal = self.pool.get('account.journal').browse(cr, uid, journal_id)
+ ref = inv.reference
+
+ journal = journal_pool.browse(cr, uid, inv.journal_id.id)
if journal.sequence_id:
- name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id)
-
+ name = sequence_pool.get_id(cr, uid, journal.sequence_id.id)
+
move = {
- 'name': name,
- 'journal_id': journal_id,
- 'voucher_type':inv.type,
- 'narration' : inv.narration,
- 'data':date
+ 'name' : name,
+ 'journal_id': journal.id,
+ 'type' : inv.type,
+ 'narration' : inv.narration and inv.narration or inv.name,
+ 'date':inv.date
}
-
+
if inv.period_id:
- move['period_id'] = inv.period_id.id
- for i in line:
- i[2]['period_id'] = inv.period_id.id
- move_id = self.pool.get('account.move').create(cr, uid, move)
- ref=move['name']
- amount=0.0
- #create the first line our self
+ move.update({
+ 'period_id': inv.period_id.id
+ })
+
+ move_id = move_pool.create(cr, uid, move)
+
+ #create the first line manually
move_line = {
'name': inv.name,
- 'voucher_invoice' : iml and iml[0]['invoice'] and iml[0]['invoice'].id or False,
'debit': False,
'credit':False,
'account_id': inv.account_id.id or False,
- 'move_id':move_id ,
- 'journal_id':journal_id ,
- 'period_id':inv.period_id.id,
+ 'move_id': move_id ,
+ 'journal_id': inv.journal_id.id,
+ 'period_id': inv.period_id.id,
'partner_id': False,
'ref': ref,
- 'date': date
+ 'date': inv.date
}
+ if diff_currency_p:
+ amount_currency = currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, inv.amount)
+ inv.amount = amount_currency
+ move_line.update({
+ 'amount_currency':amount_currency,
+ 'currency_id':inv.currency_id.id
+ })
+
if inv.type in ('rec_voucher', 'bank_rec_voucher', 'journal_pur_voucher', 'journal_voucher'):
move_line['debit'] = inv.amount
else:
- move_line['credit'] = inv.amount * (-1)
- self.pool.get('account.move.line').create(cr, uid, move_line)
- id_mapping_dict = {}
- mline_ids = []
- for line in inv.voucher_line_ids:
+ move_line['credit'] = inv.amount
+
+ line_ids = []
+ line_ids += [move_line_pool.create(cr, uid, move_line)]
+ for line in inv.payment_ids:
+ amount=0.0
move_line = {
- 'name':line.name,
- 'voucher_invoice' : iml and iml[0]['invoice'] and iml[0]['invoice'].id or False,
- 'debit':False,
- 'credit':False,
- 'move_id':move_id,
- 'account_id':line.account_id.id or False,
- 'journal_id':journal_id ,
- 'period_id':inv.period_id.id,
- 'partner_id':line.partner_id.id or False,
- 'ref':ref,
- 'date':date
- }
-
- if line.type == 'dr':
- move_line['debit'] = line.amount or False
- amount=line.amount
- elif line.type == 'cr':
- move_line['credit'] = line.amount or False
- amount=line.amount * (-1)
- ml_id=self.pool.get('account.move.line').create(cr, uid, move_line)
- id_mapping_dict[line.id] = ml_id
-
- total = 0.0
- mline = self.pool.get('account.move.line')
- if line.invoice_id.id:
- invoice = self.pool.get('account.invoice').browse(cr, uid, line.invoice_id.id)
- src_account_id = invoice.account_id.id
- cr.execute('select id from account_move_line where move_id in ('+str(invoice.move_id.id)+')')
- temp_ids = map(lambda x: x[0], cr.fetchall())
- temp_ids.append(ml_id)
- mlines = mline.browse(cr, uid, temp_ids)
- for ml in mlines:
- if ml.account_id.id==src_account_id:
- mline_ids.append(ml.id)
- total += (ml.debit or 0.0) - (ml.credit or 0.0)
- #end if line.invoice_id.id:
- if inv.narration:
- line.name=inv.narration
- else:
- line.name=line.name
-
+ 'name': line.name,
+ 'debit': False,
+ 'credit': False,
+ 'account_id': line.account_id.id or False,
+ 'move_id': move_id ,
+ 'journal_id': inv.journal_id.id,
+ 'period_id': inv.period_id.id,
+ 'partner_id': line.partner_id.id or False,
+ 'ref': ref,
+ 'date': inv.date,
+ 'analytic_account_id': False
+ }
+
+ if diff_currency_p:
+ amount_currency = currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, line.amount)
+ line.amount = amount_currency
+ move_line.update({
+ 'amount_currency':amount_currency,
+ 'currency_id':inv.currency_id.id
+ })
+
if line.account_analytic_id:
- an_line = {
- 'name':line.name,
- 'date':date,
- 'amount':amount,
- 'account_id':line.account_analytic_id.id or False,
- 'move_id':ml_id,
- 'journal_id':an_journal_id ,
- 'general_account_id':line.account_id.id,
- 'ref':ref
- }
- self.pool.get('account.analytic.line').create(cr, uid, an_line)
- if mline_ids:
- self.pool.get('account.move.line').reconcile_partial(cr, uid, mline_ids, 'manual', context={})
- self.write(cr, uid, [inv.id], {'move_id': move_id})
- obj=self.pool.get('account.move').browse(cr, uid, move_id)
-
- for line in obj.line_id :
- cr.execute('insert into voucher_id (account_id,rel_account_move) values (%d, %d)',(int(ids[0]),int(line.id)))
-
- return True
+ move_line.update({
+ 'analytic_account_id':line.account_analytic_id.id
+ })
+
+ if line.type == 'dr':
+ move_line.update({
+ 'debit': line.amount or False
+ })
+ amount = line.amount
+
+ elif line.type == 'cr':
+ move_line.update({
+ 'credit': line.amount or False
+ })
+ amount = line.amount
+
+ if line.invoice_id:
+ move_line.update({
+ 'invoice_id':line.invoice_id.id
+ })
+ invoice_pool.pay_and_reconcile(cr, uid, [line.invoice_id.id], amount, inv.account_id.id, inv.period_id.id, inv.journal_id.id, False, False, False)
+
+ move_line_id = move_line_pool.create(cr, uid, move_line)
+ line_ids += [move_line_id]
+
+ rec = {
+ 'move_id': move_id,
+ 'move_ids':[(6, 0,line_ids)]
+ }
+ self.write(cr, uid, [inv.id], rec)
+
+ return True
account_voucher()
@@ -222,18 +179,29 @@ class account_voucher_line(osv.osv):
res['invoice'] = line.invoice_id or False
return res
- def onchange_invoice_id(self, cr, uid, ids, invoice_id, context={}):
- lines = []
- if 'lines' in self.voucher_context:
- lines = [x[2] for x in self.voucher_context['lines']]
+ def onchange_invoice_id(self, cr, uid, ids, invoice_id, currency_id):
+ currency_pool = self.pool.get('res.currency')
+ invoice_pool = self.pool.get('account.invoice')
+ res = {
+ 'amount':0.0
+ }
if not invoice_id:
- return {'value':{}}
+ return {
+ 'value':res
+ }
else:
- invoice_obj = self.pool.get('account.invoice').browse(cr, uid, invoice_id, context)
- residual = invoice_obj.residual
- same_invoice_amounts = [x['amount'] for x in lines if x['invoice_id']==invoice_id]
- residual -= sum(same_invoice_amounts)
- return {'value' : {'amount':residual}}
+ invoice = invoice_pool.browse(cr, uid, invoice_id)
+ residual = invoice.residual
+ if invoice.currency_id.id != currency_id:
+ residual = currency_pool.compute(cr, uid, invoice.currency_id.id, currency_id, invoice.residual)
+
+ res.update({
+ 'amount': residual
+ })
+
+ return {
+ 'value':res
+ }
def onchange_line_account(self, cr, uid, ids, account_id, type, type1):
if not account_id:
diff --git a/addons/account_voucher_payment/account_voucher_payment_view.xml b/addons/account_voucher_payment/account_voucher_payment_view.xml
index 106f47c14ae..cc11d3a064c 100755
--- a/addons/account_voucher_payment/account_voucher_payment_view.xml
+++ b/addons/account_voucher_payment/account_voucher_payment_view.xml
@@ -1,21 +1,6 @@
-
-
- account.voucher.line.form.inherit
- account.voucher.line
- form
-
-
-
-
-
-
-
-
account.voucher.form.inherit
account.voucher
@@ -23,12 +8,12 @@
-
+
-
+
diff --git a/addons/account_voucher_payment/wizard/account_voucher_unreconcile.py b/addons/account_voucher_payment/wizard/account_voucher_unreconcile.py
index d6f468a1ab2..f91ee20925f 100644
--- a/addons/account_voucher_payment/wizard/account_voucher_unreconcile.py
+++ b/addons/account_voucher_payment/wizard/account_voucher_unreconcile.py
@@ -27,20 +27,20 @@ class account_voucher_unreconcile(osv.osv_memory):
def trans_unrec(self, cr, uid, ids, context=None):
if context is None:
context = {}
- obj_voucher = self.pool.get('account.voucher')
- obj_reconcile = self.pool.get('account.move.reconcile')
+ voucher_pool = self.pool.get('account.voucher')
+ reconcile_pool = self.pool.get('account.move.reconcile')
if context.get('active_id'):
voucher = obj_voucher.browse(cr, uid, context.get('active_id'), context=context)
recs = []
for line in voucher.move_ids:
if line.reconcile_id:
recs = [line.reconcile_id.id]
-
+
for rec in recs:
obj_reconcile.unlink(cr, uid, rec)
-
+
return {}
account_voucher_unreconcile()
-# 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_payment/wizard/account_voucher_unreconcile_view.xml b/addons/account_voucher_payment/wizard/account_voucher_unreconcile_view.xml
index 70c54e61b70..138aaec586f 100644
--- a/addons/account_voucher_payment/wizard/account_voucher_unreconcile_view.xml
+++ b/addons/account_voucher_payment/wizard/account_voucher_unreconcile_view.xml
@@ -2,28 +2,36 @@
-
+
Account voucher unreconcile
account.voucher.unreconcile
form
-
-
-
+
+
+ Unreconcile entries
+ account.voucher.unreconcile
+ form
+ form
+
+ new
+
+
+
+
+
+
+
+
+
-
\ No newline at end of file
+