1 : put a button [set to draft] when purchase order is cancelled in draft state.

2: removed readonly in confirmed state for order line.
3: kept validation on cancel purchase order validation for pickings and invoices

bzr revid: nch@tinyerp.com-20081013130808-3ya3nhjuufuxcf7q
This commit is contained in:
Naresh Choksy 2008-10-13 18:38:08 +05:30
parent 7b0731a579
commit b0a5381dd8
3 changed files with 44 additions and 11 deletions

View File

@ -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):
@ -327,6 +336,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):
@ -446,7 +480,7 @@ class purchase_order_line(osv.osv):
res = {'value': {'price_unit': price, 'name':prod_name, 'taxes_id':prod['supplier_taxes_id'], 'date_planned': dt,'notes':prod['description_purchase'], 'product_uom': uom}}
domain = {}
taxes = self.pool.get('account.tax').browse(cr, uid,prod['supplier_taxes_id'])
taxep = None
if partner_id:

View File

@ -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"/>

View File

@ -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>