[IMP] purchase_stock: Adapt tests to work with/without demo data
This commit is contained in:
@@ -22,11 +22,6 @@ class TestPurchase(TestStockCommon):
|
||||
product.name, '/', self.env.company, order_values)
|
||||
])
|
||||
|
||||
def _load(self, module, *args):
|
||||
tools.convert_file(self.cr, 'purchase',
|
||||
get_module_resource(module, *args),
|
||||
{}, 'init', False, 'test', self.registry._assertion_report)
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestPurchase, cls).setUpClass()
|
||||
|
||||
@@ -4,15 +4,16 @@
|
||||
import time
|
||||
|
||||
from .common import TestPurchase
|
||||
from odoo.addons.stock_account.tests.stock_account_minimal_test import StockAccountMinimalTest
|
||||
|
||||
|
||||
class TestAveragePrice(TestPurchase):
|
||||
class TestAveragePrice(TestPurchase, StockAccountMinimalTest):
|
||||
|
||||
def test_00_average_price(self):
|
||||
""" Testcase for average price computation"""
|
||||
|
||||
self._load('account', 'test', 'account_minimal_test.xml')
|
||||
self._load('stock_account', 'test', 'stock_valuation_account.xml')
|
||||
res_partner_3 = self.env['res.partner'].create({
|
||||
'name': 'Gemini Partner',
|
||||
})
|
||||
|
||||
# Set a product as using average price.
|
||||
product_cable_management_box = self.env['product.product'].create({
|
||||
@@ -29,12 +30,12 @@ class TestAveragePrice(TestPurchase):
|
||||
})
|
||||
product_cable_management_box.categ_id.property_cost_method = 'average'
|
||||
product_cable_management_box.categ_id.property_valuation = 'real_time'
|
||||
product_cable_management_box.categ_id.property_stock_account_input_categ_id = self.ref('purchase.o_expense')
|
||||
product_cable_management_box.categ_id.property_stock_account_output_categ_id = self.ref('purchase.o_income')
|
||||
product_cable_management_box.categ_id.property_stock_account_input_categ_id = self.o_expense
|
||||
product_cable_management_box.categ_id.property_stock_account_output_categ_id = self.o_income
|
||||
|
||||
# I create a draft Purchase Order for first incoming shipment for 10 pieces at 60€
|
||||
purchase_order_1 = self.env['purchase.order'].create({
|
||||
'partner_id': self.env.ref('base.res_partner_3').id,
|
||||
'partner_id': res_partner_3.id,
|
||||
'order_line': [(0, 0, {
|
||||
'name': 'Average Ice Cream',
|
||||
'product_id': product_cable_management_box.id,
|
||||
@@ -62,7 +63,7 @@ class TestAveragePrice(TestPurchase):
|
||||
|
||||
# I create a draft Purchase Order for second incoming shipment for 30 pieces at 80€
|
||||
purchase_order_2 = self.env['purchase.order'].create({
|
||||
'partner_id': self.env.ref('base.res_partner_3').id,
|
||||
'partner_id': res_partner_3.id,
|
||||
'order_line': [(0, 0, {
|
||||
'name': product_cable_management_box.name,
|
||||
'product_id': product_cable_management_box.id,
|
||||
@@ -108,7 +109,7 @@ class TestAveragePrice(TestPurchase):
|
||||
|
||||
# Make a new purchase order with 500 g Average Ice Cream at a price of 0.2€/g
|
||||
purchase_order_3 = self.env['purchase.order'].create({
|
||||
'partner_id': self.env.ref('base.res_partner_3').id,
|
||||
'partner_id': res_partner_3.id,
|
||||
'order_line': [(0, 0, {
|
||||
'name': product_cable_management_box.name,
|
||||
'product_id': product_cable_management_box.id,
|
||||
|
||||
@@ -10,9 +10,9 @@ class TestCreatePicking(common.TestProductCommon):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCreatePicking, self).setUp()
|
||||
self.partner_id = self.env.ref('base.res_partner_1')
|
||||
self.product_id_1 = self.env.ref('product.product_product_8')
|
||||
self.product_id_2 = self.env.ref('product.product_product_11')
|
||||
self.partner_id = self.env['res.partner'].create({'name': 'Wood Corner Partner'})
|
||||
self.product_id_1 = self.env['product.product'].create({'name': 'Large Desk'})
|
||||
self.product_id_2 = self.env['product.product'].create({'name': 'Conference Chair'})
|
||||
res_users_purchase_user = self.env.ref('purchase.group_purchase_user')
|
||||
|
||||
Users = self.env['res.users'].with_context({'no_reset_password': True, 'mail_create_nosubscribe': True})
|
||||
|
||||
@@ -3,15 +3,16 @@
|
||||
import time
|
||||
|
||||
from .common import TestPurchase
|
||||
from odoo.addons.stock_account.tests.stock_account_minimal_test import StockAccountMinimalTest
|
||||
|
||||
|
||||
class TestFifoPrice(TestPurchase):
|
||||
class TestFifoPrice(TestPurchase, StockAccountMinimalTest):
|
||||
|
||||
def test_00_test_fifo(self):
|
||||
""" Test product cost price with fifo removal strategy."""
|
||||
|
||||
self._load('account', 'test', 'account_minimal_test.xml')
|
||||
self._load('stock_account', 'test', 'stock_valuation_account.xml')
|
||||
res_partner_3 = self.env['res.partner'].create({
|
||||
'name': 'Gemini Partner',
|
||||
})
|
||||
|
||||
# Set a product as using fifo price
|
||||
product_cable_management_box = self.env['product.product'].create({
|
||||
@@ -28,12 +29,12 @@ class TestFifoPrice(TestPurchase):
|
||||
})
|
||||
product_cable_management_box.categ_id.property_cost_method = 'fifo'
|
||||
product_cable_management_box.categ_id.property_valuation = 'real_time'
|
||||
product_cable_management_box.categ_id.property_stock_account_input_categ_id = self.ref('purchase.o_expense')
|
||||
product_cable_management_box.categ_id.property_stock_account_output_categ_id = self.ref('purchase.o_income')
|
||||
product_cable_management_box.categ_id.property_stock_account_input_categ_id = self.o_expense
|
||||
product_cable_management_box.categ_id.property_stock_account_output_categ_id = self.o_income
|
||||
|
||||
# I create a draft Purchase Order for first in move for 10 kg at 50 euro
|
||||
purchase_order_1 = self.env['purchase.order'].create({
|
||||
'partner_id': self.env.ref('base.res_partner_3').id,
|
||||
'partner_id': res_partner_3.id,
|
||||
'order_line': [(0, 0, {
|
||||
'name': 'FIFO Ice Cream',
|
||||
'product_id': product_cable_management_box.id,
|
||||
@@ -61,7 +62,7 @@ class TestFifoPrice(TestPurchase):
|
||||
|
||||
# I create a draft Purchase Order for second shipment for 30 kg at 80 euro
|
||||
purchase_order_2 = self.env['purchase.order'].create({
|
||||
'partner_id': self.env.ref('base.res_partner_3').id,
|
||||
'partner_id': res_partner_3.id,
|
||||
'order_line': [(0, 0, {
|
||||
'name': 'FIFO Ice Cream',
|
||||
'product_id': product_cable_management_box.id,
|
||||
@@ -144,7 +145,7 @@ class TestFifoPrice(TestPurchase):
|
||||
|
||||
# Create PO for 30000 g at 0.150$/g and 10 kg at 150$/kg
|
||||
purchase_order_usd = self.env['purchase.order'].create({
|
||||
'partner_id': self.env.ref('base.res_partner_3').id,
|
||||
'partner_id': res_partner_3.id,
|
||||
'currency_id': NewUSD.id,
|
||||
'order_line': [(0, 0, {
|
||||
'name': 'FIFO Ice Cream',
|
||||
@@ -229,8 +230,8 @@ class TestFifoPrice(TestPurchase):
|
||||
})
|
||||
product_fifo_negative.categ_id.property_cost_method = 'fifo'
|
||||
product_fifo_negative.categ_id.property_valuation = 'real_time'
|
||||
product_fifo_negative.categ_id.property_stock_account_input_categ_id = self.ref('purchase.o_expense')
|
||||
product_fifo_negative.categ_id.property_stock_account_output_categ_id = self.ref('purchase.o_income')
|
||||
product_fifo_negative.categ_id.property_stock_account_input_categ_id = self.o_expense
|
||||
product_fifo_negative.categ_id.property_stock_account_output_categ_id = self.o_income
|
||||
|
||||
# Create outpicking.create delivery order of 100 kg.
|
||||
outgoing_shipment_neg = self.env['stock.picking'].create({
|
||||
@@ -283,7 +284,7 @@ class TestFifoPrice(TestPurchase):
|
||||
|
||||
# Receive purchase order with 50 kg Ice Cream at 50€/kg
|
||||
purchase_order_neg = self.env['purchase.order'].create({
|
||||
'partner_id': self.env.ref('base.res_partner_3').id,
|
||||
'partner_id': res_partner_3.id,
|
||||
'order_line': [(0, 0, {
|
||||
'name': 'FIFO Ice Cream',
|
||||
'product_id': product_fifo_negative.id,
|
||||
@@ -303,7 +304,7 @@ class TestFifoPrice(TestPurchase):
|
||||
|
||||
# Receive purchase order with 600 kg FIFO Ice Cream at 80 euro/kg
|
||||
purchase_order_neg2 = self.env['purchase.order'].create({
|
||||
'partner_id': self.env.ref('base.res_partner_3').id,
|
||||
'partner_id': res_partner_3.id,
|
||||
'order_line': [(0, 0, {
|
||||
'name': product_cable_management_box.name,
|
||||
'product_id': product_fifo_negative.id,
|
||||
|
||||
@@ -4,14 +4,16 @@ import time
|
||||
|
||||
from .common import TestPurchase
|
||||
from odoo.tests.common import Form
|
||||
from odoo.addons.stock_account.tests.stock_account_minimal_test import StockAccountMinimalTest
|
||||
|
||||
class TestFifoReturns(TestPurchase):
|
||||
|
||||
class TestFifoReturns(TestPurchase, StockAccountMinimalTest):
|
||||
|
||||
def test_fifo_returns(self):
|
||||
"""Test to create product and purchase order to test the FIFO returns of the product"""
|
||||
|
||||
self._load('account', 'test', 'account_minimal_test.xml')
|
||||
self._load('stock_account', 'test', 'stock_valuation_account.xml')
|
||||
res_partner_3 = self.env['res.partner'].create({
|
||||
'name': 'Gemini Partner',
|
||||
})
|
||||
|
||||
# Set a product as using fifo price
|
||||
product_fiforet_icecream = self.env['product.product'].create({
|
||||
@@ -26,12 +28,12 @@ class TestFifoReturns(TestPurchase):
|
||||
})
|
||||
product_fiforet_icecream.categ_id.property_cost_method = 'fifo'
|
||||
product_fiforet_icecream.categ_id.property_valuation = 'real_time'
|
||||
product_fiforet_icecream.categ_id.property_stock_account_input_categ_id = self.ref('purchase.o_expense')
|
||||
product_fiforet_icecream.categ_id.property_stock_account_output_categ_id = self.ref('purchase.o_income')
|
||||
product_fiforet_icecream.categ_id.property_stock_account_input_categ_id = self.o_expense
|
||||
product_fiforet_icecream.categ_id.property_stock_account_output_categ_id = self.o_income
|
||||
|
||||
# I create a draft Purchase Order for first in move for 10 kg at 50 euro
|
||||
purchase_order_1 = self.env['purchase.order'].create({
|
||||
'partner_id': self.ref('base.res_partner_3'),
|
||||
'partner_id': res_partner_3.id,
|
||||
'order_line': [(0, 0, {
|
||||
'name': 'FIFO Ice Cream',
|
||||
'product_id': product_fiforet_icecream.id,
|
||||
@@ -44,7 +46,7 @@ class TestFifoReturns(TestPurchase):
|
||||
|
||||
# Create a draft Purchase Order for second shipment for 30kg at 80€/kg
|
||||
purchase_order_2 = self.env['purchase.order'].create({
|
||||
'partner_id': self.ref('base.res_partner_3'),
|
||||
'partner_id': res_partner_3.id,
|
||||
'order_line': [(0, 0, {
|
||||
'name': 'FIFO Ice Cream',
|
||||
'product_id': product_fiforet_icecream.id,
|
||||
|
||||
@@ -83,7 +83,7 @@ class TestOnchangeProductId(TransactionCase):
|
||||
po_line._onchange_quantity()
|
||||
self.assertEqual(1200, po_line.price_unit, "Unit price should be 1200 for one Dozen")
|
||||
|
||||
product_ipad = self.env.ref('product.product_product_4')
|
||||
product_ipad = self.env['product.product'].create({'name': 'Conference Chair'})
|
||||
po_line2 = self.po_line_model.create({
|
||||
'name': product_ipad.name,
|
||||
'product_id': product_ipad.id,
|
||||
|
||||
@@ -11,19 +11,32 @@ class TestDeleteOrder(TestPurchase):
|
||||
''' Testcase for deleting purchase order with purchase user group'''
|
||||
|
||||
# In order to test delete process on purchase order,tried to delete a confirmed order and check Error Message.
|
||||
purchase_order_1 = self.env.ref('purchase.purchase_order_1').with_user(self.res_users_purchase_user)
|
||||
partner = self.env['res.partner'].create({'name': 'My Partner'})
|
||||
|
||||
purchase_order = self.env['purchase.order'].create({
|
||||
'partner_id': partner.id,
|
||||
'state': 'purchase',
|
||||
})
|
||||
purchase_order_1 = purchase_order.with_user(self.res_users_purchase_user)
|
||||
with self.assertRaises(UserError):
|
||||
purchase_order_1.unlink()
|
||||
|
||||
# Delete 'cancelled' purchase order with user group
|
||||
purchase_order_7 = self.env.ref('purchase.purchase_order_7').with_user(self.res_users_purchase_user)
|
||||
purchase_order_7.button_cancel()
|
||||
self.assertEqual(purchase_order_7.state, 'cancel', 'PO is cancelled!')
|
||||
purchase_order_7.unlink()
|
||||
purchase_order = self.env['purchase.order'].create({
|
||||
'partner_id': partner.id,
|
||||
'state': 'purchase',
|
||||
})
|
||||
purchase_order_2 = purchase_order.with_user(self.res_users_purchase_user)
|
||||
purchase_order_2.button_cancel()
|
||||
self.assertEqual(purchase_order_2.state, 'cancel', 'PO is cancelled!')
|
||||
purchase_order_2.unlink()
|
||||
|
||||
# Delete 'draft' purchase order with user group
|
||||
purchase_order_5 = self.env.ref('purchase.purchase_order_5').with_user(self.res_users_purchase_user)
|
||||
self.assertEqual(purchase_order_5.state, 'draft', 'PO in draft state!')
|
||||
purchase_order_5.button_cancel()
|
||||
self.assertEqual(purchase_order_5.state, 'cancel', 'PO is cancelled!')
|
||||
purchase_order_5.unlink()
|
||||
purchase_order = self.env['purchase.order'].create({
|
||||
'partner_id': partner.id,
|
||||
'state': 'draft',
|
||||
})
|
||||
purchase_order_3 = purchase_order.with_user(self.res_users_purchase_user)
|
||||
purchase_order_3.button_cancel()
|
||||
self.assertEqual(purchase_order_3.state, 'cancel', 'PO is cancelled!')
|
||||
purchase_order_3.unlink()
|
||||
|
||||
@@ -16,9 +16,9 @@ class TestPurchaseOrder(AccountingTestCase):
|
||||
# Useful models
|
||||
self.PurchaseOrder = self.env['purchase.order']
|
||||
self.PurchaseOrderLine = self.env['purchase.order.line']
|
||||
self.partner_id = self.env.ref('base.res_partner_1')
|
||||
self.product_id_1 = self.env.ref('product.product_product_8')
|
||||
self.product_id_2 = self.env.ref('product.product_product_11')
|
||||
self.partner_id = self.env['res.partner'].create({'name': 'Wood Corner Partner'})
|
||||
self.product_id_1 = self.env['product.product'].create({'name': 'Large Desk'})
|
||||
self.product_id_2 = self.env['product.product'].create({'name': 'Conference Chair'})
|
||||
|
||||
(self.product_id_1 | self.product_id_2).write({'purchase_method': 'purchase'})
|
||||
self.po_vals = {
|
||||
|
||||
@@ -7,7 +7,11 @@ class TestPurchaseOrderProcess(TestPurchase):
|
||||
""" Test cancel purchase order with group user."""
|
||||
|
||||
# In order to test the cancel flow,start it from canceling confirmed purchase order.
|
||||
po_edit_with_user = self.env.ref('purchase.purchase_order_5').with_user(self.res_users_purchase_user)
|
||||
purchase_order = self.env['purchase.order'].create({
|
||||
'partner_id': self.env['res.partner'].create({'name': 'My Partner'}).id,
|
||||
'state': 'draft',
|
||||
})
|
||||
po_edit_with_user = purchase_order.with_user(self.res_users_purchase_user)
|
||||
|
||||
# Confirm the purchase order.
|
||||
po_edit_with_user.button_confirm()
|
||||
|
||||
@@ -17,8 +17,16 @@ class TestStockValuation(TransactionCase):
|
||||
super(TestStockValuation, self).setUp()
|
||||
self.supplier_location = self.env.ref('stock.stock_location_suppliers')
|
||||
self.stock_location = self.env.ref('stock.stock_location_stock')
|
||||
self.partner_id = self.env.ref('base.res_partner_1')
|
||||
self.product1 = self.env.ref('product.product_product_8')
|
||||
self.partner_id = self.env['res.partner'].create({
|
||||
'name': 'Wood Corner Partner',
|
||||
'company_id': self.env.user.company_id.id,
|
||||
})
|
||||
self.product1 = self.env['product.product'].create({
|
||||
'name': 'Large Desk',
|
||||
'standard_price': 1299.0,
|
||||
'list_price': 1799.0,
|
||||
'type': 'product',
|
||||
})
|
||||
Account = self.env['account.account']
|
||||
self.stock_input_account = Account.create({
|
||||
'name': 'Stock Input',
|
||||
@@ -287,7 +295,8 @@ class TestStockValuationWithCOA(AccountingTestCase):
|
||||
super(TestStockValuationWithCOA, self).setUp()
|
||||
self.supplier_location = self.env.ref('stock.stock_location_suppliers')
|
||||
self.stock_location = self.env.ref('stock.stock_location_stock')
|
||||
self.partner_id = self.env.ref('base.res_partner_1')
|
||||
self.partner_id = self.env['res.partner'].create({'name': 'Wood Corner Partner'})
|
||||
self.product1 = self.env['product.product'].create({'name': 'Large Desk'})
|
||||
|
||||
self.cat = self.env['product.category'].create({
|
||||
'name': 'cat',
|
||||
@@ -520,6 +529,7 @@ class TestStockValuationWithCOA(AccountingTestCase):
|
||||
"""
|
||||
company = self.env.user.company_id
|
||||
company.anglo_saxon_accounting = True
|
||||
company.currency_id = self.usd_currency
|
||||
|
||||
date_po = '2019-01-01'
|
||||
|
||||
@@ -587,6 +597,7 @@ class TestStockValuationWithCOA(AccountingTestCase):
|
||||
self.assertEqual(len(move_lines), 2)
|
||||
|
||||
payable_line = move_lines.filtered(lambda l: l.account_id.internal_type == 'payable')
|
||||
|
||||
self.assertEqual(payable_line.amount_currency, -100.0)
|
||||
self.assertAlmostEqual(payable_line.balance, -66.67)
|
||||
|
||||
@@ -603,6 +614,7 @@ class TestStockValuationWithCOA(AccountingTestCase):
|
||||
"""
|
||||
company = self.env.user.company_id
|
||||
company.anglo_saxon_accounting = True
|
||||
company.currency_id = self.usd_currency
|
||||
self.product1.product_tmpl_id.categ_id.property_cost_method = 'average'
|
||||
self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'
|
||||
|
||||
@@ -778,6 +790,7 @@ class TestStockValuationWithCOA(AccountingTestCase):
|
||||
"""
|
||||
company = self.env.user.company_id
|
||||
company.anglo_saxon_accounting = True
|
||||
company.currency_id = self.usd_currency
|
||||
self.product1.product_tmpl_id.categ_id.property_cost_method = 'average'
|
||||
self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'
|
||||
|
||||
@@ -938,6 +951,7 @@ class TestStockValuationWithCOA(AccountingTestCase):
|
||||
"""
|
||||
company = self.env.user.company_id
|
||||
company.anglo_saxon_accounting = True
|
||||
company.currency_id = self.usd_currency
|
||||
exchange_diff_journal = company.currency_exchange_journal_id.exists()
|
||||
|
||||
date_po = '2019-01-01'
|
||||
|
||||
Reference in New Issue
Block a user