[MERGE] MErged from main branch
[odoo/odoo.git] / addons / purchase_requisition / test / purchase_requisition.yml
1
2 -
3   In order to test the purchase requisition module, I will do a sale order -> purchase_requisition ->
4   purchase flow and I will buy the required products at two different suppliers.
5
6   I start by creating a new product 'Laptop ACER', which is purchased at Asustek, in MTO,
7   with the generation of purchase requisitions.
8
9   !record {model: product.product, id: product_product_laptopacer0}:
10     categ_id: product.product_category_3
11     cost_method: standard
12     mes_type: fixed
13     name: Laptop ACER
14     procure_method: make_to_order
15     purchase_requisition: 1
16     seller_ids:
17       - delay: 1
18         name: base.res_partner_asus
19         qty: 5.0
20     supply_method: buy
21     type: product
22     uom_id: product.product_uom_unit
23     uom_po_id: product.product_uom_unit
24     volume: 0.0
25     warranty: 0.0
26     weight: 0.0
27     weight_net: 0.0
28     list_price: 100.0    
29
30   Then I sell 5 Laptop ACER to the customer Agrolait, sale order TEST/TENDER/0001.
31
32   !record {model: sale.order, id: sale_order_testtender0}:
33     date_order: '2010-05-10'
34     invoice_quantity: order
35     name: TEST/TENDER/0001
36     order_line:
37       - name: Laptop ACER
38         price_unit: 100.0
39         product_uom: product.product_uom_unit
40         product_uom_qty: 5.0
41         state: draft
42         delay: 7.0
43         product_id: product_product_laptopacer0
44         product_uos_qty: 5.0
45         th_weight: 0.0
46         type: make_to_order
47     order_policy: manual
48     partner_id: base.res_partner_agrolait
49     partner_invoice_id: base.res_partner_address_8
50     partner_order_id: base.res_partner_address_8
51     partner_shipping_id: base.res_partner_address_8
52     picking_policy: direct
53     pricelist_id: product.list0
54     shop_id: sale.shop
55
56   I confirm the sale order.
57
58   !workflow {model: sale.order, action: order_confirm, ref: sale_order_testtender0}
59
60   I launch he scheduler to compute all procurements, and specify all requisitions orders.
61
62   !python {model: mrp.procurement.compute.all}: |
63     proc_obj = self.pool.get('mrp.procurement')
64     proc_obj._procure_confirm(cr,uid)
65 -
66   On the purchase tender, I create a new purchase order for the supplier 'DistriPC' by clicking on
67   the button 'New RfQ'. This opens a window to ask me the supplier and I set DistriPC . 
68
69   !record {model: purchase.requisition.partner, id: purchase_requisition_partner_0}:
70     partner_address_id: base.res_partner_address_7
71     partner_id: base.res_partner_4
72
73   I create a new purchase order.
74
75   !python {model: purchase.requisition.partner}: |
76     req_obj = self.pool.get('purchase.requisition')
77     ids =req_obj.search(cr, uid, [('origin','=','TEST/TENDER/0001')])
78     self.create_order(cr, uid, [ref("purchase_requisition_partner_0")], {"lang":
79       'en_US', "active_model": "purchase.requisition", "tz": False, "record_id":
80       1, "active_ids": ids, "active_id": ids[0], })
81     
82 -
83  I check that I have two purchase orders on the purchase tender.  
84 -
85  !python {model: purchase.order}: |
86     order_ids =self.search(cr, uid, [('origin','=','TEST/TENDER/0001')])
87     ids=len(order_ids)
88     assert (ids==2), "Purchase order  hasn't Created"
89
90  I set the purchase requisition as 'Not Exclusive'.
91 -
92  !python {model: purchase.requisition}: |
93     ids =self.search(cr, uid, [('origin','=','TEST/TENDER/0001')])
94     self.write(cr,uid,ids[0],{'exclusive': 'multiple' })
95 -
96   I change the quantities so that the purchase order for DistriPC includes 3 pieces and the
97   purchase order for Asustek includes 2 pieces.
98
99   !python {model: purchase.order}: |
100     line_obj=self.pool.get('purchase.order.line')  
101     partner_obj=self.pool.get('res.partner')    
102     requistion_obj=self.pool.get('purchase.requisition')
103     requistion_ids =requistion_obj.search(cr, uid, [('origin','=','TEST/TENDER/0001')])    
104     partner_id1=partner_obj.search(cr,uid,[('name','=','ASUStek')])[0] 
105     partner_id2=partner_obj.search(cr,uid,[('name','=','Distrib PC')])[0]   
106     purchase_id1= self.search(cr, uid, [('partner_id','=',partner_id1),('requisition_id','in',requistion_ids)])
107     purchase_id2= self.search(cr, uid, [('partner_id','=',partner_id2),('requisition_id','in',requistion_ids)])
108     order_line1=self.browse(cr, uid, purchase_id1, context)[0].order_line[0].id
109     order_line2=self.browse(cr, uid, purchase_id2, context)[0].order_line[0].id
110     line_obj.write(cr, uid, order_line1, {'product_qty':2})
111     line_obj.write(cr, uid, order_line2, {'product_qty':3})  
112 -
113   I confirm and validate both purchase orders.
114 -
115   !python {model: purchase.order}: |
116    order_ids= self.search(cr, uid, [])
117    import netsvc
118    wf_service = netsvc.LocalService("workflow")  
119    for id in order_ids:    
120       wf_service.trg_validate(uid, 'purchase.order',id,'purchase_confirm', cr)    
121       wf_service.trg_validate(uid, 'purchase.order',id,'purchase_approve', cr) 
122 -
123   I check that the delivery order of the customer is in state 'Waiting Goods'.
124 -
125   !python {model: stock.picking }: |
126     picking_id = self.search(cr, uid, [('origin','=','TEST/TENDER/0001'),('type','=','delivery')])
127     if picking_id:
128       pick=self.browse(cr,uid,picking_id[0])
129       assert (pick.state) =='confirmed'," Order is  not confirm"
130       assert(pick.move_lines[0].state=='wating'),'Order is  not wating"'
131 -
132   I receive the order of the supplier Asustek from the Incoming Products menu.
133 -
134   !python {model: stock.picking }: |
135    import time
136    partner_obj=self.pool.get('res.partner')    
137    order_obj=self.pool.get('purchase.order')
138    partner_id=partner_obj.search(cr,uid,[('name','=','ASUStek')])[0]    
139    picking_id = self.search(cr, uid, [('address_id.partner_id','=',partner_id),('type','=','in')])
140    if picking_id:
141      pick=self.browse(cr,uid,picking_id[0])
142      move =pick.move_lines[0]
143      partial_datas = {
144               'partner_id': 2,
145               'address_id': 6,
146               'delivery_date' : time.strftime('%Y-%m-%d'),
147            }
148      partial_datas['move%s'%(move.id)]= {
149        'product_id': move.product_id,
150        'product_qty': move.product_qty,
151        'product_uom': move.product_uom.id,
152       } 
153      self.do_partial(cr, uid, picking_id,partial_datas)
154 -
155  I receive the order of the supplier DistriPC from the Incoming Shipments menu.
156 -   
157   !python {model: stock.picking }: |
158    import time
159    partner_id=self.pool.get('res.partner').search(cr,uid,[('name','=','Distrib PC')])[0]     
160    picking_id = self.search(cr, uid, [('address_id.partner_id','=',partner_id),('type','=','in')])
161    if picking_id:
162       pick=self.browse(cr,uid,picking_id[0])
163       move =pick.move_lines[0]
164       partial_datas = {
165            'partner_id':pick.address_id.partner_id.id,
166             'address_id': pick.address_id.id,
167             'delivery_date' : time.strftime('%Y-%m-%d'),
168            }
169       partial_datas['move%s'%(move.id)]= {
170           'product_id': move.product_id,
171           'product_qty': move.product_qty,
172           'product_uom': move.product_uom.id,
173       } 
174       self.do_partial(cr, uid, picking_id,partial_datas)
175 -
176   I check that the delivery order of the customer is in the state Available.
177 -
178   !python {model: stock.picking }: |
179    picking_id = self.search(cr, uid, [('origin','=','TEST/TENDER/0001'),('type','=','out')])
180    if picking_id:
181       pick=self.browse(cr,uid,picking_id[0])
182       assert (pick.state) =='available'," Order is  not available"    
183