Skip to content

Commit

Permalink
[MIG] stock_quant_cost_info: Migration to 15.0
Browse files Browse the repository at this point in the history
- Module renamed from stock_inventory_cost_info to stock_quant_cost_info
- Add changes to allow show the cost difference when changing qty from stock.quants

TT36551
  • Loading branch information
CarlosRoca13 committed Jan 16, 2023
1 parent fb0e5d1 commit 5c10e83
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 144 deletions.

This file was deleted.

File renamed without changes.
6 changes: 3 additions & 3 deletions stock_quant_cost_info/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Copyright 2019 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Stock Inventory Cost Info",
"summary": "Shows the cost of the inventory adjustments",
"version": "14.0.1.0.0",
"name": "Stock Quant Cost Info",
"summary": "Shows the cost of the quants",
"version": "15.0.1.0.0",
"author": "Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Warehouse",
Expand Down
4 changes: 2 additions & 2 deletions stock_quant_cost_info/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

def pre_init_hook(cr):
cr.execute(
"""ALTER TABLE stock_inventory_line
"""ALTER TABLE stock_quant
ADD COLUMN adjustment_cost numeric
DEFAULT 0"""
)

cr.execute(
"""ALTER TABLE stock_inventory_line
"""ALTER TABLE stock_quant
ALTER COLUMN adjustment_cost DROP DEFAULT;"""
)
39 changes: 21 additions & 18 deletions stock_quant_cost_info/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,41 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-07-19 18:15+0000\n"
"PO-Revision-Date: 2019-07-19 18:15+0000\n"
"POT-Creation-Date: 2023-01-16 09:20+0000\n"
"PO-Revision-Date: 2023-01-16 10:21+0100\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"Language: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"X-Generator: Poedit 3.2.2\n"

#. module: stock_inventory_cost_info
#: model_terms:ir.ui.view,arch_db:stock_inventory_cost_info.report_inventory_cost_info
#. module: stock_quant_cost_info
#: model_terms:ir.ui.view,arch_db:stock_quant_cost_info.report_inventory_cost_info
msgid "<strong>Adjustment cost</strong>"
msgstr "<strong>Coste de ajuste</strong>"

#. module: stock_inventory_cost_info
#: model:ir.model.fields,field_description:stock_inventory_cost_info.field_stock_inventory_line__adjustment_cost
#. module: stock_quant_cost_info
#: model:ir.model.fields,field_description:stock_quant_cost_info.field_stock_quant__adjustment_cost
msgid "Adjustment cost"
msgstr "Coste de ajuste"

#. module: stock_inventory_cost_info
#: model:ir.model.fields,field_description:stock_inventory_cost_info.field_stock_inventory_line__currency_id
#. module: stock_quant_cost_info
#: model:ir.model.fields,field_description:stock_quant_cost_info.field_stock_quant__currency_id
msgid "Currency"
msgstr "Moneda"

#. module: stock_inventory_cost_info
#: model:ir.model,name:stock_inventory_cost_info.model_stock_inventory_line
msgid "Inventory Line"
msgstr "Línea de inventario"
#. module: stock_quant_cost_info
#: model:ir.model,name:stock_quant_cost_info.model_stock_quant
msgid "Quants"
msgstr "Quants"

#. module: stock_inventory_cost_info
#: model_terms:ir.ui.view,arch_db:stock_inventory_cost_info.stock_inventory_line_tree
#: model_terms:ir.ui.view,arch_db:stock_inventory_cost_info.stock_inventory_line_tree2
#. module: stock_quant_cost_info
#: model_terms:ir.ui.view,arch_db:stock_quant_cost_info.view_stock_quant_tree_inventory_editable
msgid "Total"
msgstr ""
msgstr "Total"

#~ msgid "Inventory Line"
#~ msgstr "Línea de inventario"
54 changes: 0 additions & 54 deletions stock_quant_cost_info/i18n/stock_inventory_cost_info.pot

This file was deleted.

41 changes: 41 additions & 0 deletions stock_quant_cost_info/i18n/stock_quant_cost_info.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_quant_cost_info
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-01-16 09:20+0000\n"
"PO-Revision-Date: 2023-01-16 09:20+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: stock_quant_cost_info
#: model_terms:ir.ui.view,arch_db:stock_quant_cost_info.report_inventory_cost_info
msgid "<strong>Adjustment cost</strong>"
msgstr ""

#. module: stock_quant_cost_info
#: model:ir.model.fields,field_description:stock_quant_cost_info.field_stock_quant__adjustment_cost
msgid "Adjustment cost"
msgstr ""

#. module: stock_quant_cost_info
#: model:ir.model.fields,field_description:stock_quant_cost_info.field_stock_quant__currency_id
msgid "Currency"
msgstr ""

#. module: stock_quant_cost_info
#: model:ir.model,name:stock_quant_cost_info.model_stock_quant
msgid "Quants"
msgstr ""

#. module: stock_quant_cost_info
#: model_terms:ir.ui.view,arch_db:stock_quant_cost_info.view_stock_quant_tree_inventory_editable
msgid "Total"
msgstr ""
2 changes: 1 addition & 1 deletion stock_quant_cost_info/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import stock_inventory
from . import stock_quant
22 changes: 0 additions & 22 deletions stock_quant_cost_info/models/stock_inventory.py

This file was deleted.

24 changes: 24 additions & 0 deletions stock_quant_cost_info/models/stock_quant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2019 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class StockQuant(models.Model):
_inherit = "stock.quant"

currency_id = fields.Many2one(
comodel_name="res.currency", string="Currency", related="company_id.currency_id"
)
adjustment_cost = fields.Monetary(
string="Adjustment cost", compute="_compute_adjustment_cost", store=True
)

@api.depends("inventory_diff_quantity", "product_id.standard_price")
def _compute_adjustment_cost(self):
for record in self:
record.adjustment_cost = False
if record.inventory_diff_quantity:
record.adjustment_cost = (
record.inventory_diff_quantity * record.product_id.standard_price
)
52 changes: 17 additions & 35 deletions stock_quant_cost_info/tests/test_stock_inventory_cost_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


@tagged("post_install", "-at_install")
class TestStockInventoryCostInfo(TransactionCase):
class TestStockQuantCostInfo(TransactionCase):
def setUp(self):
super().setUp()
product_obj = self.env["product.product"]
Expand All @@ -16,40 +16,22 @@ def setUp(self):
self.product_2 = product_obj.create(
{"name": "product test 2", "type": "product", "standard_price": 2000}
)
self.inventory = self.env["stock.inventory"].create(
{
"name": "Another inventory",
"line_ids": [
(
0,
0,
{
"product_id": self.product_1.id,
"product_qty": 10,
"location_id": self.env.ref(
"stock.warehouse0"
).lot_stock_id.id,
},
),
(
0,
0,
{
"product_id": self.product_2.id,
"product_qty": 20,
"location_id": self.env.ref(
"stock.warehouse0"
).lot_stock_id.id,
},
),
],
}
)

def test_compute_adjustment_cost(self):
"""Tests if the adjustment_cost is correctly computed."""
lines = self.inventory.line_ids
line1 = lines.filtered(lambda r: r.product_id == self.product_1)
self.assertEqual(line1.adjustment_cost, 10000)
line2 = lines.filtered(lambda r: r.product_id == self.product_2)
self.assertEqual(line2.adjustment_cost, 40000)
quant_prod_1 = self.env["stock.quant"].create(
{
"product_id": self.product_1.id,
"location_id": self.env.ref("stock.stock_location_stock").id,
"inventory_quantity": 10.0,
}
)
self.assertEqual(quant_prod_1.adjustment_cost, 10000)
quant_prod_2 = self.env["stock.quant"].create(
{
"product_id": self.product_2.id,
"location_id": self.env.ref("stock.stock_location_stock").id,
"inventory_quantity": 20.0,
}
)
self.assertEqual(quant_prod_2.adjustment_cost, 40000)
7 changes: 5 additions & 2 deletions stock_quant_cost_info/views/report_stockinventory.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
<odoo>
<template id="report_inventory_cost_info" inherit_id="stock.report_inventory">
<xpath
expr="//table[.//span[@t-field='line.product_qty']]/thead/tr"
expr="//table[.//span[@t-field='line.inventory_quantity']]/thead/tr"
position="inside"
>
<th class="text-right">
<strong>Adjustment cost</strong>
</th>
</xpath>
<xpath expr="//tr[.//span[@t-field='line.product_qty']]" position="inside">
<xpath
expr="//tr[.//span[@t-field='line.inventory_quantity']]"
position="inside"
>
<td class="text-right">
<span t-field="line.adjustment_cost" />
</td>
Expand Down
11 changes: 5 additions & 6 deletions stock_quant_cost_info/views/stock_inventory_views.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="stock_inventory_line_tree" model="ir.ui.view">
<field name="name">stock.inventory.line.tree.cost.info</field>
<field name="model">stock.inventory.line</field>
<field name="inherit_id" ref="stock.stock_inventory_line_tree" />
<record id="view_stock_quant_tree_inventory_editable" model="ir.ui.view">
<field name="model">stock.quant</field>
<field name="inherit_id" ref="stock.view_stock_quant_tree_inventory_editable" />
<field name="arch" type="xml">
<field name="product_uom_id" position="after">
<field name="inventory_diff_quantity" position="after">
<field name="currency_id" invisible="1" />
<field name="adjustment_cost" sum="Total" />
<field name="adjustment_cost" sum="Total" optional="show" />
</field>
</field>
</record>
Expand Down

0 comments on commit 5c10e83

Please sign in to comment.