Odoo Help

0

How to return a required view of object by default function?

By
vadivel
on 2/10/16, 12:00 AM 1,011 views

Hi friends,

Im working in odoo8.I have wrote a default function to returns invoice ID's to one2many, based on condition.in tree view of one2many it shows customer tree view instead of supplier invoice tree view.How can i change that to supplier invoice tree view.Here i given my code for the reference:

class project_usage_wizard(osv.osv_memory):

_name = 'project.usage.wizard'

_description = 'Project Used Quantity'

_columns = {

'project_id': fields.many2one('project.project', 'Project'),

'budget_id': fields.many2one('boq.info.line','Budget'),

'budget_invoice_ids': fields.one2many('account.invoice', 'invoice_id', 'Invoice',),

'budget_receipt_ids': fields.one2many('account.voucher', 'voucher_id', 'Purchase Receipts'),

}


below function returns ids of invoice to one2many:

def default_get(self, cr, uid, fields, context=None):

account_obj = self.pool.get('account.invoice')

voucher_obj=self.pool.get('account.voucher')

if context is None:

context = {}

res = super(project_usage_wizard, self).default_get(cr, uid, fields, context=context)

line_list = []

vals = []

v_vals=[]

res_ids = context and context.get('active_ids', [])

budget_obj = self.pool.get('boq.info.line')

budget = budget_obj.browse(cr, uid, res_ids, context=context)

project_obj = self.pool.get('project.project')

project_id = project_obj.browse(cr,uid,budget.project_id.id, context=context)

account_line_obj=self.pool.get('account.invoice.line')

line_ids = account_line_obj.search(cr,uid,[('budget_line_id','=',budget.id)])

for inv in account_line_obj.browse(cr,uid,line_ids):

    print "inv",inv

    account_ids = account_obj.search(cr,uid, [('id','=',inv.invoice_id.id),('state','in',('open','paid'))])

    print "account_ids",account_ids

    if account_ids:

        for invoice in account_obj.browse(cr,uid,account_ids):

            vals.append(invoice.id)

            res.update(budget_invoice_ids=vals)

# for purchase receipts

budget_obj = self.pool.get('boq.info.line')

budget = budget_obj.browse(cr, uid, res_ids, context=context)

project_obj = self.pool.get('project.project')

project_id = project_obj.browse(cr,uid,budget.project_id.id, context=context)

voucher_line_obj=self.pool.get('account.voucher.line')

v_line_ids = voucher_line_obj.search(cr,uid,[('budget_line_id','=',budget.id)])

for voucher in voucher_line_obj.browse(cr,uid,v_line_ids):

    print "voucher",voucher

    voucher_ids=voucher_obj.search(cr,uid, [('id','=',voucher.voucher_id.id),('state','=','posted')])

    if voucher_ids:

         for v_ids in voucher_obj.browse(cr,uid,voucher_ids):

            v_vals.append(v_ids.id)

            res.update(budget_receipt_ids=v_vals)

return res

In xml:

<record id="view_project_usage_view" model="ir.ui.view">

<field name="name">Project Usage</field>

<field name="model">project.usage.wizard</field>

<field name="arch" type="xml">

<form string="Usage">

<group>

<group>

<field name="project_id" readonly="1"/>

<field name="budget_id" readonly="1"/>

</group>

</group>

<notebook>

<page>

<group string="Invoice Information">

    <field name="budget_invoice_ids" readonly="1"/> one2many for displays invoice ids returned from function

</group>

<group string="Receipts Information">

<field name="budget_receipt_ids" readonly="1"/>

</group>

</page>

</notebook>

</form>

</field>

</record>

Please help me in this situation to resolve this.Thanks in advance.

2
Axel Mendoza
On 2/10/16, 1:14 AM

On the field budget_invoice_ids define the view you like using the context key tree_view_ref like:

<field name="budget_invoice_ids" readonly="1" context="{'tree_view_ref': 'stock.view_move_tree'}"/>

It Worked.Thank u Axel Mendoza

vadivel
on 2/10/16, 2:30 AM

Could you accept the answer?

Axel Mendoza
on 2/10/16, 3:46 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 2/10/16, 12:00 AM
Seen: 1011 times
Last updated: 2/10/16, 4:41 AM