[IMP] stock_dropshipping: Adapt tests to work with/without demo data

This commit is contained in:
Yannick Tivisse
2019-11-05 16:18:10 +01:00
parent 9fd98d0e03
commit 09ed7a3554
5 changed files with 79 additions and 36 deletions
@@ -40,7 +40,7 @@ class TestCrossdock(common.TransactionCase):
# Create a sales order with a line of 100 PCE incoming shipment with route_id crossdock shipping
so_form = Form(self.env['sale.order'])
so_form.partner_id = self.env.ref('base.res_partner_4')
so_form.partner_id = self.env['res.partner'].create({'name': 'My Test Partner'})
so_form.warehouse_id = wh_pps
with mute_logger('odoo.tests.common.onchange'):
@@ -8,7 +8,7 @@ from odoo.tools import mute_logger
class TestDropship(common.TransactionCase):
def test_change_qty(self):
# enable the dropship and MTO route on the product
prod = self.env.ref('product.product_product_8')
prod = self.env['product.product'].create({'name': 'Large Desk'})
dropshipping_route = self.env.ref('stock_dropshipping.route_drop_shipping')
mto_route = self.env.ref('stock.route_warehouse0_mto')
prod.write({'route_ids': [(6, 0, [dropshipping_route.id, mto_route.id])]})
@@ -87,7 +87,7 @@ class TestDropship(common.TransactionCase):
# Create a sales order with a line of 200 PCE incoming shipment, with route_id drop shipping
so_form = Form(self.env['sale.order'])
so_form.partner_id = self.env.ref('base.res_partner_2')
so_form.partner_id = self.env['res.partner'].create({'name': 'My Test Partner'})
so_form.payment_term_id = self.env.ref('account.account_payment_term_end_following_month')
with mute_logger('odoo.tests.common.onchange'):
# otherwise complains that there's not enough inventory and
@@ -2,21 +2,15 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, tools
from odoo.addons.stock_account.tests.stock_account_minimal_test import StockAccountMinimalTest
from odoo.modules.module import get_module_resource
from odoo.tests import common, Form
class TestLifoPrice(common.TransactionCase):
def _load(self, module, *args):
tools.convert_file(
self.cr, 'stock_dropshipping', get_module_resource(module, *args), {}, 'init', False, 'test', self.registry._assertion_report)
class TestLifoPrice(StockAccountMinimalTest):
def test_lifoprice(self):
self._load('account', 'test', 'account_minimal_test.xml')
self._load('stock_account', 'test', 'stock_valuation_account.xml')
# Set product category removal strategy as LIFO
product_category_001 = self.env['product.category'].create({
'name': 'Lifo Category',
@@ -24,6 +18,7 @@ class TestLifoPrice(common.TransactionCase):
'property_valuation': 'real_time',
'property_cost_method': 'fifo',
})
res_partner_3 = self.env['res.partner'].create({'name': 'My Test Partner'})
# Set a product as using lifo price
product_form = Form(self.env['product.product'])
@@ -39,8 +34,8 @@ class TestLifoPrice(common.TransactionCase):
# category (or hand-assign the property_* version which seems...)
# product_form.categ_id.valuation = 'real_time'
# product_form.categ_id.property_cost_method = 'fifo'
product_form.categ_id.property_stock_account_input_categ_id = self.env.ref('stock_dropshipping.o_expense')
product_form.categ_id.property_stock_account_output_categ_id = self.env.ref('stock_dropshipping.o_income')
product_form.categ_id.property_stock_account_input_categ_id = self.o_expense
product_form.categ_id.property_stock_account_output_categ_id = self.o_income
product_lifo_icecream = product_form.save()
std_price_wiz = Form(self.env['stock.change.standard.price'].with_context(active_id=product_lifo_icecream.id, active_model='product.product'))
@@ -49,7 +44,7 @@ class TestLifoPrice(common.TransactionCase):
# I create a draft Purchase Order for first in move for 10 pieces at 60 euro
order_form = Form(self.env['purchase.order'])
order_form.partner_id = self.env.ref('base.res_partner_3')
order_form.partner_id = res_partner_3
with order_form.order_line.new() as line:
line.product_id = product_lifo_icecream
line.product_qty = 10.0
@@ -58,7 +53,7 @@ class TestLifoPrice(common.TransactionCase):
# I create a draft Purchase Order for second shipment for 30 pieces at 80 euro
order2_form = Form(self.env['purchase.order'])
order2_form.partner_id = self.env.ref('base.res_partner_3')
order2_form.partner_id = res_partner_3
with order2_form.order_line.new() as line:
line.product_id = product_lifo_icecream
line.product_qty = 30.0
@@ -8,6 +8,12 @@ class TestProcurementException(common.TransactionCase):
def test_00_procurement_exception(self):
res_partner_2 = self.env['res.partner'].create({'name': 'My Test Partner'})
res_partner_address = self.env['res.partner'].create({
'name': 'My Test Partner Address',
'parent_id': res_partner_2.id,
})
# I create a product with no supplier define for it.
product_form = Form(self.env['product.product'])
product_form.name = 'product with no seller'
@@ -18,12 +24,11 @@ class TestProcurementException(common.TransactionCase):
std_price_wiz = Form(self.env['stock.change.standard.price'].with_context(active_id=product_with_no_seller.id, active_model='product.product'))
std_price_wiz.new_price = 70.0
std_price_wiz.save()
# I create a sales order with this product with route dropship.
so_form = Form(self.env['sale.order'])
so_form.partner_id = self.env.ref('base.res_partner_2')
so_form.partner_invoice_id = self.env.ref('base.res_partner_address_3')
so_form.partner_shipping_id = self.env.ref('base.res_partner_address_3')
so_form.partner_id = res_partner_2
so_form.partner_invoice_id = res_partner_address
so_form.partner_shipping_id = res_partner_address
so_form.payment_term_id = self.env.ref('account.account_payment_term_end_following_month')
with so_form.order_line.new() as line:
line.product_id = product_with_no_seller
@@ -39,7 +44,7 @@ class TestProcurementException(common.TransactionCase):
with Form(product_with_no_seller) as f:
with f.seller_ids.new() as seller:
seller.delay = 1
seller.name = self.env.ref('base.res_partner_2')
seller.name = res_partner_2
seller.min_qty = 2.0
# I confirm the sales order, no error this time
@@ -1,25 +1,67 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.account.tests.account_test_classes import AccountingTestCase
from odoo.addons.stock_account.tests.stock_account_minimal_test import StockAccountMinimalTest
from odoo.tests import Form, tagged
@tagged('post_install', '-at_install')
class TestStockValuation(AccountingTestCase):
def setUp(self):
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.categ_id = self.product1.categ_id
class TestStockValuation(StockAccountMinimalTest):
self.acc_payable = self.partner_id.property_account_payable_id.id
self.acc_expense = self.categ_id.property_account_expense_categ_id.id
self.acc_receivable = self.partner_id.property_account_receivable_id.id
self.acc_sale = self.categ_id.property_account_income_categ_id.id
self.acc_stock_in = self.categ_id.property_stock_account_input_categ_id.id
self.acc_stock_out = self.categ_id.property_stock_account_output_categ_id.id
@classmethod
def setUpClass(cls):
super(TestStockValuation, cls).setUpClass()
# Setup a new company to avoid any external influence
cls.company = cls.env['res.company'].create({
'name': 'My Test Company',
'currency_id': cls.env.ref('base.USD').id,
})
cls.env.user.company_id = cls.company
cls.create_accounting_minimal_data()
cls.supplier_location = cls.env.ref('stock.stock_location_suppliers')
cls.stock_location = cls.env.ref('stock.stock_location_stock')
cls.partner_id = cls.env['res.partner'].create({'name': 'My Test Partner'})
cls.product1 = cls.env['product.product'].create({
'name': 'Large Desk',
'type': 'product',
'categ_id': cls.env.ref('product.product_category_all').id,
'taxes_id': [(6, 0, [])],
})
cls.categ_id = cls.product1.categ_id
cls.stock_input_account = cls.env['account.account'].create({
'name': 'Stock Input',
'code': 'StockIn',
'user_type_id': cls.env.ref('account.data_account_type_current_assets').id,
'reconcile': True,
})
cls.stock_output_account = cls.env['account.account'].create({
'name': 'Stock Output',
'code': 'StockOut',
'user_type_id': cls.env.ref('account.data_account_type_current_assets').id,
'reconcile': True,
})
cls.stock_valuation_account = cls.env['account.account'].create({
'name': 'Stock Valuation',
'code': 'Stock Valuation',
'user_type_id': cls.env.ref('account.data_account_type_current_assets').id,
})
cls.stock_journal = cls.env['account.journal'].create({
'name': 'Stock Journal',
'code': 'STJTEST',
'type': 'general',
})
cls.product1.categ_id.write({
'property_stock_account_input_categ_id': cls.stock_input_account.id,
'property_stock_account_output_categ_id': cls.stock_output_account.id,
'property_stock_valuation_account_id': cls.stock_valuation_account.id,
'property_stock_journal': cls.stock_journal.id,
})
cls.acc_payable = cls.partner_id.property_account_payable_id.id
cls.acc_expense = cls.categ_id.property_account_expense_categ_id.id
cls.acc_receivable = cls.partner_id.property_account_receivable_id.id
cls.acc_sale = cls.categ_id.property_account_income_categ_id.id
cls.acc_stock_in = cls.categ_id.property_stock_account_input_categ_id.id
cls.acc_stock_out = cls.categ_id.property_stock_account_output_categ_id.id
def _dropship_product1(self):
# enable the dropship and MTO route on the product
@@ -47,6 +89,7 @@ class TestStockValuation(AccountingTestCase):
'product_uom_qty': 1,
'product_uom': self.product1.uom_id.id,
'price_unit': 12,
'tax_id': [(6, 0, [])],
})],
'pricelist_id': self.env.ref('product.list0').id,
'picking_policy': 'direct',
@@ -69,6 +112,7 @@ class TestStockValuation(AccountingTestCase):
move_form = Form(self.env['account.move'].with_context(default_type='in_invoice'))
move_form.partner_id = vendor1
move_form.purchase_id = self.purchase_order1
move_form.line_ids.tax_ids = False
self.vendor_bill1 = move_form.save()
self.vendor_bill1.post()
@@ -261,7 +305,6 @@ class TestStockValuation(AccountingTestCase):
self.acc_stock_in: (8.0, 8.0),
self.acc_stock_out: (8.0, 8.0),
}
self._check_results(expected_aml, 10, all_amls)
def test_dropship_standard_perpetual_anglosaxon_ordered_return(self):