I have been trying to override ( def get_worked_day_lines ) to get total attendance from time_sheet_sheet.sheet for each employee so I can make a payslip for him based on total_attendance.
class hr_payslip(osv.osv):
_inherit = 'hr.payslip'
_columns = {
}
def get_worked_day_lines(self, cr, uid, ids, employee_id, date_to, context=None):
res = []
working_days = self.pool.get('hr_timesheet_sheet.sheet')
for record in self.browse(cr, uid, ids, context = context):
search_sheet = working_days.search(cr, uid, [('state','=','draft')])
for rec in working_days.browse(cr, uid, search_sheet, context=None):
attendances = {
'name': _("Normal Working Days paid at 100%"),
'sequence': 1,
'code': 'WORK100',
'number_of_days': 0.0,
'number_of_hours': 0.0,
#'contract_id': ,
}
if rec.day == record.numero :
attendances['code'] = rec.day
leaves = {}
leaves = [value for key,value in leaves.items()]
res += [attendances] + leaves
return res
ps: when I put
search_sheet = working_days.search(cr, uid,[('state','=','draft')])
I will be able to get total_attendance from all draft time sheets
output for search_sheet = working_days.search(cr, uid,[('state','=','draft')])
I actually work on OpenERP v7, so I know what is going on here. If you aren't getting anything with the [('employee_id','=',employee_id)] search criteria, then its because the value of the employee_id argument, doesn't equal any employee_id in the database.
What you should do is check the value of the employee_id that is passed in as an argument to the function. If the value is an integer, then check if that id exists in the database. You should see data if that id exists on that table. If the value of employee_id is False or None, then you will not get any data back from the search()
Related
on odoo i was try to onchange. The condition is, after i was insert the data like "SO00012", my code will try to browse the data by the insert code. here is my code :
def onchange_data(self, cr, uid, vals, ids, context=None):
stocks_picking_onchange = self.browse(cr, uid)
products = []
stiks = self.browse(cr, uid, ids)
objk = self.pool.get('purchase.order')
objeck = self.pool.get('data.stock.picking')
objecks = objk.search(cr, uid,[('name','=',stiks.origin)])
datas = objk.browse(cr, uid, objecks)
if datas:
for data in datas:
for line in data.order_line:
products.append((0, 0, {
'data1': line.id,
'data2' : line.product_qty,
'data3' : line.bonus,
}))
But i was never get the data, My friend sugges me to add method create like :
def onchange_data(self, cr, uid, vals, ids, context=None):
res = super(stock_picking, self).create(cr, uid, vals, context=context)
stocks_picking_onchange = self.browse(cr, uid)
products = []
But, it's stil not working
It's true that you created the list of records but you didn't affect it to any field of your model:
if datas:
products.append((5,0,false)) # if you want to remove all old records
# i think without this line you will add the new record to the old list
for data in datas:
for line in data.order_line:
products.append((0, 0, {
'data1': line.id,
'data2' : line.product_qty,
'data3' : line.bonus,
}))
# return your value
return {'values' : {'your_field_name_here': products}}
one thing you should know with onchange data1, data2 and data3 must appear in the tree of your field or web client will not know where to store them and they will be lost.
I am trying to change the value of my selection field using on_change. I have the code below.
.xml
<field name="product_id" on_change="onchange_partner_id_override(product_id, context)"
.py
class sale_order_line(osv.osv):
_inherit = "sale.order.line"
_columns = {
'product_id': fields.many2one('product.product', "Product"),
'price_select': fields.selection(SELECT_PRICE, "Unit Price"),
}
def product_id_change_override(self, cr, uid, ids, product, context=None):
result = []
product_obj = self.pool.get('product.product')
product_obj = product_obj.browse(cr, uid, product, context=context_partner)
global SELECT_PRICE
SELECT_PRICE = [
('sale_price', product_obj.list_price),
('dist_price', product_obj.distributor_price),
('emp_price', product_obj.employee_price),
]
# How could I change the value of my selection field 'price_select'
return {'value': result}
But i don't know the syntax on how to append this data on my selection field.
Could someone help me Please !
You need to override product_id_change method and specify the value of price_select field in value dict:
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None):
res = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty,
uom, qty_uos, uos, name, partner_id,
lang, update_tax, date_order, packaging, fiscal_position, flag, context)
res['value'].update({'price_select': 'emp_price'})
return res
How to make functional field editable in Openerp?
When we create
'capname': fields.function(
_convert_capital, string='Display Name', type='char', store=True
),
This will be displayed has read-only and we can't able to edit the text.
How we make this field has editable?
A computed field has a function that automatically calculates it's value on some source data.
It is possible to add it the inverse operation, updating the source data based on a value manually set on it, thus making it editable.
From the documentation:
to allow setting values on a computed field, use the inverse parameter. It is the name of a function reversing the computation and setting the relevant fields:
Example code:
document = fields.Char(compute='_get_document', inverse='_set_document')
def _get_document(self):
for record in self:
with open(record.get_document_path) as f:
record.document = f.read()
def _set_document(self):
for record in self:
if not record.document: continue
with open(record.get_document_path()) as f:
f.write(record.document)
You must add a inverse function to make the field editable. This parameter is called fnct_inv in OpenERP v7. An example:
def _get_test(self, cr, uid, ids, name, args=None, context=None):
result = dict.fromkeys(ids, False)
for line in self.browse(cr, uid, ids, context=context):
if line.test:
result[line.id] = line.test
return result
def _set_test(self, cr, uid, id, field_name, field_value, args=None, context=None):
obj = self.browse(cr, uid, id)
for record in obj:
if record.test != field_value:
# The record already exists
...
cr.execute(
'UPDATE your_table '
'SET test=%s '
'WHERE id=%s', (field_value, id)
)
else:
# It is a new record
# (or the value of the field was not modified)
return True
_columns = {
'test': fields.function(
string='String for testing',
fnct=_get_test,
fnct_inv=_set_test,
type='char',
size=50,
store=True,
),
}
below shows my source code fragment.i need to check if null values returns from both functions.?
1.when i use fresh DB then bpl_worker will empty & then its return getitem error.i added coalesce keyword also but result same
(function 1)
2.when i use fresh DB then bpl.company.define table will empty and its also return error.how to check null in that type function.?
(function 2)
i tried with below code.but result same
if no_define_object_no[0].current_no :
please advice me on this.all times when i use new DB i have to face that issue
def _max_reg_no(self, cr, uid, context=None):
cr.execute("""
select coalesce(register_no, 'W00001') as reg_no
from bpl_worker
where id in (select max(id) from bpl_worker)
""")
if cr:
res = cr.fetchone()[0]
emp_no = str(res)
emp_int = emp_no[1:6]
emp_no_int = int(emp_int)
result = 'W' + (str(emp_no_int + 1).zfill(4))
return result
def on_change_division(self, cr, uid, ids, division_id, context=None):
if division_id:
division_object = self.pool.get('bpl.division.n.registration')
division_browse = division_object.browse(cr, uid, division_id, context=context)
result_division_id = division_browse.id
search_condition = [
('department_id', '=', result_division_id)
]
no_define_object = self.pool.get('bpl.company.define')
no_define_id = no_define_object.search(cr, uid, search_condition, context=context)
no_define_object_no = no_define_object.browse(cr, uid, no_define_id, context=context)
return {'value': {'emp_no': no_define_object_no[0].current_no }}
Try this code:
emp_no = no_define_object_no and no_define_object_no[0].current_no or False
return {'value': {'emp_no': emp_no}}
I have a module that has, a creation date (of course, the day it was created) and a deadline date.
The thing is that I want to be able to set a default value to this deadline date according to the date it was created.
But I want to be able to configurate this dynamically from (lets say) res_config.
e.g.
If I configured the default values in res_config to 5 days, I want the default value for the deadline date to be populated with a date 5 days ahead of the creation date.
Is this possible?
Thank you
I managed to do this using the model ir.configure_parameter.
In res_config.py:
class my_configuration(osv.osv_memory):
_inherit = ['res.confi.settings']
_columns = {
'default_deadline' : fields.integer('Days per default', help="""Help field"""),
}
...
def set_default_deadline(self, cr, uid, ids, context=None):
config = self.browse(cr, uid, ids)
config = config and config[0]
val = '%s' %(config.default_deadline) or '10'
self.pool.geet('ir.config_parameter').set_param(cr,uid, 'key_value', val)
return True
Whit this we have created a system parameter. It is actually created as a mapping from 'key_value' to val that is a string, so we will have to cast it to the desired type when necessary.
In my case, y created a function to get the deadline date in my module:
def _get_deadline_date(self, cr, uid, context=None):
val = self.pool.get('ir.config_parameter').get_param(cr, uid, 'key_value')
try:
val = int(val)
except:
# Just in case...
val = 30
return (datetime.now() + timedelta(days=val)).strftime('%Y,%m,%d')
_defaults = {
'deadline_date': lambda s, cr, uid, c: s._get_deadline_date(self, cr, uid, context=c),
}
Thank you, hope it helps!