mrp operation and purchase workflow improvements
bzr revid: hda@tinyerp.com-20081022102847-tmwvy5b43zim489j
This commit is contained in:
commit
455eced1cd
|
@ -58,7 +58,7 @@ class mrp_production_workcenter_line(osv.osv):
|
|||
'product':fields.related('production_id','product_id',type='many2one',relation='product.product',string='Product'),
|
||||
'qty':fields.related('production_id','product_qty',type='float',string='Qty'),
|
||||
'uom':fields.related('production_id','product_uom',type='many2one',relation='product.uom',string='UOM'),
|
||||
|
||||
|
||||
|
||||
}
|
||||
_defaults = {
|
||||
|
@ -70,8 +70,8 @@ class mrp_production_workcenter_line(osv.osv):
|
|||
wf_service = netsvc.LocalService("workflow")
|
||||
oper_obj=self.browse(cr,uid,ids)[0]
|
||||
prod_obj=self.pool.get('mrp.production').browse(cr,uid,[oper_obj.production_id.id])[0]
|
||||
if action=='start':
|
||||
if prod_obj.state =='ready':
|
||||
if action=='start':
|
||||
if prod_obj.state =='ready':
|
||||
wf_service.trg_validate(uid, 'mrp.production', prod_obj.id, 'button_produce', cr)
|
||||
elif prod_obj.state =='in_production':
|
||||
return
|
||||
|
@ -87,35 +87,29 @@ class mrp_production_workcenter_line(osv.osv):
|
|||
if flag:
|
||||
wf_service.trg_validate(uid, 'mrp.production', oper_obj.production_id.id, 'button_produce_done', cr)
|
||||
return
|
||||
|
||||
|
||||
def action_draft(self, cr, uid, ids):
|
||||
self.write(cr, uid, ids, {'state':'draft'})
|
||||
# self.write(cr, uid, ids, {'state':'draft','date_start':None})
|
||||
return True
|
||||
|
||||
def action_start_working(self, cr, uid, ids):
|
||||
self.modify_production_order_state(cr,uid,ids,'start')
|
||||
self.write(cr, uid, ids, {'state':'startworking'})
|
||||
# self.write(cr, uid, ids, {'state':'confirm','date_start':DateTime.now().strftime('%Y-%m-%d %H:%M:%S')})
|
||||
return True
|
||||
|
||||
def action_done(self, cr, uid, ids):
|
||||
self.write(cr, uid, ids, {'state':'done'})
|
||||
self.modify_production_order_state(cr,uid,ids,'done')
|
||||
# self.write(cr, uid, ids, {'state':'done','date_finnished':DateTime.now().strftime('%Y-%m-%d %H:%M:%S')})
|
||||
return True
|
||||
|
||||
def action_cancel(self, cr, uid, ids):
|
||||
self.write(cr, uid, ids, {'state':'cancel'})
|
||||
# self.write(cr, uid, ids, {'state':'cancel','date_start':None})
|
||||
return True
|
||||
|
||||
|
||||
def action_pause(self, cr, uid, ids):
|
||||
print "callled THE ACTUAL PAUSE"
|
||||
self.write(cr, uid, ids, {'state':'pause'})
|
||||
# self.write(cr, uid, ids, {'state':'draft','date_start':None})
|
||||
return True
|
||||
|
||||
|
||||
def action_resume(self, cr, uid, ids):
|
||||
self.write(cr, uid, ids, {'state':'startworking'})
|
||||
return True
|
||||
|
@ -127,18 +121,12 @@ class mrp_production(osv.osv):
|
|||
_inherit = 'mrp.production'
|
||||
_description = 'Production'
|
||||
|
||||
# def action_confirm(self, cr, uid, ids):
|
||||
# obj=self.browse(cr,uid,ids)[0]
|
||||
# for workcenter_line in obj.workcenter_lines:
|
||||
# tmp=self.pool.get('mrp.production.workcenter.line').action_start_working(cr,uid,[workcenter_line.id])
|
||||
# return super(mrp_production,self).action_confirm(cr,uid,ids)
|
||||
|
||||
def action_production_end(self, cr, uid, ids):
|
||||
obj=self.browse(cr,uid,ids)[0]
|
||||
for workcenter_line in obj.workcenter_lines:
|
||||
tmp=self.pool.get('mrp.production.workcenter.line').action_done(cr,uid,[workcenter_line.id])
|
||||
return super(mrp_production,self).action_production_end(cr,uid,ids)
|
||||
#
|
||||
|
||||
def action_cancel(self, cr, uid, ids):
|
||||
obj=self.browse(cr,uid,ids)[0]
|
||||
for workcenter_line in obj.workcenter_lines:
|
||||
|
@ -158,32 +146,32 @@ mrp_operations_operation_code()
|
|||
|
||||
class mrp_operations_operation(osv.osv):
|
||||
_name="mrp_operations.operation"
|
||||
|
||||
|
||||
def _order_date_search_production(self,cr,uid,ids):
|
||||
operation_ids=self.pool.get('mrp_operations.operation').search(cr,uid,[('production_id','=',ids[0])])
|
||||
return operation_ids
|
||||
|
||||
|
||||
def _get_order_date(self, cr, uid, ids, field_name, arg, context):
|
||||
res={}
|
||||
operation_obj=self.browse(cr, uid, ids, context=context)
|
||||
for operation in operation_obj:
|
||||
res[operation.id]=operation.production_id.date_planned
|
||||
return res
|
||||
|
||||
|
||||
def calc_delay(self,cr,uid,vals):
|
||||
code_lst=[]
|
||||
time_lst=[]
|
||||
|
||||
|
||||
code_ids=self.pool.get('mrp_operations.operation.code').search(cr,uid,[('id','=',vals['code_id'])])
|
||||
code=self.pool.get('mrp_operations.operation.code').browse(cr,uid,code_ids)[0]
|
||||
|
||||
|
||||
oper_ids=self.search(cr,uid,[('production_id','=',vals['production_id']),('workcenter_id','=',vals['workcenter_id'])])
|
||||
oper_objs=self.browse(cr,uid,oper_ids)
|
||||
|
||||
|
||||
for oper in oper_objs:
|
||||
code_lst.append(oper.code_id.start_stop)
|
||||
time_lst.append(oper.date_start)
|
||||
|
||||
|
||||
code_lst.append(code.start_stop)
|
||||
time_lst.append(vals['date_start'])
|
||||
h=m=s=days=0
|
||||
|
@ -211,34 +199,34 @@ class mrp_operations_operation(osv.osv):
|
|||
h=0
|
||||
delay=str(days) +" Days "+ str(h) + " hrs and " + str(m)+ " mins"
|
||||
return delay
|
||||
|
||||
|
||||
def check_operation(self,cr,uid,vals):
|
||||
code_ids=self.pool.get('mrp_operations.operation.code').search(cr,uid,[('id','=',vals['code_id'])])
|
||||
code=self.pool.get('mrp_operations.operation.code').browse(cr,uid,code_ids)[0]
|
||||
code_lst = []
|
||||
oper_ids=self.search(cr,uid,[('production_id','=',vals['production_id']),('workcenter_id','=',vals['workcenter_id'])])
|
||||
oper_objs=self.browse(cr,uid,oper_ids)
|
||||
|
||||
|
||||
if not oper_objs:
|
||||
if code.start_stop!='start':
|
||||
raise osv.except_osv(_('Sorry!'),_('Operation is not started yet !'))
|
||||
return False
|
||||
else:
|
||||
else:
|
||||
for oper in oper_objs:
|
||||
code_lst.append(oper.code_id.start_stop)
|
||||
if code.start_stop=='start':
|
||||
if 'start' in code_lst:
|
||||
if 'start' in code_lst:
|
||||
raise osv.except_osv(_('Sorry!'),_('Operation has already started !' 'You can either Pause /Finish/Cancel the operation'))
|
||||
return False
|
||||
if code.start_stop=='pause':
|
||||
if code_lst[len(code_lst)-1]!='resume' and code_lst[len(code_lst)-1]!='start':
|
||||
if code_lst[len(code_lst)-1]!='resume' and code_lst[len(code_lst)-1]!='start':
|
||||
raise osv.except_osv(_('Error!'),_('You cannot Pause the Operation other then Start/Resume state !'))
|
||||
return False
|
||||
if code.start_stop=='resume':
|
||||
if code_lst[len(code_lst)-1]!='pause':
|
||||
if code.start_stop=='resume':
|
||||
if code_lst[len(code_lst)-1]!='pause':
|
||||
raise osv.except_osv(_('Error!'),_(' You cannot Resume the operation other then Pause state !'))
|
||||
return False
|
||||
|
||||
|
||||
if code.start_stop=='done':
|
||||
if code_lst[len(code_lst)-1]!='start' and code_lst[len(code_lst)-1]!='resume':
|
||||
raise osv.except_osv(_('Sorry!'),_('You cannot finish the operation without Starting/Resuming it !'))
|
||||
|
@ -254,24 +242,24 @@ class mrp_operations_operation(osv.osv):
|
|||
raise osv.except_osv(_('Error!'),_('Operation is already finished !'))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
oper_objs=self.browse(cr,uid,ids)[0]
|
||||
vals['production_id']=oper_objs.production_id.id
|
||||
vals['workcenter_id']=oper_objs.workcenter_id.id
|
||||
|
||||
|
||||
if 'code_id' in vals:
|
||||
self.check_operation(cr, uid, vals)
|
||||
|
||||
|
||||
if 'date_start' in vals:
|
||||
vals['date_start']=vals['date_start']
|
||||
vals['code_id']=oper_objs.code_id.id
|
||||
delay=self.calc_delay(cr, uid, vals)
|
||||
wc_op_id=self.pool.get('mrp.production.workcenter.line').search(cr,uid,[('workcenter_id','=',vals['workcenter_id']),('production_id','=',vals['production_id'])])
|
||||
self.pool.get('mrp.production.workcenter.line').write(cr,uid,wc_op_id,{'delay':delay})
|
||||
|
||||
|
||||
return super(mrp_operations_operation, self).write(cr, uid, ids, vals, context=context)
|
||||
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
wf_service = netsvc.LocalService('workflow')
|
||||
code_ids=self.pool.get('mrp_operations.operation.code').search(cr,uid,[('id','=',vals['code_id'])])
|
||||
|
@ -281,31 +269,34 @@ class mrp_operations_operation(osv.osv):
|
|||
if not wc_op_id:
|
||||
production_obj=self.pool.get('mrp.production').browse(cr,uid,vals['production_id'])
|
||||
wc_op_id.append(self.pool.get('mrp.production.workcenter.line').create(cr,uid,{'production_id':vals['production_id'],'name':production_obj.product_id.name,'workcenter_id':vals['workcenter_id']}))
|
||||
|
||||
if code.start_stop=='start':
|
||||
tmp=self.pool.get('mrp.production.workcenter.line').action_start_working(cr,uid,wc_op_id)
|
||||
|
||||
wf_service.trg_validate(uid, 'mrp.production.workcenter.line', wc_op_id[0], 'button_start_working', cr)
|
||||
|
||||
if code.start_stop=='done':
|
||||
tmp=self.pool.get('mrp.production.workcenter.line').action_done(cr,uid,wc_op_id)
|
||||
wf_service.trg_validate(uid, 'mrp.production.workcenter.line', wc_op_id[0], 'button_done', cr)
|
||||
self.pool.get('mrp.production').write(cr,uid,vals['production_id'],{'date_finnished':DateTime.now().strftime('%Y-%m-%d %H:%M:%S')})
|
||||
|
||||
|
||||
if code.start_stop=='pause':
|
||||
print "in PAUSE"
|
||||
tmp=self.pool.get('mrp.production.workcenter.line').action_pause(cr,uid,wc_op_id)
|
||||
|
||||
wf_service.trg_validate(uid, 'mrp.production.workcenter.line', wc_op_id[0], 'button_pause', cr)
|
||||
|
||||
if code.start_stop=='resume':
|
||||
tmp=self.pool.get('mrp.production.workcenter.line').action_resume(cr,uid,wc_op_id)
|
||||
|
||||
wf_service.trg_validate(uid, 'mrp.production.workcenter.line', wc_op_id[0], 'button_resume', cr)
|
||||
|
||||
if code.start_stop=='cancel':
|
||||
tmp=self.pool.get('mrp.production.workcenter.line').action_cancel(cr,uid,wc_op_id)
|
||||
|
||||
wf_service.trg_validate(uid, 'mrp.production.workcenter.line', wc_op_id[0], 'button_cancel', cr)
|
||||
|
||||
if not self.check_operation(cr, uid, vals):
|
||||
return
|
||||
delay=self.calc_delay(cr, uid, vals)
|
||||
self.pool.get('mrp.production.workcenter.line').write(cr,uid,wc_op_id,{'delay':delay})
|
||||
|
||||
|
||||
return super(mrp_operations_operation, self).create(cr, uid, vals, context=context)
|
||||
|
||||
|
||||
_columns={
|
||||
'production_id':fields.many2one('mrp.production','Production',required=True),
|
||||
'workcenter_id':fields.many2one('mrp.workcenter','Workcenter',required=True),
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<field name="arch" type="xml">
|
||||
<field name="hour" position="after">
|
||||
<button name="button_done" string="Finished" states="startworking"/>
|
||||
<button name="button_start_working" string="Start working" states="draft,pause"/>
|
||||
<button name="button_start_working" string="Start working" states="draft,pause"/>
|
||||
<field name="uom"/>
|
||||
<field name="qty"/>
|
||||
<field name="product"/>
|
||||
|
@ -167,7 +167,7 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
||||
|
||||
<!--<record model="ir.ui.view" id="mrp_production_operation_form_view">
|
||||
<field name="name">mrp.production.operation.form</field>
|
||||
|
@ -191,12 +191,12 @@
|
|||
<field name="view_id" ref="mrp_production_operation_tree_view"/>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
<menuitem
|
||||
name="Work Order Events Using Bar Codes"
|
||||
parent="mrp.menu_mrp_root"
|
||||
id="menu_mrp_production_operation_action"
|
||||
parent="mrp.menu_mrp_root"
|
||||
id="menu_mrp_production_operation_action"
|
||||
action="mrp_production_operation_action"/>
|
||||
|
||||
|
||||
<record model="ir.ui.view" id="operation_calendar_view">
|
||||
<field name="name">mrp.perations.calendar</field>
|
||||
<field name="model">mrp_operations.operation</field>
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
<field name="flow_stop">True</field>
|
||||
<field name="action">action_done()</field>
|
||||
</record>
|
||||
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# Transition
|
||||
# -----------------------------------------------------------
|
||||
|
@ -84,11 +84,29 @@
|
|||
<field name="act_to" ref="prod_act_wc_pause"/>
|
||||
<field name="signal">button_pause</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record model="workflow.transition" id="prod_trans_wc_pause_resume">
|
||||
<field name="act_from" ref="prod_act_wc_pause"/>
|
||||
<field name="act_to" ref="prod_act_wc_resume"/>
|
||||
<field name="signal">button_resume</field>
|
||||
</record>
|
||||
|
||||
<record model="workflow.transition" id="prod_trans_wc_resume_pause">
|
||||
<field name="act_from" ref="prod_act_wc_resume"/>
|
||||
<field name="act_to" ref="prod_act_wc_pause"/>
|
||||
<field name="signal">button_pause</field>
|
||||
</record>
|
||||
<record model="workflow.transition" id="prod_trans_wc_resume_cancel">
|
||||
<field name="act_from" ref="prod_act_wc_resume"/>
|
||||
<field name="act_to" ref="prod_act_wc_cancel"/>
|
||||
<field name="signal">button_cancel</field>
|
||||
</record>
|
||||
<record model="workflow.transition" id="prod_trans_wc_resume_done">
|
||||
<field name="act_from" ref="prod_act_wc_resume"/>
|
||||
<field name="act_to" ref="prod_act_wc_done"/>
|
||||
<field name="signal">button_done</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -154,7 +154,7 @@ class purchase_order(osv.osv):
|
|||
|
||||
_columns = {
|
||||
'name': fields.char('Order Reference', size=64, required=True, select=True),
|
||||
'origin': fields.char('Origin', size=64,
|
||||
'origin': fields.char('Origin', size=64,
|
||||
help="Reference of the document that generated this purchase order request."
|
||||
),
|
||||
'partner_ref': fields.char('Partner Ref.', size=64),
|
||||
|
@ -173,7 +173,7 @@ class purchase_order(osv.osv):
|
|||
'pricelist_id':fields.many2one('product.pricelist', 'Pricelist', required=True, states={'confirmed':[('readonly',True)], 'approved':[('readonly',True)]}, help="The pricelist sets the currency used for this purchase order. It also computes the supplier price for the selected products/quantities."),
|
||||
|
||||
'state': fields.selection([('draft', 'Request for Quotation'), ('wait', 'Waiting'), ('confirmed', 'Confirmed'), ('approved', 'Approved'),('except_picking', 'Shipping Exception'), ('except_invoice', 'Invoice Exception'), ('done', 'Done'), ('cancel', 'Cancelled')], 'Order Status', readonly=True, help="The state of the purchase order or the quotation request. A quotation is a purchase order in a 'Draft' state. Then the order has to be confirmed by the user, the state switch to 'Confirmed'. Then the supplier must confirm the order to change the state to 'Approved'. When the purchase order is paid and received, the state becomes 'Done'. If a cancel action occurs in the invoice or in the reception of goods, the state becomes in exception.", select=True),
|
||||
'order_line': fields.one2many('purchase.order.line', 'order_id', 'Order Lines', states={'confirmed':[('readonly',True)], 'approved':[('readonly',True)]}),
|
||||
'order_line': fields.one2many('purchase.order.line', 'order_id', 'Order Lines', states={'approved':[('readonly',True)]}),
|
||||
'validator' : fields.many2one('res.users', 'Validated by', readonly=True),
|
||||
'notes': fields.text('Notes'),
|
||||
'invoice_id': fields.many2one('account.invoice', 'Invoice', readonly=True),
|
||||
|
@ -274,6 +274,15 @@ class purchase_order(osv.osv):
|
|||
'account_analytic_id': ol.account_analytic_id.id,
|
||||
})
|
||||
|
||||
def action_cancel_draft(self, cr, uid, ids, *args):
|
||||
if not len(ids):
|
||||
return False
|
||||
self.write(cr, uid, ids, {'state':'draft','shipped':0})
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
for p_id in ids:
|
||||
wf_service.trg_create(uid, 'purchase.order', p_id, cr)
|
||||
return True
|
||||
|
||||
def action_invoice_create(self, cr, uid, ids, *args):
|
||||
res = False
|
||||
for o in self.browse(cr, uid, ids):
|
||||
|
@ -318,6 +327,31 @@ class purchase_order(osv.osv):
|
|||
return True
|
||||
return False
|
||||
|
||||
def action_cancel(self, cr, uid, ids, context={}):
|
||||
ok = True
|
||||
purchase_order_line_obj = self.pool.get('purchase.order.line')
|
||||
for purchase in self.browse(cr, uid, ids):
|
||||
for pick in purchase.picking_ids:
|
||||
if pick.state not in ('draft','cancel'):
|
||||
raise osv.except_osv(
|
||||
_('Could not cancel purchase order !'),
|
||||
_('You must first cancel all packings attached to this purchase order.'))
|
||||
for r in self.read(cr,uid,ids,['picking_ids']):
|
||||
for pick in r['picking_ids']:
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
wf_service.trg_validate(uid, 'stock.picking', pick, 'button_cancel', cr)
|
||||
for inv in purchase.invoice_ids:
|
||||
if inv.state not in ('draft','cancel'):
|
||||
raise osv.except_osv(
|
||||
_('Could not cancel this purchase order !'),
|
||||
_('You must first cancel all invoices attached to this purchase order.'))
|
||||
for r in self.read(cr,uid,ids,['invoice_ids']):
|
||||
for inv in r['invoice_ids']:
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
wf_service.trg_validate(uid, 'account.invoice', inv, 'invoice_cancel', cr)
|
||||
self.write(cr,uid,ids,{'state':'cancel'})
|
||||
return True
|
||||
|
||||
def action_picking_create(self,cr, uid, ids, *args):
|
||||
picking_id = False
|
||||
for order in self.browse(cr, uid, ids):
|
||||
|
|
|
@ -63,8 +63,8 @@
|
|||
<button name="purchase_appbuyer" states="wait_auth" string="Approve Purchase"/>
|
||||
<button name="purchase_approve" states="confirmed" string="Approved by Supplier"/>
|
||||
<button name="purchase_cancel" states="draft,confirmed,wait_auth" string="Cancel Purchase Order"/>
|
||||
|
||||
<button name="purchase_cancel" states="approved" string="Cancel Purchase Order"/>
|
||||
<button name="action_cancel_draft" states="cancel" string="Set to Draft" type="object"/>
|
||||
<button name="action_cancel" states="approved" string="Cancel Purchase Order" type="object"/>
|
||||
|
||||
<button name="shipping_ok" states="except_shipping" string="Shipping Done"/>
|
||||
<button name="invoice_ok" states="except_invoice" string="Invoice Done"/>
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
|
||||
<record id="purchase_order" model="workflow">
|
||||
<field name="name">Purchase Order Basic Workflow</field>
|
||||
<field name="osv">purchase.order</field>
|
||||
<field name="on_create">True</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="act_draft" model="workflow.activity">
|
||||
<field name="wkf_id" ref="purchase_order"/>
|
||||
<field name="flow_start">True</field>
|
||||
|
@ -22,9 +22,8 @@
|
|||
<record id="act_cancel" model="workflow.activity">
|
||||
<field name="wkf_id" ref="purchase_order"/>
|
||||
<field name="name">cancel</field>
|
||||
<field name="kind">function</field>
|
||||
<field name="action">write({'state':'cancel'})</field>
|
||||
<field name="kind">stopall</field>
|
||||
<field name="flow_stop">True</field>
|
||||
</record>
|
||||
<record id="act_except_invoice" model="workflow.activity">
|
||||
<field name="wkf_id" ref="purchase_order"/>
|
||||
|
@ -84,7 +83,7 @@
|
|||
<field name="flow_stop">True</field>
|
||||
<field name="join_mode">AND</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="trans_draft_confirmed" model="workflow.transition">
|
||||
<field name="act_from" ref="act_draft"/>
|
||||
<field name="act_to" ref="act_confirmed"/>
|
||||
|
@ -177,6 +176,6 @@
|
|||
<field name="act_from" ref="act_invoice_end"/>
|
||||
<field name="act_to" ref="act_done"/>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
Loading…
Reference in New Issue