[IMP] stock_warehouse_calendar: black, isort

This commit is contained in:
Lois Rilo
2019-12-17 09:32:43 +01:00
parent a268a8e3a5
commit ec24e4c3ef
4 changed files with 94 additions and 82 deletions

View File

@@ -7,17 +7,11 @@
"version": "12.0.1.0.1",
"license": "LGPL-3",
"website": "https://github.com/stock-logistics-warehouse",
"author": "Eficent, "
"Odoo Community Association (OCA)",
"author": "Eficent, " "Odoo Community Association (OCA)",
"category": "Warehouse Management",
"depends": [
"stock",
"resource",
],
"data": [
"views/stock_warehouse_views.xml",
],
"depends": ["stock", "resource"],
"data": ["views/stock_warehouse_views.xml"],
"installable": True,
'development_status': 'Beta',
'maintainers': ['jbeficent'],
"development_status": "Beta",
"maintainers": ["jbeficent"],
}

View File

@@ -1,23 +1,41 @@
# Copyright 2018-19 Eficent Business and IT Consulting Services, S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import models
from datetime import datetime
from odoo import models
class StockRule(models.Model):
_inherit = 'stock.rule'
_inherit = "stock.rule"
def _get_stock_move_values(self, product_id, product_qty, product_uom,
location_id, name, origin, values, group_id):
def _get_stock_move_values(
self,
product_id,
product_qty,
product_uom,
location_id,
name,
origin,
values,
group_id,
):
res = super(StockRule, self)._get_stock_move_values(
product_id, product_qty, product_uom,
location_id, name, origin, values, group_id)
product_id,
product_qty,
product_uom,
location_id,
name,
origin,
values,
group_id,
)
warehouse = self.propagate_warehouse_id or self.warehouse_id
if warehouse.calendar_id and self.delay:
date_expected = warehouse.wh_plan_days(
values['date_planned'], -1 * self.delay)
values["date_planned"], -1 * self.delay
)
if date_expected > datetime.now():
res['date'] = date_expected
res['date_expected'] = date_expected
res["date"] = date_expected
res["date_expected"] = date_expected
return res

View File

@@ -7,11 +7,10 @@ from odoo import fields, models
class StockWarehouse(models.Model):
_inherit = 'stock.warehouse'
_inherit = "stock.warehouse"
calendar_id = fields.Many2one(
comodel_name='resource.calendar',
string='Working Hours',
comodel_name="resource.calendar", string="Working Hours"
)
def wh_plan_days(self, date_from, delta):

View File

@@ -6,69 +6,65 @@ from odoo.tests.common import TransactionCase
class TestStockWarehouseCalendar(TransactionCase):
def setUp(self):
super(TestStockWarehouseCalendar, self).setUp()
self.wh_obj = self.env['stock.warehouse']
self.move_obj = self.env['stock.move']
self.company = self.env.ref('base.main_company')
self.warehouse = self.env.ref('stock.warehouse0')
self.customer_loc = self.env.ref('stock.stock_location_customers')
self.company_partner = self.env.ref('base.main_partner')
self.calendar = self.env.ref('resource.resource_calendar_std')
self.wh_obj = self.env["stock.warehouse"]
self.move_obj = self.env["stock.move"]
self.company = self.env.ref("base.main_company")
self.warehouse = self.env.ref("stock.warehouse0")
self.customer_loc = self.env.ref("stock.stock_location_customers")
self.company_partner = self.env.ref("base.main_partner")
self.calendar = self.env.ref("resource.resource_calendar_std")
self.warehouse.calendar_id = self.calendar
self.warehouse_2 = self.wh_obj.create({
'code': 'WH-T',
'name': 'Warehouse Test',
'calendar_id': self.calendar.id,
})
self.warehouse_3 = self.wh_obj.create({
'code': 'WH-no-calendar',
'name': 'Warehouse Test 2',
})
self.warehouse_2 = self.wh_obj.create(
{"code": "WH-T", "name": "Warehouse Test", "calendar_id": self.calendar.id}
)
self.warehouse_3 = self.wh_obj.create(
{"code": "WH-no-calendar", "name": "Warehouse Test 2"}
)
self.product = self.env['product.product'].create({
'name': 'test product',
'default_code': 'PRD',
'type': 'product',
})
self.product = self.env["product.product"].create(
{"name": "test product", "default_code": "PRD", "type": "product"}
)
route_vals = {
'name': 'WH2 -> WH',
}
self.transfer_route = self.env['stock.location.route'].create(
route_vals)
route_vals = {"name": "WH2 -> WH"}
self.transfer_route = self.env["stock.location.route"].create(route_vals)
rule_vals = {
'location_id': self.warehouse.lot_stock_id.id,
'location_src_id': self.warehouse_2.lot_stock_id.id,
'action': 'pull_push',
'warehouse_id': self.warehouse.id,
'propagate_warehouse_id': self.warehouse_2.id,
'picking_type_id': self.env.ref('stock.picking_type_internal').id,
'name': 'WH2->WH',
'route_id': self.transfer_route.id,
'delay': 1,
"location_id": self.warehouse.lot_stock_id.id,
"location_src_id": self.warehouse_2.lot_stock_id.id,
"action": "pull_push",
"warehouse_id": self.warehouse.id,
"propagate_warehouse_id": self.warehouse_2.id,
"picking_type_id": self.env.ref("stock.picking_type_internal").id,
"name": "WH2->WH",
"route_id": self.transfer_route.id,
"delay": 1,
}
self.transfer_rule = self.env['stock.rule'].create(rule_vals)
self.transfer_rule = self.env["stock.rule"].create(rule_vals)
self.product.route_ids = [(6, 0, self.transfer_route.ids)]
def test_01_procurement_with_calendar(self):
values = {
'date_planned': '2097-01-07 09:00:00', # Monday
'warehouse_id': self.warehouse,
'company_id': self.company,
'rule_id': self.transfer_rule,
"date_planned": "2097-01-07 09:00:00", # Monday
"warehouse_id": self.warehouse,
"company_id": self.company,
"rule_id": self.transfer_rule,
}
self.env['procurement.group'].run(
self.product, 100,
self.env["procurement.group"].run(
self.product,
100,
self.product.uom_id,
self.warehouse.lot_stock_id, 'Test',
'Test', values)
move = self.env['stock.move'].search(
[('product_id', '=', self.product.id)], limit=1)
self.warehouse.lot_stock_id,
"Test",
"Test",
values,
)
move = self.env["stock.move"].search(
[("product_id", "=", self.product.id)], limit=1
)
date_expected = fields.Date.to_date(move.date_expected)
# Friday 4th Jan 2017
friday = fields.Date.to_date('2097-01-04 09:00:00')
friday = fields.Date.to_date("2097-01-04 09:00:00")
self.assertEquals(date_expected, friday)
@@ -76,21 +72,26 @@ class TestStockWarehouseCalendar(TransactionCase):
"""Test procuring at the beginning of the day, with no work intervals
before."""
values = {
'date_planned': '2097-01-07 01:00:00', # Monday
'warehouse_id': self.warehouse,
'company_id': self.company,
'rule_id': self.transfer_rule,
"date_planned": "2097-01-07 01:00:00", # Monday
"warehouse_id": self.warehouse,
"company_id": self.company,
"rule_id": self.transfer_rule,
}
self.env['procurement.group'].run(
self.product, 100,
self.env["procurement.group"].run(
self.product,
100,
self.product.uom_id,
self.warehouse.lot_stock_id, 'Test',
'Test', values)
move = self.env['stock.move'].search(
[('product_id', '=', self.product.id)], limit=1)
self.warehouse.lot_stock_id,
"Test",
"Test",
values,
)
move = self.env["stock.move"].search(
[("product_id", "=", self.product.id)], limit=1
)
date_expected = fields.Date.to_date(move.date_expected)
# Friday 4th Jan 2017
friday = fields.Date.to_date('2097-01-04 09:00:00')
friday = fields.Date.to_date("2097-01-04 09:00:00")
self.assertEquals(date_expected, friday)