For example, I have this tree view in one2many field:
<tree editable="bottom" class="check_class">
<field name="check" class="oe_edit_only" string=" "/>
<field name="description" decoration-crossed="check == True" string="Чек лист"/>
</tree>
When I click button "add new", in tree view appears a new line and focus go to first field. I want to autofocus second field. Is there some parameter or attribute to achieve this?
Related
I want to add button in one2many tree view line. I have placed button in tree view and these button shows successfully.
But when i click on button, it display form define against one2many field instead of function call.
Need guidance how to call function/form on button click.
<page name="component_line_id" string="Component Lines">
<field name="component_line_id">
<tree>
<field name="purchase_order_id" required="1"/>
<field name="description"/>
<field name="payable_amount"/>
<field name="file_name" string="Attachment"/>
<button string="Create Bill" name="create_bill" type="object" class="oe_highlight" icon="fa-icon_you_like"/>
<button string="View Bill" name="view_bill" type="object" class="oe_highlight" icon="fa-icon_you_like"/>
</tree>
<form string="Component Lines">
<group>
<group>
<field name="purchase_order_id"/>
<field name="description"/>
<field name="payable_amount"/>
</group>
<group>
<field name="attachment_file" filename="file_name"/>
<field name="file_name" invisible="1"/>
</group>
</group>
</form>
</field>
</page>
I think you need to save the record first to be able to run the button. Are you sure it was not on edit mode?
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
Odoo v9.
I would like to prompt the user with a yes/no option before certain python code is executed.
If this were in a button I could use the confirm="text?" attribute, however I do not want to trigger any database updates irrespective of the users answer to this particular prompt.
e.g. onchange event triggers yes/no box, which can then manipulate page, however the user still has to press "save" to keep any changes.
Is there any way of doing this using base odoo?
onchange events can't return a dialog because they were simply not built to do that https://www.odoo.com/forum/how-to/developers-13/what-should-onchange-methods-do-and-return-57760
You can use a wizard (it's not really a wizard it's just a form) and show it as a popup. our wizard model will be a Transient model, which would be discarded by odoo after a specified amount of time.
from openerp import fields, models, api
class test_model(models.Model):
_name = 'test.model'
name = fields.Char(string='Value')
#api.multi
def call_up_wizard(self):
return {
'name': 'Are you sure?',
'type': 'ir.actions.act_window',
'res_model': 'wizard',
'view_mode': 'form',
'view_type': 'form',
'target': 'new',
}
class wizard(models.TransientModel):
_name = 'wizard'
yes_no = fields.Char(default='Do you want to proceed?')
#api.multi
def yes(self):
pass
# sure continue!
#api.multi
def no(self):
pass # don't do anything stupid
This is how your view would look like
<record id="cashadvance_list" model="ir.ui.view">
<field name="name">Test Dialog</field>
<field name="model">test.model</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Test Dialog" version="8.0">
<group>
<button class="oe_highlight" name="call_up_wizard" string="confirm" type="object" />
</group>
</form>
</field>
</record>
<record model="ir.ui.view" id="wizard_form">
<field name="name">wizard.form</field>
<field name="model">wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Confirm dialog">
<field name="yes_no" readonly="1" />
<footer>
<button class="oe_highlight" name="yes" string="Yes" />
<button class="oe_highlight" name="no" string="No" />
</footer>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_test">
<field name="name">Cash advance list</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">test.model</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
It's empty, create something
</p>
</field>
</record>
In our test_model view we have a button that's shows the wizard as a popup, and then in the wizard buttons are handled by the yes and no methods respectively, this gives you better control over the buttons as you know have separate methods controlling the two buttons you have on the form.
I just put this answer, for anyone who happens to stumble on this thread and wants to know how to create a popup from a button.
I managed to add two custom fields to the settings by inheriting res.config.settings in a new module created. The xml page of the same is
<record id="op_product_fast_moving_parts_form" model="ir.ui.view">
<field name="name">Configure Fast Moving Parts</field>
<field name="model">fastmovingparts.config.settings</field>
<field name="arch" type="xml">
<form string="FastMoving">
<header>
<button string="Apply" type="object" name="execute" class="oe_highlight"/>
or
<button string="Cancel" type="object" name="cancel" class="oe_link"/>
</header>
<separator string="Configure Fast Moving Parts"/>
<group name="Configure Fast Moving Parts">
<field string="Minimum Quantity" name="fast_moving_parts_min_qty"/>
</group>
<group>
<field string="Interval" name="fast_moving_parts_chk_interval"/>
</group>
</form>
</field>
</record>
It is updating the settings when clicking on the Apply button.
Here I have one more requirement that I need to open a wizard on clicking Apply button which will display products tree. How can I achieve this?
Thanks in advance
I didn't get your question, but I think that you want to open a wizard on clicking Apply button which will display products tree.
I have selection field in the form
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
I have to pass the value selected in the selection field in domain filter as company_id in below
<tree string="Components" editable="bottom">
<field name="product_id" context="{'default_supply_method':'produce'}" on_change="onchange_product_id(product_id, name)" domain="[('company_id','=',**company_id**),('stage','=','confirmed')]" />
</tree>
Now , I need to pass value of field with name company_id into the domain with field product_id
Help me on this.
To get the value of the field 'company_id' that is saved on form view, you need to add this field on your tree view definition and if you don't need to see it on tree view, put invisible="1" in xml definition.
<tree string="Components" editable="botton">
<field name="company_id" invisible="1" />
<field name="product_id" context="{'default_supply_method':'produce'}" on_change="onchange_product_id(product_id, name)" domain="[('company_id','=',**company_id**),('stage','=','confirmed')]" />
</tree>