这是对MRO模块的重新设计,可从此链接获取 - https://www.odoo.com/apps/modules/8.0/mro/
以下是工作流程序列
1)将创建维护请求,然后在确认后继续维护订单
2)当处理维护订单并最终达到状态“完成”时,作为订单来源的维护请求文档也将达到“完成”状态。
有两个班级
mro.request
class mro_request(osv.osv):
"""
Maintenance Requests
"""
_name = 'mro.request'
_description = 'Maintenance Request'
_inherit = ['mail.thread', 'ir.needaction_mixin']
STATE_SELECTION = [
('draft', 'Draft'),
('claim', 'Claim'),
('run', 'Execution'),
('done', 'Done'),
('reject', 'Rejected'),
('cancel', 'Canceled')
]
_track = {
'state': {
'mro.mt_request_sent': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'claim',
'mro.mt_request_confirmed': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'run',
'mro.mt_request_rejected': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'reject',
},
}
_columns = {
'name': fields.char('Reference', size=64),
'state': fields.selection(STATE_SELECTION, 'Status', readonly=True,
help="When the maintenance request is created the status is set to 'Draft'.\n\
If the request is sent the status is set to 'Claim'.\n\
If the request is confirmed the status is set to 'Execution'.\n\
If the request is rejected the status is set to 'Rejected'.\n\
When the maintenance is over, the status is set to 'Done'."),
'asset_id': fields.many2one('asset.asset', 'Asset', required=True, readonly=True, states={'draft': [('readonly', False)]}),
'cause': fields.char('Cause', size=64, translate=True, required=True, readonly=True, states={'draft': [('readonly', False)]}),
'description': fields.text('Description', readonly=True, states={'draft': [('readonly', False)]}),
'reject_reason': fields.text('Reject Reason', readonly=True),
'requested_date': fields.datetime('Requested Date', required=True, select=1, readonly=True, states={'draft': [('readonly', False)]}, help="Date requested by the customer for maintenance."),
'execution_date': fields.datetime('Execution Date', required=True, select=1, readonly=True, states={'draft':[('readonly',False)],'claim':[('readonly',False)]}),
'breakdown': fields.boolean('Breakdown', readonly=True, states={'draft': [('readonly', False)]}),
'create_uid': fields.many2one('res.users', 'Responsible'),
}
_defaults = {
'state': 'draft',
'requested_date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'execution_date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'breakdown': False,
}
然后有mro.order类
class mro_order(osv.osv):
"""
Maintenance Orders
"""
_name = 'mro.order'
_description = 'Maintenance Order'
_inherit = ['mail.thread', 'ir.needaction_mixin']
STATE_SELECTION = [
('draft', 'DRAFT'),
('released', 'WAITING PARTS'),
('ready', 'READY TO MAINTENANCE'),
('done', 'DONE'),
('cancel', 'CANCELED')
]
MAINTENANCE_TYPE_SELECTION = [
('bm', 'Breakdown'),
('cm', 'Corrective')
]
_track = {
'state': {
'mro.mt_order_confirmed': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'ready',
},
}
_columns = {
'name': fields.char('Reference', size=64),
'origin': fields.char('Source Document', size=64, readonly=True, states={'draft': [('readonly', False)]},
help="Reference of the document that generated this maintenance order."),
'state': fields.selection(STATE_SELECTION, 'Status', readonly=True,
help="When the maintenance order is created the status is set to 'Draft'.\n\
If the order is confirmed the status is set to 'Waiting Parts'.\n\
If the stock is available then the status is set to 'Ready to Maintenance'.\n\
When the maintenance is over, the status is set to 'Done'."),
'maintenance_type': fields.selection(MAINTENANCE_TYPE_SELECTION, 'Maintenance Type', required=True, readonly=True, states={'draft': [('readonly', False)]}),
'task_id': fields.many2one('mro.task', 'Task', readonly=True, states={'draft': [('readonly', False)]}),
'description': fields.char('Description', size=64, translate=True, required=True, readonly=True, states={'draft': [('readonly', False)]}),
'asset_id': fields.many2one('asset.asset', 'Asset', required=True, readonly=True, states={'draft': [('readonly', False)]}),
'date_planned': fields.datetime('Planned Date', required=True, select=1, readonly=True, states={'draft':[('readonly',False)]}),
'date_scheduled': fields.datetime('Scheduled Date', required=True, select=1, readonly=True, states={'draft':[('readonly',False)],'released':[('readonly',False)],'ready':[('readonly',False)]}),
'date_execution': fields.datetime('Execution Date', required=True, select=1, readonly=True, states={'draft':[('readonly',False)],'released':[('readonly',False)],'ready':[('readonly',False)]}),
'parts_lines': fields.one2many('mro.order.parts.line', 'maintenance_id', 'Planned parts',
readonly=True, states={'draft':[('readonly',False)]}),
'parts_ready_lines': fields.function(_get_available_parts, relation="stock.move", method=True, type="one2many", multi='parts'),
'parts_move_lines': fields.function(_get_available_parts, relation="stock.move", method=True, type="one2many", multi='parts'),
'parts_moved_lines': fields.function(_get_available_parts, relation="stock.move", method=True, type="one2many", multi='parts'),
'tools_description': fields.text('Tools Description',translate=True),
'labor_description': fields.text('Labor Description',translate=True),
'operations_description': fields.text('Operations Description',translate=True),
'documentation_description': fields.text('Documentation Description',translate=True),
'problem_description': fields.text('Problem Description'),
'company_id': fields.many2one('res.company','Company',required=True, readonly=True, states={'draft':[('readonly',False)]}),
'procurement_group_id': fields.many2one('procurement.group', 'Procurement group', copy=False),
}
_defaults = {
'state': lambda *a: 'draft',
'maintenance_type': lambda *a: 'bm',
'date_planned': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'date_scheduled': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'date_execution': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'mro.order', context=c),
}
然后有一个按钮是"完成"这将完成维护订单的流程
def action_done(self, cr, uid, ids, context=None):
for order in self.browse(cr, uid, ids, context=context):
self.pool.get('stock.move').action_done(cr, uid, [x.id for x in order.parts_move_lines])
self.write(cr, uid, ids, {'state': 'done', 'date_execution': time.strftime('%Y-%m-%d %H:%M:%S')})
return True
我想要当" DONE"单击按钮," date_execution"的值MRO.ORDER的字段值将更新为"执行日期" MRO.REQUEST的领域
对于这种情况,我尝试使用以下代码:
def action_done(self, cr, uid, ids, context=None):
sobj = self.pool.get('mro.request')
sobj1 = self.browse(cr, uid, ids)
for order in self.browse(cr, uid, ids, context=context):
ref_date = sobj1.date_execution
self.pool.get('stock.move').action_done(cr, uid, [x.id for x in order.parts_move_lines])
sobj2 = sobj.browse(cr, uid, ids, [('name','=','sobj1.origin')])
sobj2.write(cr, uid, ids, {'execution_date':'ref_date'})
self.write(cr, uid, ids, {'state': 'done', 'date_execution': time.strftime('%Y-%m-%d %H:%M:%S')})
return True
好吧,直到现在我都无法成功。有建议的任何人都会非常有帮助。谢谢!!!