~unifield-team/unifield-addons/uf-1261

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
-
  In order to test the Sale module in OpenERP,
  I create a Sale Order for Slider Mobile for qty 500 having Shipping Policy is 'Invoice on order after Delivery'
-
  !record {model: sale.order, id: sale_order_so8}:
    date_order: !eval time.strftime('%Y-%m-%d')
    invoice_quantity: order
    name: Test_SO008
    order_line:
      - name: Slider Mobile
        price_unit: 200.0
        product_uom: product.product_uom_unit
        product_uom_qty: 500.0
        state: draft
        delay: 7.0
        product_id: sale.product_product_slidermobile0
        product_uos_qty: 500.0
        type: make_to_order
    order_policy: postpaid
    partner_id: sale.res_partner_cleartrail0
    partner_invoice_id: sale.res_partner_address_2
    partner_order_id: sale.res_partner_address_1
    partner_shipping_id: sale.res_partner_address_3
    picking_policy: direct
    pricelist_id: product.list0
    shop_id: sale.shop
    yml_module_name: sale
-
  I confirm the Sale Order.
-
  !workflow {model: sale.order, action: order_confirm, ref: sale_order_so8}
-
  I verify that the picking has been generated for the sale order
-
  !python {model: sale.order}: |
    so = self.browse(cr, uid, ref("sale_order_so8"))
    assert so.picking_ids,"Picking has not been generated for sale_order_so8"
-
  Then I done the picking
-
  !python {model: stock.picking }: |
   import time
   sale_order_obj = self.pool.get('sale.order')
   so = sale_order_obj.browse(cr, uid, ref("sale_order_so8"))
   picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')])
   if picking_id:
      pick=self.browse(cr,uid,picking_id[0])
      pick.force_assign(cr, uid)
      partial_datas = {
           'partner_id':pick.address_id.partner_id.id,
            'address_id': pick.address_id.id,
            'delivery_date' : time.strftime('%Y-%m-%d'),
           }
      move = pick.move_lines[0]
      partial_datas['move%s'%(move.id)]= {
          'product_id': move.product_id.id,
          'product_qty': move.product_qty,
          'product_uom': move.product_uom.id,
      }
      self.do_partial(cr, uid, [pick.id],partial_datas)
-
  I verify that picking order is in done state.
-
  !python {model: stock.picking }: |
   sale_order_obj = self.pool.get('sale.order')
   so = sale_order_obj.browse(cr, uid, ref("sale_order_so8"))
   picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')])
   modules = self.pool.get('ir.module.module')
   mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])])
   if picking_id and not mod_pur:
     pick = self.browse(cr,uid,picking_id[0])
     assert (pick.state == 'done'), "Picking for SO is not in done state."
-
  I verify that delivery order has been generated for sale order
-
  !python {model: stock.picking }: |
   sale_order_obj = self.pool.get('sale.order')
   so = sale_order_obj.browse(cr, uid, ref("sale_order_so8"))
   picking_id = self.search(cr, uid, [('origin','=',so.name)])
   assert (picking_id),"Delivery order has not been generated"
-
  I click on the Products Sent button and then on the Validate button
-
  !python {model: stock.picking }: |
   import time
   sale_order_obj = self.pool.get('sale.order')
   so = sale_order_obj.browse(cr, uid, ref("sale_order_so8"))
   picking_id = self.search(cr, uid, [('origin','=',so.name)])
   if picking_id:
      pick=self.browse(cr,uid,picking_id[0])
      pick.force_assign(cr, uid)
      partial_datas = {
           'partner_id':pick.address_id.partner_id.id,
            'address_id': pick.address_id.id,
            'delivery_date' : time.strftime('%Y-%m-%d'),
           }
      move = pick.move_lines[0]
      partial_datas['move%s'%(move.id)]= {
          'product_id': move.product_id.id,
          'product_qty': move.product_qty,
          'product_uom': move.product_uom.id,
      }
      self.do_partial(cr, uid, [pick.id],partial_datas)
-
  I verify that delivery state is done
-
  !python {model: stock.picking }: |
   sale_order_obj = self.pool.get('sale.order')
   so = sale_order_obj.browse(cr, uid, ref("sale_order_so8"))
   picking_id = self.search(cr, uid, [('origin','=',so.name)])
   modules = self.pool.get('ir.module.module')
   mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])])
   if picking_id and not mod_pur:
     pick = self.browse(cr,uid,picking_id[0])
     assert (pick.state) =='done', "Picking for SO is not in done state."
-
  I verify that a procurement has been generated for so
-
  !python {model: procurement.order}: |
    from tools.translate import _
    sale_order_obj = self.pool.get('sale.order')
    so = sale_order_obj.browse(cr, uid, ref("sale_order_so8"))
    proc_ids = self.search(cr, uid, [('origin','=',so.name)])
    assert proc_ids, _('No Procurements!')
-
  Then I click on the "Run Procurement" button
-
  !python {model: procurement.order}: |
    sale_order_obj = self.pool.get('sale.order')
    so = sale_order_obj.browse(cr, uid, ref("sale_order_so8"))
    import netsvc
    wf_service = netsvc.LocalService("workflow")
    proc_ids = self.search(cr, uid, [('origin','=',so.name)])
    for proc in proc_ids:
      wf_service.trg_validate(uid, 'procurement.order',proc,'button_check', cr)
-
  I verify that a procurement state is "running"
-
  !python {model: procurement.order}: |
    from tools.translate import _
    modules = self.pool.get('ir.module.module')
    mod_pur = modules.search(cr, uid, [('name','=','purchase')])
    mod_brw = modules.browse(cr,uid,mod_pur)[0]
    if (mod_brw.state == 'installed'):
        sale_order_obj = self.pool.get('sale.order')
        so = sale_order_obj.browse(cr, uid, ref("sale_order_so8"))
        proc_ids = self.search(cr, uid, [('origin','=',so.name),('state','=','running')])
        assert proc_ids, _('Procurement is not in the running state!')
-
  I verify that a purchase order has been generated
-
  !python {model: sale.order}: |
    from tools.translate import _
    modules = self.pool.get('ir.module.module')
    mod_pur = modules.search(cr, uid, [('name','=','purchase')])
    mod_brw = modules.browse(cr,uid,mod_pur)[0]
    if (mod_brw.state == 'installed'):
        so = self.browse(cr, uid, ref("sale_order_so8"))
        pur_obj=self.pool.get('purchase.order')
        pur_id=pur_obj.search(cr, uid, [('origin','=',so.name)])
        assert pur_id, _('Purchase order has not been generated')
-
  I click on the "Confirm" button to confirm the purchase order
-
  !python {model: sale.order}: |
    from tools.translate import _
    modules = self.pool.get('ir.module.module')
    mod_pur = modules.search(cr, uid, [('name','=','purchase')])
    mod_brw = modules.browse(cr,uid,mod_pur)[0]
    if (mod_brw.state == 'installed'):
        pur_obj=self.pool.get('purchase.order')
        so = self.browse(cr, uid, ref("sale_order_so8"))
        import netsvc
        wf_service = netsvc.LocalService("workflow")
        pur_ids = pur_obj.search(cr, uid, [('origin','=',so.name)])
        # Avoid analytic distribution error
        pur_obj.write(cr, uid, pur_ids, {'from_yml_test': True})
        for pur in pur_ids:
          wf_service.trg_validate(uid, 'purchase.order',pur,'purchase_confirm', cr)
-
  I click on the "Approved by supplier" button to approve the purchase order
-
  !python {model: sale.order}: |
    from tools.translate import _
    modules = self.pool.get('ir.module.module')
    mod_pur = modules.search(cr, uid, [('name','=','purchase')])
    mod_brw = modules.browse(cr,uid,mod_pur)[0]
    if (mod_brw.state == 'installed'):
        pur_obj = self.pool.get('purchase.order')
        so = self.browse(cr, uid, ref("sale_order_so8"))
        import netsvc
        wf_service = netsvc.LocalService("workflow")
        pur_ids = pur_obj.search(cr, uid, [('origin','=',so.name)])
        # Avoid analytic distribution error
        pur_obj.write(cr, uid, pur_ids, {'from_yml_test': True})
        for pur in pur_ids:
          wf_service.trg_validate(uid, 'purchase.order',pur,'purchase_approve', cr)
-
  I verify that a picking related to purchase order has been generated.
-
  !python {model: sale.order}: |
    modules = self.pool.get('ir.module.module')
    mod_pur = modules.search(cr, uid, [('name','=','purchase')])
    mod_brw = modules.browse(cr,uid,mod_pur)[0]
    if (mod_brw.state == 'installed'):
        pur_obj = self.pool.get('purchase.order')
        so = self.browse(cr, uid, ref("sale_order_so8"))
        pur_id = pur_obj.search(cr, uid, [('origin','=',so.name)])
        po = pur_obj.browse(cr, uid, pur_id)[0]
        assert(po.picking_ids),"Picking for purchase order has not been generated"
-
  Then I click on the "Products Received" button of Incoming Shipments
-
  !record {model: stock.partial.picking, id: stock_partial_picking_0}:
    date: !eval time.strftime('%Y-%m-%d %H:%M:%S')
-
  I click on the "Validate" button
-
  !python {model: stock.picking}: |
    modules = self.pool.get('ir.module.module')
    mod_pur = modules.search(cr, uid, [('name','=','purchase')])
    mod_brw = modules.browse(cr,uid,mod_pur)[0]
    if (mod_brw.state == 'installed'):
        sale_order_obj = self.pool.get('sale.order')
        pur_obj = self.pool.get('purchase.order')
        so = sale_order_obj.browse(cr, uid, ref("sale_order_so8"))
        pur_id = pur_obj.search(cr, uid, [('origin','=',so.name)])
        po = pur_obj.browse(cr, uid, pur_id)[0]
        pick_ser_id = self.search(cr, uid, [('purchase_id', '=', po.id )])
        import netsvc
        wf_service = netsvc.LocalService("workflow")
        for pick in pick_ser_id:
          wf_service.trg_validate(uid, 'stock.picking',pick,'button_done', cr)
-
  I verify that picking for purchase order has been done.
-
  !python {model: sale.order}: |
    from tools.translate import _
    modules = self.pool.get('ir.module.module')
    mod_pur = modules.search(cr, uid, [('name','=','purchase')])
    mod_brw = modules.browse(cr,uid,mod_pur)[0]
    if (mod_brw.state == 'installed'):
        pur_obj = self.pool.get('purchase.order')
        so = self.browse(cr, uid, ref("sale_order_so8"))
        pur_id = pur_obj.search(cr, uid, [('origin','=',so.name)])
        po = pur_obj.browse(cr, uid, pur_id)[0]
        picking_obj = self.pool.get('stock.picking')
        ids = picking_obj.search(cr, uid, [('purchase_id', '=', po.id ),('state', '=', 'done')])
        assert ids, _('Picking is not in the done state!')
-
  I verify that a "Picked" has been set to true
-
  !python {model: sale.order}: |
    so = self.browse(cr, uid, ref("sale_order_so8"))
    assert (so.shipped == True), "Picking is not done."
-
  I verify that an invoice has been generated for SO
-
  !python {model: sale.order}: |
    so = self.browse(cr, uid, ref("sale_order_so8"))
    assert so.invoice_ids, "Invoice has not been generated"
-
  I open the Invoice for the SO.
-
  !python {model: account.invoice}: |
    sale_order_obj = self.pool.get('sale.order')
    so = sale_order_obj.browse(cr, uid, ref("sale_order_so8"))
    import netsvc
    wf_service = netsvc.LocalService("workflow")
    invoice_ids = so.invoice_ids
    self.write(cr, uid, [x.id for x in invoice_ids], {'from_yml_test': True})
    for invoice in invoice_ids:
      wf_service.trg_validate(uid, 'account.invoice',invoice.id,'invoice_open', cr)
-
  Assign analytic journal into bank journal
-
  !record {model: account.journal, id: sale.account_journal_bankjournal0}:
    analytic_journal_id: account.cose_journal_sale
-
  I pay the invoice
-
  !python {model: account.invoice}: |
    sale_order_obj = self.pool.get('sale.order')
    so = sale_order_obj.browse(cr, uid, ref("sale_order_so8"))
    invoice_id = self.search(cr, uid, [('origin','=',so.name),('state','=','open')])
    self.pay_and_reconcile(cr, uid, invoice_id,
        so.amount_total, ref('account.cash'), ref('account.period_8'),
        ref('sale.account_journal_bankjournal0'), ref('account.cash'),
        ref('account.period_8'), ref('sale.account_journal_bankjournal0'),
        name='test')
-
  I verify the invoice are in paid state or not.
-
  !python {model: account.invoice}: |
    modules = self.pool.get('ir.module.module')
    mod_pur = modules.search(cr, uid, [('name','=','purchase')])
    mod_brw = modules.browse(cr,uid,mod_pur)[0]
    if (mod_brw.state == 'installed'):
        sale_order_obj = self.pool.get('sale.order')
        so = sale_order_obj.browse(cr, uid, ref("sale_order_so8"))
        invoice_ids = so.invoice_ids
        for invoice in invoice_ids:
            assert (invoice.state) =='paid', "Invoice for SO is not in done state."
-
  I verify that Paid has been set to true.
-
  !python {model: sale.order}: |
    sale_id=self.browse(cr, uid, ref("sale_order_so8"))
    assert(sale_id.invoiced == True), "Paid has not been set to true"
-
  I verify that sale order is in done state
-
   !python {model: sale.order}: |
    so = self.browse(cr, uid, ref("sale_order_so8"))
    assert (so.state == 'done'), "Sale order is not in the done state."