inherited function odoo python

2024/10/13 21:16:09

i want to inherit function in module 'hr_holidays' that calculate remaining leaves the function is :

hr_holiday.py:

def _get_remaining_days(self, cr, uid, ids, name, args, context=None):cr.execute("""SELECTsum(h.number_of_days) as days,h.employee_idfromhr_holidays hjoin hr_holidays_status s on (s.id=h.holiday_status_id)whereh.state='validate' ands.limit=False andh.employee_id in %sgroup by h.employee_id""", (tuple(ids),))res = cr.dictfetchall()remaining = {}for r in res:remaining[r['employee_id']] = r['days']for employee_id in ids:if not remaining.get(employee_id):remaining[employee_id] = 0.0return remaining

i had create my own module that inherited to hr_holidays and try this code to inherit but it isnt work


myclass.py

class HrHolidays(models.Model):_inherit = 'hr.holidays'interim = fields.Many2one('hr.employee',string="Interim")partner_id = fields.Many2one('res.partner', string="Customer")remaining_leaves = fields.Char(string='Leaves remaining')def _get_remaining_days(self, cr, uid, ids, name, args, context=None):res = super(hr_holidays,self)._get_remaining_days(cr, uid, ids, name, args, context)return res

please help me

Answer

You need to call super with HrHolidays and pass just name and args to _get_remaining_days method and override remaining_leaves field:

Python

class HrHolidays(models.Model):
_inherit = 'hr.employee'@api.model
def _get_remaining_days(self):res = super(HrHolidays, self)._get_remaining_days(name='', args={})for record in self:if record.id in res:record.remaining_leaves = res.get(record.id)return resremaining_leaves = fields.Float(compute='_get_remaining_days',string='Remaining Legal Leaves')
https://en.xdnf.cn/q/118036.html

Related Q&A

ValueError in pipeline - featureHasher not working?

I think Im having issues getting my vectorizer working within a gridsearch pipeline:data as panda df x_train:bathrooms bedrooms price building_id manager_id 10 1.5 3 3000 53a5b119b…

pandas dataframe: meaning of .index

I am trying to understand the meaning of the output of the following code:import pandas as pdindex = [index1,index2,index3] columns = [col1,col2,col3] df = pd.DataFrame([[1,2,3],[1,2,3],[1,2,3]], index…

Extract text inside XML tags with in Python (while avoiding p tags)

Im working with the NYT corpus in Python and attempting to extract only whats located inside "full_text" class of every .xml article file. For example: <body.content><block class=&qu…

Python (Flask) and MQTT listening

Im currently trying to get my Python (Flask) webserver to display what my MQTT script is doing. The MQTT script, In essence, its subscribed to a topic and I would really like to categorize the info it …

I dont show the image in Tkinter

The image doesnt show in Tkinter. The same code work in a new window, but in my class it does not. What could be the problem ?import Tkinterroot = Tkinter.Tkclass InterfaceApp(root):def __init__(self,…

Read temperature with MAX31855 Thermocouple Sensor on Windows IoT

I am working on a Raspberry Pi 2 with Windows IoT. I want to connect the Raspberry Pi with a MAX31855 Thermocouple Sensor which I bought on Adafruit. Theres a Python libary available on GitHub to read …

PIP: How to Cascade Requirements Files and Use Private Indexes? [duplicate]

This question already has an answer here:Installing Packages from Multiple Servers from One or More Requirements File(1 answer)Closed 9 years ago.I am trying to deploy a Django app to Heroku where one …

Python error: TypeError: cannot compare a dtyped [float64] array with a scalar of type [bool]

Below is a small sample of my dataframe. In [10]: dfOut[10]:TXN_KEY Send_Agent Pay_Agent Send_Amount Pay_Amount 0 13272184 AWD120279 AEU002152 85.99 85.04 1 13272947 ARA03012…

How to remove grey boundary lines in a map when plotting a netcdf using imshow in matplotlib?

Is it possible to remove the grey boundary lines around the in following map? I am trying to plotting a netcdf using matplotlib.from netCDF4 import Dataset # clarify use of Dataset import matplotlib.p…

function that takes one column value and returns another column value

Apologies, if this is a duplicate please let me know, Ill gladly delete.My dataset: Index Col 1 Col 20 1 4, 5, 6 1 2 7, 8, 9 2 3 10, 11, 12 3 …