[IMP] stock_demand_estimate_matrix: black, isort, prettier

This commit is contained in:
davidborromeo
2021-03-11 13:01:55 +01:00
parent 5be6cc9942
commit ea239daac3
6 changed files with 78 additions and 20 deletions

View File

@@ -0,0 +1 @@
../../../../stock_demand_estimate_matrix

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

View File

@@ -8,7 +8,9 @@ class DateRange(models.Model):
_inherit = "date.range"
days = fields.Integer(
string="Days between dates", compute="_compute_days", readonly=True,
string="Days between dates",
compute="_compute_days",
readonly=True,
)
@api.depends("date_start", "date_end")

View File

@@ -12,7 +12,10 @@ class StockDemandEstimate(models.Model):
)
@api.depends(
"date_range_id", "manual_duration", "manual_date_from", "manual_date_to",
"date_range_id",
"manual_duration",
"manual_date_from",
"manual_date_to",
)
def _compute_dates(self):
date_range_records = self.filtered(lambda r: r.date_range_id)
@@ -28,7 +31,9 @@ class StockDemandEstimate(models.Model):
res = super(StockDemandEstimate, self - date_range_records).name_get()
for rec in date_range_records:
name = "{} - {} - {}".format(
rec.date_range_id.name, rec.product_id.name, rec.location_id.name,
rec.date_range_id.name,
rec.product_id.name,
rec.location_id.name,
)
res.append((rec.id, name))
return res

View File

@@ -22,8 +22,16 @@ class TestStockDemandEstimate(SavepointCase):
cls.company = cls.env.ref("base.main_company")
# Create users:
cls.manager = cls._create_user("user_1", [cls.g_stock_manager], cls.company,).id
cls.user = cls._create_user("user_2", [cls.g_stock_user], cls.company,).id
cls.manager = cls._create_user(
"user_1",
[cls.g_stock_manager],
cls.company,
).id
cls.user = cls._create_user(
"user_2",
[cls.g_stock_user],
cls.company,
).id
cls.drt_monthly = cls.env["date.range.type"].create(
{"name": "Month", "allow_overlap": False}
)
@@ -84,7 +92,9 @@ class TestStockDemandEstimate(SavepointCase):
sheets = self.env["stock.demand.estimate.sheet"].search([])
for sheet in sheets:
self.assertEqual(
len(sheet.line_ids), 12, "There should be 12 lines.",
len(sheet.line_ids),
12,
"There should be 12 lines.",
)
self.assertEqual(
fields.Date.to_string(sheet.date_start),
@@ -97,7 +107,9 @@ class TestStockDemandEstimate(SavepointCase):
"The date end should be 1943-12-31",
)
self.assertEqual(
sheet.location_id.id, self.location.id, "Wrong location",
sheet.location_id.id,
self.location.id,
"Wrong location",
)
for line in sheet.line_ids:
line.product_uom_qty = 1
@@ -119,7 +131,9 @@ class TestStockDemandEstimate(SavepointCase):
[("date_range_id", "in", ranges.ids)]
)
self.assertEqual(
len(estimates), 12, "There should be 12 estimate records.",
len(estimates),
12,
"There should be 12 estimate records.",
)
for estimate in estimates:
self.assertEqual(
@@ -151,7 +165,9 @@ class TestStockDemandEstimate(SavepointCase):
for sheet in sheets:
for line in sheet.line_ids:
self.assertEqual(
line.product_uom_qty, 1, "The quantity should be 1",
line.product_uom_qty,
1,
"The quantity should be 1",
)
def test_02_invalid_dates(self):

View File

@@ -10,23 +10,38 @@ class StockDemandEstimateSheet(models.TransientModel):
_name = "stock.demand.estimate.sheet"
_description = "Stock Demand Estimate Sheet"
date_start = fields.Date(string="Date From", readonly=True,)
date_end = fields.Date(string="Date to", readonly=True,)
date_start = fields.Date(
string="Date From",
readonly=True,
)
date_end = fields.Date(
string="Date to",
readonly=True,
)
date_range_type_id = fields.Many2one(
string="Date Range Type", comodel_name="date.range.type", readonly=True,
string="Date Range Type",
comodel_name="date.range.type",
readonly=True,
)
location_id = fields.Many2one(
comodel_name="stock.location", string="Location", readonly=True,
comodel_name="stock.location",
string="Location",
readonly=True,
)
line_ids = fields.Many2many(
string="Estimates",
comodel_name="stock.demand.estimate.sheet.line",
relation="stock_demand_estimate_line_rel",
)
product_ids = fields.Many2many(string="Products", comodel_name="product.product",)
product_ids = fields.Many2many(
string="Products",
comodel_name="product.product",
)
@api.onchange(
"date_start", "date_end", "date_range_type_id",
"date_start",
"date_end",
"date_range_type_id",
)
def _onchange_dates(self):
for sheet in self:
@@ -166,15 +181,28 @@ class DemandEstimateWizard(models.TransientModel):
_name = "stock.demand.estimate.wizard"
_description = "Stock Demand Estimate Wizard"
date_start = fields.Date(string="Date From", required=True,)
date_end = fields.Date(string="Date To", required=True,)
date_start = fields.Date(
string="Date From",
required=True,
)
date_end = fields.Date(
string="Date To",
required=True,
)
date_range_type_id = fields.Many2one(
string="Date Range Type", comodel_name="date.range.type", required=True,
string="Date Range Type",
comodel_name="date.range.type",
required=True,
)
location_id = fields.Many2one(
comodel_name="stock.location", string="Location", required=True,
comodel_name="stock.location",
string="Location",
required=True,
)
product_ids = fields.Many2many(
comodel_name="product.product",
string="Products",
)
product_ids = fields.Many2many(comodel_name="product.product", string="Products",)
@api.onchange("date_range_type_id")
def _onchange_date_range_type_id(self):