[IMP] Purchase: Optimize Purcase Code for merging PO
[odoo/odoo.git] / addons / purchase / test / purchase_order_merge.yml
1 -
2   In order to test to merge two purchase order,I start by creating a new product 'Nokia3110c'
3 -
4  !record {model: product.product, id: product_product_nokia3110c}:
5     categ_id: 'product.product_category_3'
6     cost_method: standard
7     mes_type: fixed
8     name: NOKIA 3110c
9     price_margin: 1.0
10     procure_method: make_to_order
11     property_stock_inventory: stock.location_inventory
12     property_stock_procurement: stock.location_procurement
13     property_stock_production: stock.location_production
14     seller_delay: '1'
15     standard_price: 5000.0
16     supply_method: buy
17     type: product
18     uom_id: product.product_uom_unit
19     uom_po_id: product.product_uom_unit
20     volume: 0.0
21     warranty: 0.0
22     weight: 0.0
23     weight_net: 0.0
24 -
25   In order to test the merge purchase order flow,I create a new record where "invoice_method" is From Order.
26 -
27   I create first purchase order for Nokia3110c.
28 -
29   !record {model: purchase.order, id: purchase_order_po_nokia1}:
30     company_id: base.main_company
31     date_order: !eval time.strftime('%Y-%m-%d')
32     invoice_method: order
33     location_id: stock.stock_location_stock
34     order_line:
35       - date_planned: !eval time.strftime('%Y-%m-%d')
36         name: NOKIA 3110c
37         price_unit: 100.0
38         product_id: 'product_product_nokia3110c'
39         product_qty: 10.0
40         product_uom: product.product_uom_unit
41         state: draft
42     partner_address_id: base.res_partner_address_7
43     partner_id: base.res_partner_4
44     pricelist_id: purchase.list0
45 -
46   Initially first purchase order is in the draft state.
47 -
48   !assert {model: purchase.order, id: purchase_order_po_nokia1}:
49     - state == 'draft'
50 -
51   I create second purchase order for Nokia3110c with same supplier,have same stock location, same pricelist as First Purchase order of Nokia3110.
52 -
53   !record {model: purchase.order, id: purchase_order_po_nokia2}:
54     company_id: base.main_company
55     date_order: !eval time.strftime('%Y-%m-%d')
56     invoice_method: order
57     location_id: stock.stock_location_stock
58     order_line:
59       - date_planned: !eval time.strftime('%Y-%m-%d')
60         name: NOKIA 3110c
61         price_unit: 100.0
62         product_id: 'product_product_nokia3110c'
63         product_qty: 20.0
64         product_uom: product.product_uom_unit
65         state: draft
66     partner_address_id: base.res_partner_address_7
67     partner_id: base.res_partner_4
68     pricelist_id: purchase.list0
69 -
70   Initially second purchase order is in the draft state.
71 -
72   !assert {model: purchase.order, id: purchase_order_po_nokia2}:
73     - state == 'draft'
74 -
75   I have merged first and second purchase order which are in draft state, belong to the same supplier,have same stock location, same pricelist.
76 -
77   !python {model: purchase.order.group}: |
78     ids = [ref("purchase_order_po_nokia1"),ref("purchase_order_po_nokia2")]
79     self.fields_view_get(cr, uid, context={'active_ids': ids})  
80     self.merge_orders(cr, uid, [1], context={'active_ids': ids})