Merge lp:~camptocamp/openerp-humanitarian-ngo/purchase-wkfl-improve-preq-cancel-use-super-nbi into lp:openerp-humanitarian-ngo/purchase-wkfl

Proposed by Nicolas Bessi - Camptocamp
Status: Merged
Merged at revision: 79
Proposed branch: lp:~camptocamp/openerp-humanitarian-ngo/purchase-wkfl-improve-preq-cancel-use-super-nbi
Merge into: lp:openerp-humanitarian-ngo/purchase-wkfl
Diff against target: 123 lines (+71/-16)
3 files modified
purchase_extended/model/purchase_order.py (+4/-0)
purchase_extended/test/process/po2order.yml (+1/-1)
purchase_requisition_extended/model/purchase_requisition.py (+66/-15)
To merge this branch: bzr merge lp:~camptocamp/openerp-humanitarian-ngo/purchase-wkfl-improve-preq-cancel-use-super-nbi
Reviewer Review Type Date Requested Status
OpenERP for Humanitarian Core Editors Pending
Review via email: mp+219989@code.launchpad.net

Description of the change

Fix to enable the use of super

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'purchase_extended/model/purchase_order.py'
2--- purchase_extended/model/purchase_order.py 2014-01-08 14:07:48 +0000
3+++ purchase_extended/model/purchase_order.py 2014-05-19 07:39:04 +0000
4@@ -106,6 +106,10 @@
5 'context': context,
6 }
7
8+ def action_cancel_no_reason(self, cr, uid, ids, context=None):
9+ return super(PurchaseOrder, self).action_cancel(cr, uid, ids,
10+ context=context)
11+
12 def action_cancel_ok(self, cr, uid, ids, context=None):
13 reason_id = self.pool.get('purchase.action_modal_cancelreason').read(cr, uid,
14 context['active_id'], ['reason_id'], context=context,
15
16=== modified file 'purchase_extended/test/process/po2order.yml'
17--- purchase_extended/test/process/po2order.yml 2013-08-13 07:46:34 +0000
18+++ purchase_extended/test/process/po2order.yml 2014-05-19 07:39:04 +0000
19@@ -3,7 +3,7 @@
20 -
21 Create draft PO
22 -
23- !record {model: purchase.order, id: purchase_order_ext_po2order1, context: '{"draft_po": 1}'}:
24+ !record {model: purchase.order, id: purchase_order_ext_po2order1, context: {"draft_po": 1}}:
25 partner_id: base.res_partner_1
26 invoice_method: order
27 date_order: '2013-08-02'
28
29=== modified file 'purchase_requisition_extended/model/purchase_requisition.py'
30--- purchase_requisition_extended/model/purchase_requisition.py 2014-02-20 14:46:52 +0000
31+++ purchase_requisition_extended/model/purchase_requisition.py 2014-05-19 07:39:04 +0000
32@@ -231,25 +231,76 @@
33 _('You do not have valid sent RFQs.'))
34 return super(PurchaseRequisition, self).tender_open(cr, uid, ids, context=context)
35
36+ def _get_po_to_cancel(self, cr, uid, callforbids, context=None):
37+ """Get the list of PO/RFQ that can be canceled on RFQ
38+
39+ :param callforbids: `purchase.requisition` record
40+
41+ :returns: List of candidate PO/RFQ record
42+
43+ """
44+ res = []
45+ for purchase in callforbids.purchase_ids:
46+ if purchase.state in ('draft', 'sent'):
47+ res.append(purchase)
48+ return res
49+
50+ def _check_can_be_canceled(self, callforbids, context=None):
51+ """Raise an exception if callforbids can not be cancelled
52+ :param callforbids: `purchase.requisition` record
53+
54+ :returns: True or raise exception
55+
56+ """
57+ for purchase in callforbids.purchase_ids:
58+ if purchase.state not in ('draft', 'sent'):
59+ raise orm.except_orm(
60+ _('Error'),
61+ _('You cannot cancel a call for bids which '
62+ 'has already received bids.'))
63+ return True
64+
65+ def _cancel_po_with_reason(self, cr, uid, po_list, reason_id, context=None):
66+ """Cancel purchase order of a tender, using given reasons
67+ :param po_list: list of po record to cancel
68+ :param reason_id: reason id of cancelation
69+
70+ :returns: cancel po record list
71+
72+ """
73+ purchase_order_obj = self.pool.get('purchase.order')
74+ purchase_order_obj.write(cr, uid,
75+ [x.id for x in po_list],
76+ {'cancel_reason': reason_id},
77+ context=context)
78+ for order in po_list:
79+ # passing full list raises assert error
80+ purchase_order_obj.action_cancel_no_reason(cr, uid, [order.id],
81+ context=context)
82+ return po_list
83+
84+ def _get_default_reason(self, cr, uid, context=None):
85+ """Return default cancel reason"""
86+ reason = self.pool.get('ir.model.data').get_object_reference(
87+ cr,
88+ uid,
89+ 'purchase_requisition_extended',
90+ 'purchase_cancelreason_callforbids_canceled'
91+ )
92+ return reason[1]
93+
94 def tender_cancel(self, cr, uid, ids, context=None):
95 """
96- Try to cancel all RFQs
97+ Cancel call for bids and try to cancelrelated RFQs/PO
98+
99 """
100- cancel_ids = []
101+ reason_id = self._get_default_reason(cr, uid, context=context)
102 for callforbids in self.browse(cr, uid, ids, context=context):
103- for purchase in callforbids.purchase_ids:
104- if (purchase.state in ('draft', 'sent')):
105- cancel_ids.append(purchase.id)
106- else:
107- raise orm.except_orm(
108- _('Error'),
109- _('You cannot cancel a call for bids which has already received bids.'))
110- if cancel_ids:
111- reason_id = self.pool.get('ir.model.data').get_object_reference(cr, uid,
112- 'purchase_requisition_extended', 'purchase_cancelreason_callforbids_canceled')[1]
113- purchase_order_obj = self.pool.get('purchase.order')
114- purchase_order_obj.write(cr, uid, cancel_ids, {'cancel_reason': reason_id}, context=context)
115- purchase_order_obj.action_cancel(cr, uid, [purchase.id])
116+ self._check_can_be_canceled(callforbids, context=context)
117+ po_to_cancel = self._get_po_to_cancel(cr, uid, callforbids, context=context)
118+ if po_to_cancel:
119+ self._cancel_po_with_reason(cr, uid, po_to_cancel, reason_id,
120+ context=context)
121 return self.write(cr, uid, ids, {'state': 'cancel'})
122
123 def tender_close(self, cr, uid, ids, context=None):

Subscribers

People subscribed via source and target branches