odoo/addons/purchase/test/purchase_from_picking.yml

148 lines
5.4 KiB
YAML

-
In order to test the purchase flow,I start by creating a new product 'iPod'
-
!record {model: product.product, id: product_product_ipod0}:
categ_id: 'product.product_category_3'
cost_method: standard
mes_type: fixed
name: iPod
price_margin: 2.0
procure_method: make_to_stock
property_stock_inventory: stock.location_inventory
property_stock_procurement: stock.location_procurement
property_stock_production: stock.location_production
seller_delay: '1'
standard_price: 100.0
supply_method: buy
type: product
uom_id: product.product_uom_unit
uom_po_id: product.product_uom_unit
volume: 0.0
warranty: 0.0
weight: 0.0
weight_net: 0.0
-
In order to test the purchase flow,I create a new record where "invoice_method" is From Picking
-
I create purchase order for iPod.
-
!record {model: purchase.order, id: purchase_order_po2}:
company_id: base.main_company
date_order: !eval time.strftime('%Y-%m-%d')
invoice_method: picking
location_id: stock.stock_location_stock
order_line:
- date_planned: !eval time.strftime('%Y-%m-%d')
name: iPod
price_unit: 100.0
product_id: 'product_product_ipod0'
product_qty: 10.0
product_uom: product.product_uom_unit
state: draft
partner_address_id: base.res_partner_address_7
partner_id: base.res_partner_4
pricelist_id: purchase.list0
-
Initially purchase order is in the draft state.
-
!assert {model: purchase.order, id: purchase_order_po2}:
- state == 'draft'
-
I confirm the purchase order for iPod.
-
!workflow {model: purchase.order, action: purchase_confirm, ref: purchase_order_po2}
-
I check that the order which was initially in the draft state has transit to confirm state.
-
!assert {model: purchase.order, id: purchase_order_po2}:
- state == 'approved'
-
I check that an entry gets created in the "Lines to Invoice" of Invoice Control on the basis of purchase order line.
-
!python {model: purchase.order}: |
from tools.translate import _
pur_order_obj=self.browse(cr, uid, ref("purchase_order_po2"))
pur_line=self.pool.get( 'purchase.order.line')
search_ids=pur_line.search(cr, uid, [('order_id', '=', pur_order_obj.name) ])
assert search_ids, _('Purchase order line is not created!')
-
To check that wizard "Create Invoices" gets opened.
-
I create purchase order line invoice entry.
-
!record {model: purchase.order.line_invoice, id: purchase_order_line_invoice_0}:
{}
-
I create invoice for products in the purchase order.
-
!python {model: purchase.order.line_invoice}: |
pur_obj=self.pool.get('purchase.order')
ids = []
pur_id1=pur_obj.browse(cr, uid, ref("purchase_order_po2"))
for line in pur_id1.order_line:
ids.append(line.id)
self.makeInvoices(cr, uid, [1], context={'active_ids': ids})
-
I check that invoice gets created.
-
!python {model: purchase.order}: |
from tools.translate import _
pur_order_obj=self.browse(cr, uid, ref("purchase_order_po2"))
pur_line=self.pool.get( 'purchase.order.line')
search_ids=pur_line.search(cr, uid, [('order_id', '=', pur_order_obj.name),('invoiced', '=', '1') ])
assert search_ids, _('Invoice is not created!')
-
I check that a record gets created in the Pending Invoices.
-
!python {model: purchase.order}: |
from tools.translate import _
pur_id1=self.browse(cr, uid, ref("purchase_order_po2"))
account_obj = self.pool.get('account.invoice')
ids = account_obj.search(cr, uid, [('origin', '=', 'PO-'+str(pur_id1.id))])
assert ids, _('Pending Invoice is not created!')
-
I check that the order which was initially in the confirmed state has transit to approved state.
-
!assert {model: purchase.order, id: purchase_order_po2}:
- state == 'approved'
-
I check that date_approve field of Delivery&Invoices gets bind with the date on which it has been approved.
-
!python {model: purchase.order}: |
pur_id=self.browse(cr, uid, ref("purchase_order_po2"))
assert(pur_id.date_approve)
-
I check that an entry gets created in the stock.picking.
-
!python {model: purchase.order}: |
pur_id=self.browse(cr, uid, ref("purchase_order_po2"))
assert(pur_id.picking_ids)
-
I check that an entry gets created related to stock move.
-
!python {model: purchase.order}: |
pur_id1=self.browse(cr, uid, ref("purchase_order_po2"))
picking_obj = self.pool.get('stock.picking')
ids = picking_obj.search(cr, uid, [('origin', '=', pur_id1.name)])
pick_id = picking_obj.browse(cr, uid, ids)[0]
move_obj = self.pool.get('stock.move')
search_id = move_obj.search(cr, uid, [('picking_id', '=', pick_id.name)])
assert search_id, 'No Incoming Product!'
-
Then I create an invoice from picking by clicking on "Create Invoice" wizard
-
!python {model: stock.invoice.onshipping}: |
import time
pur_obj=self.pool.get('purchase.order')
pur_id1=pur_obj.browse(cr, uid, ref("purchase_order_po2"))
pick_ids = [x.id for x in pur_id1.picking_ids]
id = self.create(cr, uid, {'invoice_date': time.strftime('%Y-%m-%d'), 'journal_id': ref('account.expenses_journal')},
{'active_ids': pick_ids})
self.create_invoice(cr, uid, [id], {"active_ids": pick_ids, "active_id": pick_ids[0]})
-
I check that an invoice_ids field of Delivery&Invoices gets bind with the value.
-
!python {model: purchase.order}: |
pur_id2=self.browse(cr, uid, ref("purchase_order_po2"))
assert(pur_id2.invoice_ids)