2
Creating a service location
4
!record {model: stock.location, id: location_service}:
6
location_category: other
10
Creating a res.partner record
12
!record {model: res.partner, id: res_partner_a0}:
19
Creating a res.partner.address record
21
!record {model: res.partner.address, id: res_partner_address_0}:
22
partner_id: res_partner_a0
25
Creating a product.product record service with reception
27
!record {model: product.product, id: product_service_recep_p1}:
31
procure_method: make_to_order
32
international_status: product_attributes.int_1
35
Creating a product.product record stockable
37
!record {model: product.product, id: product_stockable_p2}:
41
international_status: product_attributes.int_1
44
0. I create a Sale order and trigger it to Outgoing shipment in
45
order to test the code related to sale order.
47
!record {model: sale.order, id: sale_order_00}:
48
partner_id: res_partner_a0
49
pricelist_id: product.list0
50
partner_invoice_id: res_partner_address_0
51
partner_order_id: res_partner_address_0
52
partner_shipping_id: res_partner_address_0
58
!record {model: sale.order.line, id: sale_order_line_00}:
59
name: sale order line test
60
order_id: sale_order_00
61
product_id: product_stockable_p2
62
product_uom: product.product_uom_unit
68
I validate the sale order
71
!python {model: sale.order}: |
73
wf_service = netsvc.LocalService("workflow")
74
wf_service.trg_validate(uid, 'sale.order', ref("sale_order_00"), 'order_confirm', cr)
76
# check the order_type of outgoing object
77
picking_obj = self.pool.get('stock.picking')
78
ids = picking_obj.search(cr, uid, [('sale_id', '=', ref("sale_order_00"))], context=None)
79
assert len(ids) == 1, 'The number of OUtoing picking is not correct (1 - %s)'%len(ids)
80
pick = picking_obj.browse(cr, uid, ids[0], context=None)
81
assert pick.order_category == 'medical', 'The order type of the outgoing picking object is not correct (medical, %s)'%pick.order_type
84
1. I create a purchase order with a service product.
85
The purchase order is then converted to purchase order
86
and validated. No incoming shipment are created because
87
only Service product present in the purchase order.
89
Creating a purchase.order record
91
!record {model: purchase.order, id: purchase_order_po0}:
92
partner_id: res_partner_a0
93
partner_address_id: res_partner_address_0
94
pricelist_id: product.list0
95
location_id: stock.stock_location_stock
99
I validate the purchase order and check that no Incoming shipment has been created
102
!python {model: purchase.order}: |
103
# try on change functions
104
prod = self.pool.get('product.product')
105
prod.on_change_type(cr, uid, [ref("product_service_recep_p1")], 'product', context=None)
106
prod.on_change_type(cr, uid, [ref("product_service_recep_p1")], 'service_recep', context=None)
108
2. I create a purchase order with a stockable product, a service with reception product,
109
and a service product. After validation process, an incoming shipment is created
110
with two stock moves, one for the stockable and one for the service with reception product.
112
Creating a purchase.order record
114
!record {model: purchase.order, id: purchase_order_po1}:
115
partner_id: res_partner_a0
116
partner_address_id: res_partner_address_0
117
pricelist_id: product.list0
118
location_id: stock.stock_location_stock
122
Creating a purchase.order.line record for service with reception product
124
!record {model: purchase.order.line, id: purchase_order_line_p02}:
125
order_id: purchase_order_po1
127
product_id: product_service_recep_p1
128
product_uom: product.product_uom_unit
131
Creating a purchase.order.line record for service with stockable product
133
!record {model: purchase.order.line, id: purchase_order_line_p03}:
134
order_id: purchase_order_po1
136
product_id: product_stockable_p2
137
product_uom: product.product_uom_unit
141
I validate the purchase order and check that no Incoming shipment has been created and
142
contains the two correct stock moves
145
!python {model: purchase.order}: |
147
wf_service = netsvc.LocalService("workflow")
148
wf_service.trg_validate(uid, 'purchase.order', ref("purchase_order_po1"), 'purchase_confirm', cr)
149
wf_service.trg_validate(uid, 'purchase.order', ref("purchase_order_po1"), 'purchase_approve', cr)
151
pick_obj = self.pool.get('stock.picking')
152
ids = pick_obj.search(cr, uid, [('purchase_id', '=', ref("purchase_order_po1"))], context=context)
153
assert len(ids) == 1, 'No incoming shipment found, an incoming shipment should have been created with service with reception and stockable product (0 - %s)'%len(ids)
155
pick = pick_obj.browse(cr, uid, ids[0], context=context)
156
# the category must be log
157
assert pick.order_category == 'log', "the order category does not correspond to purchase order category (log - %s)"%pick.order_category
159
for move in pick.move_lines:
161
assert move.product_id.id in (ref("product_service_recep_p1"), ref("product_stockable_p2")), "product of stock move is not correct (%s, %s) - %s"%(ref("product_service_recep_p1"), ref("product_stockable_p2"), move.product_id.id)
163
assert count == 2, "the number of stock moves is wrong 2 - %s"%count
166
3. I create a purchase order with type Direct Purchase Order, with service with reception product.
167
No incoming shipment should be created.
169
Creating a purchase.order record
171
!record {model: purchase.order, id: purchase_order_po2}:
172
partner_id: res_partner_a0
173
partner_address_id: res_partner_address_0
174
pricelist_id: product.list0
175
location_id: stock.stock_location_stock
180
Creating a purchase.order.line record for service product
182
!record {model: purchase.order.line, id: purchase_order_line_p04}:
183
order_id: purchase_order_po2
185
product_id: product_service_recep_p1
186
product_uom: product.product_uom_unit
190
I validate the purchase order and check that no Incoming shipment has been created
193
!python {model: purchase.order}: |
195
wf_service = netsvc.LocalService("workflow")
196
wf_service.trg_validate(uid, 'purchase.order', ref("purchase_order_po2"), 'purchase_confirm', cr)
197
wf_service.trg_validate(uid, 'purchase.order', ref("purchase_order_po2"), 'purchase_approve', cr)
199
pick_obj = self.pool.get('stock.picking')
200
ids = pick_obj.search(cr, uid, [('purchase_id', '=', ref("purchase_order_po2"))], context=context)
201
assert len(ids) == 0, 'An incoming shipment is found, no incoming shipment should have been created with service product (0 - %s)'%len(ids)
204
4. I test the constraint of purchase order. A purchase order with category Service should
205
not contain any non service (service, service with reception) product.
207
Creating a purchase.order record
209
!record {model: purchase.order, id: purchase_order_po3}:
210
partner_id: res_partner_a0
211
partner_address_id: res_partner_address_0
212
pricelist_id: product.list0
213
location_id: stock.stock_location_stock
217
Creating a purchase.order.line record for service product
219
!record {model: purchase.order.line, id: purchase_order_line_p05}:
220
order_id: purchase_order_po3
222
product_id: product_stockable_p2
223
product_uom: product.product_uom_unit
227
I change the category of the purchase order to service, an exception should have been raised
230
!python {model: purchase.order}: |
231
from osv.osv import except_osv
232
po = self.browse(cr, uid, ref("purchase_order_po3"), context=context)
234
po.write({'categ':'service'}, context=context)
235
except except_osv as e:
236
assert False, 'The constraint about Purchase Order of type Category Service with not only Service with Reception Products has been triggered'
237
# ok the constraint is triggered