Merge branch 'master' of https://github.com/odoo/odoo
[odoo/odoo.git] / addons / sale_stock / test / picking_order_policy.yml
1 -
2   In order to test process of the Sale Order with access rights of saleman,
3 -
4   !context
5     uid: 'res_sale_stock_salesman'
6 -
7   Create a new SO to be sure we don't have one with product that can explode in mrp
8 -
9   !record {model: sale.order, id: sale_order_service}:
10     partner_id: base.res_partner_18
11     partner_invoice_id: base.res_partner_18
12     partner_shipping_id: base.res_partner_18
13     user_id: base.user_root
14     pricelist_id: product.list0
15     warehouse_id: stock.warehouse0
16     order_policy: picking
17 -
18   Add SO line with service type product in SO to check flow which contain service type product in SO(BUG#1167330).
19 -
20   !record {model: sale.order.line, id: sale_order_1}:
21     name: 'On Site Assistance'
22     product_id: product.product_product_2
23     product_uom_qty: 1.0
24     product_uom: 1
25     price_unit: 150.0
26     order_id: sale_order_service
27 -
28   Add a second SO line with a normal product
29 -
30   !record {model: sale.order.line, id: sale_order_2}:
31     name: 'Mouse Optical'
32     product_id: product.product_product_10
33     product_uom_qty: 1.0
34     product_uom: 1
35     price_unit: 150.0
36     order_id: sale_order_service
37 -
38   First I check the total amount of the Quotation before Approved.
39 -
40   !python {model: sale.order}: |
41     from openerp.tools import float_compare
42     so = self.browse(cr, uid, ref('sale_order_service'))
43     float_compare(sum([l.price_subtotal for l in so.order_line]), so.amount_untaxed, precision_digits=2) == 0, "The amount of the Quotation is not correctly computed"
44
45   I set an explicit invoicing partner that is different from the main SO Customer
46 -
47   !python {model: sale.order}: |
48     order = self.browse(cr, uid, ref("sale_order_service"))
49     order.write({'partner_invoice_id': ref('base.res_partner_address_29')})
50 -
51   I confirm the quotation with Invoice based on deliveries policy.
52 -
53   !workflow {model: sale.order, action: order_confirm, ref: sale_order_service}
54 -
55   I check that invoice should not created before dispatch delivery.
56 -
57   !python {model: sale.order}: |
58     order = self.pool.get('sale.order').browse(cr, uid, ref("sale_order_service"))
59     assert order.state == 'progress', 'Order should be in inprogress.'
60     assert len(order.invoice_ids) == False, "Invoice should not created."
61 -
62   I check the details of procurement after confirmed quotation.
63 -
64   !python {model: sale.order}: |
65     from datetime import datetime, timedelta
66     from dateutil.relativedelta import relativedelta
67     from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
68     order = self.browse(cr, uid, ref("sale_order_service"))
69     for order_line in order.order_line:
70         if order_line.product_id.type == 'product':
71             procurement = order_line.procurement_ids[0]
72             date_planned = datetime.strptime(order.date_order, DEFAULT_SERVER_DATETIME_FORMAT) + relativedelta(days=order_line.delay or 0.0)
73             date_planned = (date_planned - timedelta(days=order.company_id.security_lead)).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
74             assert procurement.date_planned == date_planned, "Scheduled date is not correspond."
75             assert procurement.product_id.id == order_line.product_id.id, "Product is not correspond."
76             assert procurement.product_qty == order_line.product_uom_qty, "Qty is not correspond."
77             assert procurement.product_uom.id == order_line.product_uom.id, "UOM is not correspond."
78 -
79   Only stock user can change data related warehouse therefore test with that user which have stock user rights,
80 -
81   !context
82     uid: 'res_stock_user'
83 -
84   I run the scheduler.
85 -
86   !python {model: procurement.order}: |
87     self.run_scheduler(cr, uid)
88 -
89   Salesman can also check order therefore test with that user which have salesman rights,
90 -
91   !context
92     uid: 'res_sale_stock_salesman'
93 -
94   I check the details of delivery order after confirmed quotation.
95 -
96   !python {model: sale.order}: |
97     from datetime import datetime, timedelta
98     from dateutil.relativedelta import relativedelta
99     from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
100     sale_order = self.browse(cr, uid, ref("sale_order_service"))
101     assert sale_order.picking_ids, "Delivery order is not created."
102     for picking in sale_order.picking_ids:
103       assert picking.state == "auto" or "confirmed", "Delivery order should be in 'Waitting Availability' state."
104       assert picking.origin == sale_order.name,"Origin of Delivery order is not correspond with sequence number of sale order."
105       assert picking.picking_type_id == self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'picking_type_out', context=context),"Shipment should be Outgoing."
106       assert picking.move_type == sale_order.picking_policy,"Delivery Method is not corresponding with delivery method of sale order."
107       assert picking.partner_id.id == sale_order.partner_shipping_id.id,"Shipping Address is not correspond with sale order."
108       assert picking.note == sale_order.note,"Note is not correspond with sale order."
109       assert picking.invoice_state == (sale_order.order_policy=='picking' and '2binvoiced') or 'none',"Invoice policy is not correspond with sale order."
110       assert len(picking.move_lines) == len(sale_order.order_line) - 1, "Total move of delivery order are not corresposning with total sale order lines."
111       location_id = sale_order.warehouse_id.lot_stock_id.id
112       for move in picking.move_lines:
113          order_line = move.procurement_id.sale_line_id
114          date_planned = datetime.strptime(sale_order.date_order, DEFAULT_SERVER_DATETIME_FORMAT) + relativedelta(days=order_line.delay or 0.0)
115          date_planned = (date_planned - timedelta(days=sale_order.company_id.security_lead)).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
116          assert datetime.strptime(move.date_expected, DEFAULT_SERVER_DATETIME_FORMAT) == datetime.strptime(date_planned, DEFAULT_SERVER_DATETIME_FORMAT), "Excepted Date is not correspond with Planned Date."
117          assert move.product_id.id == order_line.product_id.id,"Product is not correspond."
118          assert move.product_qty == order_line.product_uom_qty,"Product Quantity is not correspond."
119          assert move.product_uom.id == order_line.product_uom.id,"Product UOM is not correspond."
120          assert move.product_uos_qty == (order_line.product_uos and order_line.product_uos_qty or order_line.product_uom_qty), "Product UOS Quantity is not correspond."
121          assert move.product_uos.id == (order_line.product_uos and order_line.product_uos.id or order_line.product_uom.id), "Product UOS is not correspond"
122          assert move.product_packaging.id == order_line.product_packaging.id,"Product packaging is not correspond."
123          assert move.partner_id.id == order_line.address_allotment_id.id or sale_order.partner_shipping_id.id,"Address is not correspond"
124          #assert move.location_id.id == location_id,"Source Location is not correspond."
125 -
126   Now, I dispatch delivery order.
127 -
128   !python {model: stock.picking}: |
129     order = self.pool.get('sale.order').browse(cr, uid, ref("sale_order_service"), context=context)
130     for pick in order.picking_ids:
131         data = pick.force_assign()
132         if data == True:
133           pick.do_transfer()
134 -
135   I run the scheduler.
136 -
137   !python {model: procurement.order}: |
138     self.run_scheduler(cr, uid)
139 -
140   I check sale order to verify shipment.
141 -
142   !python {model: sale.order}: |
143     order = self.pool.get('sale.order').browse(cr, uid, ref("sale_order_service"))
144     assert order.shipped == True, "Sale order is not Delivered."
145     #assert order.state == 'progress', 'Order should be in inprogress.'
146     assert len(order.invoice_ids) == False, "Invoice should not created on dispatch delivery order."
147 -
148   I create Invoice from Delivery Order.
149 -
150   !python {model: stock.invoice.onshipping}: |
151     sale = self.pool.get('sale.order')
152     sale_order = sale.browse(cr, uid, ref("sale_order_service"))
153     ship_ids = [x.id for x in sale_order.picking_ids]
154     wiz_id = self.create(cr, uid, {'journal_id': ref('account.sales_journal')},
155       {'active_ids': ship_ids, 'active_model': 'stock.picking'})
156     self.create_invoice(cr, uid, [wiz_id], {"active_ids": ship_ids, "active_id": ship_ids[0]})
157 -
158   I check the invoice details after dispatched delivery.
159 -
160   !python {model: sale.order}: |
161     from openerp.tools import float_compare
162     order = self.browse(cr, uid, ref("sale_order_service"))
163     assert order.invoice_ids, "Invoice is not created."
164     ac = order.partner_invoice_id.property_account_receivable.id
165     journal_ids = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'sale'), ('company_id', '=', order.company_id.id)])
166     for invoice in order.invoice_ids:
167         assert invoice.type == 'out_invoice',"Invoice should be Customer Invoice."
168         assert invoice.account_id.id == ac,"Invoice account is not correspond."
169         assert invoice.reference == order.client_order_ref or order.name,"Reference is not correspond."
170         assert invoice.partner_id.id == order.partner_invoice_id.id,"Customer does not correspond."
171         assert invoice.currency_id.id == order.pricelist_id.currency_id.id, "Currency is not correspond."
172         assert (invoice.comment or '') == (order.note or ''),"Note is not correspond."
173         assert invoice.journal_id.id in journal_ids,"Sales Journal is not link on Invoice."
174         assert invoice.payment_term.id == order.payment_term.id, "Payment term is not correspond."
175     for so_line in order.order_line:
176         inv_line = so_line.invoice_lines[0]
177         ac = so_line.product_id.property_account_income.id or so_line.product_id.categ_id.property_account_income_categ.id
178         assert inv_line.product_id.id == so_line.product_id.id or False,"Product is not correspond"
179         assert inv_line.account_id.id == ac,"Account of Invoice line is not corresponding."
180         assert inv_line.uos_id.id == (so_line.product_uos and so_line.product_uos.id or so_line.product_uom.id), "Product UOS is not correspond."
181         assert float_compare(inv_line.price_unit, so_line.price_unit , precision_digits=2) == 0, "Price Unit is not correspond."
182         assert inv_line.quantity == (so_line.product_uos and so_line.product_uos_qty or so_line.product_uom_qty), "Product qty is not correspond."
183         assert inv_line.price_subtotal == so_line.price_subtotal, "Price sub total is not correspond."
184 -
185   Only Stock manager can open the Invoice therefore test with that user which have stock manager rights,
186 -
187   !context
188     uid: 'res_stock_manager'
189 -
190   I open the Invoice.
191 -
192   !python {model: sale.order}: |
193     so = self.browse(cr, uid, ref("sale_order_service"))
194     account_invoice_obj = self.pool.get('account.invoice')
195     for invoice in so.invoice_ids:
196       account_invoice_obj.signal_workflow(cr, uid, [invoice.id], 'invoice_open')
197 -
198   I pay the invoice
199 -
200   !python {model: account.invoice}: |
201     sale_order = self.pool.get('sale.order')
202     order = sale_order.browse(cr, uid, ref("sale_order_service"))
203     journal_ids = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'cash'), ('company_id', '=', order.company_id.id)], limit=1)
204     for invoice in order.invoice_ids:
205         invoice.pay_and_reconcile(
206             invoice.amount_total, ref('account.cash'), ref('account.period_8'),
207             journal_ids[0], ref('account.cash'),
208             ref('account.period_8'), journal_ids[0],
209             name='test')
210 -
211   To test process of the Sale Order with access rights of saleman,
212 -
213   !context
214     uid: 'res_sale_stock_salesman'
215 -
216   I check the order after paid invoice.
217 -
218   !python {model: sale.order}: |
219     order = self.browse(cr, uid, ref("sale_order_service"))
220     assert order.invoiced == True, "Sale order is not invoiced."
221     assert order.invoiced_rate == 100, "Invoiced progress is not 100%."
222     assert order.state == 'done', 'Order should be in closed.'