Skip to content
Snippets Groups Projects
Commit 6fb8e51b authored by Yannick Tivisse's avatar Yannick Tivisse
Browse files

[IMP] stock_landed_costs: Convert yml tests to python

parent cbbd9c44
No related branches found
No related tags found
No related merge requests found
......@@ -23,12 +23,6 @@ This module allows you to easily add extra costs on pickings and decide the spli
'views/stock_landed_cost_views.xml',
'views/res_config_settings_views.xml',
],
'test': [
'../account/test/account_minimal_test.xml',
'../stock_account/test/stock_valuation_account.xml',
'test/stock_landed_costs.yml',
'test/stock_landed_costs_rounding.yml',
],
'installable': True,
'auto_install': False,
}
-
In order to test the landed costs feature of stock, I create a landed cost, confirm it and check its account move created
-
I create 2 products with different volume and gross weight and configure them for real_time valuation and fifo costing method
-
!record {model: product.product, id: product_landed_cost_1}:
name: "LC product 1"
cost_method: fifo
valuation: real_time
weight: 10
volume: 1
property_stock_account_input: o_expense
property_stock_account_output: o_income
-
!record {model: product.product, id: product_landed_cost_2}:
name: "LC product 2"
cost_method: fifo
valuation: real_time
weight: 20
volume: 1.5
property_stock_account_input: o_expense
property_stock_account_output: o_income
-
I create 2 picking moving those products
-
!record {model: stock.picking, id: picking_landed_cost_1}:
name: 'LC_pick_1'
picking_type_id: stock.picking_type_out
move_lines:
- name: move 1
product_id: product_landed_cost_1
product_uom_qty: 5
product_uom: product.product_uom_unit
location_id: stock.stock_location_stock
location_dest_id: stock.stock_location_customers
-
Confirm and assign picking
-
!python {model: stock.picking, id: picking_landed_cost_1}: |
self.env.user.company_id.anglo_saxon_accounting = True
self.action_confirm()
self.action_assign()
self.move_lines.quantity_done = 5
self.button_validate()
-
!record {model: stock.picking, id: picking_landed_cost_2}:
name: 'LC_pick_2'
picking_type_id: stock.picking_type_out
move_lines:
- name: move 2
product_id: product_landed_cost_2
product_uom_qty: 10
product_uom: product.product_uom_unit
location_id: stock.stock_location_stock
location_dest_id: stock.stock_location_customers
-
Confirm and assign picking
-
!python {model: stock.picking, id: picking_landed_cost_2}: |
self.action_confirm()
self.action_assign()
self.move_lines.quantity_done = 10
self.button_validate()
-
I create a landed cost for those 2 pickings
-
!record {model: stock.landed.cost, id: stock_landed_cost_1}:
picking_ids: [picking_landed_cost_1, picking_landed_cost_2]
account_journal_id: expenses_journal
cost_lines:
- name: 'equal split'
split_method: 'equal'
price_unit: 10
product_id: product.product_product_2
- name: 'split by quantity'
split_method: 'by_quantity'
price_unit: 150
product_id: product.product_product_2
- name: 'split by weight'
split_method: 'by_weight'
price_unit: 250
product_id: product.product_product_2
- name: 'split by volume'
split_method: 'by_volume'
price_unit: 20
product_id: product.product_product_2
valuation_adjustment_lines: []
-
I compute the landed cost using Compute button
-
!python {model: stock.landed.cost, id: stock_landed_cost_1}: |
self.compute_landed_cost()
-
I check the valuation adjustment lines
-
!python {model: stock.landed.cost, id: stock_landed_cost_1}: |
for valuation in self.valuation_adjustment_lines:
if valuation.cost_line_id.name == 'equal split':
assert valuation.additional_landed_cost == 5
elif valuation.cost_line_id.name == 'split by quantity' and valuation.move_id.name == "move 1":
assert valuation.additional_landed_cost == 50
elif valuation.cost_line_id.name == 'split by quantity' and valuation.move_id.name == "move 2":
assert valuation.additional_landed_cost == 100
elif valuation.cost_line_id.name == 'split by weight' and valuation.move_id.name == "move 1":
assert valuation.additional_landed_cost == 50
elif valuation.cost_line_id.name == 'split by weight' and valuation.move_id.name == "move 2":
assert valuation.additional_landed_cost == 200
elif valuation.cost_line_id.name == 'split by volume' and valuation.move_id.name == "move 1":
assert valuation.additional_landed_cost == 5
elif valuation.cost_line_id.name == 'split by volume' and valuation.move_id.name == "move 2":
assert valuation.additional_landed_cost == 15
else:
raise 'unrecognized valuation adjustment line'
-
I confirm the landed cost
-
!python {model: stock.landed.cost, id: stock_landed_cost_1}: |
self.button_validate()
-
I check that the landed cost is now "Closed" and that it has an accounting entry
-
!assert {model: stock.landed.cost, id: stock_landed_cost_1}:
- state == 'done'
- account_move_id
- len(account_move_id.line_ids) == 48
-
In order to test the rounding in landed costs feature of stock, I create 2 landed cost
-
Define undivisible units
-
!record {model: product.uom, id: product_uom_unit_round_1}:
category_id: product.product_uom_categ_unit
name: Undivisible Unit(s)
factor: 1.0
rounding: 1.0
-
I create 2 products with different cost prices and configure them for real_time valuation and real price costing method
-
!record {model: product.product, id: product_landed_cost_3}:
name: "LC product 3"
cost_method: fifo
uom_id: product_uom_unit_round_1
valuation: real_time
property_stock_account_input: o_expense
property_stock_account_output: o_income
-
!record {model: product.product, id: product_landed_cost_4}:
name: "LC product 4"
cost_method: fifo
uom_id: product_uom_unit_round_1
valuation: real_time
property_stock_account_input: o_expense
property_stock_account_output: o_income
-
I create 2 pickings moving those products
-
!record {model: stock.picking, id: picking_landed_cost_3}:
name: 'LC_pick_3'
picking_type_id: stock.picking_type_in
move_lines:
- name: move 3
product_id: product_landed_cost_3
product_uom_qty: 13
product_uom: product_uom_unit_round_1
location_id: stock.stock_location_customers
location_dest_id: stock.stock_location_stock
-
!record {model: stock.picking, id: picking_landed_cost_4}:
name: 'LC_pick_4'
picking_type_id: stock.picking_type_in
move_lines:
- name: move 4
product_id: product_landed_cost_4
product_uom_qty: 1
product_uom: product.product_uom_dozen
location_id: stock.stock_location_customers
location_dest_id: stock.stock_location_stock
price_unit: !eval 17.00/12.00
-
We perform all the tests for LC_pick_3
-
I receive picking LC_pick_3, and check how many quants are created
-
!python {model: stock.picking, id: picking_landed_cost_3}: |
self.move_lines.price_unit = 1.0
self.action_confirm()
self.action_assign()
self.action_done()
-
I create a landed cost for picking 3
-
!record {model: stock.landed.cost, id: stock_landed_cost_2}:
picking_ids: [picking_landed_cost_3]
account_journal_id: expenses_journal
cost_lines:
- name: 'equal split'
split_method: 'equal'
price_unit: 15
product_id: product.product_product_1
valuation_adjustment_lines: []
-
I compute the landed cost using Compute button
-
!python {model: stock.landed.cost, id: stock_landed_cost_2}: |
self.compute_landed_cost()
-
I check the valuation adjustment lines
-
!python {model: stock.landed.cost, id: stock_landed_cost_2}: |
for valuation in self.valuation_adjustment_lines:
assert valuation.additional_landed_cost == 15
-
I confirm the landed cost
-
!python {model: stock.landed.cost, id: stock_landed_cost_2}: |
self.button_validate()
-
I check that the landed cost is now "Closed" and that it has an accounting entry
-
!assert {model: stock.landed.cost, id: stock_landed_cost_2}:
- state == 'done'
- account_move_id
-
We perform all the tests for LC_pick_4
-
I receive picking LC_pick_4, and check how many quants are created
-
!python {model: stock.picking, id: picking_landed_cost_4}: |
self.move_lines.price_unit = 17.0/12.0
self.action_confirm()
self.action_assign()
self.action_done()
-
I create a landed cost for picking 4
-
!record {model: stock.landed.cost, id: stock_landed_cost_3}:
picking_ids: [picking_landed_cost_4]
account_journal_id: expenses_journal
cost_lines:
- name: 'equal split'
split_method: 'equal'
price_unit: 11
product_id: product.product_product_1
valuation_adjustment_lines: []
-
I compute the landed cost using Compute button
-
!python {model: stock.landed.cost, id: stock_landed_cost_3}: |
self.compute_landed_cost()
-
I check the valuation adjustment lines
-
!python {model: stock.landed.cost, id: stock_landed_cost_3}: |
for valuation in self.valuation_adjustment_lines:
assert valuation.additional_landed_cost == 11
-
I confirm the landed cost
-
!python {model: stock.landed.cost, id: stock_landed_cost_3}: |
self.button_validate()
-
I check that the landed cost is now "Closed" and that it has an accounting entry
-
!assert {model: stock.landed.cost, id: stock_landed_cost_3}:
- state == 'done'
- account_move_id
# -*- coding: utf-8 -*-
from . import test_stock_landed_costs
from . import test_stock_landed_costs_purchase
from . import test_stock_landed_costs_rounding
# -*- coding: utf-8 -*-
from odoo import tools
from odoo.addons.account.tests.account_test_classes import AccountingTestCase
from odoo.modules.module import get_module_resource
class TestStockLandedCostsCommon(AccountingTestCase):
def _load(self, module, *args):
tools.convert_file(self.cr, 'stock_landed_costs',
get_module_resource(module, *args),
{}, 'init', False, 'test', self.registry._assertion_report)
def setUp(self):
super(TestStockLandedCostsCommon, self).setUp()
# Objects
......
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.stock_landed_costs.tests.common import TestStockLandedCostsCommon
from odoo.exceptions import ValidationError
class TestStockLandedCosts(TestStockLandedCostsCommon):
def test_stock_landed_costs(self):
# In order to test the landed costs feature of stock,
# I create a landed cost, confirm it and check its account move created
self._load('account', 'test', 'account_minimal_test.xml')
self._load('stock_account', 'test', 'stock_valuation_account.xml')
# I create 2 products with different volume and gross weight and configure
# them for real_time valuation and fifo costing method
product_landed_cost_1 = self.env['product.product'].create({
'name': "LC product 1",
'cost_method': 'fifo',
'valuation': 'real_time',
'weight': 10,
'volume': 1,
'property_stock_account_input': self.ref('stock_landed_costs.o_expense'),
'property_stock_account_output': self.ref('stock_landed_costs.o_income'),
})
product_landed_cost_2 = self.env['product.product'].create({
'name': "LC product 2",
'cost_method': 'fifo',
'valuation': 'real_time',
'weight': 20,
'volume': 1.5,
'property_stock_account_input': self.ref('stock_landed_costs.o_expense'),
'property_stock_account_output': self.ref('stock_landed_costs.o_income'),
})
picking_default_vals = self.env['stock.picking'].default_get(list(self.env['stock.picking'].fields_get()))
# I create 2 picking moving those products
vals = dict(picking_default_vals, **{
'name': 'LC_pick_1',
'picking_type_id': self.ref('stock.picking_type_out'),
'move_lines': [(0, 0, {
'product_id': product_landed_cost_1.id,
'product_uom_qty': 5,
'product_uom': self.ref('product.product_uom_unit'),
'location_id': self.ref('stock.stock_location_stock'),
'location_dest_id': self.ref('stock.stock_location_customers'),
})],
})
picking_landed_cost_1 = self.env['stock.picking'].new(vals)
picking_landed_cost_1.onchange_picking_type()
picking_landed_cost_1.move_lines.onchange_product_id()
picking_landed_cost_1.move_lines.name = 'move 1'
vals = picking_landed_cost_1._convert_to_write(picking_landed_cost_1._cache)
picking_landed_cost_1 = self.env['stock.picking'].create(vals)
# Confirm and assign picking
self.env.user.company_id.anglo_saxon_accounting = True
picking_landed_cost_1.action_confirm()
picking_landed_cost_1.action_assign()
picking_landed_cost_1.move_lines.quantity_done = 5
picking_landed_cost_1.button_validate()
vals = dict(picking_default_vals, **{
'name': 'LC_pick_2',
'picking_type_id': self.ref('stock.picking_type_out'),
'move_lines': [(0, 0, {
'product_id': product_landed_cost_2.id,
'product_uom_qty': 10,
'product_uom': self.ref('product.product_uom_unit'),
'location_id': self.ref('stock.stock_location_stock'),
'location_dest_id': self.ref('stock.stock_location_customers'),
})],
})
picking_landed_cost_2 = self.env['stock.picking'].new(vals)
picking_landed_cost_2.onchange_picking_type()
picking_landed_cost_2.move_lines.onchange_product_id()
picking_landed_cost_2.move_lines.name = 'move 2'
vals = picking_landed_cost_2._convert_to_write(picking_landed_cost_2._cache)
picking_landed_cost_2 = self.env['stock.picking'].create(vals)
# Confirm and assign picking
picking_landed_cost_2.action_confirm()
picking_landed_cost_2.action_assign()
picking_landed_cost_2.move_lines.quantity_done = 10
picking_landed_cost_2.button_validate()
# I create a landed cost for those 2 pickings
default_vals = self.env['stock.landed.cost'].default_get(list(self.env['stock.landed.cost'].fields_get()))
default_vals.update({
'picking_ids': [picking_landed_cost_1.id, picking_landed_cost_2.id],
'account_journal_id': self.ref('stock_landed_costs.expenses_journal'),
'cost_lines': [
(0, 0, {'product_id': self.ref('product.product_product_2')}),
(0, 0, {'product_id': self.ref('product.product_product_2')}),
(0, 0, {'product_id': self.ref('product.product_product_2')}),
(0, 0, {'product_id': self.ref('product.product_product_2')})],
'valuation_adjustment_lines': [],
})
cost_lines_values = {
'name': ['equal split', 'split by quantity', 'split by weight', 'split by volume'],
'split_method': ['equal', 'by_quantity', 'by_weight', 'by_volume'],
'price_unit': [10, 150, 250, 20],
}
stock_landed_cost_1 = self.env['stock.landed.cost'].new(default_vals)
for index, cost_line in enumerate(stock_landed_cost_1.cost_lines):
cost_line.onchange_product_id()
cost_line.name = cost_lines_values['name'][index]
cost_line.split_method = cost_lines_values['split_method'][index]
cost_line.price_unit = cost_lines_values['price_unit'][index]
vals = stock_landed_cost_1._convert_to_write(stock_landed_cost_1._cache)
stock_landed_cost_1 = self.env['stock.landed.cost'].create(vals)
# I compute the landed cost using Compute button
stock_landed_cost_1.compute_landed_cost()
# I check the valuation adjustment lines
for valuation in stock_landed_cost_1.valuation_adjustment_lines:
if valuation.cost_line_id.name == 'equal split':
self.assertEqual(valuation.additional_landed_cost, 5)
elif valuation.cost_line_id.name == 'split by quantity' and valuation.move_id.name == "move 1":
self.assertEqual(valuation.additional_landed_cost, 50)
elif valuation.cost_line_id.name == 'split by quantity' and valuation.move_id.name == "move 2":
self.assertEqual(valuation.additional_landed_cost, 100)
elif valuation.cost_line_id.name == 'split by weight' and valuation.move_id.name == "move 1":
self.assertEqual(valuation.additional_landed_cost, 50)
elif valuation.cost_line_id.name == 'split by weight' and valuation.move_id.name == "move 2":
self.assertEqual(valuation.additional_landed_cost, 200)
elif valuation.cost_line_id.name == 'split by volume' and valuation.move_id.name == "move 1":
self.assertEqual(valuation.additional_landed_cost, 5)
elif valuation.cost_line_id.name == 'split by volume' and valuation.move_id.name == "move 2":
self.assertEqual(valuation.additional_landed_cost, 15)
else:
raise ValidationError('unrecognized valuation adjustment line')
# I confirm the landed cost
stock_landed_cost_1.button_validate()
# I check that the landed cost is now "Closed" and that it has an accounting entry
self.assertEqual(stock_landed_cost_1.state, "done")
self.assertTrue(stock_landed_cost_1.account_move_id)
self.assertEqual(len(stock_landed_cost_1.account_move_id.line_ids), 48)
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.stock_landed_costs.tests.common import TestStockLandedCostsCommon
class TestStockLandedCostsRounding(TestStockLandedCostsCommon):
def test_stock_landed_costs_rounding(self):
# In order to test the rounding in landed costs feature of stock, I create 2 landed cost
self._load('account', 'test', 'account_minimal_test.xml')
self._load('stock_account', 'test', 'stock_valuation_account.xml')
# Define undivisible units
product_uom_unit_round_1 = self.env['product.uom'].create({
'category_id': self.ref('product.product_uom_categ_unit'),
'name': 'Undivisible Unit(s)',
'factor': 1.0,
'rounding': 1.0,
})
# I create 2 products with different cost prices and configure them for real_time
# valuation and real price costing method
product_landed_cost_3 = self.env['product.product'].create({
'name': "LC product 3",
'cost_method': 'fifo',
'uom_id': product_uom_unit_round_1.id,
'valuation': 'real_time',
'property_stock_account_input': self.ref('stock_landed_costs.o_expense'),
'property_stock_account_output': self.ref('stock_landed_costs.o_income'),
})
product_landed_cost_4 = self.env['product.product'].create({
'name': "LC product 4",
'cost_method': 'fifo',
'uom_id': product_uom_unit_round_1.id,
'valuation': 'real_time',
'property_stock_account_input': self.ref('stock_landed_costs.o_expense'),
'property_stock_account_output': self.ref('stock_landed_costs.o_income'),
})
picking_default_vals = self.env['stock.picking'].default_get(list(self.env['stock.picking'].fields_get()))
# I create 2 pickings moving those products
vals = dict(picking_default_vals, **{
'name': 'LC_pick_3',
'picking_type_id': self.ref('stock.picking_type_in'),
'move_lines': [(0, 0, {
'product_id': product_landed_cost_3.id,
'product_uom_qty': 13,
'product_uom': product_uom_unit_round_1.id,
'location_id': self.ref('stock.stock_location_customers'),
'location_dest_id': self.ref('stock.stock_location_stock'),
})],
})
picking_landed_cost_3 = self.env['stock.picking'].new(vals)
picking_landed_cost_3.onchange_picking_type()
picking_landed_cost_3.move_lines.onchange_product_id()
picking_landed_cost_3.move_lines.name = 'move 3'
vals = picking_landed_cost_3._convert_to_write(picking_landed_cost_3._cache)
picking_landed_cost_3 = self.env['stock.picking'].create(vals)
vals = dict(picking_default_vals, **{
'name': 'LC_pick_4',
'picking_type_id': self.ref('stock.picking_type_in'),
'move_lines': [(0, 0, {
'product_id': product_landed_cost_4.id,
'product_uom_qty': 1,
'product_uom': self.ref('product.product_uom_dozen'),
'location_id': self.ref('stock.stock_location_customers'),
'location_dest_id': self.ref('stock.stock_location_stock'),
'price_unit': 17.00 / 12.00,
})],
})
picking_landed_cost_4 = self.env['stock.picking'].new(vals)
picking_landed_cost_4.onchange_picking_type()
picking_landed_cost_4.move_lines.onchange_product_id()
picking_landed_cost_4.move_lines.name = 'move 4'
vals = picking_landed_cost_4._convert_to_write(picking_landed_cost_4._cache)
picking_landed_cost_4 = self.env['stock.picking'].create(vals)
# We perform all the tests for LC_pick_3
# I receive picking LC_pick_3, and check how many quants are created
picking_landed_cost_3.move_lines.price_unit = 1.0
picking_landed_cost_3.action_confirm()
picking_landed_cost_3.action_assign()
picking_landed_cost_3.action_done()
# I create a landed cost for picking 3
default_vals = self.env['stock.landed.cost'].default_get(list(self.env['stock.landed.cost'].fields_get()))
default_vals.update({
'picking_ids': [picking_landed_cost_3.id],
'account_journal_id': self.ref('stock_landed_costs.expenses_journal'),
'cost_lines': [(0, 0, {'product_id': self.ref('product.product_product_1')})],
'valuation_adjustment_lines': [],
})
stock_landed_cost_2 = self.env['stock.landed.cost'].new(default_vals)
stock_landed_cost_2.cost_lines.onchange_product_id()
stock_landed_cost_2.cost_lines.name = 'equal split'
stock_landed_cost_2.cost_lines.split_method = 'equal'
stock_landed_cost_2.cost_lines.price_unit = 15
vals = stock_landed_cost_2._convert_to_write(stock_landed_cost_2._cache)
stock_landed_cost_2 = self.env['stock.landed.cost'].create(vals)
# I compute the landed cost using Compute button
stock_landed_cost_2.compute_landed_cost()
# I check the valuation adjustment lines
for valuation in stock_landed_cost_2.valuation_adjustment_lines:
self.assertEqual(valuation.additional_landed_cost, 15)
# I confirm the landed cost
stock_landed_cost_2.button_validate()
# I check that the landed cost is now "Closed" and that it has an accounting entry
self.assertEqual(stock_landed_cost_2.state, 'done')
self.assertTrue(stock_landed_cost_2.account_move_id)
# We perform all the tests for LC_pick_4
# I receive picking LC_pick_4, and check how many quants are created
picking_landed_cost_4.move_lines.price_unit = 17.0/12.0
picking_landed_cost_4.action_confirm()
picking_landed_cost_4.action_assign()
picking_landed_cost_4.action_done()
# I create a landed cost for picking 4
default_vals = self.env['stock.landed.cost'].default_get(list(self.env['stock.landed.cost'].fields_get()))
default_vals.update({
'picking_ids': [picking_landed_cost_4.id],
'account_journal_id': self.ref('stock_landed_costs.expenses_journal'),
'cost_lines': [(0, 0, {'product_id': self.ref('product.product_product_1')})],
'valuation_adjustment_lines': [],
})
stock_landed_cost_3 = self.env['stock.landed.cost'].new(default_vals)
stock_landed_cost_3.cost_lines.onchange_product_id()
stock_landed_cost_3.cost_lines.name = 'equal split'
stock_landed_cost_3.cost_lines.split_method = 'equal'
stock_landed_cost_3.cost_lines.price_unit = 11
vals = stock_landed_cost_3._convert_to_write(stock_landed_cost_3._cache)
stock_landed_cost_3 = self.env['stock.landed.cost'].create(vals)
# I compute the landed cost using Compute button
stock_landed_cost_3.compute_landed_cost()
# I check the valuation adjustment lines
for valuation in stock_landed_cost_3.valuation_adjustment_lines:
self.assertEqual(valuation.additional_landed_cost, 11)
# I confirm the landed cost
stock_landed_cost_3.button_validate()
# I check that the landed cost is now "Closed" and that it has an accounting entry
self.assertEqual(stock_landed_cost_3.state, 'done')
self.assertTrue(stock_landed_cost_3.account_move_id)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment