Skip to content

Commit

Permalink
[IMP] stock_demand_estimate_matrix: black, isort, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBForgeFlow authored and kaynnan committed Jul 15, 2023
1 parent ce926f4 commit 6643899
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 20 deletions.
4 changes: 3 additions & 1 deletion stock_demand_estimate_matrix/models/date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 7 additions & 2 deletions stock_demand_estimate_matrix/models/stock_demand_estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -28,7 +31,9 @@ def name_get(self):
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
28 changes: 22 additions & 6 deletions stock_demand_estimate_matrix/tests/test_stock_demand_estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ def setUpClass(cls):
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}
)
Expand Down Expand Up @@ -84,7 +92,9 @@ def test_01_demand_estimate_wizard(self):
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),
Expand All @@ -97,7 +107,9 @@ def test_01_demand_estimate_wizard(self):
"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
Expand All @@ -119,7 +131,9 @@ def test_01_demand_estimate_wizard(self):
[("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(
Expand Down Expand Up @@ -151,7 +165,9 @@ def test_01_demand_estimate_wizard(self):
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 6643899

Please sign in to comment.