# create invoice: only 'invoice on order' products are invoiced
inv_id=so.action_invoice_create()
inv=inv_obj.browse(inv_id)
self.assertEqual(len(inv.invoice_line_ids),2,'Sale: invoice is missing lines')
self.assertEqual(inv.amount_total,sum([2*p.list_priceifp.invoice_policy=='order'else0forpinself.products.values()]),'Sale: invoice total amount is wrong')
self.assertTrue(so.invoice_status=='no','Sale: SO status after invoicing should be "nothing to invoice"')
self.assertTrue(len(so.invoice_ids)==1,'Sale: invoice is missing')
self.assertTrue(so.invoice_status=='to invoice','Sale: SO status after delivery should be "to invoice"')
inv_id=so.action_invoice_create()
inv=inv_obj.browse(inv_id)
self.assertEqual(len(inv.invoice_line_ids),2,'Sale: second invoice is missing lines')
self.assertEqual(inv.amount_total,sum([2*p.list_priceifp.invoice_policy=='delivery'else0forpinself.products.values()]),'Sale: second invoice total amount is wrong')
self.assertTrue(so.invoice_status=='invoiced','Sale: SO status after invoicing everything should be "invoiced"')
self.assertTrue(len(so.invoice_ids)==2,'Sale: invoice is missing')
# go over the sold quantity
forlineinso.order_line:
ifline.product_id==self.products['serv_order']:
line.qty_delivered=10
self.assertTrue(so.invoice_status=='upselling','Sale: SO status after increasing delivered qty higher than ordered qty should be "upselling"')
# upsell and invoice
forlineinso.order_line:
ifline.product_id==self.products['serv_order']:
line.product_uom_qty=10
inv_id=so.action_invoice_create()
inv=inv_obj.browse(inv_id)
self.assertEqual(len(inv.invoice_line_ids),1,'Sale: third invoice is missing lines')
self.assertEqual(inv.amount_total,8*self.products['serv_order'].list_price,'Sale: second invoice total amount is wrong')
self.assertTrue(so.invoice_status=='invoiced','Sale: SO status after invoicing everything (including the upsel) should be "invoiced"')
deftest_unlink_cancel(self):
""" Test deleting and cancelling sales orders depending on their state and on the user's rights """
account_payable=self.env['account.account'].create({'code':'X1111','name':'Sale - Test Payable Account','user_type_id':self.env.ref('account.data_account_type_payable').id,'reconcile':True})
account_income=self.env['account.account'].create({'code':'X1112','name':'Sale - Test Account','user_type_id':self.env.ref('account.data_account_type_direct_costs').id})
self.assertTrue(sol,'Sale: cost invoicing does not add lines when confirming vendor invoice')
self.assertEquals((sol.price_unit,sol.qty_delivered,sol.product_uom_qty,sol.qty_invoiced),(160,2,0,0),'Sale: line is wrong after confirming vendor invoice')