Odoo Help

Welcome!

This community 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.

0

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

By
vadivel
on 2/10/16, 12:00 AM 570 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.

1

Axel Mendoza

--Axel Mendoza--
10238
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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