Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.0][FIX] mrp_multi_level: locale issue #290

Merged
merged 2 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion mrp_multi_level/data/mrp_area_data.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">

<record id="mrp_area_stock_wh0" model="mrp.area">
<field name="name">WH/Stock</field>
<field name="warehouse_id" ref="stock.warehouse0"/>
<field name="location_id" ref="stock.stock_location_stock"/>
<field name="calendar_id" ref="resource.resource_calendar_std"/>
</record>

</odoo>
7 changes: 5 additions & 2 deletions mrp_multi_level/models/mrp_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ class MrpArea(models.Model):
required=True,
)
active = fields.Boolean(default=True)
calendar_id = fields.Many2one('resource.calendar',
'Working Hours')
calendar_id = fields.Many2one(
comodel_name='resource.calendar',
string='Working Hours',
related='warehouse_id.calendar_id',
)
13 changes: 13 additions & 0 deletions mrp_multi_level/readme/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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>`_)
* [FIX] Working Hours are now defined only at Warehouse level and displayed
as a related on MRP Areas.
(`#290 <https://github.com/OCA/manufacture/pull/290>`__)

11.0.1.0.0 (2018-07-09)
~~~~~~~~~~~~~~~~~~~~~~~

* Start of the history.
7 changes: 4 additions & 3 deletions mrp_multi_level/tests/test_mrp_multi_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def setUpClass(cls):
cls.customer_location = cls.env.ref(
'stock.stock_location_customers')
cls.calendar = cls.env.ref('resource.resource_calendar_std')
# Add calendar to WH:
cls.wh.calendar_id = cls.calendar

# Partner:
vendor1 = cls.partner_obj.create({'name': 'Vendor 1'})
Expand Down Expand Up @@ -367,9 +369,8 @@ def test_07_procure_mo(self):
('product_id', '=', self.fp_1.id)])
self.assertTrue(mos)
self.assertEqual(mos.product_qty, 100.0)
datetime_5 = fields.Datetime.to_string(
self.calendar.plan_days(5 + 1, datetime.today()).date())
self.assertEqual(mos.date_planned_start, datetime_5)
mo_date_start = mos.date_planned_start.split(' ')[0]
self.assertEqual(mo_date_start, self.date_5)

# TODO: test procure wizard: pos, multiple...
# TODO: test multiple destination IDS:...
42 changes: 25 additions & 17 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 @@ -273,11 +274,7 @@ def create_move(self, mrp_product_id, mrp_date, mrp_qty, name):
mrp_date_demand_2,
bom, name)
mrpmove_id2 = self.env['mrp.move'].create(move_data)
sql_stat = "INSERT INTO mrp_move_rel (" \
"move_up_id, " \
"move_down_id) values (%d, %d)" % \
(mrpmove_id, mrpmove_id2, )
self.env.cr.execute(sql_stat)
mrpmove_id.mrp_move_down_ids = [(4, mrpmove_id2.id)]
values['qty_ordered'] = qty_ordered
log_msg = '%s' % qty_ordered
logger.info(log_msg)
Expand Down Expand Up @@ -637,25 +634,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 +674,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 +692,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