Schedular Method Return to form of Openrp - openerp-7

I have an scheduler method of OpenERP. I want to return data to every seconds to Form.
My method like that.
def hello(self, cr, uid, context=None):
now = datetime.now()
cr.execute('select employee_id,count from late_to_leave (%s,%s)', (now.month, now.year))
datas = cr.fetchall()
for data in datas:
id = data[0]
count = data[1]
print 'id is ....',id
print 'count is ....',count
I want to return data to form of hr.attendance.
What should i do.?Help Me.

In you scenario
You should require to set the scheduled action in OpenERP and your method will be defined and called as filed.function() fields same method and its arguments as scheduled action form
view where you can set the OpenERP Scheduled Action.
the functionality can be accessed via the field of your form view.
Just check out My simple Schedule action Action For Birthday Schedular for hr.employee model.
You can see that the scheduled action in OpenERP 7.0
You can click Setting Menu
Technical >>Schedular >>Scheduled Actions

Related

How to store logged user in Odoo14

I am trying to store the currently logged user into a many2one field using compute method. It's working fine if i define the Mnay2one field without the store="True" parameter. Actually, i need to save it.
Here is the code:
def get_logged_user(self):
for rec in self:
print('inside get_logged_user---------------',rec.env.user.name)
rec.logged_user_id = rec.env.user.id
logged_user_id = fields.Many2one('res.users',string="Logged user",store=True,compute="get_logged_user")
EDIT:
If you only need to control visibility of a field/button inside QWeb view you could archive this without dedicated field. You could use context.get('uid') to get current user like this:
<button ... invisible="context.get('uid') == assigned_user_id">
But if you need to store logged-in user inside a field you could use default instead of compute.
Something like this:
logged_user_id = fields.Many2one('res.users', string="Logged user", default=lambda self: self.env.user)
Note usage of lambda function.
If you really need to use compute field with store=True you need to specify when to compute it. By using api.depends decorator you can trigger it when your_field is changed.
#api.depends('your_field')
def get_logged_user(self):
But I would ask a question why do you need to store logged-in user inside a field? If you could provide more context maybe we could suggest different solution.

Batch create based on user selection in Odoo

I have the following models Program, Course, ProgramAdmission, CourseEnrollment.
Each course is associated with a program.
During program admission, I am showing the list of available courses for the selected program. For each shown course, I want to show a dropdown menu with the following selections: Not Planned and Planned.
Now if the user saves the new program admission, I want also to enroll the user in the planned courses by creating CourseEnrollment in the server-side for each planned course.
And if the user discards the new program admission, nothing should be created in the database.
How can I allow for such conditional batch creation of model objects?
Thank you!
It's easy, you just need to start to coding it. Create the module with the models relations and fields. On the ProgramAdmission model add a Many2one field to the Program model and another to the Course model. If you cancel the form while creating a new record nothing will be saved in your DB, but if you hit the Save button it will call the create method for new records and write methods for existing ones. Override the create method to be able to dynamically create a new record of the CourseEnrollment model and associate it with the ProgramAdmission record to be created by saving it to a new Many2one field in the same ProgramAdmission model.
To make what I mean more clear:
from odoo import models, fields, api
class Program(models.Model):
_name = 'school.program'
name = fields.Char()
class Course(models.Model):
_name = 'school.course'
name = fields.Char()
class ProgramAdmission(models.Model):
_name = 'school.program.admission'
course_id = fields.Many2one('school.course')
program_id = fields.Many2one('school.program')
enrollment_id = fields.Many2one('school.course.enrollment')
#api.model
def create(self, vals):
enrollment_id = self.env['school.course.enrollment'].create({
'course_id': vals['course_id'],
'program_id': vals['program_id']
})
vals['enrollment_id'] = enrollment_id.id
return super(ProgramAdmission, self).create(vals)
class CourseEnrollment(models.Model):
_name = 'school.course.enrollment'
course_id = fields.Many2one('school.course')
program_id = fields.Many2one('school.program')

Stop creating mail message and Followers in perticular model in odoo

When I create new sale order,it also creates the mail messages and followers at bottom of form view.
But I want to make that system should not create mail message and followers while users creates or writes data of "sale.order" model.
How can I stop such message and followers creation .?
Just need to apply context in create and write method of that model.
#api.model
def create(self,vals):
res=super(sale_order,self.with_context({'mail_create_nosubscribe':True,'tracking_disable':True})).create(vals)
return res
#api.multi
def write(self,vals):
res=super(sale_order,self.with_context({'mail_create_nosubscribe':True,'tracking_disable':True})).write(vals)
return res
If you just want to remove it from the view then override the template and remove the fields named:
message_follower_ids
message_ids
These two fields are responsible for the view part.
Code to remove the fields:
<xpath expr="//field[#name='message_follower_ids']" position="replace"/>
Will this be fine or should I tell you how to update the record at model level?

Generate a code with a wizard on openERP 7

i'm new to openERP and I hadn't found an exhaustive and simple guide for wizards.
I have to do a wizard that generates a code by using the product_id.
This wizard have to generate the code of all the products when i click on it and put it in in the field EAN13. I have no idea how to create the wizard that take the code, generates his own code and put it in the field.
Sorry for my bad english :(
You can check OpenERP Technical Memento
You need to create a new memory model
class ean13_wiz(osv.osv_memory):
_name = 'ean13.wiz'
_description = 'EAN13 wizard'
_columns = {
'ean_template':fields.char('ean_template', size=13, required=True),
}
_defaults = {
'ean_template': '2100000000000',
}
def ean13_logic(self, cr, uid, ids, context=None):
# your duplicate buziness logic
...
I added only 1 field for init the ean13 template
When you click on the submit button you should add the view xml action to your ean13_logic to add a ean to every product. maybe have some feedback how many are changed.
look at the link for more info: wizard example

How to retrieve the current user in OpenERP module

I'm developing an OpenERP 7 module and I need to add a field that logs the user who created each record. How do I retrieve the current user object?
this kind of field is already available in openerp, as create_uid and write_uid.
In OpenERP Python code, functions generally take cr, the database pointer, and uid, the user id, as arguments. If all you need is the id of the current res.users object (for instance, to write into the one2many field), you can use uid as is. If you need to access the object (to see fields, etc.), something like:
current_user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
should work.