diff options
| author | Mantavya Gajjar <mga@tinyerp.com> | 2010-08-17 18:54:18 +0530 |
|---|---|---|
| committer | Mantavya Gajjar <mga@tinyerp.com> | 2010-08-17 18:54:18 +0530 |
| commit | ea1ae2aeb2d8dd376de507a80a891008125f9aec (patch) | |
| tree | 341fd16fdca30283b83bacb3b8758fed21373916 | |
| parent | 7838abef1f0ee4ca0c502e203ab6fa8b596bdf5d (diff) | |
[IMP]: improvement in voucher module
bzr revid: mga@tinyerp.com-20100817132418-fhe3m9vua6tnuwr8
| -rw-r--r-- | addons/account_voucher/voucher.py | 159 | ||||
| -rw-r--r-- | addons/account_voucher/voucher_view.xml | 86 | ||||
| -rwxr-xr-x | addons/account_voucher_payment/account_voucher_payment.py | 146 | ||||
| -rwxr-xr-x | addons/account_voucher_payment/account_voucher_payment_view.xml | 2 |
4 files changed, 264 insertions, 129 deletions
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 } - - 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] + 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] 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 @@ <field name="type" on_change="onchange_type(parent.partner_id,type,parent.type, parent.currency_id)"/> <field name="amount"/> <field name="ref"/> - <field name="account_analytic_id" groups="base.group_extended"/> + <field name="account_analytic_id"/> </tree> </field> <group col="2" colspan="3"> @@ -54,11 +54,20 @@ <field name="narration" colspan="2" nolabel="1"/> </group> <group col="2" colspan="1"> - <separator string="Other Information" colspan="2"/> - <field name="number"/> - <field name="reference" select="1"/> - <field name="date" select="1" on_change="onchange_date(date)"/> - <field name="currency_id" select="1" attrs="{'readonly':[('type','in',['sale', 'purchase'])]}"/> + <group col="2" colspan="1" attrs="{'invisible': [('type','!=','sale')]}"> + <separator string="Payment Options" colspan="2"/> + <field name="pay_now"/> + <field name="pay_journal_id" on_change="onchange_pay_journal(pay_journal_id,type)" attrs="{'readonly': [('pay_now','=',False)], 'required': [('pay_now','=',True)]}"/> + <field name="pay_account_id" attrs="{'readonly': [('pay_now','=',False)], 'required': [('pay_now','=',True)]}"/> + <field name="pay_amount"/> + </group> + <group col="2" colspan="1"> + <separator string="Other Information" colspan="2"/> + <field name="number"/> + <field name="reference" select="1"/> + <field name="date" select="1" on_change="onchange_date(date)"/> + <field name="currency_id" select="1" attrs="{'readonly':[('type','in',['sale', 'purchase'])]}"/> + </group> </group> </page> <page string="Journal Items"> @@ -100,13 +109,13 @@ <separator orientation="vertical"/> <field name="number" select='1'/> <field name="account_id" select="1"/> - <field name="partner_id" select='1'/> + <field name="partner_id" select='1'/> <field name="date" select='1'/> </group> <newline/> <group col='8' colspan='4'> <field name="journal_id" widget="selection" context="{'journal_id': self, 'set_visible':False}" /> - <field name="period_id" context="{'period_id': self}" groups="base.group_extended"/> + <field name="period_id" context="{'period_id': self}" groups="base.group_extended"/> </group> <newline/> <group expand="0" string="Group By..." col='8' colspan='4'> @@ -147,7 +156,7 @@ <newline/> <group col='8' colspan='4'> <field name="journal_id" widget="selection" select="1"/> - <field name="period_id" select="1"/> + <field name="period_id" select="1"/> </group> <newline/> <group expand="0" string="Group By..." colspan="12" col="10"> @@ -178,10 +187,10 @@ </graph> </field> </record> - + <!-- Receipt Vouchers --> <record model="ir.actions.act_window" id="action_receipt_vou_voucher_list"> - <field name="name">Sales Vouchers</field> + <field name="name">Sales Receipt</field> <field name="res_model">account.voucher</field> <field name="view_type">form</field> <field name="view_mode">tree,form,graph</field> @@ -192,10 +201,24 @@ </record> <menuitem id="menu_action_receipt_vou_voucher_list" action="action_receipt_vou_voucher_list" parent="account.menu_finance_receivables" sequence="12"/> + + <!-- Sale Receipt Vouchers --> +<!-- <record model="ir.actions.act_window" id="action_receipt_vou_voucher_list_pay_now">--> +<!-- <field name="name">Sales Receipt Payment</field>--> +<!-- <field name="res_model">account.voucher</field>--> +<!-- <field name="view_type">form</field>--> +<!-- <field name="view_mode">tree,form,graph</field>--> +<!-- <field name="view_id" eval="view_voucher_tree"/>--> +<!-- <field name="domain">[('journal_id.type','=','sale')]</field>--> +<!-- <field name="context">{'type':'sale', 'pay_new':True}</field>--> +<!-- <field name="search_view_id" ref="view_voucher_filter_new"/>--> +<!-- </record>--> +<!-- <menuitem id="menu_action_receipt_vou_voucher_list_pay_now"--> +<!-- action="action_receipt_vou_voucher_list_pay_now" parent="account.menu_finance_receivables" sequence="12"/>--> <!-- Purchase Vouchers --> <record model="ir.actions.act_window" id="action_pay_vou_voucher_list"> - <field name="name">Purchase Vouchers</field> + <field name="name">Vendor Bills</field> <field name="res_model">account.voucher</field> <field name="view_type">form</field> <field name="view_mode">tree,form,graph</field> @@ -220,35 +243,50 @@ <menuitem action="action_voucher_list" id="menu_encode_entries_by_voucher" parent="account.menu_finance_entries" sequence="6"/> <record id="action_cheque_register" model="ir.actions.act_window"> - <field name="name">Receive Payments</field> + <field name="name">Sales Payments</field> <field name="type">ir.actions.act_window</field> <field name="res_model">account.voucher</field> <field name="view_type">form</field> <field name="view_mode">tree,form</field> - <field name="domain">[('journal_id.type', '=', 'bank'), ('type','=','receipt')]</field> + <field name="domain">[('journal_id.type', 'in', ['bank', 'cash']), ('type','=','receipt')]</field> <field name="context">{'type':'bank'}</field> <field name="view_id" ref="view_voucher_tree"/> <field name="search_view_id" ref="view_voucher_filter_new"/> </record> - <menuitem action="action_cheque_register" - id="menu_action_cheque_register" - parent="account.menu_finance_bank_and_cash"/> - + <menuitem action="action_cheque_register" + id="menu_action_cheque_register" + parent="account.menu_finance_receivables"/> + <record id="action_cheque_pay" model="ir.actions.act_window"> - <field name="name">Pay Bills</field> + <field name="name">Vendor Payment</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">account.voucher</field> + <field name="view_type">form</field> + <field name="view_mode">tree,form</field> + <field name="domain">[('journal_id.type', 'in', ['bank', 'cash']), ('type','=','payment')]</field> + <field name="context">{'type':'bank'}</field> + <field name="view_id" ref="view_voucher_tree"/> + <field name="search_view_id" ref="view_voucher_filter_new"/> + </record> + <menuitem action="action_cheque_pay" + id="menu_action_cheque_pay" + parent="account.menu_finance_payables"/> + + <record id="action_cheque_pay_voucher" model="ir.actions.act_window"> + <field name="name">Cheques</field> <field name="type">ir.actions.act_window</field> <field name="res_model">account.voucher</field> <field name="view_type">form</field> <field name="view_mode">tree,form</field> - <field name="domain">[('journal_id.type', '=', 'bank'), ('type','=','payment')]</field> + <field name="domain">[('journal_id.type', 'in', ['bank']), ('type','=','payment')]</field> <field name="context">{'type':'bank'}</field> <field name="view_id" ref="view_voucher_tree"/> <field name="search_view_id" ref="view_voucher_filter_new"/> </record> - <menuitem action="action_cheque_pay" - id="menu_action_cheque_pay" + <menuitem action="action_cheque_pay_voucher" + id="menu_action_cheque_pay_voucher" parent="account.menu_finance_bank_and_cash"/> - + <record model="ir.ui.view" id="view_account_journal_form_inherit"> <field name="name">account.journal.form.inherit</field> <field name="model">account.journal</field> @@ -268,7 +306,7 @@ context="{'journal_id': active_id, 'type':type}" res_model="account.voucher" src_model="account.journal"/> - + <record model="ir.actions.act_window" id="action_review_voucher_list"> <field name="name">Vouchers Entries</field> <field name="res_model">account.voucher</field> 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 @@ <tree string="Voucher Lines" editable="top"> <!-- <field name="name"/>--> <field name="ref" on_change="onchange_partner(parent.partner_id,type,parent.type, parent.currency_id)"/> - <field name="move_id" context="{'ttype':parent.type, 'partner_id':parent.partner_id, 'voucher':True}" on_change="onchange_invoice_id(move_id, parent.currency_id)" domain="[('state','=','posted'), ('partner_id','=',parent.partner_id)]"/> + <field name="move_id" context="{'ttype':parent.type, 'partner_id':parent.partner_id, 'voucher':True}" on_change="onchange_invoice_id(move_id, parent.currency_id)" domain="[('state','=','posted'), ('partner_id','=',parent.partner_id), ('reconcile_id','=', False)]"/> <field name="amount"/> <field name="type" on_change="onchange_type(parent.partner_id,type,parent.type, parent.currency_id)"/> <field name="account_id"/> |
