I building a custom module in openerp version 7. I'm facing problems in trying to link an anchor tag in a kanban view item to an action window which will open the clicked on item in a form view.
Here's a sinppet of the kanban view
<a type="action" name="myaction">
<img t-att-src="kanban_image('vessel', 'image_medium', record.id.value)" class="oe_employee_picture" />
</a>
Here's the action that will be invoked on click
<record model="ir.actions.act_window" id="myaction">
<field name="name">Vessel</field>
<field name="res_model">vessel</field>
<field name="view_type">form</field>
<field name="view_id" ref="crew_management.view_crew_management_vessels_form"/>
<field name="view_mode">form</field>
<field name="context">{'id': active_id}</field>
</record>
Currently when clicking on the link it opens the correct form view but empty. It seems that the active id of the selected item is not passed somehow.
To pass the active id of an object use res_id instead.
<field name="context">{'res_id': active_id}</field>
The complete code would be
<a type="action" name="action_id">
<!-- Anything Here -->
</a
<record model="ir.actions.act_window" id="action_id">
<field name="name">demo</field>
<field name="res_model">demo</field>
<field name="view_type">form</field>
<field name="view_id" ref="my_module.demo_view_id"/>
<field name="view_mode">form</field>
<field name="context">{'res_id': active_id}</field>
</record>
try passing <field name="context">{'active_id': active_id}</field>
Related
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>
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
I am trying to inherit the Website settings menu and have two views. website.config.settings is a models.TransientModel
When I am inheriting that and viewing with a new menuitem it overwrites the previous view. Like - There are two views now, the new record I defined named Website Event Settings . When I click on that it loads the new modified view but when I click on existing Settings menu, it shows nothing.
In summary, the existing website settings menu not working and new menu does. I need both of them.
The py code and record view I used are following -
class cofair_website_design_config(models.TransientModel):
_name = 'website.config.settings'
_inherit = 'website.config.settings'
event_title = fields.Char(related='website_id.event_title', string='Event Title')
XML:
<record id="view_website_event_config_settings" model="ir.ui.view">
<field name="name">Website Event Settings</field>
<field name="model">website.config.settings</field>
<field name="arch" type="xml">
<form class="oe_form_configuration">
<header>
<button string="Apply" type="object" name="execute" class="oe_highlight"/>
<button string="Cancel" type="object" name="cancel" class="oe_link"/>
</header>
<div>
<group string="Event Page Section">
<group>
<field name="event_title_color"/>
</group>
</group>
</div>
</form>
</field>
</record>
<record id="action_website_event_configuration" model="ir.actions.act_window">
<field name="name">Website Event Settings</field>
<field name="res_model">website.config.settings</field>
<field name="view_mode">form</field>
<field name="target">inline</field>
<field name="view_id" ref="view_website_event_config_settings"/>
</record>
<menuitem id="menu_website_event_settings" parent="website.menu_website_configuration" name="Website Event Settings" action="action_website_event_configuration"/>
Instead of renaming the modules (which causes relational error), I found a workaround. I have inherited the main settings and put a view id there and called it with menuitem -
<!-- Bring settings menu out -->
<record id="website.action_website_configuration" model="ir.actions.act_window">
<field name="name">Website Settings</field>
<field name="res_model">website.config.settings</field>
<field name="view_mode">form</field>
<field name="target">inline</field>
<field name="view_id" ref="website.view_website_config_settings"/>
</record>
<menuitem id="website.menu_website_website_settings" parent="website.menu_website_configuration" name="Website Admin" action="website.action_website_configuration"/>
Then I called my record action and it loaded the view and action. Another catch point is I had to show website_id to show the values of specific websites or the transient model will always be empty.
Change the _name attribute in your model definition to something else and also modify the xml appropraitely.
class cofair_website_design_config(models.TransientModel):
_name = 'something.else'
_inherit = 'website.config.settings'
event_title = fields.Char(related='website_id.event_title', string='Event Title')
ir.ui.view
<field name="model">something.else</field>
and ir.actions.act_window
<field name="res_model">something.else</field>
That should copy all the fields and methods from website.config.settings to the new model something.else and keep it separate from website.config.settings
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'}"/>
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.