merge_order.yml 1.99 KB
Newer Older
François C. committed
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
-
  In order to merge RFQ, I merge two RFQ which has same supplier and check new merged order.
-
  !python {model: purchase.order}: |
    new_id = self.do_merge(cr, uid, [ref('purchase.purchase_order_4'), ref('purchase.purchase_order_7')])
    order4 = self.browse(cr, uid, ref('purchase.purchase_order_4'))
    order7 = self.browse(cr, uid, ref('purchase.purchase_order_7'))
    total_qty = sum([x.product_qty for x in order4.order_line] + [x.product_qty for x in order7.order_line])

    assert order4.state == 'cancel', "Merged order should be canceled"
    assert order7.state == 'cancel', "Merged order should be canceled"

    def merged_data(lines):
        product_id =[]
        product_uom = []
        res = {}
        for line in lines:
          product_id.append(line.product_id.id) 
          product_uom.append(line.product_uom.id) 
        res.update({'product_ids': product_id,'product_uom':product_uom})
        return res

    for order in self.browse(cr, uid, new_id.keys()):
       total_new_qty = [x.product_qty for x in order.order_line]
       total_new_qty = sum(total_new_qty)
       
       assert total_new_qty == total_qty,"product quantities are not correspond: {} != {}".format(total_new_qty, total_qty)
       assert order.partner_id == order4.partner_id ,"partner is not correspond"
       assert order.warehouse_id == order4.warehouse_id or order7.warehouse_id,"Warehouse is not correspond"
       assert order.state == 'draft',"New created order state should be in draft"
       assert order.pricelist_id == order4.pricelist_id,"Price list is not correspond"
       assert order.date_order == order4.date_order ,"Date of order is not correspond"
       assert order.location_id == order4.location_id ,"Location is not correspond"
       n_product_data = merged_data(order.order_line)
       o_product_data= merged_data(order4.order_line)
       o_pro_data = merged_data(order7.order_line)
       
       assert n_product_data == o_product_data or o_pro_data,"product data are not correspond"