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
Related
I want the use a field from wizard to my form view.
Let me explain with code:
class CancelAppointmentWizard(models.Model):
_name = "cancel.appointment.wizard"
_description = "Cancel Appointment Wizard"
reason = fields.Text(string="Reason")
and i want the show this "reason" field inside of some form views.
<record id="view_hospital_appointment_form" model="ir.ui.view">
<field name="name">hospital.appointment.form</field>
<field name="model">hospital.appointment</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="reason"/>
</group>
</sheet>
</form>
</field>
</record>
but of course this give me error like
hospital.appointment don't have a field like reason.
How can show this field ?
I tried to make a dummy code, i hope i was able to explain my problem.
I assume the wizard is called from the view_hospital_appointment_form. And in the wizard view let say there is a button tag with name attribute, which is this attribute associated to python method in your wizard class.
Wizard view
<record id="view_cancel_appointment_wizard_form" model="ir.ui.view">
<field name="name">cancel.appointment.wizard.form</field>
<field name="model">cancel.appointment.wizard</field>
<field name="arch" type="xml">
<form>
…
…
<footer>
<button name="action_ok" string="Ok" type="object"/>
</footer>
</form>
</field>
</record>
Python method
def action_ok(self):
ids = self.env.context.get('active_ids')
hospital_appointment = self.env['hospital.appointment'].browse(ids)
hospital_appointment.reason = self.reason
return {'type': 'ir.actions.act_window_close'}
I have made a new module, everything seems to be ok (i can CRUD product), but list of products is empty.
What can cause such trouble? Something wrong with
<!-- Action to open list -->
<act_window id="action_for_menu"
name="List of products"
res_model="x.x"
view_type="form"
view_mode="tree,form" />
<!-- List view. -->
<record id="x_list_view" model="ir.ui.view">
<field name="name">x.list</field>
<field name="model">x.x</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="descr"/>
</tree>
</field>
</record>
The reason of my trouble was in field "active", which i made default=False. The active field is used to inactivate records, and by default only active records will be shown.
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 have created few custom fields for products.Products appear in sales,purchase,warehouse and manufacturing module.I want to make my custom fields appear only in manufacturing module and hide everywhere else.So how to put condition on invisible attribute.I tried like this and got error as Unknown field _name in domain
attrs="{'invisible': [('_name', '!=', 'mrp.bom')]}"
Python file,
from openerp import fields,models, api
class product_template(models.Model):
_inherit = "product.template"
rim_weight = fields.Float(string='Rim Weight(KG)', readonly=True, compute='_compute_one_rim_weight')
width = fields.Float(string='Width(cm)',default='50')
length = fields.Float(string='Length(cm)',default='63')
gsm = fields.Float(string='Gram per square meter(gsm)',default='230')
Xml file,
<record id="product_template_form_view_dis_inherit" model="ir.ui.view">
<field name="name">product.template.common.form.dis.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//page[#string='Accounting']" position='after'>
<page string='Cover Page Paper'>
<group>
<field name="width"/>
<field name="length"/>
<field name="gsm"/>
<field name="rim_weight"/>
</group>
</page>
</xpath>
</field>
</record>
There are many ways to do this, however I suggest following options to you.
Modify an existing action and set context inside that and based on that context just write condition in view. (Remember here you need to override an action, and if you want to create another then you need to redefine menu to assign new action to that menu).
Create new view and set this view reference in an action of that model in which you want to show these fields. In new view you need to visible those fields, no need to extend product template existing view.
However the 1st solution is easy to achieve and 2nd one is lengthy.
Example of 1st solution:
<record id="action_name" model="ir.actions.act_window">
<field name="name">Name</field>
<field name="res_model">product.template</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context" eval="{'is_manufacturing_model':True}" />
</record>
And then in view just write like this
<page string='Cover Page Paper'>
<group invisible="context.get('is_manufacturing_model',False)">
<field name="width"/>
<field name="length"/>
<field name="gsm"/>
<field name="rim_weight"/>
<group>
</page>
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>