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

Behavior of action

By
Magen
on 6/8/16, 12:19 PM 259 views

I have added project_id to the account.invoice and invoice_ids to project.project I want to see the related invoices in the ProjectForm view

So far I have added:

<button name="action_view_invoice"
type="object"
class="oe_stat_button"
icon="fa-pencil-square-o"
attrs="{'invisible': [('invoice_count', '=', 0)]}">
<field name="invoice_count" widget="statinfo" string="Invoices"/>
</button>

 And:

@api.multi
def action_view_invoice(self):
invoice_ids = self.mapped('invoice_ids')
imd = self.env['ir.model.data']
action = imd.xmlid_to_object('account.action_invoice_tree1')
list_view_id = imd.xmlid_to_res_id('account.invoice_tree')
form_view_id = imd.xmlid_to_res_id('account.invoice_form')
result = {
'name': action.name,
'help': action.help,
'type': action.type,
'views': [[list_view_id, 'tree'], [form_view_id, 'form'], [False, 'graph'], [False, 'kanban'], [False, 'calendar'], [False, 'pivot']],
'target': action.target,
'context': action.context,
'res_model': action.res_model,
}
if len(invoice_ids) > 1:
result['domain'] = "[('id','in',%s)]" % invoice_ids.ids
elif len(invoice_ids) == 1:
result['views'] = [(form_view_id, 'form')]
result['res_id'] = invoice_ids.ids[0]
else:
result = {'type': 'ir.actions.act_window_close'}
return result


So far it works, now the problem is when I press the button and see the invoices related to the project if I chose to create new invoice it doesn't automatically sets the default project to the current one. I would like to have the same behavior like  in Contacts when you go to Sales it shows you the sales related to the contact AND creating new sale automatically sets the customer to the current one

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: 6/8/16, 12:19 PM
Seen: 259 times
Last updated: 6/9/16, 4:23 AM