From b0a5381dd8ea499bd522fbc4e202bfd133b5bbb5 Mon Sep 17 00:00:00 2001 From: Naresh Choksy Date: Mon, 13 Oct 2008 18:38:08 +0530 Subject: [PATCH] 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 --- addons/purchase/purchase.py | 40 +++++++++++++++++++++++++-- addons/purchase/purchase_view.xml | 4 +-- addons/purchase/purchase_workflow.xml | 11 ++++---- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 84074b0a0ae..5fac8eaff20 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -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: diff --git a/addons/purchase/purchase_view.xml b/addons/purchase/purchase_view.xml index 48a24bee967..1504bd88db9 100644 --- a/addons/purchase/purchase_view.xml +++ b/addons/purchase/purchase_view.xml @@ -63,8 +63,8 @@