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