To change the position of the smart button whether it is inherited or newly created, it is a method to add this in the code.
Add this line in your code
<field name="priority" eval="99" />
Add this line like this:
<record id="view_custom_inherit" model="ir.ui.view">
<field name="name">res.partner.form</field>
<field name="model">res.partner</field>
<field name="priority" eval="99" />
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
The priority in this code is which position that button should be placed
Related
I want to create a button that opens a popup that takes over some form fields.
These fields can be modified / filled in.
When closing the fields concerned are updated.
without saving or creating the record before I click on the save button.
I don't see how to get there knowing that there are no relational fields.
Should I create a widget, a wizard, both ....
Help me please.
Here is my current code :
test_scale.py :
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class TestScale(models.Model):
_name = 'test.scale'
name = fields.Char(required=True)
weighing = fields.Integer('weighing', default=0)
test_scale.xml :
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="test_scale_tree_view" model="ir.ui.view">
<field name="name">test.scale.tree</field>
<field name="model">test.scale</field>
<field name="arch" type="xml">
<tree string="Test scale">
<field name="name"></field>
<field name="weighing"></field>
</tree>
</field>
</record>
<record id="test_scale_form_view" model="ir.ui.view">
<field name="name">test.scale.form</field>
<field name="model">test.scale</field>
<field name="arch" type="xml">
<form string="Test scale">
<sheet>
<group name="main_info">
<field name="name"></field>
<field name="weighing"></field>
<button name="%(test_scale_configurator_action)d"
type="action"
string="Weighing"
class="oe_highlight"
context="{'weighing': weighing}"></button>
</group>
</sheet>
</form>
</field>
</record>
<record id="saisie_menu_action" model="ir.actions.act_window">
<field name="name">Test_scale</field>
<field name="res_model">test.scale</field>
<field name="type">ir.actions.act_window</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Aucun enregistrement
</p>
</field>
</record>
<menuitem id="test_scale_menu"
name="Test_scale"/>
<menuitem id="test_scale_saisie_menu"
parent="test_scale_menu"
name="Saisie"
action="saisie_menu_action"/>
</odoo>
test_scale_configurator.xml :
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="test_scale_configurator_view_form" model="ir.ui.view">
<field name="name">test.scale.configurator.view.form</field>
<field name="model">test.scale.configurator</field>
<field name="arch" type="xml">
<form>
<field name="weighing"/>
<footer>
<button type="object"
name="button_save"
string="Save"
/>
<button special="cancel"
string="Cancel"
class="btn-secondary"/>
</footer>
</form>
</field>
</record>
<record id="test_scale_configurator_action" model="ir.actions.act_window">
<field name="name">Test Scale</field>
<field name="res_model">test.scale.configurator</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="view_id" ref="test_scale_configurator_view_form"/>
</record>
</odoo>
test_scale_configurator.py :
# -*- coding: utf-8 -*-
from odoo import models, fields
class TestScaleConfigurator(models.TransientModel):
_name = 'test.scale.configurator'
weighing = fields.Integer(string='weighing')
def button_save(self):
self.ensure_one()
return True
This thing is done by relational fields of odoo , For EX:-
In your test.scale model your field is weighing,
First you need to configure your current model test.scale 's id in wizard so you can reference it, like this you can add the field in wizard.
test_scale_id = fields.Many2one(string="Test Scale")
After that add context in you main model's xml file where is the button which one opens the wizard like this.
<button name="%(test_scale_configurator_action)d"
type="action"
string="Weighing"
class="oe_highlight"
context="{'default_test_scale_id': active_id}"></button>
After that this field needs to be invisible in your wizard's form in order to save data in wizard so you can refernce it later.
<field name="test_scale_id" invisible="1"/>
and in your wizard weighing field is stayed like this.
weighing = fields.Integer(string='weighing', related='test_scale_id.weighing', readonly=False)
Note: This process , making field is one time process.
after that you can use any field which is in your main model and you want to use in wizard you can get those fields by test_scale_id.any_of_your_field.
I'm trying to hide the create and edit button from the model stock.picking
I already hide it from invoices but when I try to do it in picking like this
<record id="picking_view_inherit_duvan1" model="ir.ui.view">
<field name="name">my.picking.custom2</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<xpath expr="//form/sheet/notebook/page/field[#name='move_lines']/tree/field[#name='product_id']" position="attributes">
<attribute name="options">{'no_create_edit':True,'no_create':True,'no_open':True}</attribute>
</xpath>
<xpath expr="//field[#name='partner_id']" position="attributes">
<attribute name="options">{'no_create_edit':True,'no_create':True,'no_open':True}</attribute>
</xpath>
</field>
</record>
Appears the following error
Element '<xpath expr="//form/sheet/notebook/page/field[#name='move_lines']/tree/field[#name='product_id']">' cannot be located in parent view
Apparently doesn't find the product_id, I also tried changing the /tree/field for /kanban/field and allow me to upgrade the module but doesn't work neither to hide the create and edit button so any help will be appreciated.
I found the solution
What I had to do was the following
I have to change the model from stock.picking to stock.move because the move lines are from there and also change the ref to stock.view_move_picking_tree like the following code and it work!
<record id="picking_view_inherit_duvan1" model="ir.ui.view">
<field name="name">my.picking.custom2</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_picking_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='product_id']" position="attributes">
<attribute name="options">{'no_create_edit':True,'no_create':True,'no_open':True}</attribute>
</xpath>
</field>
</record>
Here is the answer in the Odoo Forum. https://www.odoo.com/es_ES/forum/ayuda-1/question/hide-the-create-and-edit-button-from-product-id-in-move-lines-stock-picking-159503.
I have a form view which looks like this :
the xml looks like this :
<notebook>
<page>
<group string="In case of student employee or intern">
<field name="immatriculation" attrs="{'readonly':True}"/>
<field name="studentStatus" attrs="{'readonly':True}"/>
<field name="studentQuestionnaire" attrs="{'readonly':True}"/>
<field name="studentOtherjobs" attrs="{'readonly':True}"/>
</group>
</page>
</notebook>
I would like to increase the width of these fields so that All text (e.g. Confirmation of Student Status (Mandatory Internship) )
comes in a single line. I tried below but didnt see any changes in width :
<field name="studentStatus" attrs="{'readonly':True}" style="width:200px"/>
What is the right way to change the width of these fields inside a group?
Just put a <div/> tag it will render 50% space for label and 50% for fields
Like this
<group string="In case of student employee or intern">
<div /> <!-- here it is -->
<field name="immatriculation" attrs="{'readonly':True}"/>
<field name="studentStatus" attrs="{'readonly':True}"/>
<field name="studentQuestionnaire" attrs="{'readonly':True}"/>
<field name="studentOtherjobs" attrs="{'readonly':True}"/>
</group>
if you need space more then 50% then you have to apply style
When the checkbox string is long, I'd put the string to the right of the box.
You may consider below view.
<group>
<label string="Confirmation" for="confirm1" class="oe_inline"/>
<div>
<field name="confirm1" nolabel="1" class="oe_inline" modifiers="{}"/>
<label string="blah blah blah" class="oe_inline"/>
</div>
<label string=" " for="confirm2" class="oe_inline"/>
<div>
<field name="confirm2" nolabel="1" class="oe_inline" modifiers="{}"/>
<label string="blah blah blah" class="oe_inline"/>
</div>
<label string=" " for="confirm3" class="oe_inline"/>
<div>
<field name="confirm3" nolabel="1" class="oe_inline" modifiers="{}"/>
<label string="blah blah blah" class="oe_inline"/>
</div>
</group>
It's a bit tricky but you could try a simple solution by setting colspan to use the whole width of the notebook page.
<group string="In case of student employee or intern" colspan="4">
Try this one ... maybe u have to do it on every field
<field name="field1" style="width:40%%" />
According to requirements, need to customize Contact Us form which inserts into CRM.lead model (CRM module - Odoo 11)
I need to add additional fields in this model.
Issue! Already added new fields in this model but now showing on form view.
<record id="crm_case_form_view_leads_inherited" model="ir.ui.view">
<field name="name">crm.lead.form.lead.inherited</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_leads" />
<field name="arch" type="xml">
<notebook position="inside">
<page string="Extra fields">
<group>
<field name="field_x"/>
<field name="field_y"/>
<field name="field_z"/>
</group>
</page>
</notebook>
</field>
class Lead(models.Model):
_inherit = 'crm.lead'
field_x = fields.Char(string='Field X)
field_y = fields.Text(string='Field Y')
field_z = fields.Char(string='Field Z')
Problem is not showing fields values on form view.
Check this link which appears as issue :
https://drive.google.com/file/d/1ZoqU2REHlpwJm_oQ7mXJmNJSqF8v22KA/view
<record id="crm_case_form_view_leads_inherited" model="ir.ui.view">
<field name="name">crm.lead.form.lead.inherited</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_oppor" />
<field name="arch" type="xml">
<xpath expr="//page[#name='lead']" position="after">
<page string="Extra fields">
<group>
<field name="field_x"/>
<field name="field_y"/>
<field name="field_z"/>
</group>
</page>
</xpath>
</field>
I've added a notes section in the project kanban view. The problem is when I click it I get an error NameError: name 'active_id' is not defined
I've used this method to create smart buttons in project, contact, and product form views and it works well. When you click the smart button it will redirect to a pre-filtered notes page. I fear that since there's not really an "active" project open, that there will not be an active_id. If that's the case, how can I filter by the one I've clicked on?
Kanban view
<record id="view_project_notes_kanban" model="ir.ui.view">
<field name="name">triangle.project.note.kanban</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.view_project_kanban"/>
<field name="arch" type="xml">
<data>
<xpath expr="//div[#class='o_project_kanban_boxes']" position="inside">
<div class="o_project_kanban_box">
<a name="%(note.action_note_note)d" type="action" context="{'search_default_project': active_id, 'default_project': active_id}">
<span class="o_value"><field name="note_count"/></span>
<span class="o_label">Notes</span>
</a>
</div>
</xpath>
</data>
</field>
</record>
Form view (which works)
<record id="view_project_notes_form" model="ir.ui.view">
<field name="name">triangle.project.note.form</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.edit_project"/>
<field name="arch" type="xml">
<data>
<xpath expr="//div[#name='button_box']" position="inside">
<button class="oe_stat_button" type="action" name="%(note.action_note_note)d"
icon="fa-sticky-note" context="{'search_default_project': active_id, 'default_project': active_id}">
<field string="Notes" name="note_count" widget="statinfo"/>
</button>
</xpath>
</data>
</field>
</record>
Please try record.id instead of active_id, ie :-
<record id="view_project_notes_kanban" model="ir.ui.view">
<field name="name">triangle.project.note.kanban</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.view_project_kanban"/>
<field name="arch" type="xml">
<data>
<xpath expr="//div[#class='o_project_kanban_boxes']" position="inside">
<div class="o_project_kanban_box">
<a name="%(note.action_note_note)d" type="action" context="{'search_default_project': record.id, 'default_project': record.id}">
<span class="o_value"><field name="note_count"/></span>
<span class="o_label">Notes</span>
</a>
</div>
</xpath>
</data>
</field>
</record>
Ok, I adjusted my method a little bit because the context should actually be on the note.note action and not the project.project view.
New Project Kanban:
<record id="view_project_notes_kanban" model="ir.ui.view">
<field name="name">triangle.project.note.kanban</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.view_project_kanban"/>
<field name="arch" type="xml">
<data>
<xpath expr="//div[#class='o_project_kanban_boxes']" position="inside">
<a name="%(triangle.act_project_2_note)d" type="action" class="o_project_kanban_box">
<span class="o_value"><field name="note_count"/></span>
<span class="o_label">Notes</span>
</a>
</xpath>
</data>
</field>
</record>
New Note Window Action:
<act_window id="act_project_2_note"
name="Notes"
res_model="note.note"
view_mode="kanban,tree,form"
context="{'search_default_project': [active_id], 'default_project': active_id}"/>
This totally solved my problem!