Merge lp:~camptocamp/openobject-addons/7.0-fix_1220716-rha+srt+afe into lp:openobject-addons/7.0

Proposed by Alexandre Fayolle - camptocamp
Status: Needs review
Proposed branch: lp:~camptocamp/openobject-addons/7.0-fix_1220716-rha+srt+afe
Merge into: lp:openobject-addons/7.0
Diff against target: 126 lines (+61/-13)
4 files modified
purchase_requisition/purchase_requisition.py (+37/-6)
purchase_requisition/test/cancel_purchase_requisition.yml (+6/-6)
purchase_requisition/test/purchase_requisition.yml (+11/-0)
purchase_requisition/test/purchase_requisition_demo.yml (+7/-1)
To merge this branch: bzr merge lp:~camptocamp/openobject-addons/7.0-fix_1220716-rha+srt+afe
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+209937@code.launchpad.net

Description of the change

I rebased the changes of Rifakat <email address hidden> on top of the 7.0 branch, fixing the conflicts in the way Stefan Rijnhart (Therp) (stefan-therp) suggested in the other MP, and added fixes I made for OCB in order to repair the tests so that runbot should be green for this branch.

To post a comment you must log in.
Revision history for this message
Rifakat Husen (OpenERP) (rha-openerp) wrote :

Hi,

_requisition_procurement_cancel() would become private method, could we change the name? What do you say?

Regards.

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

Hi Rifakat,

I think that introducing a new public method in stable is not accepted, so in order to give this patch a chance of getting merged I'm -1 on changing the name.

Revision history for this message
Rifakat Husen (OpenERP) (rha-openerp) wrote :

Yes right. Thanks Alexandre.

Unmerged revisions

9878. By Alexandre Fayolle - camptocamp on 2014-03-07

[FIX] purchase_requisition: fix broken test

cancel_purchase_requisition.yml:
  * use a different requisition from the one processed int purchase_requision.yml
  * fix the 'I delete requisition' step which used to destroy a purchase.order

purchase_requisition.yml:
  * add a check taht the purchase.requisition cannot be cancelled if the purchase.order are not cancelled first.

9877. By Rifakat Husen (OpenERP) on 2013-06-12

[IMP] refactorize code by adding new function to be reused from unlink() and tender_cancel()

9876. By Rifakat Husen (OpenERP) on 2013-06-12

[FIX] purchase_requisition: restricitng deletion of PR and also imp for cancelling PR

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'purchase_requisition/purchase_requisition.py'
2--- purchase_requisition/purchase_requisition.py 2013-11-26 18:07:26 +0000
3+++ purchase_requisition/purchase_requisition.py 2014-03-07 14:48:16 +0000
4@@ -65,14 +65,45 @@
5 'name': self.pool.get('ir.sequence').get(cr, uid, 'purchase.order.requisition'),
6 })
7 return super(purchase_requisition, self).copy(cr, uid, id, default, context)
8-
9+
10+ def unlink(self, cr, uid, ids, context=None):
11+ """
12+ Deletes Requisition and related RFQs
13+ """
14+ if context is None: context = {}
15+ purchase_obj = self.pool.get('purchase.order')
16+ purchase_ids = self._requisition_procurement_cancel(cr, uid, ids, context=context)
17+ if purchase_ids:
18+ purchase_obj.unlink(cr, uid, purchase_ids, context=context)
19+ return super(purchase_requisition, self).unlink(cr, uid, ids, context=context)
20+
21+ def _requisition_procurement_cancel(self, cr, uid, ids, context=None):
22+ """
23+ Cancels procurement order related to requisition
24+ @param ids: requisition ids
25+ @return: Returns purchase orders associated with requisition if any
26+ """
27+ if context is None: context = {}
28+ purchase_ids = []
29+ procurement_ids = []
30+ procurement_obj = self.pool.get('procurement.order')
31+ for requisition in self.browse(cr, uid, ids, context=context):
32+ purchase_ids.extend(purchase.id for purchase in requisition.purchase_ids)
33+ if requisition.state == 'cancel':
34+ continue
35+ procurement_ids.extend(procurement_obj.search(cr, uid,
36+ [('requisition_id', '=', requisition.id)], context=context))
37+ if procurement_ids:
38+ procurement_obj.action_cancel(cr, uid, procurement_ids)
39+ return purchase_ids
40+
41 def tender_cancel(self, cr, uid, ids, context=None):
42+ if context is None: context = {}
43 purchase_order_obj = self.pool.get('purchase.order')
44- for purchase in self.browse(cr, uid, ids, context=context):
45- for purchase_id in purchase.purchase_ids:
46- if str(purchase_id.state) in('draft'):
47- purchase_order_obj.action_cancel(cr,uid,[purchase_id.id])
48- return self.write(cr, uid, ids, {'state': 'cancel'})
49+ purchase_ids = self._requisition_procurement_cancel(cr, uid, ids, context=context)
50+ if purchase_ids:
51+ purchase_order_obj.action_cancel(cr, uid, purchase_ids, context=context)
52+ return self.write(cr, uid, ids, {'state': 'cancel'}, context=context)
53
54 def tender_in_progress(self, cr, uid, ids, context=None):
55 return self.write(cr, uid, ids, {'state':'in_progress'} ,context=context)
56
57=== modified file 'purchase_requisition/test/cancel_purchase_requisition.yml'
58--- purchase_requisition/test/cancel_purchase_requisition.yml 2011-12-02 05:15:06 +0000
59+++ purchase_requisition/test/cancel_purchase_requisition.yml 2014-03-07 14:48:16 +0000
60@@ -2,25 +2,25 @@
61 I cancel requisition.
62 -
63 !python {model: purchase.requisition}: |
64- self.tender_cancel(cr, uid, [ref("requisition1")])
65+ self.tender_cancel(cr, uid, [ref("requisition2")])
66 -
67 I check requisition after cancelled.
68 -
69- !assert {model: purchase.requisition, id: requisition1}:
70+ !assert {model: purchase.requisition, id: requisition2}:
71 - state == 'cancel'
72 -
73 I reset requisition as "New".
74 -
75 !python {model: purchase.requisition}: |
76- self.tender_reset(cr, uid, [ref('requisition1')])
77+ self.tender_reset(cr, uid, [ref('requisition2')])
78 -
79 I duplicate requisition.
80 -
81 !python {model: purchase.requisition}: |
82- self.copy(cr, uid, ref('requisition1'))
83+ self.copy(cr, uid, ref('requisition2'))
84 -
85 I delete requisition.
86 -
87- !python {model: purchase.order}: |
88- self.unlink(cr, uid, [ref("requisition1")])
89+ !python {model: purchase.requisition}: |
90+ self.unlink(cr, uid, [ref("requisition2")])
91
92
93=== modified file 'purchase_requisition/test/purchase_requisition.yml'
94--- purchase_requisition/test/purchase_requisition.yml 2012-11-29 22:26:45 +0000
95+++ purchase_requisition/test/purchase_requisition.yml 2014-03-07 14:48:16 +0000
96@@ -88,3 +88,14 @@
97 (data, format) = netsvc.LocalService('report.purchase.requisition').create(cr, uid, [ref('purchase_requisition.requisition1')], {}, {})
98 if tools.config['test_report_directory']:
99 file(os.path.join(tools.config['test_report_directory'], 'purchase_requisition-purchase_requisition_report.'+format), 'wb+').write(data)
100+-
101+ I check that I cannot cancel the requisision
102+-
103+ !python {model: purchase.requisition}: |
104+ from openerp.osv.osv import except_osv
105+ try:
106+ self.tender_cancel(cr, uid, [ref("requisition1")])
107+ except except_osv, exc:
108+ assert exc.args == (u'Unable to cancel this purchase order.', u'First cancel all receptions related to this purchase order.')
109+ else:
110+ assert False, 'tender_cancel should have failed'
111
112=== modified file 'purchase_requisition/test/purchase_requisition_demo.yml'
113--- purchase_requisition/test/purchase_requisition_demo.yml 2013-01-03 23:10:05 +0000
114+++ purchase_requisition/test/purchase_requisition_demo.yml 2014-03-07 14:48:16 +0000
115@@ -7,4 +7,10 @@
116 - product_id: product.product_product_9
117 product_qty: 10.0
118 product_uom_id: product.product_uom_unit
119-
120+-
121+ !record {model: purchase.requisition, id: requisition2}:
122+ exclusive: exclusive
123+ line_ids:
124+ - product_id: product.product_product_13
125+ product_qty: 10.0
126+ product_uom_id: product.product_uom_unit