SAP Fiori Elements - Object Page Table Items XML Annotation - abap

Please, what are the XML annotations needed in a Fiori Elements Object Page in order to display a table in it?
This app is not a RAP one, this is OData service with gateway (SEGW).
Example: Main Entity Purchase Orders and in Object Page display all PO Items.

You need to add ReferenceFacet annotations that point to the LineItem annotation.
ReferenceFacet annotations will create a new section in the Object Page. The LineItem annotation will add a table to it.
More details you can find in the documentation.
Facet annotation:
<Annotation Term="UI.Facets">
<Record Type="UI.ReferenceFacet">
<PropertyValue Property="ID" String="to_Children"/>
<PropertyValue Property="Target" AnnotationPath="children/#UI.LineItem"/>
<PropertyValue Property="Label" String="{#i18n>CHILDREN_LABEL}"/>
</Record>
</Annotation>
LineItem annotation
<Annotations Target="MyService.Children" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<Annotation Term="UI.LineItem">
<Collection>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="FullName"/>
</Record>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="Age"/>
</Record>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="EyeColor"/>
</Record>
</Collection>
</Annotation>
</Annotations>

Related

Odoo write to field not part of the current view

I want to update the field done_date which is part of the project.task form view when pulling a Kanban tile on the stage that is indicated as being the final stage.
My code below works fine if the field is part of the Kanban view but fails to write if the field is only part of the task form view and not part of the Kanban project view.
The done_date field should be written even without being part of the Kanban view.
models.py
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class project_set_end_date(models.Model):
inherit = 'project.task.type'
last_stage = fields.Boolean(string="Final stage")
class project_set_end_date(models.Model):
_inherit = 'project.task'
#api.onchange('stage_id')
def _set_end_date(self):
if self.stage_id.last_stage:
self.date_finished = fields.Datetime.now()
views.py
<odoo>
<data>
<!-- explicit list view definition -->
<record model="ir.ui.view" id="project_set_end_date">
<field name="name">project.task.type.form</field>
<field name="model">project.task.type</field>
<field name="inherit_id" ref="project.task_type_edit"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='fold']" position='after'>
<field name="last_stage"/>
</xpath>
</field>
</record>
</data>
</odoo>
Odoo doesn't write to a field that doesn't exist in the current view. So I suggest adding the field but with the attribute invisible = True to avoid showing it:
<field name="your_field" invisible="True"/>

How do I add multiple models to one view?

I'm trying to use three different models in one view. I've created a new model that inherits the models which seems to work fine.
from openerp import models, fields, api
class ProjectNote(models.Model):
_name = "triangle.project.note"
_inherit = ["note.note", "project.project", "triangle.note"]
My problem is in the view. I use my new model as the model and inherit a view from project.
<record id="view_project_notes_form" model="ir.ui.view">
<field name="name">triangle.project.note.form</field>
<field name="model">triangle.project.note</field>
<field name="inherit_id" ref="project.edit_project"/>
<field name="arch" type="xml">
<data>
<xpath expr="//field[#name='privacy_visibility']" position="replace">
<h2>
<field name="title" placeholder="Title"/>
</h2>
</xpath>
</data>
</field>
</record>
I don't get any errors but my field is not being added.
Any help is appreciated!
If you're trying to open a project.project view and wondering why there is no field title in it: there can't be. You aren't extending the project view for model project.project but are defining a form view for your model triangle.project.note which inherits the project view.
So the project views are untouched, you've just created the first form view for your new model.

Error while adding custom field using module: ParseError: "arch" while parsing file

I am trying to add a custom field to Odoo 9 res.partner model using module. I have used scoffold command to generate the module files and added following code to models.py and views.xml.
models/models.py
from openerp import models, fields, api
class SeicoPartner(models.Model):
_name = 'res.partner'
_inherit = 'res.partner'
no_of_ac = fields.Integer('No of AC', default=0)
review = fields.Char('Company Review')
views/views.xml
<openerp>
<data>
<record id="res_partner_field_ac" model="ir.ui.view">
<field name="no_of_ac">10</field>
</record>
</data>
</openerp>
Upon installation of this module from Apps screen, I got the following error:
Traceback (most recent call last):
...
File "C:\Program Files (x86)\Odoo 9.0-20160719\server\openerp\addons\base\ir\ir_ui_view.py", line 344, in create
ParseError: "arch" while parsing file:///C:/Program%20Files%20(x86)/Odoo%209.0-20160719/server/openerp/addons/mymodule1/views/views.xml:4, near
<record id="res_partner_field_ac" model="ir.ui.view">
<field name="no_of_ac">10</field>
</record>
From the Settings -> Database Structure -> Fields I can see that res.partner has the no_of_ac field, but the field is not visible while editing any customer details.
That's because you're missing the arch field with describes the type of view (either xml or html), in most cases xml is just fine,
You're also missing the model name, the view name, so odoo doesn't know which model your view belongs to. you also have to specify the existing model form you want to over-ride and the position where you want the new field to be, in this case i used an xpath expression to display the field after the website field in the parent view, it can be anywhere you want it to be.
<openerp>
<data>
<record id="res_partner_field_ac" model="ir.ui.view">
<field name="name">res.partner.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='website']" position="after">
<field name="no_of_ac" />
</xpath>
</field>
</record>
</data>
</openerp>
also you don't need to specify _name if you just want to extend a model and add extra fields to it, so change your model code to this
from openerp import models, fields, api
class SeicoPartner(models.Model):
_inherit = 'res.partner'
no_of_ac = fields.Integer('No of AC', default=0)
review = fields.Char('Company Review')
If you want to add a data record you should use res.partner as model and define the required fields:
<record id="res_partner_field_ac" model="res.partner">
<field name="no_of_ac">10</field>
<field name="name">NEW PARTNER NAME</field>
<!-- define required fields -->
</record>
To define a view, take a look at Odoo views
You are inserting a new record in ir.ui.view data model.
<openerp>
<data>
<record id="res_partner_field_ac" model="ir.ui.view">
<field name="no_of_ac">10</field>
</record>
</data>
</openerp>
But you want to insert data to : res.partner
<openerp>
<data>
<record id="res_partner_field_ac" model="res.partner">
<field name="name">a name here because it's required when the field type != 'contact' </field>
<field name="no_of_ac">10</field>
</record>
</data>
</openerp>
NOTE :you encountered a problem because arch is a requrired field inir.ui.view model.

Odoo header buttons missing

I'm having a problem with the create button appearing in tree view. Neither does the next or previous buttons appear in the form view. However, the data is being retrieved from the database.
Tree form with missing buttons
The module I'm trying to make is an extended module of the human resource module, like the included HR attendance module. The extended module doesn't inherit anything and security hasn't been added yet. Only a menu item is added to the main module.
A module I previously created by inheriting the main HR module created the buttons as expected.
Expected outcome(different module)
training.py:
from openerp import fields, models, api
class ew_training(models.Model):
_name = 'hr.training'
var = fields.Char( string='variable')
training_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Main Submenu -->
<menuitem id="menu_training_tree" action="action_view_training"
parent="hr.menu_hr_main" sequence="6"/>
<record id="action_view_training" model="ir.actions.act_window">
<field name="name">Training</field>
<field name="res_model">hr.training</field>
<field name="view_type">tree</field>
<field name="view_mode">tree,form</field>
</record>
<record id="view_training_tree" model="ir.ui.view">
<field name="name">hr.training.tree</field>
<field name="model">hr.training</field>
<field name="arch" type="xml">
<tree>
<field name="var"/>
</tree>
</field>
</record>
<record id="view_training_form" model="ir.ui.view">
...
</record>
</data>
</openerp>
Please try avoid using the old API
EDIT
This should be work if you are trying to call differents views in differents actions.
The problem is not the button create, the problem is that you are not calling the tree view on your action action_view_training, try adding this line after view_mode:
<field name="view_id" ref="view_training_tree"/>
EDIT
To solve your case you only need to change in the view_type, you should use form:
<record id="action_view_training" model="ir.actions.act_window">
<field name="name">Training</field>
<field name="res_model">hr.training</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
It should be work perfectly!!! I hope this could be helpful for you.
Just for Information.
in action view_type tree can be used when you want to create hierarchical view, It will not give you ability to create or update record. view of company structure in Odoo is the example of view type tree.
and view_type to form in action will allow you to create normal tree, form view with ability to Create, Update, Duplicate, Delete.
Hope this helps.

New State in Openerp7

... In openerp7
I want my new state to show up in sale module ... But it is not appearing
Pls have a look at code below
In sale.py module I added state like:
class Sale_order(osv.Model):
_inherit = 'sale.order'
_columns = {
'state': fields.selection([
('draft', 'Draft Quotation'),
('my_new_state', 'My New State'),
('sent', 'Quotation Sent'),
('cancel', 'Cancelled'),
('waiting_date', 'Waiting Schedule'),
('progress', 'Sales Order'),
('manual', 'Sale to Invoice'),
('invoice_except', 'Invoice Exception'),
('done', 'Done'),
], 'Status', readonly=True, track_visibility='onchange',
help="Gives the status of the quotation or sales order. \nThe exception status is automatically set when a cancel operation occurs in the processing of a document linked to the sales order. \nThe 'Waiting Schedule' status is set when the invoice is confirmed but waiting for the scheduler to run on the order date.", select=True),
}
And in sale_view.xml, I added this piece of code..
<openerp>
<data>
<!-- Inherit the sale order model's form view and customize -->
<record id="sale_form_view" model="ir.ui.view">
<field name="name">sale.order.form.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<!-- Statusbar widget should also contain the new status -->
<field name="state" position="replace">
<field name="state" widget="statusbar" statusbar_visible="draft,my_new_state,sent,invoiced,done" statusbar_colors='{"invoice_except":"red","waiting_date":"blue"}'/>
</field>
</field>
</record>
</data>
But.... My new state is not appearing between draft quotation and quotation sent
Please guide
Why is this so
Thanks
First thing I would check is to make sure you are replacing the proper field in your view (if there are several instances of a field named "state" in the view you inherit, the wrong occurence could be replaced). Check the view by opening the 'Modify FormView' item in the developper tools/view.
If it is the wrong occurence you are replacing, you main need to change your view definition by using an xpath expression.
Second thing I would check, is make sure the sequence of your inherited view is smaller that the original view you are trying to replace/modify. You can check in 'Manage Views' item in the developper tools/view.
Third thing I would try is to rename your class from 'Sale_order' to 'sale_order' just to match the name of the original class your are trying to override.
Hope this helps.