This question has been flagged
2 Replies
5871 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

Avatar
Discard
Best Answer

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

Avatar
Discard
Author Best Answer

Thank you Axel. I appreciate your response.


Regards.

Avatar
Discard