当前位置: 首页>>代码示例>>Python>>正文


Python api.model方法代码示例

本文整理汇总了Python中openerp.api.model方法的典型用法代码示例。如果您正苦于以下问题:Python api.model方法的具体用法?Python api.model怎么用?Python api.model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openerp.api的用法示例。


在下文中一共展示了api.model方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_flextime_limit

# 需要导入模块: from openerp import api [as 别名]
# 或者: from openerp.api import model [as 别名]
def check_flextime_limit(self):
        """Checks if flextime has passed the warning limit."""
        _logger.warn(self.name)
        _logger.warn(self.get_flextime_total())
        # Flextidsgräns per schema
        if self.contract_id and self.contract_id.working_hours and self.contract_id.working_hours.flextime_warning and abs(self.get_flextime_total()) > self.contract_id.working_hours.flextime_warning:
            subject = 'Flextime overdue %s' % self.name
            _logger.warn(subject)
            if not self.env['mail.nodup'].check_dup(self.user_id.partner_id.email, subject):
                partner_ids = []
                if self.user_id:
                    partner_ids.append(self.user_id.partner_id.id)
                if self.parent_id and self.parent_id.user_id:
                    partner_ids.append(self.parent_id.user_id.partner_id.id)
                if partner_ids:
                    id = self.env['mail.message'].create({
                            'body': _("Flextime overdue %s minutes for %s\n" % (self.get_flextime_total(), self.name)),
                            'subject': subject,
                            'author_id': self.env.user.partner_id.id,
                            'partner_ids': [(6, 0, partner_ids)],
                            'res_id': self.id,
                            'model': self._name,
                            'type': 'email',
                        })
            _logger.info('Flextime overdue:  %s hours for %s ' % (self.get_flextime_total(), self.name)) 
开发者ID:vertelab,项目名称:odoo-payroll,代码行数:27,代码来源:hr_payroll.py

示例2: safe_execute

# 需要导入模块: from openerp import api [as 别名]
# 或者: from openerp.api import model [as 别名]
def safe_execute(self):
        """ Evaluates the context searching model name and record ids, browse
            records and run each one.
        """

        ctx = self.env.context

        if self._context_has_items(ctx):
            model, ids = self._get_from_context(ctx)
            if model and model == self._name and ids:
                jobs = self._get_jobs(model, ids)
                for action in jobs:
                    return self._safe_execute(action) 
开发者ID:sotogarcia,项目名称:odoo-development,代码行数:15,代码来源:base_ir_action_act_window.py

示例3: _get_jobs

# 需要导入模块: from openerp import api [as 别名]
# 或者: from openerp.api import model [as 别名]
def _get_jobs(self, model, ids):
        """ Gets all jobs with id in ids

            :param (str): name of the model
            :ids ([int]): list of ids of the records to be retrieved
            :return (recordset): recordset with the items have been retrieved
        """
        return self.env[model].browse(ids)

    # ------------------------- LONG TEXT VARIABLES --------------------------- 
开发者ID:sotogarcia,项目名称:odoo-development,代码行数:12,代码来源:base_ir_action_act_window.py

示例4: safe_execute

# 需要导入模块: from openerp import api [as 别名]
# 或者: from openerp.api import model [as 别名]
def safe_execute(self):
        """ Evaluates the context searching model name and record ids, browse
            records and run each one.
        """

        ctx = self.env.context

        if self._context_has_items(ctx):
            model, ids = self._get_from_context(ctx)
            if model and model == self._name and ids:
                jobs = self._get_jobs(model, ids)
                for job in jobs:
                    self._safe_execute(job) 
开发者ID:sotogarcia,项目名称:odoo-development,代码行数:15,代码来源:base_ir_cron.py

示例5: _safe_execute

# 需要导入模块: from openerp import api [as 别名]
# 或者: from openerp.api import model [as 别名]
def _safe_execute(self, job):
        """ Executes a planned action inside a try except block and log results

            :param job (ir.cron): planned action to be executed
        """

        try:
            _logger.info(self._executing_msg.format(job, job.name))
            self._callback(job.model, job.function, job.args, id)
        except Exception as ex:
            msg = self._error_msg.format(job, job.name, ex)
            _logger.error(msg) 
开发者ID:sotogarcia,项目名称:odoo-development,代码行数:14,代码来源:base_ir_cron.py

示例6: reload

# 需要导入模块: from openerp import api [as 别名]
# 或者: from openerp.api import model [as 别名]
def reload(self, model, _id, xml_id):
        result = False

        m_data_domain = [('model', '=', model), ('res_id', '=', _id)]
        m_data_obj = self.env['ir.model.data']
        m_data_set = m_data_obj.search(m_data_domain)

        if m_data_set:
            self._reload(m_data_set.module, model, m_data_set.name, _id)
        else:
            self._log(3, 'NOXID', _id)

        return result 
开发者ID:sotogarcia,项目名称:odoo-development,代码行数:15,代码来源:base_ir_model.py

示例7: safe_execute

# 需要导入模块: from openerp import api [as 别名]
# 或者: from openerp.api import model [as 别名]
def safe_execute(self):
        """ Evaluates the context searching model name and record ids, browse
            records and run each one.
        """

        ctx = self.env.context

        if self._context_has_items(ctx):
            model, ids = self._get_from_context(ctx)
            if model and model == self._name and ids:
                jobs = self._get_jobs(model, ids)
                for action in jobs:
                    self._safe_execute(action) 
开发者ID:sotogarcia,项目名称:odoo-development,代码行数:15,代码来源:base_ir_actions_server.py

示例8: absent_notification

# 需要导入模块: from openerp import api [as 别名]
# 或者: from openerp.api import model [as 别名]
def absent_notification(self): #send notification to employee and manager when employee is absent without leave request
        now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        employees = self.env['hr.employee'].search([('active', '=', True), ('state', '=', 'absent'), ('id', '!=', self.env.ref('hr.employee').id)])
        employees_on_vacation = request.env['hr.holidays'].search([('date_from', '<', now), ('date_to', '>=', now), ('state', '=', 'validate'), ('type', '=', 'remove')]).mapped('employee_id')
        employees -= employees_on_vacation
        for e in employees:
            if e.user_id:
                self.env['mail.message'].create({
                    'body': _("Time to work!"),
                    'subject': _("Time to work!"),
                    'author_id': self.env.ref('hr.employee').user_id.partner_id.id,
                    'res_id': e.id,
                    'model': e._name,
                    'subtype_id': self.env.ref('mail.mt_comment').id,
                    'partner_ids': [(6, 0, [e.user_id.partner_id.id])],
                    'type': 'notification',})
            if e.parent_id and e.parent_id.user_id:
                self.env['mail.message'].create({
                    'body': _("Your employee %s is not at work" %e.name),
                    'subject': _("Your employee %s is not at work" %e.name),
                    'author_id': self.env.ref('hr.employee').user_id.partner_id.id,
                    'res_id': e.parent_id.id,
                    'model': e._name,
                    'subtype_id': self.env.ref('mail.mt_comment').id,
                    'partner_ids': [(6, 0, [e.parent_id.user_id.partner_id.id])],
                    'type': 'notification',}) 
开发者ID:vertelab,项目名称:odoo-payroll,代码行数:28,代码来源:hr_attendance.py

示例9: sick_notification

# 需要导入模块: from openerp import api [as 别名]
# 或者: from openerp.api import model [as 别名]
def sick_notification(self): #send notification to employee and manager when employee is absent after 7 sick days
        today = datetime.now()
        employees_sick = request.env['hr.holidays'].search([('date_from', '<', today.strftime('%Y-%m-%d')), ('date_to', '>=', today.strftime('%Y-%m-%d')), ('state', '=', 'validate'), ('type', '=', 'remove'), ]).mapped('employee_id')
        for e in employees_sick:
            eightday_sick = request.env['hr.holidays'].search([('date_from', '>', (today - timedelta(days=8)).strftime('%Y-%m-%d 00:00:00')), ('date_from', '<', (today - timedelta(days=8)).strftime('%Y-%m-%d 23:59:59')), ('state', '=', 'validate'), ('type', '=', 'remove'), ('holiday_status_id', 'in', [self.env.ref('l10n_se_hr_payroll.sick_leave_qualify').id, self.env.ref('l10n_se_hr_payroll.sick_leave_214').id]), ('employee_id', '=', e.id)])
            nineday_sick = request.env['hr.holidays'].search([('date_from', '<', (today - timedelta(days=8)).strftime('%Y-%m-%d 00:00:00')), ('date_to', '>', (today - timedelta(days=8)).strftime('%Y-%m-%d 00:00:00')), ('state', '=', 'validate'), ('type', '=', 'remove'), ('holiday_status_id', 'in', [self.env.ref('l10n_se_hr_payroll.sick_leave_qualify').id, self.env.ref('l10n_se_hr_payroll.sick_leave_214').id]), ('employee_id', '=', e.id)])
            if len(eightday_sick) > 0 and len(nineday_sick) == 0: #send notification when it's only 8th sick day
                #~ if e.user_id:
                    #~ self.env['mail.message'].create({
                        #~ 'body': _("You have been sick for more than 7 days"),
                        #~ 'subject': _("You have been sick for more than 7 days"),
                        #~ 'author_id': self.env.ref('hr.employee').user_id.partner_id.id,
                        #~ 'res_id': e.id,
                        #~ 'model': e._name,
                        #~ 'subtype_id': self.env.ref('mail.mt_comment').id,
                        #~ 'partner_ids': [(6, 0, [e.user_id.partner_id.id])],
                        #~ 'type': 'notification',})
                if e.parent_id and e.parent_id.user_id:
                    self.env['mail.message'].create({
                        'body': _("Your employee %s has been sick for more than 7 days" %e.name),
                        'subject': _("Your employee %s has been sick for more than 7 days" %e.name),
                        'author_id': self.env.ref('hr.employee').user_id.partner_id.id,
                        'res_id': e.parent_id.id,
                        'model': e._name,
                        'subtype_id': self.env.ref('mail.mt_comment').id,
                        'partner_ids': [(6, 0, [e.parent_id.user_id.partner_id.id])],
                        'type': 'notification',})

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: 
开发者ID:vertelab,项目名称:odoo-payroll,代码行数:31,代码来源:hr_attendance.py

示例10: auto_log_out

# 需要导入模块: from openerp import api [as 别名]
# 或者: from openerp.api import model [as 别名]
def auto_log_out(self): #auto log out in midnight
        employees = self.env['hr.employee'].search([('active', '=', True), ('id', '!=', self.env.ref('hr.employee').id)]).filtered(lambda e: e.state == 'present')
        if len(employees) > 0:
            _logger.warn('Employees to logout %s' %employees)
        for e in employees:
            if e.contract_id and e.user_id:
                atts = self.search([('employee_id', '=', e.id)], order='name')
                if len(atts) != 0:
                    if atts[-1].action == 'sign_in': #last attendance is sign in
                        hours_to = {a.dayofweek: a.hour_to for a in e.contract_id.working_hours.attendance_ids}
                        now = datetime.now()
                        yesterday_utc = datetime(now.year, now.month, now.day) - timedelta(days = 1) + timedelta(minutes = (hours_to[str(now.weekday())]* 60))
                        yesterday = self.convert2utc(e, yesterday_utc).strftime('%Y-%m-%d %H:%M:%S')
                        try:
                            e.with_context({'action_date': yesterday, 'action': 'sign_out'}).attendance_action_change()
                        except Exception as ex:
                            _logger.warn(': '.join(ex))
                            self.env['mail.message'].create({
                                'body': _("Error!\n%s\nSystem tried to signed out on %s (%s)\n Current status: %s" % (ex, yesterday_utc, yesterday, e.state)),
                                'subject': _("Error Auto sign out"),
                                'author_id': self.env.ref('hr.employee').user_id.partner_id.id,
                                'res_id': e.id,
                                'model': e._name,
                                'subtype_id': self.env.ref('mail.mt_comment').id,
                                'partner_ids': [(6, 0, [e.user_id.partner_id.id])],
                                'type': 'notification',})
                            if e.parent_id:
                                self.env['mail.message'].create({
                                    'body': _("Error!\n%s\n%sSystem tried to automatically signed out on %s\n" % (ex, e.name, yesterday_utc)),
                                    'subject': _("Error Employee auto sign out"),
                                    'author_id': self.env.ref('hr.employee').user_id.partner_id.id,
                                    'res_id': e.parent_id.id,
                                    'model': e._name,
                                    'subtype_id': self.env.ref('mail.mt_comment').id,
                                    'partner_ids': [(6, 0, [e.parent_id.user_id.partner_id.id])],
                                    'type': 'notification',})
                            continue
                        self.env['mail.message'].create({
                            'body': _("You've been automatically signed out on %s (%s)\nIf this sign out time is incorrect, please contact your supervisor. Current status: %s" % (yesterday_utc, yesterday, e.state)),
                            'subject': _("Auto sign out"),
                            'author_id': self.env.ref('hr.employee').user_id.partner_id.id,
                            'res_id': e.id,
                            'model': e._name,
                            'subtype_id': self.env.ref('mail.mt_comment').id,
                            'partner_ids': [(6, 0, [e.user_id.partner_id.id])],
                            'type': 'notification',})
                        if e.parent_id:
                            self.env['mail.message'].create({
                                'body': _("%s has been automatically signed out on %s\n" % (e.name, yesterday_utc)),
                                'subject': _("Employee auto sign out"),
                                'author_id': self.env.ref('hr.employee').user_id.partner_id.id,
                                'res_id': e.parent_id.id,
                                'model': e._name,
                                'subtype_id': self.env.ref('mail.mt_comment').id,
                                'partner_ids': [(6, 0, [e.parent_id.user_id.partner_id.id])],
                                'type': 'notification',})
                    else:
                        continue
        return None 
开发者ID:vertelab,项目名称:odoo-payroll,代码行数:61,代码来源:hr_attendance.py

示例11: hr_verify_sheet

# 需要导入模块: from openerp import api [as 别名]
# 或者: from openerp.api import model [as 别名]
def hr_verify_sheet(self):
        #~ raise Warning(datetime(2016,11,21,8,32))
                        #~ self.get_working_hours += self.env['resource.calendar'].get_working_hours(self.employee_id.contract_ids[0].working_hours.id,
                    #~ datetime.strptime(start.name, tools.DEFAULT_SERVER_DATETIME_FORMAT),
                    #~ datetime.strptime(end.name, tools.DEFAULT_SERVER_DATETIME_FORMAT))

        #~ raise Warning(self.pool.get('resource.calendar').get_working_intervals_of_day(self.env.cr,self.env.uid,self.employee_id.contract_id.working_hours.id,start_dt=datetime(2016,11,21,0,0),))
        #~ raise Warning(self.env['resource.calendar'].schedule_days_get_date(1,self.employee_id.contract_id.working_hours.id,date_day=datetime(2016,11,21,0,0)))
        #~ schedule_days_get_date(self, cr, uid, id, days, day_date=None, compute_leaves=False,
                               #~ resource_id=None, default_interval=None, context=None):
        #~ """ Wrapper on _schedule_days: return the beginning/ending datetime of"""

        #raise Warning(self.worked_days_line_ids)
        #TODO: Make sure this is only written once.
        if self.state == 'draft':
            self.employee_id.set_flex_time_pot(self.flextime, self.date_to)
        return super(hr_payslip, self).hr_verify_sheet()

    #~ def refund_sheet(self, cr, uid, ids, context=None):
        #~ mod_obj = self.pool.get('ir.model.data')
        #~ for payslip in self.browse(cr, uid, ids, context=context):
            #~ id_copy = self.copy(cr, uid, payslip.id, {'credit_note': True, 'name': _('Refund: ')+payslip.name}, context=context)
            #~ self.signal_workflow(cr, uid, [id_copy], 'hr_verify_sheet')
            #~ self.signal_workflow(cr, uid, [id_copy], 'process_sheet')

        #~ form_id = mod_obj.get_object_reference(cr, uid, 'hr_payroll', 'view_hr_payslip_form')
        #~ form_res = form_id and form_id[1] or False
        #~ tree_id = mod_obj.get_object_reference(cr, uid, 'hr_payroll', 'view_hr_payslip_tree')
        #~ tree_res = tree_id and tree_id[1] or False
        #~ return {
            #~ 'name':_("Refund Payslip"),
            #~ 'view_mode': 'tree, form',
            #~ 'view_id': False,
            #~ 'view_type': 'form',
            #~ 'res_model': 'hr.payslip',
            #~ 'type': 'ir.actions.act_window',
            #~ 'nodestroy': True,
            #~ 'target': 'current',
            #~ 'domain': "[('id', 'in', %s)]" % [id_copy],
            #~ 'views': [(tree_res, 'tree'), (form_res, 'form')],
            #~ 'context': {}
        #~ } 
开发者ID:vertelab,项目名称:odoo-payroll,代码行数:44,代码来源:hr_payroll.py


注:本文中的openerp.api.model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。