Hi,
in account.invoice i have done:
class AccountInvoice(models.Model):
_inherit = "account.invoice"
invoice_type = fields.Selection([
('simple_invoice','Simple Invoice'),
('progress_invoice','Progress Invoice'),
], string = "Invoice Type", readonly=True, index=True, change_default=True,
default=lambda self: self._context.get('invoice_type', 'simple_invoice'),
track_visibility='always')
class AccountInvoiceLine(models.Model):
_inherit = "account.invoice.line"
amount_net_ht = fields.Monetary(string='Amount Net of the month HT', store=True, readonly=True)
previous_amount_ht = fields.Monetary(string='Previous Cumulative amount HT', store=True, readonly=True)
in xml i made new action and new menuitem for that action that displays account invoice form for progress_invoice type that i added :
<record id="account.action_invoice_tree1" model="ir.actions.act_window">
<field name="name">Simple Invoices</field>
<field name="res_model">account.invoice</field>
<field name="view_type">form</field>
<field name="view_mode">tree,kanban,form,calendar,pivot,graph</field>
<field eval="False" name="view_id"/>
<field name="domain">[('type','in',['out_invoice', 'out_refund']), ('invoice_type','=','simple_invoice')]</field>
<field name="context">{'type':'out_invoice', 'journal_type': 'sale'}</field>
<field name="search_view_id" ref="account.view_account_invoice_filter"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create a simple invoice.
</p>
</field>
</record>
<record id="action_situation_invoice" model="ir.actions.act_window"> # new action added for Progress Invoice
<field name="name">Progress Invoices</field>
<field name="res_model">account.invoice</field>
<field name="view_type">form</field>
<field name="view_mode">tree,kanban,form,calendar,pivot,graph</field>
<field eval="False" name="view_id"/>
<field name="domain">[('type','in',['out_invoice', 'out_refund']), ('invoice_type','=','progress_invoice')]</field>
<field name="context">{'invoice_type':'progress_invoice'}</field>
<field name="search_view_id" ref="account.view_account_invoice_filter"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create a progress invoice.
</p>
</field>
</record>
<record id="action_situation_invoice_view1" model="ir.actions.act_window.view">
<field eval="1" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="account.invoice_tree"/>
<field name="act_window_id" ref="action_situation_invoice"/>
</record>
<record id="action_situation_invoice_view2" model="ir.actions.act_window.view">
<field eval="2" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="account.invoice_form"/>
<field name="act_window_id" ref="action_situation_invoice"/>
</record>
Now what i want is when in tree field i want to show
Now, i want to show the two fields amount_net_ht and previous_amount_ht (added in account.invoice.line) in invoice_line_ids when invoice_type is progress_invoice and hide them when invoice_type is simple_invoice. For that i added context in the action of Progress Invoice and using xpath i did:
<xpath expr="//form/sheet/notebook/page/field/tree/field[@name='price_subtotal']" position="after">
<field name="cumulative_amount_ht" invisible="context.get('invoice_type','simple_invoice')"/>
<field name="previous_amount_ht" invisible="context.get('invoice_type','simple_invoice')"/>
<field name="amount_net_ht" invisible="context.get('invoice_type','simple_invoice')"/>
</xpath>
but this does not work, the two field are always shown in Simple invoice form ( not in progress invoice like i want)
I know i can achieve this by creating completely new form for Progress Invoice ( similar to the default odoo invoice form ) and adding to it the new fields but it would be a lot of duplicated code. So i want to achieve this with context if it is possible.
Thanks.
Problem solved, from here i get the answer : http://vitraining.com/show-hide-columns-in-openerp-tree-view-xml/