diff --git a/addons/stock_calendar/__openerp__.py b/addons/stock_calendar/__openerp__.py index 9d96e5c14e5..f771d78acf1 100644 --- a/addons/stock_calendar/__openerp__.py +++ b/addons/stock_calendar/__openerp__.py @@ -50,7 +50,6 @@ 'views/resource_views.xml', ], 'test': [ - 'test/orderpoint_calendar.yml' ], 'installable': True, 'application': False, diff --git a/addons/stock_calendar/test/orderpoint_calendar.yml b/addons/stock_calendar/test/orderpoint_calendar.yml deleted file mode 100644 index e1591cc07f9..00000000000 --- a/addons/stock_calendar/test/orderpoint_calendar.yml +++ /dev/null @@ -1,98 +0,0 @@ -- - Create a partner -- - !record {model: res.partner, id: res_partner_cal}: - name: Supplier - supplier: 1 -- - Create a calendar -- - !record {model: resource.calendar, id: res_cal}: - name: Calendar - attendance_ids: - - name: Thursday - dayofweek: '3' - hour_from: 08 - hour_to: 09 -- - Create a product A with orderpoint with a calendar -- - !record {model: product.product, id: product_calendar, view: False}: - name: Calendar Product - seller_ids: - - name: res_partner_cal - delay: 1 - orderpoint_ids: - - name: Product A Truck - calendar_id: res_cal - product_min_qty: 0 - product_max_qty: 10 - warehouse_id: stock.warehouse0 -- - Create delivery order with product A -- - !record {model: stock.picking, id: pick_out_calendar}: - name: Delivery order for procurement (calendar) - partner_id: res_partner_cal - picking_type_id: stock.picking_type_out - move_lines: - - product_id: product_calendar - product_uom_qty: 3.00 - location_id: stock.stock_location_stock - location_dest_id: stock.stock_location_customers - procure_method: make_to_stock -- - Create other delivery order with product A that we will give a later date afterwards (date between the two) -- - !record {model: stock.picking, id: pick_out_calendar2}: - name: Delivery order for procurement (calendar2) - partner_id: res_partner_cal - picking_type_id: stock.picking_type_out - move_lines: - - product_id: product_calendar - product_uom_qty: 4.00 - location_id: stock.stock_location_stock - location_dest_id: stock.stock_location_customers - procure_method: make_to_stock -- - Create other delivery order with product A that we will give an even later date, so it should not be taken into account -- - !record {model: stock.picking, id: pick_out_calendar3}: - name: Delivery order for procurement (calendar3) - partner_id: res_partner_cal - picking_type_id: stock.picking_type_out - move_lines: - - product_id: product_calendar - product_uom_qty: 11.00 - location_id: stock.stock_location_stock - location_dest_id: stock.stock_location_customers - procure_method: make_to_stock -- - Put different dates in pickings, confirm them, run schedulers and check that the procurement generated by the orderpoint is taking the calendar into account. Make sure also that the purchase order creates a datetime. -- - !python {model: stock.picking}: | - move_obj = self.pool.get('stock.move') - product_obj = self.pool.get('product.product') - product_obj.write(cr, uid, [ref('product_calendar')], {'route_ids': [(4, ref('purchase.route_warehouse0_buy'))]}) - import datetime - from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT - today8 = datetime.datetime.today() + datetime.timedelta(days = 7) - today21 = datetime.datetime.today() + datetime.timedelta(days = 21) - cal1 = self.browse(cr, uid, ref('pick_out_calendar')) - cal2 = self.browse(cr, uid, ref('pick_out_calendar2')) - move_obj.write(cr, uid, cal2.move_lines[0].id, {'date': today8.strftime(DEFAULT_SERVER_DATETIME_FORMAT), 'date_expected': today8.strftime(DEFAULT_SERVER_DATETIME_FORMAT)}) - cal3 = self.browse(cr, uid, ref('pick_out_calendar3')) - move_obj.write(cr, uid, cal3.move_lines[0].id, {'date_expected': today21.strftime(DEFAULT_SERVER_DATETIME_FORMAT), - 'date': today21.strftime(DEFAULT_SERVER_DATETIME_FORMAT)}) - #We need to confirm pickings and run the schedulers - self.action_confirm(cr, uid, [cal1.id, cal2.id, cal3.id]) - # Check procurements generated - proc_obj = self.pool.get("procurement.order") - proc_obj.run_scheduler(cr, uid) - proc_ids = proc_obj.search(cr, uid, [('product_id', '=', ref('product_calendar'))]) - assert len(proc_ids) == 1, 'should have one procurement' - procurement = proc_obj.browse(cr, uid, proc_ids[0]) - assert procurement.product_qty == 17, 'It should have taken the two first pickings into account for the virtual stock for the orderpoint, not the third' - assert datetime.datetime.strptime(procurement.next_delivery_date, DEFAULT_SERVER_DATETIME_FORMAT).weekday() == 3, 'The next delivery date should be on a Thursday' - purchase_line_id_date_planned = datetime.datetime.strptime(procurement.purchase_line_id.date_planned, DEFAULT_SERVER_DATETIME_FORMAT).weekday() - assert purchase_line_id_date_planned == 3, 'Check it has been put on the purchase line also, got %d' %purchase_line_id_date_planned diff --git a/addons/stock_calendar/tests/__init__.py b/addons/stock_calendar/tests/__init__.py new file mode 100644 index 00000000000..bef05832979 --- /dev/null +++ b/addons/stock_calendar/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import test_stock_calendar diff --git a/addons/stock_calendar/tests/test_stock_calendar.py b/addons/stock_calendar/tests/test_stock_calendar.py new file mode 100644 index 00000000000..6f00f5d0065 --- /dev/null +++ b/addons/stock_calendar/tests/test_stock_calendar.py @@ -0,0 +1,101 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from datetime import datetime, timedelta + +from odoo import fields +from odoo.tests import common + + +class TestsStockCalendar(common.TransactionCase): + + def setUp(self): + super(TestsStockCalendar, self).setUp() + + # Create a partner + self.stock_warehouse0_id = self.ref('stock.warehouse0') + self.purchase_route_warehouse0_buy_id = self.ref('purchase.route_warehouse0_buy') + self.stock_picking_type_out_id = self.ref('stock.picking_type_out') + self.stock_location_id = self.ref('stock.stock_location_stock') + self.stock_location_customer_id = self.ref('stock.stock_location_customers') + + self.res_partner_id = self.env['res.partner'].create({ + 'name': 'Supplier', + 'supplier': 1 + }) + + # Create a calendar + self.resource_calendar_id = self.env['resource.calendar'].create({ + 'name': 'Calendar', + 'attendance_ids': [(0, 0, { + 'name': 'Thursday', + 'dayofweek': '3', + 'hour_from': 8, + 'hour_to': 9 + })] + }) + + # Create a product A with orderpoint with a calendar + self.calendar_product_id = self.env['product.product'].create({ + 'name': 'Calendar Product', + 'seller_ids': [(0, 0, { + 'name': self.res_partner_id.id, + 'delay': 1 + })], + 'orderpoint_ids': [(0, 0, { + 'name': 'Product A Truck', + 'calendar_id': self.resource_calendar_id.id, + 'product_min_qty': 0, + 'product_max_qty': 10, + 'warehouse_id': self.stock_warehouse0_id + })] + }) + + # Create delivery order with product A + self.pick_out_calendar = self._create_stock_picking('Delivery order for procurement', self.calendar_product_id.name, 3.00) + + # Create other delivery order with product A that we will give a later date afterwards (date between the two) + self.pick_out_calendar2 = self._create_stock_picking('Delivery order for procurement2', 'stock_move_2', 4.00) + + # Create other delivery order with product A that we will give an even later date, so it should not be taken into account + self.pick_out_calendar3 = self._create_stock_picking('Delivery order for procurement3', 'stock_move_3', 11.00) + + def _create_stock_picking(self, pickname, movelinename, productqty): + return self.env['stock.picking'].create({ + 'name': pickname, + 'partner_id': self.res_partner_id.id, + 'picking_type_id': self.stock_picking_type_out_id, + 'location_id': self.stock_location_id, + 'location_dest_id': self.stock_location_customer_id, + 'move_lines': [(0, 0, {'name': movelinename, + 'product_id': self.calendar_product_id.id, + 'product_uom': self.calendar_product_id.uom_id.id, + 'product_uom_qty': productqty, + 'location_id': self.stock_location_id, + 'location_dest_id': self.stock_location_customer_id, + 'procure_method': 'make_to_stock'})] + }) + + def test_stock_calendar(self): + # Put different dates in pickings, confirm them, run schedulers and check that the procurement generated by the + # orderpoint is taking the calendar into account. Make sure also that the purchase order creates a datetime. + self.calendar_product_id.write({'route_ids': [(4, self.purchase_route_warehouse0_buy_id)]}) + today8 = datetime.now() + timedelta(days=7) + today21 = datetime.now() + timedelta(days=21) + self.pick_out_calendar2.move_lines.write({'date': fields.Datetime.to_string(today8), 'date_expected': fields.Datetime.to_string(today8)}) + self.pick_out_calendar3.move_lines.write({'date_expected': fields.Datetime.to_string(today21), 'date': fields.Datetime.to_string(today21)}) + + # We need to confirm pickings and run the schedulers + self.pick_out_calendar.action_confirm() + self.pick_out_calendar2.action_confirm() + self.pick_out_calendar3.action_confirm() + + # Check .procurements generated + Procurementorder = self.env['procurement.order'] + Procurementorder.run_scheduler() + procurement = Procurementorder.search([('product_id', '=', self.calendar_product_id.id)], limit=1) + self.assertEqual(len(procurement), 1, 'should have one procurement') + self.assertEqual(procurement.product_qty, 17, 'It should have taken the two first pickings into account for the virtual stock for the orderpoint, not the third') + self.assertEqual(fields.Datetime.from_string(procurement.next_delivery_date).weekday(), 3, 'The next delivery date should be on a Thursday') + purchase_line_id_date_planned = fields.Datetime.from_string(procurement.purchase_line_id.date_planned).weekday() + self.assertEqual(purchase_line_id_date_planned, 3, 'Check it has been put on the purchase line also, got %d' % purchase_line_id_date_planned)