[FIX]: fix a problem of the invoice selection based on the voucher type
authorMantavya Gajjar <mga@tinyerp.com>
Thu, 29 Jul 2010 15:26:57 +0000 (20:56 +0530)
committerMantavya Gajjar <mga@tinyerp.com>
Thu, 29 Jul 2010 15:26:57 +0000 (20:56 +0530)
bzr revid: mga@tinyerp.com-20100729152657-99pz4cuedrbwpymq

addons/account_voucher_payment/account_voucher_payment.py
addons/account_voucher_payment/account_voucher_payment_view.xml

index 3d86014..dca7eeb 100755 (executable)
 from osv import fields, osv
 from tools.translate import _
 
+class account_invoice(osv.osv):
+    _inherit = 'account.invoice'
+
+    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}
+    
+        @param cr: A database cursor
+        @param user: ID of the user currently logged in
+        @param args: list of conditions to be applied in search opertion
+        @param offset: default from first record, you can start from nth record
+        @param limit: number of records to be obtained as a result of search opertion
+        @param order: ordering on any field(s)
+        @param context: context arguments, like lang, time zone
+        @param count: 
+        
+        @return: Returns a list of ids based on search domain
+        """
+        ttype = context.get('ttype', False)
+        if ttype and ttype in ('rec_voucher', 'bank_rec_voucher'):
+            args += [('type','in', ['out_invoice', 'in_refund'])]
+        elif ttype and ttype in ('pay_voucher', 'bank_pay_voucher'):
+            args += [('type','in', ['in_invoice', 'out_refund'])]
+        
+        res = super(account_invoice, self).search(cr, user, args, offset, limit, order, context, count)
+        return res
+    
+account_invoice()
+
 class account_move_line(osv.osv):
     _inherit = "account.move.line"
     _columns = {
@@ -196,7 +225,7 @@ class account_voucher_line(osv.osv):
         res = super(account_voucher_line, self).move_line_get_item(cr, uid, line, context)
         res['invoice'] = line.invoice_id or False
         return res
-
+    
     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')
index 3f11812..6da4c7d 100755 (executable)
                 <field name="payment_ids" position="replace">
                     <field name="voucher_line_ids"  default_get="{'lines': voucher_line_ids}" colspan="4" nolabel="1" height="275">
                         <tree string="Voucher Lines" editable="top">
-                            <field name="partner_id" on_change="onchange_partner(partner_id,type,parent.type, parent.currency_id)"/>
+                            <field name="partner_id" on_change="onchange_partner(partner_id, type, parent.type, parent.currency_id)"/>
                             <field name="account_id" on_change="onchange_line_account(account_id, type, parent.type)"/>
                             <field name="name"/>
-                            <field name="invoice_id" on_change="onchange_invoice_id(invoice_id, parent.currency_id)" domain="[('partner_id','=',partner_id),('state','=','open'),('residual','&gt;',0.0)]"/>
+                            <field name="invoice_id" context="{'ttype':parent.type}" on_change="onchange_invoice_id(invoice_id, parent.currency_id)" domain="[('partner_id','=',partner_id),('state','=','open'),('residual','&gt;',0.0)]"/>
                             <field name="type"/>
                             <field name="amount"/>
                             <field name="account_analytic_id"/>