2
In order to test the part of sale order of the order_types module
3
we will create sale orders with different types, priority and category
4
and follow the workflow to see if the behaviour is good.
6
We create a Regular sale order with internal partner
8
!record {model: sale.order, id: sregular1}:
10
company_id: base.main_company
11
picking_policy: direct
12
invoice_quantity: order
13
partner_order_id: address1
14
partner_invoice_id: address1
15
partner_shipping_id: address1
17
pricelist_id: purchase.list0
20
We create line for this regular sale order
22
!record {model: sale.order.line, id: sregular1_l1}:
23
product_uom: product.product_uom_unit
30
We create a second line for this sale order
32
!record {model: sale.order.line, id: sregular1_l2}:
33
product_uom: product.product_uom_unit
40
We confirm this sale order
42
!workflow {model: sale.order, action: order_confirm, ref: sregular1}
44
We check if no invoice has been created
46
!python {model: account.invoice}: |
47
invoice_ids = self.search(cr, uid, [('origin', '=', 'Regular1')])
48
assert not invoice_ids, ('Invoice was generated on a Regular sale order with an internal partner')
50
We check if stock moves was generated with good data
52
!python {model: stock.move}: |
53
move_ids = self.search(cr, uid, [('sale_line_id', 'in', [ref('sregular1_l1'), ref('sregular1_l2')])])
54
assert move_ids, ('No stock moves were generated on a Regular sale order with an internal partner')
55
for move in self.browse(cr, uid, move_ids):
56
assert move.order_priority == 'normal', ('Generated move hasn\'t the good priority')
57
assert move.order_category == 'mixed', ('Generated move hasn\'t the good category')
58
assert move.order_type == 'regular', ('Generated move hasn\'t the good type')
59
reason_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'reason_types_moves', 'reason_type_deliver_partner')[1]
60
assert move.picking_id.reason_type_id.id == reason_id, ('Generated picking hasn\'t the good reason type')
62
We create a Regular sale order with external partner
64
!record {model: sale.order, id: sregular2}:
66
company_id: base.main_company
67
picking_policy: direct
68
invoice_quantity: order
69
partner_order_id: address2
70
partner_invoice_id: address2
71
partner_shipping_id: address2
73
pricelist_id: purchase.list0
76
We create line for this regular sale order
78
!record {model: sale.order.line, id: sregular2_l1}:
79
product_uom: product.product_uom_unit
85
date_planned: !eval time.strftime('%Y-%m-%d')
87
We create a second line for this sale order
89
!record {model: sale.order.line, id: sregular2_l2}:
90
product_uom: product.product_uom_unit
96
date_planned: !eval time.strftime('%Y-%m-%d')
98
We confirm this sale order
100
!workflow {model: sale.order, action: order_confirm, ref: sregular2}
102
We check if no invoice has been created
104
!python {model: account.invoice}: |
105
invoice_ids = self.search(cr, uid, [('origin', '=', 'Regular2')])
106
assert not invoice_ids, ('Invoice was generated on a Regular sale order with an external partner')
108
We check if stock moves was generated with good data
110
!python {model: stock.move}: |
111
move_ids = self.search(cr, uid, [('sale_line_id', 'in', [ref('sregular2_l1'), ref('sregular2_l2')])])
112
assert move_ids, ('No stock moves were generated on a Regular sale order with an external partner')
113
for move in self.browse(cr, uid, move_ids):
114
assert move.order_priority == 'normal', ('Generated move hasn\'t the good priority')
115
assert move.order_category == 'mixed', ('Generated move hasn\'t the good category')
116
assert move.order_type == 'regular', ('Generated move hasn\'t the good type')
117
reason_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'reason_types_moves', 'reason_type_deliver_partner')[1]
118
assert move.picking_id.reason_type_id.id == reason_id, ('Generated picking hasn\'t the good reason type')
120
We create a Donation before expiry
122
!record {model: sale.order, id: sdonation3}:
124
company_id: base.main_company
125
picking_policy: direct
127
invoice_quantity: order
128
partner_order_id: address1
129
partner_invoice_id: address1
130
partner_shipping_id: address1
131
partner_id: supplier1
132
pricelist_id: purchase.list0
133
order_type: donation_exp
135
We create line for this donation
137
!record {model: sale.order.line, id: sdonation3_l1}:
138
product_uom: product.product_uom_unit
144
date_planned: !eval time.strftime('%Y-%m-%d')
146
We create a second line for this sale order
148
!record {model: sale.order.line, id: sdonation3_l2}:
149
product_uom: product.product_uom_unit
155
date_planned: !eval time.strftime('%Y-%m-%d')
157
We confirm this sale order
159
!workflow {model: sale.order, action: order_confirm, ref: sdonation3}
161
We check if no invoice has been created
163
!python {model: account.invoice}: |
164
invoice_ids = self.search(cr, uid, [('origin', '=', 'Donation3')])
165
assert not invoice_ids, ('Invoice was generated on a Donation before expiry')
167
We check if stock moves was generated with good data
169
!python {model: stock.move}: |
170
move_ids = self.search(cr, uid, [('sale_line_id', 'in', [ref('sdonation3_l1'), ref('sdonation3_l2')])])
171
assert move_ids, ('No stock moves were generated on Donation before expiry')
172
for move in self.browse(cr, uid, move_ids):
173
assert move.order_priority == 'normal', ('Generated move hasn\'t the good priority')
174
assert move.order_category == 'mixed', ('Generated move hasn\'t the good category')
175
assert move.order_type == 'donation_exp', ('Generated move hasn\'t the good type')
176
reason_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'reason_types_moves', 'reason_type_donation_expiry')[1]
177
assert move.picking_id.reason_type_id.id == reason_id, ('Generated picking hasn\'t the good reason type')
179
We create a Standard donation
181
!record {model: sale.order, id: donation4}:
183
company_id: base.main_company
184
picking_policy: direct
186
invoice_quantity: order
187
partner_order_id: address1
188
partner_invoice_id: address1
189
partner_shipping_id: address1
190
partner_id: supplier1
191
pricelist_id: purchase.list0
192
order_type: donation_st
194
We create line for this donation
196
!record {model: sale.order.line, id: donation4_l1}:
197
product_uom: product.product_uom_unit
203
date_planned: !eval time.strftime('%Y-%m-%d')
205
We create a second line for this donation
207
!record {model: sale.order.line, id: donation4_l2}:
208
product_uom: product.product_uom_unit
214
date_planned: !eval time.strftime('%Y-%m-%d')
216
We confirm this sale order
218
!workflow {model: sale.order, action: order_confirm, ref: donation4}
220
We check if no invoice has been created
222
!python {model: account.invoice}: |
223
invoice_ids = self.search(cr, uid, [('origin', '=', 'Donation4')])
224
assert not invoice_ids, ('Invoice was generated on a standard donation')
226
We check if stock moves was generated with good data
228
!python {model: stock.move}: |
229
move_ids = self.search(cr, uid, [('sale_line_id', 'in', [ref('donation4_l1'), ref('donation4_l2')])])
230
assert move_ids, ('No stock moves were generated on a standard donation')
231
for move in self.browse(cr, uid, move_ids):
232
assert move.order_priority == 'normal', ('Generated move hasn\'t the good priority')
233
assert move.order_category == 'mixed', ('Generated move hasn\'t the good category')
234
assert move.order_type == 'donation_st', ('Generated move hasn\'t the good type')
235
reason_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'reason_types_moves', 'reason_type_donation')[1]
236
assert move.picking_id.reason_type_id.id == reason_id, ('Generated picking hasn\'t the good reason type')
240
!record {model: sale.order, id: loan5}:
242
company_id: base.main_company
243
picking_policy: direct
245
invoice_quantity: order
246
partner_order_id: address1
247
partner_invoice_id: address1
248
partner_shipping_id: address1
249
partner_id: supplier1
250
pricelist_id: purchase.list0
254
We create line for this loan
256
!record {model: sale.order.line, id: loan5_l1}:
257
product_uom: product.product_uom_unit
263
date_planned: !eval time.strftime('%Y-%m-%d')
265
We create a second line for this sale order
267
!record {model: sale.order.line, id: loan5_l2}:
268
product_uom: product.product_uom_unit
274
date_planned: !eval time.strftime('%Y-%m-%d')
276
We confirm this sale order
278
!workflow {model: sale.order, action: order_confirm, ref: loan5}
280
We check if no invoice has been created
282
!python {model: account.invoice}: |
283
invoice_ids = self.search(cr, uid, [('origin', '=', 'Loan5')])
284
assert not invoice_ids, ('Invoice was generated on a Loan')
286
We check if stock moves was generated with good data
288
!python {model: stock.move}: |
289
move_ids = self.search(cr, uid, [('sale_line_id', 'in', [ref('loan5_l1'), ref('loan5_l2')])])
290
assert move_ids, ('No stock moves were generated on a Loan')
291
for move in self.browse(cr, uid, move_ids):
292
assert move.order_priority == 'normal', ('Generated move hasn\'t the good priority')
293
assert move.order_category == 'mixed', ('Generated move hasn\'t the good category')
294
assert move.order_type == 'loan', ('Generated move hasn\'t the good type')
295
reason_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'reason_types_moves', 'reason_type_loan')[1]
296
assert move.picking_id.reason_type_id.id == reason_id, ('Generated picking hasn\'t the good reason type')
298
We check if a purchase order for counterpart of the loan has been created
300
!python {model: purchase.order}: |
301
from mx.DateTime import *
302
loan_duration = today() + RelativeDateTime(months=+6)
303
purchase_ids = self.search(cr, uid, [('loan_id', '=', ref('loan5'))])
304
assert purchase_ids, ('No purchase order has been created as counterpart of the loan')
305
for purchase in self.browse(cr, uid, purchase_ids):
306
assert purchase.delivery_requested_date == loan_duration.strftime('%Y-%m-%d'), ('Requested date of the generated purchase order is not equal to two months')
308
We force the assignation of product for the delivery order linked with the loan
310
!python {model: stock.picking}: |
311
pick_ids = self.search(cr, uid, [('sale_id', '=', ref('loan5'))])
312
self.draft_force_assign(cr, uid, pick_ids)
314
We confirm the picking.
316
!python {model: stock.picking }: |
318
pick_ids = self.search(cr, uid, [('sale_id', '=', ref('loan5'))])
319
pick=self.browse(cr,uid,pick_ids[0])
321
'partner_id': pick.address_id.partner_id.id,
322
'address_id': pick.address_id.id,
323
'delivery_date' : time.strftime('%Y-%m-%d')
325
for move in pick.move_lines:
326
partial_datas['move%s'%(move.id)]= {
327
'product_id': move.product_id,
328
'product_qty': move.product_qty,
329
'product_uom': move.product_uom.id,
331
self.do_partial(cr, uid, pick_ids,partial_datas)
333
We confirm the purchase order counterpart
335
!python {model: purchase.order}: |
337
wf_service = netsvc.LocalService('workflow')
338
purchase_ids = self.search(cr, uid, [('origin', '=', 'Loan5')])
339
for purchase in purchase_ids:
340
wf_service.trg_validate(uid, 'purchase.order', purchase, 'order_confirm', cr)
342
We check if the Loan is now in done state
344
!assert {model: sale.order, id: loan5}:
345
- state == 'done', ('Loan order is not in done state')