diff --git a/addons/account_voucher/voucher.py b/addons/account_voucher/voucher.py
index dd34d733920..45afb6dcdd6 100644
--- a/addons/account_voucher/voucher.py
+++ b/addons/account_voucher/voucher.py
@@ -91,6 +91,17 @@ class account_voucher(osv.osv):
return res[0]
else:
return False
+
+ def _get_pay_journal(self, cr, uid, context={}):
+ journal_pool = self.pool.get('account.journal')
+
+ res = journal_pool.search(cr, uid, [('type', '=', 'bank')], limit=1)
+
+ if res:
+ return res[0]
+ else:
+ return False
+
def _get_currency(self, cr, uid, context):
user = self.pool.get('res.users').browse(cr, uid, uid)
@@ -138,17 +149,21 @@ class account_voucher(osv.osv):
'number': fields.related('move_id', 'name', type="char", readonly=True, string='Number'),
'move_id':fields.many2one('account.move', 'Account Entry'),
'move_ids': fields.related('move_id','line_id', type='many2many', relation='account.move.line', string='Journal Items', readonly=True, states={'draft':[('readonly',False)]}),
- #'move_ids':fields.many2many('account.move.line', 'voucher_id', 'account_id', 'rel_account_move', 'Real Entry', readonly=True, states={'draft':[('readonly',False)]}),
'partner_id':fields.many2one('res.partner', 'Partner', readonly=True, states={'draft':[('readonly',False)]}),
'audit': fields.related('move_id','to_check', type='boolean', relation='account.move', string='Audit Complete ?'),
+ 'pay_now':fields.boolean('Pay Now ?', required=False),
+ 'pay_journal_id':fields.many2one('account.journal', 'Payment Journal', readonly=True, states={'draft':[('readonly',False)]}, domain=[('type','in',['bank','cash'])]),
+ 'pay_account_id':fields.many2one('account.account', 'Payment Account', readonly=True, states={'draft':[('readonly',False)]}, domain=[('type','<>','view')]),
+ 'pay_amount':fields.float('Payment Amount'),
}
-
+
_defaults = {
'period_id': _get_period,
'type': _get_type,
'journal_id':_get_journal,
'currency_id': _get_currency,
'state': lambda *a: 'draft',
+ 'pay_now':lambda *a: True,
'name': lambda *a: '/',
'date' : lambda *a: time.strftime('%Y-%m-%d'),
'reference_type': lambda *a: "none",
@@ -191,7 +206,25 @@ class account_voucher(osv.osv):
return {
'value':{'amount':balance}
}
-
+
+ def onchange_pay_journal(self, cr, uid, ids, journal_id, ttype):
+ res = {'pay_account_id':False}
+ if not journal_id:
+ return {
+ 'value':res
+ }
+ journal_pool = self.pool.get('account.journal')
+ journal = journal_pool.browse(cr, uid, journal_id)
+
+ if journal and ttype == 'sale':
+ account_id = journal.default_debit_account_id
+ res.update({
+ 'pay_account_id':account_id.id
+ })
+ return {
+ 'value':res
+ }
+
def onchange_journal(self, cr, uid, ids, journal_id, ttype):
res = {'account_id':False}
@@ -208,10 +241,10 @@ class account_voucher(osv.osv):
'account_id':account_id.id
})
elif journal_id and (ttype in ('payment','sale')) :
- account_id = journal.default_credit_account_id
- res.update({
- 'account_id':account_id.id
- })
+ account_id = journal.default_credit_account_id
+ res.update({
+ 'account_id':account_id.id
+ })
else:
account_id = journal.default_credit_account_id
res.update({
@@ -452,54 +485,73 @@ class account_voucher(osv.osv):
line_ids = []
line_ids += [move_line_pool.create(cr, uid, move_line)]
rec_ids = []
-
- for line in inv.payment_ids:
- amount=0.0
-
- if inv.type in ('payment'):
- ref = line.ref
-
+
+ if inv.type == 'sale' and inv.pay_now:
+ if not inv.pay_account_id or not inv.pay_journal_id:
+ raise osv.except_osv(_('Payment Error !'), _('Please define Payment Journal and Account !'))
+
+ #create the payment line manually
move_line = {
- '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
+ 'name':inv.name,
+ 'debit':inv.pay_amount,
+ 'credit':False,
+ 'account_id':inv.pay_account_id.id or False,
+ 'move_id':move_id ,
+ 'journal_id':inv.pay_journal_id.id,
+ 'period_id':inv.period_id.id,
+ 'partner_id':inv.partner_id.id,
+ 'ref':ref,
+ 'date':inv.date
}
+ line_ids += [move_line_pool.create(cr, uid, move_line)]
+ else:
+ for line in inv.payment_ids:
+ amount=0.0
- 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 inv.type in ('payment'):
+ ref = line.ref
- if line.account_analytic_id:
- move_line.update({
- 'analytic_account_id':line.account_analytic_id.id
- })
+ move_line = {
+ '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 line.type == 'dr':
- move_line.update({
- 'debit': line.amount or False
- })
- amount = line.amount
+ 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
+ })
- elif line.type == 'cr':
- move_line.update({
- 'credit': line.amount or False
- })
- amount = line.amount
+ if line.account_analytic_id:
+ move_line.update({
+ 'analytic_account_id':line.account_analytic_id.id
+ })
- move_line_id = move_line_pool.create(cr, uid, move_line)
- line_ids += [move_line_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
+
+ move_line_id = move_line_pool.create(cr, uid, move_line)
+ line_ids += [move_line_id]
rec = {
'move_id': move_id,
@@ -560,6 +612,7 @@ account_voucher()
class account_voucher_line(osv.osv):
_name = 'account.voucher.line'
_description = 'Voucher Line'
+
_columns = {
'voucher_id':fields.many2one('account.voucher', 'Voucher'),
'name':fields.related('voucher_id', 'name', size=256, type='char', string='Memo'),
diff --git a/addons/account_voucher/voucher_view.xml b/addons/account_voucher/voucher_view.xml
index 41979f4b730..aef3c1ebb2b 100644
--- a/addons/account_voucher/voucher_view.xml
+++ b/addons/account_voucher/voucher_view.xml
@@ -46,7 +46,7 @@
-
+
@@ -54,11 +54,20 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -100,13 +109,13 @@
-
+
-
+
@@ -147,7 +156,7 @@
-
+
@@ -178,10 +187,10 @@
-
+
- Sales Vouchers
+ Sales Receipt
account.voucher
form
tree,form,graph
@@ -192,10 +201,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- Purchase Vouchers
+ Vendor Bills
account.voucher
form
tree,form,graph
@@ -220,35 +243,50 @@
- Receive Payments
+ Sales Payments
ir.actions.act_window
account.voucher
form
tree,form
- [('journal_id.type', '=', 'bank'), ('type','=','receipt')]
+ [('journal_id.type', 'in', ['bank', 'cash']), ('type','=','receipt')]
{'type':'bank'}
-
-
+
+
- Pay Bills
+ Vendor Payment
ir.actions.act_window
account.voucher
form
tree,form
- [('journal_id.type', '=', 'bank'), ('type','=','payment')]
+ [('journal_id.type', 'in', ['bank', 'cash']), ('type','=','payment')]
{'type':'bank'}
-
+
+
+ Cheques
+ ir.actions.act_window
+ account.voucher
+ form
+ tree,form
+ [('journal_id.type', 'in', ['bank']), ('type','=','payment')]
+ {'type':'bank'}
+
+
+
+
-
+
account.journal.form.inherit
account.journal
@@ -268,7 +306,7 @@
context="{'journal_id': active_id, 'type':type}"
res_model="account.voucher"
src_model="account.journal"/>
-
+
Vouchers Entries
account.voucher
diff --git a/addons/account_voucher_payment/account_voucher_payment.py b/addons/account_voucher_payment/account_voucher_payment.py
index fe1d984f1f8..96431de6ffb 100755
--- a/addons/account_voucher_payment/account_voucher_payment.py
+++ b/addons/account_voucher_payment/account_voucher_payment.py
@@ -25,6 +25,34 @@ from tools.translate import _
class account_move(osv.osv):
_inherit = 'account.move'
+ def _get_line_ids(self, cr, uid, ids, context=None):
+ result = {}
+ for line in self.pool.get('account.move.line').browse(cr, uid, ids, context=context):
+ result[line.move_id.id] = True
+ return result.keys()
+
+ def _amount_all(self, cr, uid, ids, name, args, context=None):
+ res = {}
+ for move in self.browse(cr, uid, ids, context=context):
+ rs = {
+ 'reconcile_id': False,
+ }
+ for line in move.line_id:
+ if line.reconcile_id:
+ rs.update({
+ 'reconcile_id': line.reconcile_id.id
+ })
+ res[move.id] = rs
+ return res
+
+ _columns = {
+ 'reconcile_id': fields.function(_amount_all, method=True, type="many2one", relation="account.move.line", string='Reconcile',
+ store={
+ 'account.move.line': (_get_line_ids, [], 20),
+ },
+ multi='all'),
+ }
+
def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False):
"""
Returns a list of ids based on search domain {args}
@@ -153,59 +181,75 @@ class account_voucher(osv.osv):
line_ids += [move_line_pool.create(cr, uid, move_line)]
rec_ids = []
- for line in inv.payment_ids:
- amount=0.0
-
- if inv.type in ('payment'):
- ref = line.ref
-
+ if inv.type == 'sale' and inv.pay_now:
+ #create the payment line manually
move_line = {
- '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
+ 'name':inv.name,
+ 'debit':inv.pay_amount,
+ 'credit':False,
+ 'account_id':inv.pay_account_id.id or False,
+ 'move_id':move_id ,
+ 'journal_id':inv.pay_journal_id.id,
+ 'period_id':inv.period_id.id,
+ 'partner_id':inv.partner_id.id,
+ 'ref':ref,
+ 'date':inv.date
}
-
- 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:
- 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
-
- move_line_id = move_line_pool.create(cr, uid, move_line)
- line_ids += [move_line_id]
-
- if line.move_id and inv.type in ('payment', 'receipt'):
- rec_ids += [move_line_id]
- for move_line in line.move_id.line_id:
- if line.account_id.id == move_line.account_id.id:
- rec_ids += [move_line.id]
+ line_ids += [move_line_pool.create(cr, uid, move_line)]
+ else:
+ for line in inv.payment_ids:
+ amount=0.0
+
+ if inv.type in ('payment'):
+ ref = line.ref
+
+ move_line = {
+ '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:
+ 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
+
+ move_line_id = move_line_pool.create(cr, uid, move_line)
+ line_ids += [move_line_id]
+
+ if line.move_id and inv.type in ('payment', 'receipt'):
+ rec_ids += [move_line_id]
+ for move_line in line.move_id.line_id:
+ if line.account_id.id == move_line.account_id.id:
+ rec_ids += [move_line.id]
if rec_ids:
move_line_pool.reconcile_partial(cr, uid, rec_ids)
diff --git a/addons/account_voucher_payment/account_voucher_payment_view.xml b/addons/account_voucher_payment/account_voucher_payment_view.xml
index 2eb0693f440..de5d4aa4a8a 100755
--- a/addons/account_voucher_payment/account_voucher_payment_view.xml
+++ b/addons/account_voucher_payment/account_voucher_payment_view.xml
@@ -12,7 +12,7 @@
-
+