Skip to content

Commit

Permalink
[MIG] stock_demand_estimate_matrix: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kaynnan committed Oct 26, 2023
1 parent f6aaed3 commit a752179
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 40 deletions.
2 changes: 1 addition & 1 deletion stock_demand_estimate_matrix/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Stock Demand Estimate Matrix",
"summary": "Allows to create demand estimates.",
"version": "15.0.1.2.0",
"version": "16.0.1.0.0",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"development_status": "Production/Stable",
"website": "https://github.com/OCA/stock-logistics-warehouse",
Expand Down
148 changes: 145 additions & 3 deletions stock_demand_estimate_matrix/tests/test_stock_demand_estimate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Copyright 2019 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from datetime import datetime

from dateutil.rrule import MONTHLY

from odoo import fields
from odoo.exceptions import ValidationError
from odoo.exceptions import UserError, ValidationError
from odoo.tests.common import TransactionCase


Expand Down Expand Up @@ -76,8 +78,7 @@ def _create_user(cls, login, groups, company):
def test_01_demand_estimate_wizard(self):
"""Tests creation of demand estimates using wizard."""
sheets = self.env["stock.demand.estimate.sheet"].search([])
for sheet in sheets:
sheet.unlink()
list(map(lambda sheet: sheet.unlink(), sheets))
wiz = self.env["stock.demand.estimate.wizard"]
wiz = wiz.create(
{
Expand Down Expand Up @@ -199,3 +200,144 @@ def test_03_computed_fields(self):
expected_date_to = date_range.date_end
self.assertEqual(estimate.date_from, expected_date_from)
self.assertEqual(estimate.date_to, expected_date_to)

def test_04_name_get(self):
date_range = self.env["date.range"].create(
{
"name": "Test Date Range",
"type_id": self.drt_monthly.id,
"date_start": "2023-01-01",
"date_end": "2023-01-31",
}
)
estimate = self.estimate_model.create(
{
"product_id": self.product_1.id,
"location_id": self.location.id,
"date_range_id": date_range.id,
"product_uom_qty": 100.0,
}
)
estimate_name = "{} - {} - {}".format(
date_range.name,
self.product_1.name,
self.location.name,
)
estimate_name_get = estimate.name_get()
self.assertEqual(estimate_name_get, [(estimate.id, estimate_name)])

def test_05_onchange_date_range_type_id(self):
company = self.env["res.company"].create({"name": "Test Company"})
date_range_type = self.env["date.range.type"].create(
{
"name": "Test Date Range Type",
"allow_overlap": False,
"company_id": company.id,
}
)
wizard = self.env["stock.demand.estimate.wizard"].create(
{
"date_start": "1943-01-01",
"date_end": "1943-12-31",
"location_id": self.location.id,
"date_range_type_id": date_range_type.id,
"product_ids": [(6, 0, [self.product_1.id])],
}
)
result = wizard._onchange_date_range_type_id()
location_domain = result.get("domain", {}).get("location_id", [])
expected_domain = [
("company_id", "=", company.id),
]
self.assertEqual(location_domain, expected_domain)

def test_06_prepare_demand_estimate_sheet(self):
wizard = self.env["stock.demand.estimate.wizard"].create(
{
"date_start": "2023-01-01",
"date_end": "2023-12-31",
"location_id": self.location.id,
"date_range_type_id": self.drt_monthly.id,
"product_ids": [(6, 0, [self.product_1.id])],
}
)
sheet_values = wizard._prepare_demand_estimate_sheet()
expected_values = {
"date_start": datetime.strptime("2023-01-01", "%Y-%m-%d").date(),
"date_end": datetime.strptime("2023-12-31", "%Y-%m-%d").date(),
"date_range_type_id": self.drt_monthly.id,
"location_id": self.location.id,
}
self.assertEqual(sheet_values, expected_values)

def test_07_create_sheet(self):
wizard = self.env["stock.demand.estimate.wizard"].create(
{
"date_start": "2023-01-01",
"date_end": "2023-12-31",
"location_id": self.location.id,
"date_range_type_id": self.drt_monthly.id,
"product_ids": [],
}
)
with self.assertRaises(UserError):
wizard.create_sheet()

def test_08_button_validate(self):
sheet = self.env["stock.demand.estimate.sheet"].create(
{
"date_start": "2023-01-01",
"date_end": "2023-12-31",
"date_range_type_id": self.drt_monthly.id,
"location_id": self.location.id,
}
)
product = self.env["product.product"].create({"name": "Test Product"})
line1 = self.env["stock.demand.estimate.sheet.line"].create(
{
"product_id": product.id,
"product_uom_qty": 10,
"estimate_id": self.env["stock.demand.estimate"]
.create(
{
"product_id": product.id,
"product_uom_qty": 10,
"location_id": self.location.id,
}
)
.id,
}
)
line2 = self.env["stock.demand.estimate.sheet.line"].create(
{
"product_id": product.id,
"product_uom_qty": 20,
"estimate_id": self.env["stock.demand.estimate"]
.create(
{
"product_id": product.id,
"product_uom_qty": 100,
"location_id": self.location.id,
}
)
.id,
}
)
sheet.line_ids = [line1.id, line2.id]

res = sheet.button_validate()

self.assertEqual(line2.estimate_id.product_uom_qty, line2.product_uom_qty)

self.assertEqual(
res,
{
"domain": [("id", "in", [line1.estimate_id.id, line2.estimate_id.id])],
"name": "Stock Demand Estimates",
"src_model": "stock.demand.estimate.wizard",
"view_type": "form",
"view_mode": "tree",
"res_model": "stock.demand.estimate",
"type": "ir.actions.act_window",
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,26 @@
<field name="location_id" />
</group>
</group>
<div />
<group name="estimated_quantity" string="Estimated quantity">
<field
name="line_ids"
nolabel="1"
widget="x2many_2d_matrix"
field_x_axis="value_x"
field_y_axis="value_y"
field_value="product_uom_qty"
x_axis_clickable="0"
y_axis_clickable="0"
>
<tree>
<field name="value_x" />
<field name="value_y" />
<field name="product_uom_qty" />
</tree>
</field>
</group>
<notebook>
<page name="estimated_quantity" string="Estimated quantity">
<field
name="line_ids"
nolabel="1"
widget="x2many_2d_matrix"
field_x_axis="value_x"
field_y_axis="value_y"
field_value="product_uom_qty"
x_axis_clickable="0"
y_axis_clickable="0"
>
<tree>
<field name="value_x" />
<field name="value_y" />
<field name="product_uom_qty" />
</tree>
</field>
</page>
</notebook>
<footer>
<button
name="button_validate"
Expand All @@ -57,31 +58,33 @@
<sheet>
<group name="dates">
<label for="date_start" string="Period" />
<div><field name="date_start" class="oe_inline" /> to <field
name="date_end"
class="oe_inline"
/></div>
<div>
<field name="date_start" class="oe_inline" />
to
<field name="date_end" class="oe_inline" />
</div>
</group>
<group>
<group name="attributes">
<field name="date_range_type_id" />
<field name="location_id" />
</group>
</group>
<div />
<group name="products" string="Products">
<field name="product_ids" nolabel="1" />
</group>
<footer>
<button
name="create_sheet"
string="Prepare"
type="object"
class="oe_highlight"
/> or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
<notebook>
<page name="products" string="Products">
<field name="product_ids" nolabel="1" />
</page>
</notebook>
</sheet>
<footer>
<button
name="create_sheet"
string="Prepare"
type="object"
class="oe_highlight"
/>
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
Expand Down

0 comments on commit a752179

Please sign in to comment.