summaryrefslogtreecommitdiff
path: root/addons/stock_dropshipping/tests
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/stock_dropshipping/tests
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/stock_dropshipping/tests')
-rw-r--r--addons/stock_dropshipping/tests/__init__.py8
-rw-r--r--addons/stock_dropshipping/tests/test_crossdock.py64
-rw-r--r--addons/stock_dropshipping/tests/test_dropship.py123
-rw-r--r--addons/stock_dropshipping/tests/test_lifo_price.py97
-rw-r--r--addons/stock_dropshipping/tests/test_procurement_exception.py56
-rw-r--r--addons/stock_dropshipping/tests/test_stockvaluation.py300
6 files changed, 648 insertions, 0 deletions
diff --git a/addons/stock_dropshipping/tests/__init__.py b/addons/stock_dropshipping/tests/__init__.py
new file mode 100644
index 00000000..990bd059
--- /dev/null
+++ b/addons/stock_dropshipping/tests/__init__.py
@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import test_crossdock
+from . import test_dropship
+from . import test_lifo_price
+from . import test_procurement_exception
+from . import test_stockvaluation
diff --git a/addons/stock_dropshipping/tests/test_crossdock.py b/addons/stock_dropshipping/tests/test_crossdock.py
new file mode 100644
index 00000000..2d13a7c7
--- /dev/null
+++ b/addons/stock_dropshipping/tests/test_crossdock.py
@@ -0,0 +1,64 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo.tests import common, Form
+from odoo.tools import mute_logger
+
+
+class TestCrossdock(common.TransactionCase):
+
+ def test_00_crossdock(self):
+
+ # Create a supplier
+ supplier_crossdock = self.env['res.partner'].create({'name': "Crossdocking supplier"})
+
+ # I first create a warehouse with pick-pack-ship and reception in 2 steps
+ wh_pps = self.env['stock.warehouse'].create({
+ 'name': 'WareHouse PickPackShip',
+ 'code': 'whpps',
+ 'reception_steps': 'two_steps',
+ 'delivery_steps': 'pick_pack_ship',
+ })
+
+ # Check that cross-dock route is active
+ self.assertTrue(wh_pps.crossdock_route_id.active,
+ "Crossdock route should be active when reception_steps is not in 'single_step'")
+
+ p_f = Form(self.env['product.template'])
+ p_f.name = 'PCE'
+ p_f.type = 'product'
+ p_f.categ_id = self.env.ref('product.product_category_1')
+ p_f.list_price = 100.0
+ with p_f.seller_ids.new() as seller:
+ seller.name = supplier_crossdock
+ p_f.route_ids.add(wh_pps.crossdock_route_id)
+ cross_shop_product = p_f.save()
+
+ p_f.standard_price = 70.0
+
+ # 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['res.partner'].create({'name': 'My Test Partner'})
+ so_form.warehouse_id = wh_pps
+
+ with mute_logger('odoo.tests.common.onchange'):
+ # otherwise complains that there's not enough inventory and
+ # apparently that's normal according to @jco and @sle
+ with so_form.order_line.new() as line:
+ line.product_id = cross_shop_product.product_variant_ids
+ line.product_uom_qty = 100.0
+ sale_order_crossdock = so_form.save()
+
+ # Confirm sales order
+ sale_order_crossdock.action_confirm()
+
+ # Run the scheduler
+ self.env['procurement.group'].run_scheduler()
+
+ # Check a quotation was created for the created supplier and confirm it
+ po = self.env['purchase.order'].search([
+ ('partner_id', '=', supplier_crossdock.id),
+ ('state', '=', 'draft')
+ ])
+ self.assertTrue(po, "an RFQ should have been created by the scheduler")
+ po.button_confirm()
diff --git a/addons/stock_dropshipping/tests/test_dropship.py b/addons/stock_dropshipping/tests/test_dropship.py
new file mode 100644
index 00000000..a3c49b1c
--- /dev/null
+++ b/addons/stock_dropshipping/tests/test_dropship.py
@@ -0,0 +1,123 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo.tests import common, Form
+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['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])]})
+
+ # add a vendor
+ vendor1 = self.env['res.partner'].create({'name': 'vendor1'})
+ seller1 = self.env['product.supplierinfo'].create({
+ 'name': vendor1.id,
+ 'price': 8,
+ })
+ prod.write({'seller_ids': [(6, 0, [seller1.id])]})
+
+ # sell one unit of this product
+ cust = self.env['res.partner'].create({'name': 'customer1'})
+ so = self.env['sale.order'].create({
+ 'partner_id': cust.id,
+ 'partner_invoice_id': cust.id,
+ 'partner_shipping_id': cust.id,
+ 'order_line': [(0, 0, {
+ 'name': prod.name,
+ 'product_id': prod.id,
+ 'product_uom_qty': 1.00,
+ 'product_uom': prod.uom_id.id,
+ 'price_unit': 12,
+ })],
+ 'pricelist_id': self.env.ref('product.list0').id,
+ 'picking_policy': 'direct',
+ })
+ so.action_confirm()
+ po = self.env['purchase.order'].search([('group_id', '=', so.procurement_group_id.id)])
+ po_line = po.order_line
+
+ # Check the qty on the P0
+ self.assertAlmostEqual(po_line.product_qty, 1.00)
+
+ # Update qty on SO and check PO
+ so.write({'order_line': [[1, so.order_line.id, {'product_uom_qty': 2.00}]]})
+ self.assertAlmostEqual(po_line.product_qty, 2.00)
+
+ # Create a new so line
+ sol2 = self.env['sale.order.line'].create({
+ 'order_id': so.id,
+ 'name': prod.name,
+ 'product_id': prod.id,
+ 'product_uom_qty': 3.00,
+ 'product_uom': prod.uom_id.id,
+ 'price_unit': 12,
+ })
+ # there is a new line
+ pol2 = po.order_line - po_line
+ # the first line is unchanged
+ self.assertAlmostEqual(po_line.product_qty, 2.00)
+ # the new line matches the new line on the so
+ self.assertAlmostEqual(pol2.product_qty, sol2.product_uom_qty)
+
+ def test_00_dropship(self):
+
+ # Create a vendor
+ supplier_dropship = self.env['res.partner'].create({'name': 'Vendor of Dropshipping test'})
+
+ # Create new product without any routes
+ drop_shop_product = self.env['product.product'].create({
+ 'name': "Pen drive",
+ 'type': "product",
+ 'categ_id': self.env.ref('product.product_category_1').id,
+ 'lst_price': 100.0,
+ 'standard_price': 0.0,
+ 'uom_id': self.env.ref('uom.product_uom_unit').id,
+ 'uom_po_id': self.env.ref('uom.product_uom_unit').id,
+ 'seller_ids': [(0, 0, {
+ 'delay': 1,
+ 'name': supplier_dropship.id,
+ 'min_qty': 2.0
+ })]
+ })
+
+ # 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['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
+ # apparently that's normal according to @jco and @sle
+ with so_form.order_line.new() as line:
+ line.product_id = drop_shop_product
+ line.product_uom_qty = 200
+ line.price_unit = 1.00
+ line.route_id = self.env.ref('stock_dropshipping.route_drop_shipping')
+ sale_order_drp_shpng = so_form.save()
+
+ # Confirm sales order
+ sale_order_drp_shpng.action_confirm()
+
+ # Check the sales order created a procurement group which has a procurement of 200 pieces
+ self.assertTrue(sale_order_drp_shpng.procurement_group_id, 'SO should have procurement group')
+
+ # Check a quotation was created to a certain vendor and confirm so it becomes a confirmed purchase order
+ purchase = self.env['purchase.order'].search([('partner_id', '=', supplier_dropship.id)])
+ self.assertTrue(purchase, "an RFQ should have been created by the scheduler")
+ purchase.button_confirm()
+ self.assertEqual(purchase.state, 'purchase', 'Purchase order should be in the approved state')
+ self.assertEqual(len(purchase.ids), 1, 'There should be one picking')
+
+ # Send the 200 pieces
+ purchase.picking_ids.move_lines.quantity_done = purchase.picking_ids.move_lines.product_qty
+ purchase.picking_ids.button_validate()
+
+ # Check one move line was created in Customers location with 200 pieces
+ move_line = self.env['stock.move.line'].search([
+ ('location_dest_id', '=', self.env.ref('stock.stock_location_customers').id),
+ ('product_id', '=', drop_shop_product.id)])
+ self.assertEqual(len(move_line.ids), 1, 'There should be exactly one move line')
diff --git a/addons/stock_dropshipping/tests/test_lifo_price.py b/addons/stock_dropshipping/tests/test_lifo_price.py
new file mode 100644
index 00000000..02c20f6a
--- /dev/null
+++ b/addons/stock_dropshipping/tests/test_lifo_price.py
@@ -0,0 +1,97 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import fields, tools
+from odoo.addons.stock_account.tests.test_anglo_saxon_valuation_reconciliation_common import ValuationReconciliationTestCommon
+from odoo.tests import tagged, common, Form
+
+
+@tagged('-at_install', 'post_install')
+class TestLifoPrice(ValuationReconciliationTestCommon):
+
+ def test_lifoprice(self):
+
+ # Set product category removal strategy as LIFO
+ product_category_001 = self.env['product.category'].create({
+ 'name': 'Lifo Category',
+ 'removal_strategy_id': self.env.ref('stock.removal_lifo').id,
+ 'property_valuation': 'real_time',
+ 'property_cost_method': 'fifo',
+ })
+ res_partner_3 = self.env['res.partner'].create({'name': 'My Test Partner'})
+ self.company_data['default_warehouse'].out_type_id.show_operations = False
+
+ # Set a product as using lifo price
+ product_form = Form(self.env['product.product'])
+ product_form.default_code = 'LIFO'
+ product_form.name = 'LIFO Ice Cream'
+ product_form.type = 'product'
+ product_form.categ_id = product_category_001
+ product_form.lst_price = 100.0
+ product_form.uom_id = self.env.ref('uom.product_uom_kgm')
+ product_form.uom_po_id = self.env.ref('uom.product_uom_kgm')
+ # these are not available (visible) in either product or variant
+ # for views, apparently from the UI you can only set the product
+ # 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.company_data['default_account_stock_in']
+ product_form.categ_id.property_stock_account_output_categ_id = self.company_data['default_account_stock_out']
+ product_lifo_icecream = product_form.save()
+
+ product_lifo_icecream.standard_price = 70.0
+
+ # 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 = res_partner_3
+ with order_form.order_line.new() as line:
+ line.product_id = product_lifo_icecream
+ line.product_qty = 10.0
+ line.price_unit = 60.0
+ purchase_order_lifo1 = order_form.save()
+
+ # 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 = res_partner_3
+ with order2_form.order_line.new() as line:
+ line.product_id = product_lifo_icecream
+ line.product_qty = 30.0
+ line.price_unit = 80.0
+ purchase_order_lifo2 = order2_form.save()
+
+ # I confirm the first purchase order
+ purchase_order_lifo1.button_confirm()
+
+ # I check the "Approved" status of purchase order 1
+ self.assertEqual(purchase_order_lifo1.state, 'purchase')
+
+ # Process the receipt of purchase order 1
+ purchase_order_lifo1.picking_ids[0].move_lines.quantity_done = purchase_order_lifo1.picking_ids[0].move_lines.product_qty
+ purchase_order_lifo1.picking_ids[0].button_validate()
+
+ # I confirm the second purchase order
+ purchase_order_lifo2.button_confirm()
+
+ # Process the receipt of purchase order 2
+ purchase_order_lifo2.picking_ids[0].move_lines.quantity_done = purchase_order_lifo2.picking_ids[0].move_lines.product_qty
+ purchase_order_lifo2.picking_ids[0].button_validate()
+
+ # Let us send some goods
+ self.company_data['default_warehouse'].out_type_id.show_operations = False
+ out_form = Form(self.env['stock.picking'])
+ out_form.picking_type_id = self.company_data['default_warehouse'].out_type_id
+ out_form.immediate_transfer = True
+ with out_form.move_ids_without_package.new() as move:
+ move.product_id = product_lifo_icecream
+ move.quantity_done = 20.0
+ move.date = fields.Datetime.now()
+ outgoing_lifo_shipment = out_form.save()
+
+ # I assign this outgoing shipment
+ outgoing_lifo_shipment.action_assign()
+
+ # Process the delivery of the outgoing shipment
+ outgoing_lifo_shipment.button_validate()
+
+ # Check if the move value correctly reflects the fifo costing method
+ self.assertEqual(outgoing_lifo_shipment.move_lines.stock_valuation_layer_ids.value, -1400.0, 'Stock move value should have been 1400 euro')
diff --git a/addons/stock_dropshipping/tests/test_procurement_exception.py b/addons/stock_dropshipping/tests/test_procurement_exception.py
new file mode 100644
index 00000000..2d5c7e44
--- /dev/null
+++ b/addons/stock_dropshipping/tests/test_procurement_exception.py
@@ -0,0 +1,56 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo.tests import common, Form
+
+
+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'
+ product_form.lst_price = 20.00
+ product_form.categ_id = self.env.ref('product.product_category_1')
+ product_with_no_seller = product_form.save()
+
+ product_with_no_seller.standard_price = 70.0
+
+ # I create a sales order with this product with route dropship.
+ so_form = Form(self.env['sale.order'])
+ 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
+ line.product_uom_qty = 3
+ line.route_id = self.env.ref('stock_dropshipping.route_drop_shipping')
+ sale_order_route_dropship01 = so_form.save()
+
+ # I confirm the sales order, but it will raise an error
+ with self.assertRaises(Exception):
+ sale_order_route_dropship01.action_confirm()
+
+ # I set the at least one supplier on the product.
+ with Form(product_with_no_seller) as f:
+ with f.seller_ids.new() as seller:
+ seller.delay = 1
+ seller.name = res_partner_2
+ seller.min_qty = 2.0
+
+ # I confirm the sales order, no error this time
+ sale_order_route_dropship01.action_confirm()
+
+ # I check a purchase quotation was created.
+ purchase = self.env['purchase.order.line'].search([
+ ('sale_line_id', '=', sale_order_route_dropship01.order_line.ids[0])]).order_id
+
+ self.assertTrue(purchase, 'No Purchase Quotation is created')
diff --git a/addons/stock_dropshipping/tests/test_stockvaluation.py b/addons/stock_dropshipping/tests/test_stockvaluation.py
new file mode 100644
index 00000000..b1ac78d2
--- /dev/null
+++ b/addons/stock_dropshipping/tests/test_stockvaluation.py
@@ -0,0 +1,300 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+from odoo.addons.stock_account.tests.test_anglo_saxon_valuation_reconciliation_common import ValuationReconciliationTestCommon
+from odoo.tests import Form, tagged
+
+
+@tagged('post_install', '-at_install')
+class TestStockValuation(ValuationReconciliationTestCommon):
+
+ @classmethod
+ def setUpClass(cls, chart_template_ref=None):
+ super().setUpClass(chart_template_ref=chart_template_ref)
+
+ cls.supplier_location = cls.env.ref('stock.stock_location_suppliers')
+ cls.stock_location = cls.company_data['default_warehouse'].lot_stock_id
+ 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.stock_account_product_categ.id,
+ 'taxes_id': [(6, 0, [])],
+ })
+
+ def _dropship_product1(self):
+ # enable the dropship and MTO route on the product
+ dropshipping_route = self.env.ref('stock_dropshipping.route_drop_shipping')
+ mto_route = self.env.ref('stock.route_warehouse0_mto')
+ self.product1.write({'route_ids': [(6, 0, [dropshipping_route.id, mto_route.id])]})
+
+ # add a vendor
+ vendor1 = self.env['res.partner'].create({'name': 'vendor1'})
+ seller1 = self.env['product.supplierinfo'].create({
+ 'name': vendor1.id,
+ 'price': 8,
+ })
+ self.product1.write({'seller_ids': [(6, 0, [seller1.id])]})
+
+ # sell one unit of this product
+ customer1 = self.env['res.partner'].create({'name': 'customer1'})
+ self.sale_order1 = self.env['sale.order'].create({
+ 'partner_id': customer1.id,
+ 'partner_invoice_id': customer1.id,
+ 'partner_shipping_id': customer1.id,
+ 'order_line': [(0, 0, {
+ 'name': self.product1.name,
+ 'product_id': self.product1.id,
+ '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',
+ })
+ self.sale_order1.action_confirm()
+
+ # confirm the purchase order
+ self.purchase_order1 = self.env['purchase.order'].search([('group_id', '=', self.sale_order1.procurement_group_id.id)])
+ self.purchase_order1.button_confirm()
+
+ # validate the dropshipping picking
+ self.assertEqual(len(self.sale_order1.picking_ids), 1)
+ wizard = self.sale_order1.picking_ids.button_validate()
+ immediate_transfer = Form(self.env[wizard['res_model']].with_context(wizard['context'])).save()
+ immediate_transfer.process()
+ self.assertEqual(self.sale_order1.picking_ids.state, 'done')
+
+ # create the vendor bill
+ move_form = Form(self.env['account.move'].with_context(default_move_type='in_invoice'))
+ move_form.partner_id = vendor1
+ move_form.purchase_id = self.purchase_order1
+ move_form.invoice_date = move_form.date
+ for i in range(len(self.purchase_order1.order_line)):
+ with move_form.invoice_line_ids.edit(i) as line_form:
+ line_form.tax_ids.clear()
+ self.vendor_bill1 = move_form.save()
+ self.vendor_bill1.action_post()
+
+ # create the customer invoice
+ self.customer_invoice1 = self.sale_order1._create_invoices()
+ self.customer_invoice1.action_post()
+
+ all_amls = self.vendor_bill1.line_ids + self.customer_invoice1.line_ids
+ if self.sale_order1.picking_ids.move_lines.account_move_ids:
+ all_amls |= self.sale_order1.picking_ids.move_lines.account_move_ids.line_ids
+ return all_amls
+
+ def _check_results(self, expected_aml, expected_aml_count, all_amls):
+ # Construct a dict similar to `expected_aml` with `all_amls` in order to
+ # compare them.
+ result_aml = {}
+ for aml in all_amls:
+ account_id = aml.account_id.id
+ if result_aml.get(account_id):
+ debit = result_aml[account_id][0]
+ credit = result_aml[account_id][1]
+ result_aml[account_id] = (debit + aml.debit, credit + aml.credit)
+ else:
+ result_aml[account_id] = (aml.debit, aml.credit)
+
+ self.assertEqual(len(all_amls), expected_aml_count)
+
+ for k, v in expected_aml.items():
+ self.assertEqual(result_aml[k], v)
+
+ # -------------------------------------------------------------------------
+ # Continental
+ # -------------------------------------------------------------------------
+ def test_dropship_standard_perpetual_continental_ordered(self):
+ self.env.company.anglo_saxon_accounting = False
+ self.product1.product_tmpl_id.categ_id.property_cost_method = 'standard'
+ self.product1.product_tmpl_id.standard_price = 10
+ self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'
+ self.product1.product_tmpl_id.invoice_policy = 'order'
+
+ all_amls = self._dropship_product1()
+
+ expected_aml = {
+ self.company_data['default_account_payable'].id: (0.0, 8.0),
+ self.company_data['default_account_expense'].id: (8.0, 0.0),
+ self.company_data['default_account_receivable'].id: (12.0, 0.0),
+ self.company_data['default_account_revenue'].id: (0.0, 12.0),
+ }
+
+ self._check_results(expected_aml, 4, all_amls)
+
+ def test_dropship_standard_perpetual_continental_delivered(self):
+ self.env.company.anglo_saxon_accounting = False
+ self.product1.product_tmpl_id.categ_id.property_cost_method = 'standard'
+ self.product1.product_tmpl_id.standard_price = 10
+ self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'
+ self.product1.product_tmpl_id.invoice_policy = 'delivery'
+
+ all_amls = self._dropship_product1()
+
+ expected_aml = {
+ self.company_data['default_account_payable'].id: (0.0, 8.0),
+ self.company_data['default_account_expense'].id: (8.0, 0.0),
+ self.company_data['default_account_receivable'].id: (12.0, 0.0),
+ self.company_data['default_account_revenue'].id: (0.0, 12.0),
+ }
+
+ self._check_results(expected_aml, 4, all_amls)
+
+ def test_dropship_fifo_perpetual_continental_ordered(self):
+ self.env.company.anglo_saxon_accounting = False
+ self.product1.product_tmpl_id.categ_id.property_cost_method = 'fifo'
+ self.product1.product_tmpl_id.standard_price = 10
+ self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'
+ self.product1.product_tmpl_id.invoice_policy = 'order'
+
+ all_amls = self._dropship_product1()
+
+ expected_aml = {
+ self.company_data['default_account_payable'].id: (0.0, 8.0),
+ self.company_data['default_account_expense'].id: (8.0, 0.0),
+ self.company_data['default_account_receivable'].id: (12.0, 0.0),
+ self.company_data['default_account_revenue'].id: (0.0, 12.0),
+ }
+
+ self._check_results(expected_aml, 4, all_amls)
+
+ def test_dropship_fifo_perpetual_continental_delivered(self):
+ self.env.company.anglo_saxon_accounting = False
+
+ self.product1.product_tmpl_id.categ_id.property_cost_method = 'fifo'
+ self.product1.product_tmpl_id.standard_price = 10
+ self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'
+ self.product1.product_tmpl_id.invoice_policy = 'delivery'
+
+ all_amls = self._dropship_product1()
+
+ expected_aml = {
+ self.company_data['default_account_payable'].id: (0.0, 8.0),
+ self.company_data['default_account_expense'].id: (8.0, 0.0),
+ self.company_data['default_account_receivable'].id: (12.0, 0.0),
+ self.company_data['default_account_revenue'].id: (0.0, 12.0),
+ }
+
+ self._check_results(expected_aml, 4, all_amls)
+
+ # -------------------------------------------------------------------------
+ # Anglosaxon
+ # -------------------------------------------------------------------------
+ def test_dropship_standard_perpetual_anglosaxon_ordered(self):
+ self.env.company.anglo_saxon_accounting = True
+ self.product1.product_tmpl_id.categ_id.property_cost_method = 'standard'
+ self.product1.product_tmpl_id.standard_price = 10
+ self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'
+ self.product1.product_tmpl_id.invoice_policy = 'order'
+
+ all_amls = self._dropship_product1()
+
+ expected_aml = {
+ self.company_data['default_account_payable'].id: (0.0, 8.0),
+ self.company_data['default_account_expense'].id: (10.0, 0.0),
+ self.company_data['default_account_receivable'].id: (12.0, 0.0),
+ self.company_data['default_account_revenue'].id: (0.0, 12.0),
+ self.company_data['default_account_stock_in'].id: (8.0, 10.0),
+ self.company_data['default_account_stock_out'].id: (10.0, 10.0),
+ }
+ # Interim IN is not balanced because because there's a difference between the po line
+ # price unit and the standard price. We could set a price difference account on the
+ # category to compensate.
+
+ self._check_results(expected_aml, 10, all_amls)
+
+ def test_dropship_standard_perpetual_anglosaxon_delivered(self):
+ self.env.company.anglo_saxon_accounting = True
+ self.product1.product_tmpl_id.categ_id.property_cost_method = 'standard'
+ self.product1.product_tmpl_id.standard_price = 10
+ self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'
+ self.product1.product_tmpl_id.invoice_policy = 'delivery'
+
+ all_amls = self._dropship_product1()
+
+ expected_aml = {
+ self.company_data['default_account_payable'].id: (0.0, 8.0),
+ self.company_data['default_account_expense'].id: (10.0, 0.0),
+ self.company_data['default_account_receivable'].id: (12.0, 0.0),
+ self.company_data['default_account_revenue'].id: (0.0, 12.0),
+ self.company_data['default_account_stock_in'].id: (8.0, 10.0),
+ self.company_data['default_account_stock_out'].id: (10.0, 10.0),
+ }
+ # Interim IN is not balanced because because there's a difference between the po line
+ # price unit and the standard price. We could set a price difference account on the
+ # category to compensate.
+
+ self._check_results(expected_aml, 10, all_amls)
+
+ def test_dropship_fifo_perpetual_anglosaxon_ordered(self):
+ self.env.company.anglo_saxon_accounting = True
+ self.product1.product_tmpl_id.categ_id.property_cost_method = 'fifo'
+ self.product1.product_tmpl_id.standard_price = 10
+ self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'
+ self.product1.product_tmpl_id.invoice_policy = 'order'
+
+ all_amls = self._dropship_product1()
+
+ expected_aml = {
+ self.company_data['default_account_payable'].id: (0.0, 8.0),
+ self.company_data['default_account_expense'].id: (8.0, 0.0),
+ self.company_data['default_account_receivable'].id: (12.0, 0.0),
+ self.company_data['default_account_revenue'].id: (0.0, 12.0),
+ self.company_data['default_account_stock_in'].id: (8.0, 8.0),
+ self.company_data['default_account_stock_out'].id: (8.0, 8.0),
+ }
+
+ self._check_results(expected_aml, 10, all_amls)
+
+ def test_dropship_fifo_perpetual_anglosaxon_delivered(self):
+ self.env.company.anglo_saxon_accounting = True
+ self.product1.product_tmpl_id.categ_id.property_cost_method = 'fifo'
+ self.product1.product_tmpl_id.standard_price = 10
+ self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'
+ self.product1.product_tmpl_id.invoice_policy = 'delivery'
+
+ all_amls = self._dropship_product1()
+
+ expected_aml = {
+ self.company_data['default_account_payable'].id: (0.0, 8.0),
+ self.company_data['default_account_expense'].id: (8.0, 0.0),
+ self.company_data['default_account_receivable'].id: (12.0, 0.0),
+ self.company_data['default_account_revenue'].id: (0.0, 12.0),
+ self.company_data['default_account_stock_in'].id: (8.0, 8.0),
+ self.company_data['default_account_stock_out'].id: (8.0, 8.0),
+ }
+ self._check_results(expected_aml, 10, all_amls)
+
+ def test_dropship_standard_perpetual_anglosaxon_ordered_return(self):
+ self.env.company.anglo_saxon_accounting = True
+ self.product1.product_tmpl_id.categ_id.property_cost_method = 'standard'
+ self.product1.product_tmpl_id.standard_price = 10
+ self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'
+ self.product1.product_tmpl_id.invoice_policy = 'order'
+
+ all_amls = self._dropship_product1()
+
+ # return what we've done
+ stock_return_picking_form = Form(self.env['stock.return.picking']
+ .with_context(active_ids=self.sale_order1.picking_ids.ids, active_id=self.sale_order1.picking_ids.ids[0],
+ active_model='stock.picking'))
+ stock_return_picking = stock_return_picking_form.save()
+ stock_return_picking_action = stock_return_picking.create_returns()
+ return_pick = self.env['stock.picking'].browse(stock_return_picking_action['res_id'])
+ return_pick.move_lines[0].move_line_ids[0].qty_done = 1.0
+ return_pick._action_done()
+ self.assertEqual(return_pick.move_lines._is_dropshipped_returned(), True)
+
+ all_amls_return = self.vendor_bill1.line_ids + self.customer_invoice1.line_ids
+ if self.sale_order1.picking_ids.mapped('move_lines.account_move_ids'):
+ all_amls_return |= self.sale_order1.picking_ids.mapped('move_lines.account_move_ids.line_ids')
+
+ # Two extra AML should have been created for the return
+ expected_aml = {
+ self.company_data['default_account_stock_in'].id: (10.0, 0.0),
+ self.company_data['default_account_stock_out'].id: (0.0, 10.0),
+ }
+
+ self._check_results(expected_aml, 4, all_amls_return - all_amls)