mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[11.0][FIX] mrp_multi_level: the user and system locales could make the MRP run break.
This commit is contained in:
@@ -7,6 +7,7 @@ from odoo import api, fields, models, exceptions, _
|
||||
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
|
||||
from datetime import date, datetime, timedelta
|
||||
import locale
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -637,11 +638,25 @@ class MultiLevelMrp(models.TransientModel):
|
||||
|
||||
logger.info('END MRP CALCULATION')
|
||||
|
||||
@api.model
|
||||
def _convert_group_date_to_default(self, group_date):
|
||||
"""Odoo read_group time format include the month as locale’s
|
||||
abbreviated name (%b). Using 'en_GB' as common language for read_group
|
||||
calls and this conversion avoids possible issues with locales."""
|
||||
lc = locale.setlocale(locale.LC_TIME)
|
||||
try:
|
||||
locale.setlocale(locale.LC_TIME, 'en_GB.UTF-8')
|
||||
return datetime.strptime(
|
||||
group_date, ODOO_READ_GROUP_DAY_FORMAT).strftime(
|
||||
DEFAULT_SERVER_DATE_FORMAT)
|
||||
finally:
|
||||
locale.setlocale(locale.LC_TIME, lc)
|
||||
|
||||
@api.model
|
||||
def _init_mrp_inventory(self, mrp_product):
|
||||
mrp_move_obj = self.env['mrp.move']
|
||||
# Read Demand
|
||||
demand_groups = mrp_move_obj.read_group(
|
||||
demand_groups = mrp_move_obj.with_context(lang='en_GB').read_group(
|
||||
[('mrp_product_id', '=', mrp_product.id),
|
||||
('mrp_type', '=', 'd')],
|
||||
['mrp_date', 'mrp_qty'], ['mrp_date:day'],
|
||||
@@ -649,13 +664,12 @@ class MultiLevelMrp(models.TransientModel):
|
||||
demand_qty_by_date = {}
|
||||
for group in demand_groups:
|
||||
# Reformat date back to default server format.
|
||||
group_date = datetime.strptime(
|
||||
group['mrp_date:day'], ODOO_READ_GROUP_DAY_FORMAT).strftime(
|
||||
DEFAULT_SERVER_DATE_FORMAT)
|
||||
group_date = self._convert_group_date_to_default(
|
||||
group['mrp_date:day'])
|
||||
demand_qty_by_date[group_date] = group['mrp_qty']
|
||||
|
||||
# Read Supply
|
||||
supply_groups = mrp_move_obj.read_group(
|
||||
supply_groups = mrp_move_obj.with_context(lang='en_GB').read_group(
|
||||
[('mrp_product_id', '=', mrp_product.id),
|
||||
('mrp_type', '=', 's'),
|
||||
('mrp_action', '=', 'none')],
|
||||
@@ -664,16 +678,15 @@ class MultiLevelMrp(models.TransientModel):
|
||||
supply_qty_by_date = {}
|
||||
for group in supply_groups:
|
||||
# Reformat date back to default server format.
|
||||
group_date = datetime.strptime(
|
||||
group['mrp_date:day'], ODOO_READ_GROUP_DAY_FORMAT).strftime(
|
||||
DEFAULT_SERVER_DATE_FORMAT)
|
||||
group_date = self._convert_group_date_to_default(
|
||||
group['mrp_date:day'])
|
||||
supply_qty_by_date[group_date] = group['mrp_qty']
|
||||
|
||||
# Read supply actions
|
||||
# TODO: if we remove cancel take it into account here,
|
||||
# TODO: as well as mrp_type ('r').
|
||||
exclude_mrp_actions = ['none', 'cancel']
|
||||
action_groups = mrp_move_obj.read_group(
|
||||
action_groups = mrp_move_obj.with_context(lang='en_GB').read_group(
|
||||
[('mrp_product_id', '=', mrp_product.id),
|
||||
('mrp_qty', '!=', 0.0),
|
||||
('mrp_type', '=', 's'),
|
||||
@@ -683,9 +696,8 @@ class MultiLevelMrp(models.TransientModel):
|
||||
supply_actions_qty_by_date = {}
|
||||
for group in action_groups:
|
||||
# Reformat date back to default server format.
|
||||
group_date = datetime.strptime(
|
||||
group['mrp_date:day'], ODOO_READ_GROUP_DAY_FORMAT).strftime(
|
||||
DEFAULT_SERVER_DATE_FORMAT)
|
||||
group_date = self._convert_group_date_to_default(
|
||||
group['mrp_date:day'])
|
||||
supply_actions_qty_by_date[group_date] = group['mrp_qty']
|
||||
|
||||
# Dates
|
||||
|
||||
Reference in New Issue
Block a user