Custom view of model inside the form view - view

I have this two models EstatePropertyModel and AuthorsModel, and I would like to display the entries of the AuthorsModel in the form of the EstatePropertyModel:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_estate_property_advertisement_form" model="ir.ui.view">
<field name="name">estate.property.form</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
name="name"/>
name="description"/>
name="postcode"/>
name="date_availability"/>
name="expected_price"/>
name="selling_price"/>
name="bedrooms"/>
name="living_area"/>
name="facades"/>
name="garage"/>
name="garden"/>
name="garden_area"/>
name="garden_orientation"/>
name="state_property"/>
name="active"/>
<field name="author_ids" position="after">
<div class="oe_title">Authors</div>
<div class="oe_subtitle">
<t t-if="len(record.author_ids) == 0">No authors</t>
<t t-if="len(record.author_ids) > 0">
<t t-foreach="record.author_ids" t-as="author">
<span t-field="author.name"/>
</t>
</t>
</div>
</field>
</odoo>
Is this possible?
I am new in the odoo development, and I am asking to point me the direction where to look! 
Thanks

yeeah it's possible through One2many field in odoo, after that, create a Notebook in the form view in that notebook and create a page, on that page add the one2many view in it
it will be made like this...
<notebook>
<page>
<field name="one2many_field_name">
<tree string="Example" editable="bottom">
<field name="field_1_from_2nd_model"/>
<field name="field_2_from_2nd_model"/>
</tree>
</field>
</page>
</notebook>
as per the comment below the answer is below this:
class ExampleModelFirst(models.Model):
_name = 'first.model'
field_1 = fields.Char(string='Field 1')
field_2 = fields.Integer(string='Field 2')
class ExampleModelSecond(models.Model):
_name = 'second.model'
field_3 = fields.Many2one('first.model', string='reference')
field_4 = fields.Char(related='field_3.field_1')
field_5 = field.Integer(related='field_3.field_2')
Add these second.model field in form view you will get the values...

author_ids should be one2many field
To create a One2many field you can refer to this https://www.odoo.com/documentation/16.0/developer/howtos/rdtraining/08_relations.html#one2many
Do this if you want to show all fields
<notebook>
<page string="Authors">
<field name="author_ids"/>
</page>
</notebook>
Do this if you want to show specific fields
<notebook>
<page string="Authors">
<field name="author_ids">
<tree>
<field name="author_ids.name"/>
</tree>
</field>
</page>
</notebook>

Related

odoo wizard cant inherit the model

I created a model like this
class FoundCheque(models.TransientModel):
_name = "found.cheque"
date_Found = fields.Date(string='Found Date', default=fields.Date.context_today, required=True, translate=True)
and its view
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record model="ir.ui.view" id="wizard_found_cheque">
<field name="name">found.cheque.wizard</field>
<field name="model">found.cheque</field>
<field name="arch" type="xml">
<form string="found Cheque">
<group>
<field name="date_found" style="width:40%%"/>
</group>
<footer>
<button name="found_cheque" string="Post" type="object" class="oe_highlight"/>
or <button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
</data>
</odoo>
but when I try to update the module after restarting the service
it just says:
Field `date_found` does not exist
Error context:
View `found.cheque.wizard`
[view_id: 4100, xml_id: n/a, model: found.cheque, parent_id: n/a]
None" while parsing /opt/odoo/odoo11-custom-addons/cheque_management/views/found_cheque.xml:4, near
<record model="ir.ui.view" id="wizard_found_cheque">
<field name="name">found.cheque.wizard</field>
<field name="model">found.cheque</field>
<field name="arch" type="xml">
<form string="found Cheque">
<group>
<field name="date_found" style="width:40%%"/>
</group>
<footer>
<button name="found_cheque" string="Post" type="object" class="oe_highlight" confirm="آیا مطمئن هستید؟"/>
or <button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
and just to add I restarted the service several times
more information will be added on request
Your field name in python file is date_Found and date_found in xml. Both are different. so change field name in xml file
the defined field in model was "date_Found" and the defined field in wizard was "date_found"
F

add many2one field in inherited view

I want to display my Many2one field.
I inherited from the hr_timesheet_sheet.sheet model like this:
class list_activity_sheet(models.Model):
_inherit = 'hr_timesheet_sheet.sheet'
activity_id = fields.Many2one('list_activity_sheet.activity')
class List_activity(models.Model):
_name='list_activity_sheet.activity'
name= fields.Char('Description',required=True)
And for the View:
<openerp>
<data>
<record id="List_activity_form" model="ir.ui.view">
<field name="name">hr_timesheet_sheet.sheet.form.inherit</field>
<field name="model">hr_timesheet_sheet.sheet</field>
<field name="inherit_id" ref="hr_timesheet_sheet.hr_timesheet_sheet_form"/>
<field name="arch" type="xml">
<xpath expr="/form/sheet/notebook/page[#string='Details']/field/tree/field[#name='name']" position="after">
<field name="activity_id"></field>
</xpath>
</field>
</record>
</data>
When i install my addon , i got that message:
field activity_id doesn't exist in the view.
Does anyone know how to solve that?
You're working on the wrong model. If i understand your view definition correctly, you want to choose an activity on the sheet lines.
You have to inherit hr.analytic.timesheet for that instead of hr_timesheet_sheet.sheet. In Odoo 9+ you have to inherit account.analytic.line, because hr.analytic.timesheet was kicked out.

Adding a Button in Tree View Odoo 8

I've Created a Wizard in Tree View Mode and Just Want to add some button with it, is there a way to this in odoo 8?
Thanks
Yes, you can add button in the tree view like you are adding in the form view.
<tree string="My Tree">
<button name="%{action_wiz_open}d" string="Scrap Products" type="action" icon="terp-gtk-jump-to-ltr" help="calls window action" />
<button name="call_function" string="Process" type="object" help="calls python function" />
</tree>
Hope this helps!
To add a button in tree view try below code:
<tree>
<button name="your_action" icon="rupee-symbol"
String="Payment" type="action"
attrs="{'invisible':[('status','!=','Confirmed')]}" />
</tree>
Hope it will help you..
Create a folder wizard
which will have
__init__.py
file_name.py
file_name_view.xml
In Python file_name.py
def fields_view_get(self, cr, uid, view_id=None, view_type='form',
context=None, toolbar=False, submenu=False):
if context is None:
context={}
res = super(class_name_wizard, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
return res
Add your function next to it
In file_name_view.xml
<record model="ir.ui.view" id="new_id">
<field name="name">New Wizard</field>
<field name="model">my.wizard</field>
<field name="arch" type="xml">
<form string="New Form">
<header>
<button name="do_generate" string="My Function" type="object"/>
or
<button string="Cancel" class ="oe_link" special="cancel"/>
</header>
</form>
</field>
</record>
<record id="action_my_function_wizard" model="ir.actions.act_window">
<field name="name">My Function</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">my.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<act_window name="My Function"
res_model="my.wizard"
src_model="product.master"
view_mode="form"
target="new"
multi="True"
key2="client_action_multi"
id="action_view_my_new_id"/>
Note:In src_model write the table name of the tree view
Hope this will help you

inheritance view and adding fields

i have candidat model inherit the hr.emplyee model
i want to display the form view of hr.employee and add fields of my child model candidat
class hr_candidat(models.Model):
_name='hr_recrutement.candidat'
_inherit='hr.employee'
_description="Informations du Candidats"
situation=fields.Selection(string="Situation",selection=[('Nouveau','Nouveau'),('RDV Thechnique','RDV Technique'),('Annulation','Annulationn')])
.
.
.
<record id="hr_recrutement_candidat_form" model="ir.ui.view">
<field name="name">Candidat</field>
<field name="model">hr_recrutement.candidat</field>
<field name="arch" type="xml">
<form string="Candidat">
<sheet>
<group>
<field name="situation" />
.
.
</group>
</sheet>
</form>
</field>
</record>
I dont know how to display fields of hr.employee + my fields of candidat in view
Just we should set the below code from the view xml file and also
add the depended module as hr in your openerp.py and set the view xml file path as well.
Add below code in your .py file
class hr_employee(models.Model):
_inherit='hr.employee'
_description="Informations du Candidats"
situation=fields.Selection(string="Situation",selection=[('Nouveau','Nouveau'),('RDV Thechnique','RDV Technique'),('Annulation','Annulationn')])
Add below code in your .xml file
<record id="hr_recrutement_caindidat_form" model="ir.ui.view">
<field name="name">Candidat</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form" />
<field name="arch" type="xml">
<xpath expr="field[#name='work_location']" position="after">
<field name="situation" />
</xpath>
</field>
</record>
Hear We have to set the position of your element based on xpath using before,after,inside,replace Attributes of xpath tag.
I hope my answer may helpful for you :)

Odoo - search_default does not work?

I created button in partner form to show another models relation with it. It is same button like Opportunities, Meetings, Sales button at partners form showing all its Opportunities, Meetings, Sales etc.
Code looks like this:
Model:
from openerp import models, fields
from openerp import api
class res_partner(models.Model):
_inherit = 'res.partner'
service_ids = fields.One2many('calendar.service', 'partner_id', 'Calendar Services')
service_count = fields.Integer('Services', compute='_count_services')
#api.one
#api.depends('service_ids')
def _count_services(self):
self.service_count = len(self.service_ids)
Action:
<record id="action_calendar_service" model="ir.actions.act_window">
<field name="name">Services</field>
<field name="res_model">calendar.service</field>
<field name="view_mode">tree,calendar,form</field>
<field name="view_id" ref="view_calendar_service_tree"/>
<field name="search_view_id" ref="view_calendar_service_search"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create new service.
</p>
</field>
</record>
View:
<record id="view_partners_form_service1" model="ir.ui.view">
<field name="name">view.res.partner.form.crm.inherited1</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="crm.view_partners_form_crm1"/>
<field eval="18" name="priority"/>
<field name="arch" type="xml">
<button name="schedule_meeting" position="after">
<button
class="oe_inline oe_stat_button"
attrs="{'invisible': [('customer', '=', False)]}"
name="%(calendar_service.action_calendar_service)d"
icon="fa-star"
type="action"
context="{'search_default_partner_id': active_id}">
<field name="service_count" string="Services" widget="statinfo"/>
</button>
</button>
</field>
</record>
Everything works with that button except for one thing. It does not filter result with partner_id (the one that button was pressed) and it opens all 'calendar.service' records. But it should show only the ones from that specific partner. Does context="{'search_default_partner_id': active_id}"> need something more? What am I missing here?
Finally found what was missing. I needed to add this line:
<field name="partner_id" filter_domain="[('partner_id','child_of',self)]"/>
In my model search view. Without that it does not use search_default filter.

Resources