Odoo v9: choose view for "create and edit" - odoo

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'}"/>

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>

odoo many2many show selection Odoo10

we have a list of items in one model named us_inventory_line. We have another model named ladings...
class inventory_line(models.Model):
# ...
lading_item = fields.Many2one('res.lading', ondelete='set null', string="lading", index=True)
class Lading(models.Model):
# ...
us_inventory_line_item = fields.One2many(comodel_name='rodals.us_inventory_line', string="shippments", inverse_name='lading_item')
In the form, we have just simply put the field that represent one2many:
<!-- Form -->
<record model="ir.ui.view" id="us_inventory_line_form_view">
<field name="name">lading.form</field>
<field name="model">rodals.lading</field>
<field name="arch" type="xml">
<form string="Invetory Line Form">
<sheet>
<group>
<field name="delivery_date"/>
<field name="us_inventory_line_item"/>
</group>
</sheet>
</form>
</field>
</record>
When the application is opened, when the user opens the lading page, he is only able to add new us_inventory_line.
How do we go about in order to connect the tow ? Like the user need to choose, from a list of us_inventory_line that does not have a lading (because if its has lading, this means that its already shipped).
Thank you very much for the help !
<record model="ir.ui.view" id="us_inventory_line_form_view">
<field name="name">lading.form</field>
<field name="model">rodals.lading</field>
<field name="arch" type="xml">
<form string="Invetory Line Form">
<sheet>
<group>
<field name="delivery_date"/>
<field name="us_inventory_line_item">
<tree string="US Inventory Item">
<field name="lading_item"/>
</tree>
</field>
</group>
</sheet>
</form>
</field>
</record>

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

Open parent model with event_open_popup

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>

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.