Skip to content

Commit

Permalink
[11.0][FIX] mrp_multi_level: the user and system locales could make t…
Browse files Browse the repository at this point in the history
…he MRP run break.
  • Loading branch information
LoisRForgeFlow committed Aug 3, 2018
1 parent f2ce61b commit 7a4137a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion mrp_multi_level/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, '
Expand Down
10 changes: 10 additions & 0 deletions mrp_multi_level/readme/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -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.
36 changes: 24 additions & 12 deletions mrp_multi_level/wizards/mrp_multi_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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__)
Expand Down Expand Up @@ -637,25 +638,38 @@ def _mrp_calculation(self, mrp_lowest_llc):

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'],
)
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')],
Expand All @@ -664,16 +678,15 @@ def _init_mrp_inventory(self, mrp_product):
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'),
Expand All @@ -683,9 +696,8 @@ def _init_mrp_inventory(self, mrp_product):
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
Expand Down

0 comments on commit 7a4137a

Please sign in to comment.