[11.0][FIX] mrp_multi_level: the user and system locales could make the MRP run break.

This commit is contained in:
Lois Rilo
2018-08-03 13:14:25 +02:00
committed by JasminSForgeFlow
parent 7595db4ec0
commit 0e0aa087d0
3 changed files with 35 additions and 13 deletions

View File

@@ -3,7 +3,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
'name': 'MRP Multi Level',
'version': '11.0.1.0.0',
'version': '11.0.1.0.1',
'development_status': 'Beta',
'license': 'AGPL-3',
'author': 'Ucamco, '

View File

@@ -0,0 +1,10 @@
11.0.1.0.1 (2018-08-03)
~~~~~~~~~~~~~~~~~~~~~~~
* [FIX] User and system locales doesn't break MRP calculation.
(`#290 <https://github.com/OCA/manufacture/pull/290>`_)
11.0.1.0.0 (2018-07-09)
~~~~~~~~~~~~~~~~~~~~~~~
* Start of the history.

View File

@@ -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 locales
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