mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[15.0][IMP] Tests for stock valuation
[FIX] rma: rma_custmer_user has no write permissions in partner, so compute method fails. [IMP] rma: use rma user in tests [FIX] rma_account: move_line_id field string [IMP] rma, rma_account, rma_sale, rma_purchase: tests for stock valuation [FIX] account_move_line_rma_order_line: minor lint, make auto-install
This commit is contained in:
committed by
Jordi Ballester Alomar
parent
3389bca693
commit
3405225750
@@ -37,14 +37,16 @@ class StockRule(models.Model):
|
||||
if moves:
|
||||
# TODO: Should we be smart in the choice of the move?
|
||||
layers = moves.mapped("stock_valuation_layer_ids")
|
||||
cost = layers[-1].unit_cost
|
||||
res["price_unit"] = cost
|
||||
if layers:
|
||||
cost = layers[-1].unit_cost
|
||||
res["price_unit"] = cost
|
||||
elif line.account_move_line_id:
|
||||
sale_lines = line.account_move_line_id.sale_line_ids
|
||||
moves = sale_lines.mapped("move_ids")
|
||||
if moves:
|
||||
layers = moves.mapped("stock_valuation_layer_ids")
|
||||
cost = layers[-1].unit_cost
|
||||
# TODO: Should we be smart in the choice of the move?
|
||||
res["price_unit"] = cost
|
||||
if layers:
|
||||
cost = layers[-1].unit_cost
|
||||
# TODO: Should we be smart in the choice of the move?
|
||||
res["price_unit"] = cost
|
||||
return res
|
||||
|
||||
@@ -1,4 +1,2 @@
|
||||
# Copyright 2020 ForgeFlow S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from . import test_rma_sale
|
||||
from . import test_rma_stock_account_sale
|
||||
|
||||
74
rma_sale/tests/test_rma_stock_account_sale.py
Normal file
74
rma_sale/tests/test_rma_stock_account_sale.py
Normal file
@@ -0,0 +1,74 @@
|
||||
# Copyright 2022 ForgeFlow S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from odoo.tests.common import Form
|
||||
|
||||
# pylint: disable=odoo-addons-relative-import
|
||||
from odoo.addons.rma_account.tests.test_rma_stock_account import TestRmaStockAccount
|
||||
|
||||
|
||||
class TestRmaStockAccountSale(TestRmaStockAccount):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestRmaStockAccountSale, cls).setUpClass()
|
||||
customer1 = cls.env["res.partner"].create({"name": "Customer 1"})
|
||||
cls.product_fifo_1.standard_price = 1234
|
||||
cls._create_inventory(cls.product_fifo_1, 20.0, cls.env.ref("rma.location_rma"))
|
||||
cls.so1 = cls.env["sale.order"].create(
|
||||
{
|
||||
"partner_id": customer1.id,
|
||||
"partner_invoice_id": customer1.id,
|
||||
"partner_shipping_id": customer1.id,
|
||||
"order_line": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": cls.product_fifo_1.name,
|
||||
"product_id": cls.product_fifo_1.id,
|
||||
"product_uom_qty": 20.0,
|
||||
"product_uom": cls.product_fifo_1.uom_id.id,
|
||||
"price_unit": 800,
|
||||
},
|
||||
),
|
||||
],
|
||||
"pricelist_id": cls.env.ref("product.list0").id,
|
||||
}
|
||||
)
|
||||
cls.so1.action_confirm()
|
||||
for ml in cls.so1.picking_ids.move_line_ids:
|
||||
ml.qty_done = ml.product_uom_qty
|
||||
cls.so1.picking_ids.button_validate()
|
||||
|
||||
def test_01_cost_from_so_move(self):
|
||||
"""
|
||||
Test the price unit is taken from the cost of the stock move associated to
|
||||
the SO
|
||||
"""
|
||||
so_line = self.so1.order_line.filtered(
|
||||
lambda r: r.product_id == self.product_fifo_1
|
||||
)
|
||||
self.product_fifo_1.standard_price = 5678 # this should not be taken
|
||||
customer_view = self.env.ref("rma_sale.view_rma_line_form")
|
||||
rma_line = Form(
|
||||
self.rma_line.with_context(customer=1).with_user(self.rma_basic_user),
|
||||
view=customer_view.id,
|
||||
)
|
||||
rma_line.partner_id = self.so1.partner_id
|
||||
rma_line.sale_line_id = so_line
|
||||
rma_line.price_unit = 4356
|
||||
rma_line = rma_line.save()
|
||||
rma_line.action_rma_to_approve()
|
||||
picking = self._receive_rma(rma_line)
|
||||
# The price is not the standard price, is the value of the outgoing layer
|
||||
# of the SO
|
||||
rma_move_value = picking.move_lines.stock_valuation_layer_ids.value
|
||||
so_move_value = self.so1.picking_ids.mapped(
|
||||
"move_lines.stock_valuation_layer_ids"
|
||||
)[-1].value
|
||||
self.assertEqual(rma_move_value, -so_move_value)
|
||||
# Test the accounts used
|
||||
account_move = picking.move_lines.stock_valuation_layer_ids.account_move_id
|
||||
self.check_accounts_used(
|
||||
account_move, debit_account="inventory", credit_account="cogs"
|
||||
)
|
||||
Reference in New Issue
Block a user