Open parent model with event_open_popup - odoo

I've got two models : maintenance.intervention and maintenance.intervention.task
In model intervention, there's a One2many relation toward task.
When I display the tasks in calendar view and click on one of them, instead of opening a form view for the task model, I'd like to open the form view of parent intervention. (In edition mode if possible)
The field with the parent id is "intervention_id".
Q1 : Is it possible ?
Q2 : How to do it ?
The code below opens the correct view, but doesn't have the data needed.
<record id="view_maintenance_intervention_tasks_calendar" model="ir.ui.view">
<field name="name">maintenance.intervention.tasks.calendar</field>
<field name="model">maintenance.intervention.task</field>
<field eval="2" name="priority"/>
<field name="arch" type="xml">
<calendar color="user_id" date_start="date_start" date_stop="date_end" string="Task" quick_add="False"
event_open_popup="%(module.views_maintenance_intervention_form)s">
<field name="hour_to"/>
<field name="technician"/>
<field name="client_name"/>
<field name="installation_zip"/>
<field name="installation_city"/>
<field name="intervention_type"/>
<field name="name"/>
<field name="intervention_code"/>
<field name="intervention_id" invisible="1"/>
</calendar>
</field>

Related

How to edit invoice template on Odoo15

I created custom fields in Odoo v15.
PROBLEM
Now I would like to add them to invoice template.
How I could do it?
You need to inherit the form view (account.invoice.form) and add your custom fields to the view. Or if you want to test the view you can enable debug mode and click "Edit FormView" at the top right of your form view to (temporarily) edit the form view directly.
See my example below:
<record id="account_invoice_form_custom" model="ir.ui.view">
<field name="name">account.invoice.form.custom</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form" />
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="custom_field"/>
</field>
</field>
</record>

proper way to replace view form

I need to override account.account_aged_balance_view in order to hide a field (Period Length (days)) as well add new field in the same time.
I tried the following in my custom module view:
<openerp>
<data>
<record id="account_aged_balance_view" model="ir.ui.view">
<field name="name">Aged Partner Balance</field>
<field name="model">account.aged.trial.balance</field>
<field name="inherit_id" ref="account.account_aged_balance_view" />
<field name="arch" type="xml">
<form string="Report Options">
<separator string="Aged Partner Balance"/>
<label string="Dariel Partner Balance is a more detailed report of your receivables by intervals. When opening that report, Odoo asks for the name of the company, the Start Date and the size of the interval to be analyzed (in days). Odoo then calculates a table of credit balance by start Date. So if you request an interval of 30 days Odoo generates an analysis of creditors for the past month, past two months, and so on. "/>
<group col="4">
<field name="date_from"/>
<newline/>
<field name="result_selection" widget="radio"/>
<field name="target_move" widget="radio"/>
</group>
<field name="journal_ids" required="0" invisible="1"/>
</form>
</field>
</record>
</data>
</openerp>
those XML appended to the modal form instead of replacing the original form, like shown in the image.
so, am I doing it right (ofcourse it's not right) or how the proper way of doing it?
You can both replace the whole form view or remove and add only the fields you want. You have to use the xpath to do that.
To replace the whole view:
<record id="account_aged_balance_view" model="ir.ui.view">
<field name="name">Aged Partner Balance</field>
<field name="model">account.aged.trial.balance</field>
<field name="inherit_id" ref="account.account_aged_balance_view" />
<field name="arch" type="xml">
<xpath expr='//form' position='replace'>
< your form view >
</xpath>
</field>
</record>
Or you can remove only what you don't want and add what you want with:
<record id="account_aged_balance_view" model="ir.ui.view">
<field name="name">Aged Partner Balance</field>
<field name="model">account.aged.trial.balance</field>
<field name="inherit_id" ref="account.account_aged_balance_view" />
<field name="arch" type="xml">
<xpath expr='//field[#name="period_length"]' position='replace'/>
<xpath expr='//field[#name=" < name of the field you want to put yours after > "]' position='after'>
<field name=' < your field name > '/>
</xpath>
</field>
</record>
I did not try it, but it should work.

How can i set my own form view to enter customer data into res.partner model in odoo

How can I set my own form view to enter customer data into res.partner model without using base.view_partner_form form view of res_partner model?
First off, you will need the custom form view, of course.
And after that it depends, what you want to do.
Change the form view everywhere: Give your form view a lesser priority than "base.view_partner_form":
<record id="my_partner_form" model="ir.ui.view">
<field name="name">...</field>
<!-- other fields -->
<field name="priority">1</field>
<!-- arch -->
</record>
Or if you want to get a new menuitem for the users, just create one. Then create a ir.actions.act_window with your new form view as default view and link it to your new menuitem.
You can create new partner form and set priority.
By default system will load minimum priority form in odoo.
View default priority is 16 & if you give your view priority is 20 then default from view will be load.
Ex:
<record id="view_partner_title_form" model="ir.ui.view">
<field name="name">res.partner.title.form</field>
<field name="model">res.partner.title</field>
<field name="priority">20</field>
<field name="arch" type="xml">
<form string="Partner Titles">
<group col="4">
<field name="name"/>
<field name="shortcut"/>
</group>
</form>
</field>
</record>
Now your new form view priority is 20, so system will load default form view because default form view priority is 16.
You can create ir.actions.act_window.view
Based on that system will load any sequence form/tree view based on your requirement.
<record id="action_portal_partner_form" model="ir.actions.act_window">
<field name="name">Customers</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.partner</field>
<field name="domain">[('customer','=',True)]</field>
<field name="view_type">form</field>
<field name="view_mode">kanban,tree,form</field>
<field name="context">{"search_default_customer":1}</field>
<field name="search_view_id" ref="base.view_res_partner_filter"/>
</record>
<record id="action_portal_form_view2" model="ir.actions.act_window.view">
<field eval="23" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="view_partner_title_form"/>
<field name="act_window_id" ref="action_portal_partner_form"/>
</record>
View_mode : tree/form/..
View Id : your view id
Action : You must write correct action id

Odoo v9: choose view for "create and edit"

I'm using Odoo 9.
How can I set the view used when the user clicks on "create and edit" in a Many2one field?
Create new view for model. Here example for crm.team:
<record id="test_my" model="ir.ui.view">
<field name="name">my.module.form</field>
<field name="model">crm.team</field>
<field name="arch" type="xml">
<form>
<field name="name"/>
</form>
</field>
</record>
And set id of view using context:
<!-- many2one field -->
<field name="team_id" context="{'form_view_ref':'my_module.test_my'}"/>

Can't remove top "Save" button from Odoo

I want to remove the top "Save" button from the formview of my custom module.
I know that we perform this by setting write/create to false in the XML, which I did and can't figure out why it is still there.
My view:
<record id="view_module_genall_form" model="ir.ui.view">
<field name="name">module.genall.form</field>
<field name="model">module.genall</field>
<field name="arch" type="xml">
<form string="Automatically generate bills" edit="false" create="false" delete="false" write="false">
<button name="generate_all" type="object" string="Generate bills" icon="oe_highlight"/>
</form>
</field>
</record>
The related action:
<record model="ir.actions.act_window" id="action_module_genall">
<field name="name">Automatically generate bills</field>
<field name="res_model">alkivi.genall</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_module_genall_form" />
</record>
Do you have an idea ? Thanks!
From it's title it looks like the purpose of your form is to run a server method to perform some business logic.
For that you should use a Wizard instead of a regular Model: for that the module.genalshould be a models.TransientModel instead of a models.Model.