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 use two specific views (tree and form view) when using ir.actions.act_window

By
Javier
on 3/28/16, 4:39 PM 487 views

Hello everybody,


I am trying to call account.invoice_tree and account.invoice_form views as tree and form views respectively from another view. The behaviour I would like to have is that all related invoices (to a lead record, for which I defined a button  to get them) be shown, first  in a list (using account.invoice_tree view),  and then after one of the invoices is clicked, I want the invoice displayed in account.invoice_form view). I attempted to get tha behavior by using the views field inside the ir.actions.act_window record as shown below, but it does'n work (ie the app always shows invoice_supplier_form . Can anybody provide guidance on it.


Thanks a lot in advance. I apreciate your response.


Javier



<record id="action_invoice_receivable_attach" model="ir.actions.act_window">

<field name="name">Sale Invoices</field>

<field name="res_model">account.invoice</field>

<field name="view_type">form</field>

<field name="view_mode">tree,form</field>

<field name="views">[[%(account.invoice_tree)d, "tree"], [%(account.invoice_form)d, "form"]</field>

 <field name="domain">[('lead_id', '=', lead_id), '|', ('type', '=', 'out_invoice'), ('type', '=', 'out_refund')]</field>

<field name="context">{'default_lead_id': lead_id}</field>

<field name="target">current</field>

</record>

<button class="oe_stat_button" type="action" name="%(action_invoice_receivable_attach)d"

context="{'lead_id': active_id}" icon="fa-clipboard">

<field string="Sale Invoices" name="invoice_receivable_count" widget="statinfo" options="{'label_field': 'INVOICE_RECEIVABLE'}"/>

</button>


---------******-------


class crmLead(models.Model):

_inherit = 'crm.lead'

def _invoice_receivable_count(self):

invoices = 0

for invoice in self.invoices:

if 'out_invoice' == invoice.type or 'out_refund' == invoice.type:

invoices += 1

self.invoice_receivable_count = invoices

0

Axel Mendoza

--Axel Mendoza--
10308
| 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 3/29/16, 2:37 AM

Hi @Javier

There are two ways of doing that, assuming that you have a field invoices in the crm.lead and that you wanna display the invoices for the lead partner(you could change it to match your concept).

1- You could use the invoice search filters in conjunction with the button context to show the list view filtered by default with the partner of the lead. 

<button class="oe_stat_button" type="action" name="%(action_invoice_receivable_attach)d" context="{'search_default_partner_id': partner_id}" icon="fa-clipboard">

<field string="Sale Invoices" name="invoice_receivable_count" widget="statinfo" options="{'label_field': 'INVOICE_RECEIVABLE'}"/>

</button>

2- The other way involve changing the button type to "object" and in the method action for the button return the invoice action with a domain that filter all the invoice results

0
Javier
On 3/29/16, 1:43 PM

Thank you Axel. I appreciate your response.


Regards.

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: 3/28/16, 4:39 PM
Seen: 487 times
Last updated: 3/29/16, 1:43 PM