Reputation: 757
I'm working on an Odoo graph view. An SQL view was needed to display all the fields in the graph view.
This is the python code: from openerp import fields, models, tools, api
class omzettenperdag_sql_view(models.Model):
_name = "omzettenperdag_sql_view"
_auto = False
#m2o fields to retrieve data from in SQL view query:
account_invoice = fields.Many2one(comodel_name='account.invoice', readonly=True, invisible=True)
account_invoice_line = fields.Many2one(comodel_name='account.invoice.line', readonly=True, invisible=True)
#Fields returned from SQL view:
hoeveelheid = fields.Float(string="Hoeveelheid")
prijs_excl = fields.Float(string="Prijs excl. btw")
datum = fields.Datetime(String="Datum")
verkoopskanaal = fields.Char(string="Verkoopskanaal")
#Create SQL view:
def init(self, cr):
tools.drop_view_if_exists(cr, self._table)
cr.execute("""
#SQL view query here...
);
""")
This is the xml code of the graph view:
<record id="view_account_invoice_line_graph" model="ir.ui.view">
<field name="name">account.invoice.line.graph</field>
<field name="model">omzettenperdag_sql_view</field>
<field name="arch" type="xml">
<graph string="Omzetten per dag" type="pivot">
<field name="datum" type="row"/>
<field name="verkoopskanaal" type="col"/>
<field name="prijs_excl" type="measure"/>
<field name="hoeveelheid" type="measure"/>
</graph>
</field>
</record>
I can split it further by date when I rightclick the month. The issue is that it's also possible to choose the m2o fields (account_invoice and account_invoice_line). That makes no sense and ofcourse gives an error.
The fields have the invisible attribute set in the python code.
Is there any way to hide those 2 fields from that "right-click-menu"? I don't want users to click there and get errors.
Upvotes: 3
Views: 1657
Reputation: 381
According to the version 12 of odoo doc, you can simply hide a field this way:
<record id="view_account_invoice_line_graph" model="ir.ui.view">
<field name="name">account.invoice.line.graph</field>
<field name="model">omzettenperdag_sql_view</field>
<field name="arch" type="xml">
<graph string="Omzetten per dag" type="pivot">
<field name="datum" type="row"/>
<field name="verkoopskanaal" type="col"/>
<field name="prijs_excl" type="measure"/>
<field name="hoeveelheid" type="measure" />
<field name="account_invoice" invisible="1" />
<field name="account_invoice_line" invisible="1" />
</graph>
</field>
</record>
Kind regards
Upvotes: 1