[ADD] add method to open the invoice in tree or form view accordingly.
bzr revid: nco@tinyerp.com-20121102060520-5st9qkxd9p6u5uuy
This commit is contained in:
parent
e4f32e4712
commit
cd6de8ccd2
|
@ -280,6 +280,27 @@ class purchase_order(osv.osv):
|
|||
fiscal_position = supplier.property_account_position and supplier.property_account_position.id or False
|
||||
return {'value':{'pricelist_id': pricelist, 'fiscal_position': fiscal_position}}
|
||||
|
||||
def invoice_open(self, cr, uid, ids, context=None):
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
act_obj = self.pool.get('ir.actions.act_window')
|
||||
|
||||
result = mod_obj.get_object_reference(cr, uid, 'account', 'action_invoice_tree2')
|
||||
id = result and result[1] or False
|
||||
result = act_obj.read(cr, uid, [id], context=context)[0]
|
||||
inv_ids = []
|
||||
for po in self.browse(cr, uid, ids, context=context):
|
||||
inv_ids+= [invoice.id for invoice in po.invoice_ids]
|
||||
if not inv_ids:
|
||||
raise osv.except_osv(_('Error!'), _('Please create Invoices.'))
|
||||
#choose the view_mode accordingly
|
||||
if len(inv_ids)>1:
|
||||
result['domain'] = "[('id','in',["+','.join(map(str, inv_ids))+"])]"
|
||||
else:
|
||||
res = mod_obj.get_object_reference(cr, uid, 'account', 'invoice_supplier_form')
|
||||
result['views'] = [(res and res[1] or False, 'form')]
|
||||
result['res_id'] = inv_ids and inv_ids[0] or False
|
||||
return result
|
||||
|
||||
def view_invoice(self, cr, uid, ids, context=None):
|
||||
'''
|
||||
This function returns an action that display existing invoices of given sale order ids. It can either be a in a list or in a form view, if there is only one invoice to show.
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
<button type="object"
|
||||
name="view_picking"
|
||||
string="Incoming Shipments" states="approved"/>
|
||||
<button type="object" name="view_invoice"
|
||||
<button type="object" name="invoice_open"
|
||||
string="Invoices" attrs="{'invisible': [('state', '=', 'draft')]}"/>
|
||||
</div>
|
||||
</xpath>
|
||||
|
|
Loading…
Reference in New Issue