Files
manufacture/mrp_multi_level/models/mrp_area.py
Alexandre Fayolle 9d288ee154 [REF] mrp_multi_level: location management
Small refactoring adding a _get_locations method on product.mrp.area
which by defaults delegates the computation to the related mrp.area.

This enables extending a few things related to locations at the
product.mrp.area level.

Change the way `_get_locations()` work: don't return the list of child
locations, only the top-most locations, and then use the `child_of`
operator in the code that looks for locations.
2024-12-04 09:42:26 +05:30

43 lines
1.4 KiB
Python

# © 2016 Ucamco - Wim Audenaert <wim.audenaert@ucamco.com>
# Copyright 2016-21 ForgeFlow S.L. (https://www.forgeflow.com)
# - Jordi Ballester Alomar <jordi.ballester@forgeflow.com>
# - Lois Rilo Antelo <lois.rilo@forgeflow.com>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models
class MrpArea(models.Model):
_name = "mrp.area"
_description = "MRP Area"
name = fields.Char(required=True)
warehouse_id = fields.Many2one(
comodel_name="stock.warehouse", string="Warehouse", required=True
)
company_id = fields.Many2one(
comodel_name="res.company", related="warehouse_id.company_id", store=True
)
location_id = fields.Many2one(
comodel_name="stock.location", string="Location", required=True
)
active = fields.Boolean(default=True)
calendar_id = fields.Many2one(
comodel_name="resource.calendar",
string="Working Hours",
related="warehouse_id.calendar_id",
)
@api.model
def _datetime_to_date_tz(self, dt_to_convert=None):
"""Coverts a datetime to date considering the timezone of MRP Area.
If no datetime is provided, it returns today's date in the timezone."""
return fields.Date.context_today(
self.with_context(tz=self.calendar_id.tz),
timestamp=dt_to_convert,
)
def _get_locations(self):
self.ensure_one()
return self.location_id