Merge lp:~openerp-dev/openobject-addons/trunk-purchase-requisition-procurement-fix-csn into lp:openobject-addons

Proposed by Cedric Snauwaert (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-purchase-requisition-procurement-fix-csn
Merge into: lp:openobject-addons
Diff against target: 209 lines (+109/-6)
6 files modified
purchase/purchase.py (+2/-0)
purchase/purchase_workflow.xml (+1/-1)
purchase_requisition/__openerp__.py (+1/-0)
purchase_requisition/purchase_requisition.py (+16/-1)
purchase_requisition/purchase_requisition_view.xml (+4/-4)
purchase_requisition/purchase_requisition_workflow.xml (+85/-0)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-purchase-requisition-procurement-fix-csn
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Pending
OpenERP Core Team Pending
Review via email: mp+168613@code.launchpad.net

Description of the change

Using procurement to create a purchase requisition instead of a quotation was not working because procurement workflow was not correct for that case.

Modify procurement workflow to make it work with purchase requisition (this needed a workflow for the purchase requisition). Also, in order for procurement workflow to finish, we need to complete the stock move, so had to add a move_dest_id on purchase requisition object in order to forward it to quotation generated from the purchase requisition.

To post a comment you must log in.
Revision history for this message
Paulius Sladkevičius @ hbee (komsas) wrote :

I've tried to apply this patch on the v7.0. I've made few test. It worked fine.

What I'm missing here are unit-tests that could 100% approve correct behavior of procurement workflow with PR.

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Just to say that I'm basing my work to merge purchase requisitions[1] on this branch and it's working fine. However, your branch now probably has conflicts due to an improvement on retrieving the warehouse from a procurement order.

[1] https://code.launchpad.net/~therp-nl/openobject-addons/trunk-merge_purchase_requisitions/+merge/192871

Unmerged revisions

8758. By Cedric Snauwaert (OpenERP)

[FIX]purchase_requisition: missing import

8757. By Cedric Snauwaert (OpenERP)

[FIX]purchase_requisition: fix procurement workflow in case we want to create a requisition instead of a quotation when using procurement for a product. It needs to separate the workflow

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'purchase/purchase.py'
2--- purchase/purchase.py 2013-05-21 12:23:59 +0000
3+++ purchase/purchase.py 2013-06-11 08:11:29 +0000
4@@ -1060,6 +1060,8 @@
5 return False
6 return True
7
8+ def check_product_requisition(self, cr, uid, ids, context=None):
9+ return False
10
11 def action_po_assign(self, cr, uid, ids, context=None):
12 """ This is action which call from workflow to assign purchase order to procurements
13
14=== modified file 'purchase/purchase_workflow.xml'
15--- purchase/purchase_workflow.xml 2013-04-29 14:01:42 +0000
16+++ purchase/purchase_workflow.xml 2013-06-11 08:11:29 +0000
17@@ -214,7 +214,7 @@
18 <record id="trans_confirm_mto_purchase" model="workflow.transition">
19 <field name="act_from" ref="procurement.act_confirm_mto"/>
20 <field name="act_to" ref="act_buy"/>
21- <field name="condition">check_buy() and check_supplier_info()</field>
22+ <field name="condition">check_buy() and check_supplier_info() and not check_product_requisition()</field>
23 </record>
24
25 <record id="trans_buy_make_done" model="workflow.transition">
26
27=== modified file 'purchase_requisition/__openerp__.py'
28--- purchase_requisition/__openerp__.py 2012-11-29 22:26:45 +0000
29+++ purchase_requisition/__openerp__.py 2013-06-11 08:11:29 +0000
30@@ -39,6 +39,7 @@
31 'purchase_requisition_data.xml',
32 'purchase_requisition_view.xml',
33 'purchase_requisition_report.xml',
34+ 'purchase_requisition_workflow.xml',
35 'security/ir.model.access.csv','purchase_requisition_sequence.xml'
36 ],
37 'auto_install': False,
38
39=== modified file 'purchase_requisition/purchase_requisition.py'
40--- purchase_requisition/purchase_requisition.py 2013-04-15 10:23:49 +0000
41+++ purchase_requisition/purchase_requisition.py 2013-06-11 08:11:29 +0000
42@@ -24,6 +24,7 @@
43 import time
44
45 from openerp.osv import fields,osv
46+from openerp import netsvc
47 from openerp.tools.translate import _
48 import openerp.addons.decimal_precision as dp
49
50@@ -42,6 +43,7 @@
51 'company_id': fields.many2one('res.company', 'Company', required=True),
52 'purchase_ids' : fields.one2many('purchase.order','requisition_id','Purchase Orders',states={'done': [('readonly', True)]}),
53 'line_ids' : fields.one2many('purchase.requisition.line','requisition_id','Products to Purchase',states={'done': [('readonly', True)]}),
54+ 'move_dest_id': fields.many2one('stock.move', 'Reservation Destination', ondelete='set null'),
55 'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse'),
56 'state': fields.selection([('draft','New'),('in_progress','Sent to Suppliers'),('cancel','Cancelled'),('done','Purchase Done')],
57 'Status', track_visibility='onchange', required=True)
58@@ -77,7 +79,13 @@
59 return self.write(cr, uid, ids, {'state':'in_progress'} ,context=context)
60
61 def tender_reset(self, cr, uid, ids, context=None):
62- return self.write(cr, uid, ids, {'state': 'draft'})
63+ self.write(cr, uid, ids, {'state': 'draft'})
64+ wf_service = netsvc.LocalService("workflow")
65+ for p_id in ids:
66+ # Deleting the existing instance of workflow for PO
67+ wf_service.trg_delete(uid, 'purchase.requisition', p_id, cr)
68+ wf_service.trg_create(uid, 'purchase.requisition', p_id, cr)
69+ return True
70
71 def tender_done(self, cr, uid, ids, context=None):
72 return self.write(cr, uid, ids, {'state':'done', 'date_end':time.strftime('%Y-%m-%d %H:%M:%S')}, context=context)
73@@ -160,6 +168,7 @@
74 'price_unit': seller_price,
75 'date_planned': date_planned,
76 'taxes_id': [(6, 0, taxes)],
77+ 'move_dest_id': requisition.move_dest_id.id,
78 }, context=context)
79
80 return res
81@@ -246,6 +255,7 @@
82 'date_end': procurement.date_planned,
83 'warehouse_id':warehouse_id and warehouse_id[0] or False,
84 'company_id':procurement.company_id.id,
85+ 'move_dest_id':procurement.move_id.id,
86 'line_ids': [(0,0,{
87 'product_id': procurement.product_id.id,
88 'product_uom_id': procurement.product_uom.id,
89@@ -258,5 +268,10 @@
90 res = super(procurement_order, self).make_po(cr, uid, ids, context=context)
91 return res
92
93+ def check_product_requisition(self, cr, uid, ids, context=None):
94+ procurement = self.browse(cr, uid, ids, context=context)[0]
95+ if procurement.product_id.purchase_requisition:
96+ return True
97+ return False
98
99 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
100
101=== modified file 'purchase_requisition/purchase_requisition_view.xml'
102--- purchase_requisition/purchase_requisition_view.xml 2013-02-25 13:38:04 +0000
103+++ purchase_requisition/purchase_requisition_view.xml 2013-06-11 08:11:29 +0000
104@@ -30,10 +30,10 @@
105 <field name="arch" type="xml">
106 <form string="Purchase Requisition" version="7.0">
107 <header>
108- <button name="tender_in_progress" states="draft" string="Send to Suppliers" type="object" class="oe_highlight"/>
109- <button name="tender_reset" states="done,cancel" string="Reset to Draft" type="object" />
110- <button name="tender_done" states="in_progress" string="Purchase Done" type="object" class="oe_highlight"/>
111- <button name="tender_cancel" states="draft,in_progress" string="Cancel Requisition" type="object" />
112+ <button name="sent_suppliers" states="draft" string="Send to Suppliers" class="oe_highlight"/>
113+ <button name="tender_reset" states="done,cancel" string="Reset to Draft" type="object"/>
114+ <button name="done" states="in_progress" string="Purchase Done" class="oe_highlight"/>
115+ <button name="cancel_requisition" states="draft,in_progress" string="Cancel Requisition" />
116 <field name="state" widget="statusbar" statusbar_visible="draft,in_progress,done" statusbar_colors='{"in_progress":"blue"}'/>
117 </header>
118 <sheet>
119
120=== added file 'purchase_requisition/purchase_requisition_workflow.xml'
121--- purchase_requisition/purchase_requisition_workflow.xml 1970-01-01 00:00:00 +0000
122+++ purchase_requisition/purchase_requisition_workflow.xml 2013-06-11 08:11:29 +0000
123@@ -0,0 +1,85 @@
124+<?xml version="1.0" encoding="utf-8"?>
125+<openerp>
126+ <data>
127+
128+ <record id="purchase_requisition_workflow" model="workflow">
129+ <field name="name">Purchase Requisition Basic Workflow</field>
130+ <field name="osv">purchase.requisition</field>
131+ <field name="on_create">True</field>
132+ </record>
133+
134+ <record id="act_draft" model="workflow.activity">
135+ <field name="wkf_id" ref="purchase_requisition_workflow"/>
136+ <field name="flow_start">True</field>
137+ <field name="name">draft</field>
138+ </record>
139+ <record id="act_sent" model="workflow.activity">
140+ <field name="wkf_id" ref="purchase_requisition_workflow"/>
141+ <field name="name">sent</field>
142+ <field name="kind">function</field>
143+ <field name="action">tender_in_progress()</field>
144+ </record>
145+ <record id="act_cancel" model="workflow.activity">
146+ <field name="wkf_id" ref="purchase_requisition_workflow"/>
147+ <field name="name">cancel</field>
148+ <field name="kind">function</field>
149+ <field name="flow_stop">True</field>
150+ <field name="action">tender_cancel()</field>
151+ </record>
152+ <record id="act_done" model="workflow.activity">
153+ <field name="wkf_id" ref="purchase_requisition_workflow"/>
154+ <field name="name">done</field>
155+ <field name="action">tender_done()</field>
156+ <field name="kind">function</field>
157+ <field name="flow_stop">True</field>
158+ </record>
159+
160+ <record id="trans_draft_sent" model="workflow.transition">
161+ <field name="act_from" ref="act_draft"/>
162+ <field name="act_to" ref="act_sent"/>
163+ <field name="signal">sent_suppliers</field>
164+ </record>
165+ <record id="trans_draft_cancel" model="workflow.transition">
166+ <field name="act_from" ref="act_draft"/>
167+ <field name="act_to" ref="act_cancel"/>
168+ <field name="signal">cancel_requisition</field>
169+ </record>
170+ <record id="trans_sent_done" model="workflow.transition">
171+ <field name="act_from" ref="act_sent"/>
172+ <field name="act_to" ref="act_done"/>
173+ <field name="signal">done</field>
174+ </record>
175+ <record id="trans_sent_cancel" model="workflow.transition">
176+ <field name="act_from" ref="act_sent"/>
177+ <field name="act_to" ref="act_cancel"/>
178+ <field name="signal">cancel_requisition</field>
179+ </record>
180+
181+ <!-- Procurement -->
182+ <record id="act_buy_req" model="workflow.activity">
183+ <field name="wkf_id" ref="procurement.wkf_procurement"/>
184+ <field name="name">buy_requisition</field>
185+ <field name="kind">subflow</field>
186+ <field name="subflow_id" search="[('osv','=','purchase.requisition')]"/>
187+ <field name="action">action_po_assign()</field>
188+ </record>
189+
190+ <record id="trans_confirm_mto_purchase_req" model="workflow.transition">
191+ <field name="act_from" ref="procurement.act_confirm_mto"/>
192+ <field name="act_to" ref="act_buy_req"/>
193+ <field name="condition">check_buy() and check_supplier_info() and check_product_requisition()</field>
194+ </record>
195+
196+ <record id="trans_buy_make_done_req" model="workflow.transition">
197+ <field name="act_from" ref="act_buy_req"/>
198+ <field name="act_to" ref="procurement.act_make_done"/>
199+ <field name="signal">subflow.done</field>
200+ </record>
201+
202+ <record id="trans_buy_cancel_req" model="workflow.transition">
203+ <field name="act_from" ref="act_buy_req"/>
204+ <field name="act_to" ref="procurement.act_cancel"/>
205+ <field name="signal">subflow.cancel</field>
206+ </record>
207+ </data>
208+</openerp>
209\ No newline at end of file

Subscribers

People subscribed via source and target branches

to all changes: