Adding a combination of leave type in the TimeOff module in the LeaveForm? Odoo13 - odoo

I needed to add a feature that can combine two leave types in the TimeOff module form, and when a user submits the form the leaves gets deducted from the respective time off type. (In the form I am thinking to add a second dropdown menu where he/she can add the other time off).
I am using Odoo13, I am inheriting the module, but can't figure it out to add a dropdown in which the user can select multiple leaves.
model=hr.leave, externalid = hr_holidays.hr_leave_view_form
Work that I have done:
I have created a module which inherits the hr_holidays module in Odoo13, In the leave form i have sucessfully added the dropdown which is above but it is selecting the same time-off type which is selected above.
Here is the xml file:
<?xml version='1.0' encoding='UTF-8' ?>
<odoo>
<!--Adding the Drop Down-->
<record id="hr_leave_view_form_addnewleave" model="ir.ui.view">
<field name="name">leave.addleave</field>
<field name="model">hr.leave</field>
<field name="inherit_id" ref="hr_holidays.hr_leave_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[#name='description']" position="before">
<div class="row" name="status_id">
<label class="col-2 mr-0" for="holiday_status_id"/>
<!-- RLI FIXME: we should avoid redefining the domain in the view when there already is a domain on the model -->
<field name="holiday_status_id" domain="['&', ('virtual_remaining_leaves', '>', 0), '|', ('allocation_type', 'in', ['fixed_allocation', 'no']),'&',('allocation_type', '=', 'fixed'), ('max_leaves', '>', '0')]" context="{'employee_id':employee_id, 'default_date_from':date_from}" options="{'no_create': True, 'no_open': True}" class="col-9 pl-0" nolabel="1"/>
</div>
</xpath>
</field>
</record>
</odoo>
In this the code with is for the dropdown.
The LeaveForm image with dropdowm
Thanks in advance.Please look into the photo that I uploaded.

Related

Empty list view (new module on odoo 12)

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 to hide some fields to a login user in odoo

i'm working on some app, but need to hide some fields from login user.. Below is the code i've tried
class HrEmployee(models.Model):
_inherit = 'hr.employee'
grade_id = fields.Many2one(related='contract_id.grade_id', string='Grade')
rank_id = fields.Many2one(related='contract_id.rank_id', string='Point')
And this other one is the view
<!-- Employees inherited views -->
<record id="view_employee_form_grade_rank" model="ir.ui.view">
<field name="name">hr.employee.form.grade.rank</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form" />
<field name="arch" type="xml">
<field name="job_id" position="after">
<field name="grade_id"/>
<field name="rank_id" domain="[('grade_id','=',grade_id)]" />
</field>
</field>
</record>
There are many ways to achieve this:
you could simply add invisible="true"and it would hide the field for everyone(including logged users) ;)
you can use <t t-if="uid is None"> your code </t> and this would hide from logged users
you can also set security groups and allow only users from the particular group to see the field (documentation: https://www.odoo.com/documentation/10.0/reference/security.html)
The choice is yours. Let me know if this is what you've been looking for.
PS: I have used the second solution when I was working on my app that is hiding product price as well as "Add to cart" button until log in(https://www.odoo.com/apps/modules/11.0/hide_price_shop/) and the code looked like:
<t t-if="uid is None">
<p>Log In&nbsp;to see price&nbsp;</p>
</t>

Odoo 10: Add extra fields to the product form

I want to add a couple of extra fields to the product form, right after 'standard_price'.
I created a view that inherits from "product.product_template_form_view" and added my fields there:
<field name="standard_price" position="after">
<field name="my_field" />
</field>
I then restart odoo updating the module, but I don't see my new fields when I call the product form.
The fields appear on the database model (created inherited models also), but not on the user interface.
What I'm missing here?
Check these things:
Inherited from correct base form product.template.common.form
Make sure you are looking at correct form for product.template (Product), not product.product (Product Variant).
Do you see the input field without caption in edit mode? If this is the case, you can have broken structure in the html level. Next bullet will solve this.
Standard_price field has unique html structure because it can have unit of measure (uom) connected to it. Try connecting to simple field or use the container div standard_price_uom for connection, see template code below.
Template code for working view with a new field after standard_price_uom div:
<div name='standard_price_uom' position="after">
<field name="my_field" />
</div>
If these does not help, please provide whole view definition.
Make sure you use the correct model. Use product.template instead of product.product.
<record id="product_template_form" model ="ir.ui.view">
<field name="name">product.template.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<field name="standard_price" position="after">
<field name="my_field"/>
</field>
</field>
</record>
...
class ProductTemplate(models.Model):
_inherit = "product.template"
my_field = fields.Char()
Make sure you have added your XML file into your module’s __manifest__.py file. Odoo only pulls in XML from files that you tell it to.
You can see examples of this on any core modules. See sale/__manifest__.py for an example.
On your module, it would be something like this:
{
...
‘data’: [
‘views/form/form_product.xml’,
]
...
}
I have tested it in Odoo 12.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_product_template_common_form_inherit" model="ir.ui.view">
<field name="name">product.template.common.form.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="//div[#name='standard_price_uom']" position="after">
<label for="my_field" string="My Field"/>
<div>
<field name="my_field"/>
</div>
</xpath>
</field>
</record>
</odoo>

Inherit TransientModel and have two views ( website.config.settings )

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

How to use inheritance in odoo to enhance form view?

In the Account and Finance module i want to add a new field but do not want to change the current form view and also I don't want to override it. I know to create a new class and declare _inherit attribute, declare new fields there, but i think it will override the original form view.
I want both(original and inherited) form view to appear so that i can choose them based on my requirements. Is it possible?
(I desire to add discounts field in my inherited form view)
<?xml version="1.0"?>
<openerp>
<data>
<!-- 1st part of the sim_view start -->
<record model="ir.ui.view" id="account.partner_view_buttons">
<field name="name">partner.view.buttons</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="type">form</field>
<field name="arch" type="xml">
<xpath expr="//div[#name='buttons']" position="inside">
<button type="action" class="oe_stat_button" id="invoice_button" icon="fa-pencil-square-o" name="464" attrs="{'invisible': [('customer', '=', False)]}" context="{'search_default_partner_id': active_id,'default_partner_id': active_id}">
<div><strong><field name="total_invoiced" widget="monetary"/></strong><br/>Invoiced</div>
</button>
</xpath>
</field>