odoo 10使用按钮调用方法代替工作流实现审批流程

最近老大分配一个分发单的工作,最重要的工作流。odoo 10已经开始用方法实现审批流程了,废话不多说直接上代码。

gesion_distribution

# -*- coding: utf-8 -*-
# Author: Ray

from odoo import models, api, fields, _
from odoo.exceptions import UserError
import logging

from odoo.addons.muk_dms.models import dms_base

_logger = logging.getLogger(__name__)
_schema = logging.getLogger(__name__ + '.schema')


class Distribution(dms_base.DMSModel):   # 分发单
    _name = 'gesion_dms_test.doc_distribution'
    _description = "Gesion Documents Distribution"
    _inherit = ['mail.thread', 'ir.needaction_mixin']

    def get_employee(self):
        obj = self.env['hr.employee']
        idsobj = obj.search([('user_id', '=', self.env.user.id)])
        res = idsobj.read()
        return res and res[0]['id'] or 0
    # 个人tree视图字段
    title = fields.Char(u'标题', readonly=False, required=False, translate=False)
    remarks = fields.Text(u'备注', readonly=False, required=False, translate=False)
    status = fields.Selection([('0', u'同意'), ('1', u'驳回')], u'结果', readonly=False, required=False, translate=False)
    submitdate = fields.Datetime(u'提交时间', readonly=False, required=False, translate=False, default=fields.Datetime.now)
    adddate = fields.Datetime(u'审批时间', readonly=False, required=False, translate=False, default=fields.Datetime.now)
    addperson = fields.Many2one('hr.employee', u'執行者审核人', readonly=False, required=False, translate=False,
                                 default=lambda self: self.get_employee(), track_visibility='always')
    control = fields.Many2one('hr.employee', string='文控审批人', track_visibility='always')
    manager = fields.Many2one('hr.employee', u'经理审批人', readonly=False, required=False, translate=False, track_visibility='always')
    # distribution_name = fields.Char('Distribution Name', required=True, translate=True)
    # distribution_number = fields.Char(string='Distribution Number', required=True)
    # distribution_description = fields.Text(string='Distribution Description', required=True, translate=True)

    # individual_id  = fields.Many2one('gesion_dms.individual_thing')
    approve_id = fields.Many2one('gesion_dms.approve')

    # organization info
    organization_id = fields.Many2one('gesion.organization', string='Organization')
    organization_no = fields.Char(related='organization_id.organization_number', store=True, string='Organization No')

    # sender info
    sender_id = fields.Many2one('hr.employee', string='Sender', track_visibility='always')
    positon_id = fields.Many2one('hr.job', string='Position')

    # receiver list
    # reciver_id = fields.Char(related='reveiver_ids.reciver_id', string='Reciver Id')
    receiver_list = fields.One2many('reciver.list', 'doc_distribution_id')
    doc_list = fields.One2many('document.list', 'doc_distribution_id')
    review_id = fields.One2many('review.info', 'pay_id', copy=True)

    state = fields.Selection([('draft', '草稿'),('control', '文控审批'), ('approving', '总经理审批'), ('review', '执行者审核'),
                              ('done', '分发完成')], string='State', default='draft', track_visibility='always')

    @api.model
    def create(self, vals):
        result = super(Distribution, self).create(vals)
        return result

    @api.multi
    def write(self, values):
        result = super(Distribution, self).write(values)
        return result

    @api.multi
    def unlink(self):
        return super(Distribution, self).unlink()

    @api.multi
    def copy(self, default=None):
        return super(Distribution, self).copy(default)

    @api.multi
    def search(self, args, offset=0, limit=None, order=None, context=None, count=False):
        domain = None
        domain = [('state', '=', '0')]
        return super(Distribution, self).search(args, offset=offset, limit=limit, order=order, count=count)

    # @api.onchange('organization_id')
    # def _onchage_organization(self):
        # self.organization_no = self.env['project.project'].

    @api.onchange('sender_id')
    def _onchange_sender(self):
        self.sender_name = self.sender_id.name
        # self.sender_position = self.sender_id


class ReceiverList(dms_base.DMSModel):
    _name = 'reciver.list'

    doc_distribution_id = fields.Many2one('gesion_dms_test.doc_distribution')

    reveiver_ids = fields.Many2one('hr.employee', string='Reciver')
    discipline_id = fields.Many2one('project.discipline', string='Discipline')
    positon_id = fields.Many2one('hr.job', string='Position')
    remarks = fields.Char(string='Remarks')
    # discipline = fields.Char(related='discipline_id.name', string='Discipline')


class DocumentList(dms_base.DMSModel):
    _name = 'document.list'

    doc_distribution_id = fields.Many2one('gesion_dms_test.doc_distribution')

    discipline_id = fields.Many2one('project.discipline', string='Discipline')


class ReviewInfo(models.Model):
    _name = 'review.info'

    def get_employee(self, cr, uid, context={}):
        obj = self.pool.get('hr.employee')
        ids = obj.search(cr, uid, [('user_id', '=', uid)])
        res = obj.read(cr, uid, ids, ['id', 'name'], context)
        return res and res[0]['id'] or 0

    pay_id = fields.Many2one('gesion_dms_test.doc_distribution', required=True, ondelete='cascade', index=True, copy=False)

    title = fields.Char(u'标题', readonly=False, required=False, translate=False)
    remarks = fields.Text(u'备注', readonly=False, required=False, translate=False)
    addperson = fields.Many2one('hr.employee', u'审批人', readonly=False, required=False, translate=False)
    submitdate = fields.Datetime(u'提交时间', readonly=False, required=False, translate=False, default=fields.Datetime.now)
    adddate = fields.Datetime(u'处理时间', readonly=False, required=False, translate=False)
    status = fields.Selection([('0', u'同意'), ('1', u'驳回')], u'结果', readonly=False, required=False, translate=False)

    @api.model
    def create(self, vals):
        result = super(ReviewInfo, self).create(vals)
        return result

    @api.multi
    def write(self, values):
        result = super(ReviewInfo, self).write(values)

        return result

    @api.multi
    def unlink(self):
        return super(ReviewInfo, self).unlink()

    @api.multi
    def copy(self, default=None):
        return super(ReviewInfo, self).copy(default)

    @api.multi
    def search(self, args, offset=0, limit=None, order=None, context=None, count=False):
        domain = None
        domain = [('state', '=', '0')]
        return super(ReviewInfo, self).search(args, offset=offset, limit=limit, order=order, count=count)

gesion_dms_distribution

# -*- coding: utf-8 -*-
# Author: Ray

from odoo import models, api, fields, _
from odoo.exceptions import UserError
import logging

from odoo.addons.muk_dms.models import dms_base

_logger = logging.getLogger(__name__)
_schema = logging.getLogger(__name__ + '.schema')


class Distribution(dms_base.DMSModel):   # 分发单
    _name = 'gesion_dms_test.doc_distribution'
    _description = "Gesion Documents Distribution"
    _inherit = ['mail.thread', 'ir.needaction_mixin']

    def get_employee(self):
        obj = self.env['hr.employee']
        idsobj = obj.search([('user_id', '=', self.env.user.id)])
        res = idsobj.read()
        return res and res[0]['id'] or 0
    # 个人tree视图字段
    title = fields.Char(u'标题', readonly=False, required=False, translate=False)
    remarks = fields.Text(u'备注', readonly=False, required=False, translate=False)
    status = fields.Selection([('0', u'同意'), ('1', u'驳回')], u'结果', readonly=False, required=False, translate=False)
    submitdate = fields.Datetime(u'提交时间', readonly=False, required=False, translate=False, default=fields.Datetime.now)
    adddate = fields.Datetime(u'审批时间', readonly=False, required=False, translate=False, default=fields.Datetime.now)
    addperson = fields.Many2one('hr.employee', u'執行者审核人', readonly=False, required=False, translate=False,
                                 default=lambda self: self.get_employee(), track_visibility='always')
    control = fields.Many2one('hr.employee', string='文控审批人', track_visibility='always')
    manager = fields.Many2one('hr.employee', u'经理审批人', readonly=False, required=False, translate=False, track_visibility='always')
    # distribution_name = fields.Char('Distribution Name', required=True, translate=True)
    # distribution_number = fields.Char(string='Distribution Number', required=True)
    # distribution_description = fields.Text(string='Distribution Description', required=True, translate=True)

    # individual_id  = fields.Many2one('gesion_dms.individual_thing')
    approve_id = fields.Many2one('gesion_dms.approve')

    # organization info
    organization_id = fields.Many2one('gesion.organization', string='Organization')
    organization_no = fields.Char(related='organization_id.organization_number', store=True, string='Organization No')

    # sender info
    sender_id = fields.Many2one('hr.employee', string='Sender', track_visibility='always')
    positon_id = fields.Many2one('hr.job', string='Position')

    # receiver list
    # reciver_id = fields.Char(related='reveiver_ids.reciver_id', string='Reciver Id')
    receiver_list = fields.One2many('reciver.list', 'doc_distribution_id')
    doc_list = fields.One2many('document.list', 'doc_distribution_id')
    review_id = fields.One2many('review.info', 'pay_id', copy=True)

    state = fields.Selection([('draft', '草稿'),('control', '文控审批'), ('approving', '总经理审批'), ('review', '执行者审核'),
                              ('done', '分发完成')], string='State', default='draft', track_visibility='always')

    @api.model
    def create(self, vals):
        result = super(Distribution, self).create(vals)
        return result

    @api.multi
    def write(self, values):
        result = super(Distribution, self).write(values)
        return result

    @api.multi
    def unlink(self):
        return super(Distribution, self).unlink()

    @api.multi
    def copy(self, default=None):
        return super(Distribution, self).copy(default)

    @api.multi
    def search(self, args, offset=0, limit=None, order=None, context=None, count=False):
        domain = None
        domain = [('state', '=', '0')]
        return super(Distribution, self).search(args, offset=offset, limit=limit, order=order, count=count)

    # @api.onchange('organization_id')
    # def _onchage_organization(self):
        # self.organization_no = self.env['project.project'].

    @api.onchange('sender_id')
    def _onchange_sender(self):
        self.sender_name = self.sender_id.name
        # self.sender_position = self.sender_id


class ReceiverList(dms_base.DMSModel):
    _name = 'reciver.list'

    doc_distribution_id = fields.Many2one('gesion_dms_test.doc_distribution')

    reveiver_ids = fields.Many2one('hr.employee', string='Reciver')
    discipline_id = fields.Many2one('project.discipline', string='Discipline')
    positon_id = fields.Many2one('hr.job', string='Position')
    remarks = fields.Char(string='Remarks')
    # discipline = fields.Char(related='discipline_id.name', string='Discipline')


class DocumentList(dms_base.DMSModel):
    _name = 'document.list'

    doc_distribution_id = fields.Many2one('gesion_dms_test.doc_distribution')

    discipline_id = fields.Many2one('project.discipline', string='Discipline')


class ReviewInfo(models.Model):
    _name = 'review.info'

    def get_employee(self, cr, uid, context={}):
        obj = self.pool.get('hr.employee')
        ids = obj.search(cr, uid, [('user_id', '=', uid)])
        res = obj.read(cr, uid, ids, ['id', 'name'], context)
        return res and res[0]['id'] or 0

    pay_id = fields.Many2one('gesion_dms_test.doc_distribution', required=True, ondelete='cascade', index=True, copy=False)

    title = fields.Char(u'标题', readonly=False, required=False, translate=False)
    remarks = fields.Text(u'备注', readonly=False, required=False, translate=False)
    addperson = fields.Many2one('hr.employee', u'审批人', readonly=False, required=False, translate=False)
    submitdate = fields.Datetime(u'提交时间', readonly=False, required=False, translate=False, default=fields.Datetime.now)
    adddate = fields.Datetime(u'处理时间', readonly=False, required=False, translate=False)
    status = fields.Selection([('0', u'同意'), ('1', u'驳回')], u'结果', readonly=False, required=False, translate=False)

    @api.model
    def create(self, vals):
        result = super(ReviewInfo, self).create(vals)
        return result

    @api.multi
    def write(self, values):
        result = super(ReviewInfo, self).write(values)

        return result

    @api.multi
    def unlink(self):
        return super(ReviewInfo, self).unlink()

    @api.multi
    def copy(self, default=None):
        return super(ReviewInfo, self).copy(default)

    @api.multi
    def search(self, args, offset=0, limit=None, order=None, context=None, count=False):
        domain = None
        domain = [('state', '=', '0')]
        return super(ReviewInfo, self).search(args, offset=offset, limit=limit, order=order, count=count)

approve_wizard.xml



    
        
            线索
            gesion_dms.approve
            
                
线索 ir.actions.act_window gesion_dms.approve form form new 线索 gesion_dms.approve
线索 ir.actions.act_window gesion_dms.approve form form new 线索 gesion_dms.approve
线索 ir.actions.act_window gesion_dms.approve form form new 线索 gesion_dms.approve
线索 ir.actions.act_window gesion_dms.approve form form new

approve_wizard.py

# -*- coding: utf-8 -*-

from odoo import api, fields, models, _


class Approve(models.Model):
    """审核"""
    _name = 'gesion_dms.approve'

    distribution_ids = fields.One2many('gesion_dms_test.doc_distribution', 'approve_id')
    title = fields.Char(u'标题', readonly=False, required=False, translate=False)
    remarks = fields.Text(u'备注', readonly=False, required=False, translate=False)

    def agree1(self):
        model_data = self.env['ir.model.data']
        model_self = super(Approve, self).read(['title', 'remarks'])[0]
        vals = {}
        vals['pay_id'] = self._context.get('pay_id')
        vals['title'] = model_self['title']
        vals['remarks'] = model_self['remarks']
        vals['addperson'] = self.env.user.id
        vals['adddate'] = fields.Datetime.now()
        vals['status'] = '0'
        result = self.env['review.info'].create(vals)

        result1 = self.env['gesion_dms_test.doc_distribution'].create(vals)
        self.env['gesion_dms_test.doc_distribution'].search([('state', '=', 'draft')]).write({'state': 'control', 'adddate': fields.datetime.now()})

        return True

    # def refuse1(self):
    #     model_data = self.env['ir.model.data']
    #     model_self = super(Approve, self).read(['title', 'remarks'])[0]
    #     vals = {}
    #     vals['pay_id'] = self._context.get('pay_id')
    #     vals['title'] = model_self['title']
    #     vals['remarks'] = model_self['remarks']
    #     vals['addperson'] = self.env.user.id
    #     vals['submitdate'] = fields.Datetime.now()
    #     vals['status'] = '1'
    #     result = self.env['review.info'].create(vals)
    #     result1 = self.env['gesion_dms_test.doc_distribution'].create(vals)
    #     return True

    def agree2(self):
        model_data = self.env['ir.model.data']
        model_self = super(Approve, self).read(['title', 'remarks'])[0]
        vals = {}
        vals['pay_id'] = self._context.get('pay_id')
        vals['title'] = model_self['title']
        vals['remarks'] = model_self['remarks']
        vals['addperson'] = self.env.user.id
        vals['adddate'] = fields.Datetime.now()
        vals['status'] = '0'
        result = self.env['review.info'].create(vals)
        result1 = self.env['gesion_dms_test.doc_distribution'].create(vals)

        self.env['gesion_dms_test.doc_distribution'].search([('state', '=', 'control')]).write({'state': 'approving', 'adddate': fields.datetime.now()})
        return True

    def refuse2(self):
        model_data = self.env['ir.model.data']
        model_self = super(Approve, self).read(['title', 'remarks'])[0]
        vals = {}
        vals['pay_id'] = self._context.get('pay_id')
        vals['title'] = model_self['title']
        vals['remarks'] = model_self['remarks']
        vals['addperson'] = self.env.user.id
        vals['adddate'] = fields.Datetime.now()
        vals['status'] = '1'
        result = self.env['review.info'].create(vals)
        result1 = self.env['gesion_dms_test.doc_distribution'].create(vals)
        self.env['gesion_dms_test.doc_distribution'].search([('state', '=', 'control')]).write({'state': 'draft', 'adddate': fields.datetime.now()})
        return True

    def agree3(self):
        model_data = self.env['ir.model.data']
        model_self = super(Approve, self).read(['title', 'remarks'])[0]
        vals = {}
        vals['pay_id'] = self._context.get('pay_id')
        vals['title'] = model_self['title']
        vals['remarks'] = model_self['remarks']
        vals['addperson'] = self.env.user.id
        vals['adddate'] = fields.Datetime.now()
        vals['status'] = '0'
        result = self.env['review.info'].create(vals)

        # 添加收件人看到的信息
        recipient_data = {}
        for r in self:
            self._cr.execute('select name from muk_dms_file where id =%s', (r.id,))
            filename_val = self._cr.fetchone()

            self._cr.execute('select file_code from muk_dms_file where id =%s', (r.id,))
            file_code_val = self._cr.fetchone()

            self._cr.execute('select sender_id from gesion_dms_test_doc_distribution where id =%s', (r.id,))
            sender_val = self._cr.fetchone()
            print(sender_val)

        recipient_data['filename'] = filename_val
        recipient_data['file_code'] = file_code_val
        recipient_data['sender'] = sender_val
        recipient_data['sender_time'] = fields.Datetime.now()
        result2 = self.env['gesion_dms.recipient_tree_view_info'].create(recipient_data)

        result1 = self.env['gesion_dms_test.doc_distribution'].create(vals)
        self.env['gesion_dms_test.doc_distribution'].search([('state', '=', 'approving')]).write({'state': 'review', 'adddate': fields.datetime.now()})
        return True

    def refuse3(self):
        model_data = self.env['ir.model.data']
        model_self = super(Approve, self).read(['title', 'remarks'])[0]
        vals = {}
        vals['pay_id'] = self._context.get('pay_id')
        vals['title'] = model_self['title']
        vals['remarks'] = model_self['remarks']
        vals['addperson'] = self.env.user.id
        vals['adddate'] = fields.Datetime.now()
        vals['status'] = '1'
        result = self.env['review.info'].create(vals)
        result1 = self.env['gesion_dms_test.doc_distribution'].create(vals)
        self.env['gesion_dms_test.doc_distribution'].search([('state', '=', 'approving')]).write({'state': 'control', 'adddate': fields.datetime.now()})
        return True

    def agree4(self):
        model_data = self.env['ir.model.data']
        model_self = super(Approve, self).read(['title', 'remarks'])[0]
        vals = {}
        vals['pay_id'] = self._context.get('pay_id')
        vals['title'] = model_self['title']
        vals['remarks'] = model_self['remarks']
        vals['addperson'] = self.env.user.id
        vals['adddate'] = fields.Datetime.now()
        vals['status'] = '0'
        result = self.env['review.info'].create(vals)
        result1 = self.env['gesion_dms_test.doc_distribution'].create(vals)

        self.env['gesion_dms_test.doc_distribution'].search([('state', '=', 'review')]).write({'state': 'done', 'adddate': fields.datetime.now()})
        return True

    def refuse4(self):
        model_data = self.env['ir.model.data']
        model_self = super(Approve, self).read(['title', 'remarks'])[0]
        vals = {}
        vals['pay_id'] = self._context.get('pay_id')
        vals['title'] = model_self['title']
        vals['remarks'] = model_self['remarks']
        vals['addperson'] = self.env.user.id
        vals['adddate'] = fields.Datetime.now()
        vals['status'] = '1'
        result = self.env['review.info'].create(vals)
        result1 = self.env['gesion_dms_test.doc_distribution'].create(vals)
        self.env['gesion_dms_test.doc_distribution'].search([('state', '=', 'review')]).write({'state': 'approving', 'adddate': fields.datetime.now()})
        return True

到此就实现了,审批时点击按钮弹出页面进行填入审批意见,同意后执行改变状态的方法,进而实现状态的改变。打日志的方式把审批过程记录下来。此过程还没有写完,后续还有叠加版本。

你可能感兴趣的:(odoo,10框架)