<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Stock Out Alert
#    Copyright (C) 2013 Enterprise Objects Consulting
#                       http://www.eoconsulting.com.ar
#    Authors: <NAME> <<EMAIL>>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import osv
from openerp import pooler
from openerp import tools
from openerp.tools.translate import _
import logging

_logger = logging.getLogger(__name__)


class stock_move(osv.osv):
    _inherit = "stock.move"

    def run_check_op_stock_availability(self, cr, uid, use_new_cursor=False, context={}):
        """
        Runs through scheduler.
        @param use_new_cursor: False or the dbname
        """
        if context is None:
            context = {}
        try:
            if use_new_cursor:
                cr = pooler.get_db(use_new_cursor).cursor()
            _logger.info("Starting products availability check...")
            prod_list = self._check_op_stock_availability(cr, uid, context)
            if len(prod_list) > 0:
                _logger.info("...%s products out of stock found." % len(prod_list))
                mail_message_obj = self.pool['mail.message']
                user_obj = self.pool['res.users']
                group_obj = self.pool['res.groups']
                email_body = self.make_stock_out_email(cr, uid, prod_list, context)
                if _logger.isEnabledFor(logging.DEBUG):
                    _logger.debug("\n" + email_body)
                email_from = tools.config.get('email_from', False)
                if not email_from:
                    email_from = str(user_obj.browse(cr, uid, uid, context=context).user_email)
                wm_monitor_id = group_obj.search(cr, uid, [('name', '=', 'Stock Monitor'), ('category_id.name', '=', 'Warehouse Management')],
                                                 context=context)[0]
                email_to = [str(u.user_email) for u in group_obj.browse(cr, uid, wm_monitor_id, context=context).users]
                mail_message_obj.schedule_with_attach(cr, uid,
                                                      email_from,
                                                      email_to,
                                                      "ERP - " + str(len(prod_list)) + " " + _("products out of stock found"),
                                                      email_body,
                                                      attachments=None,
                                                      subtype='plain',
                                                      reply_to=email_from,
                                                      auto_delete=True,
                                                      context=context)
            else:
                _logger.info("...no product out of stock found.")
            if use_new_cursor:
                cr.commit()
        finally:
            if use_new_cursor:
                try:
                    cr.close()
                except Exception:
                    pass

    def _check_op_stock_availability(self, cr, uid, context={}):
        orderpoint_obj = self.pool.get('stock.warehouse.orderpoint')
        uom_obj = self.pool.get('product.uom')
        prod_list = []
        for op_id in orderpoint_obj.search(cr, uid, [('active', '=', True)], context=context):
            op = orderpoint_obj.browse(cr, uid, op_id, context=context)
            product = op.product_id
            uom = product.product_tmpl_id.uom_id
            uom_po = product.product_tmpl_id.uom_po_id
            product_min_qty = uom_obj._compute_qty(cr, uid, op.product_uom.id, op.product_min_qty, uom.id)
            qty = product_min_qty - product.virtual_available
            if qty > 0:
                prod = {}
                prod['uom'] = uom_po
                prod['qty'] = uom_obj._compute_qty(cr, uid, uom.id, qty, uom_po.id)
                prod['product'] = product
                prod['location'] = op.location_id
                prod['company'] = op.company_id
                prod_list.append(prod)<commit_msg>[stock_out_alert] no email cancellation<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Stock Out Alert
#    Copyright (C) 2013 Enterprise Objects Consulting
#                       http://www.eoconsulting.com.ar
#    Authors: <NAME> <<EMAIL>>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import osv
from openerp import pooler
from openerp import tools
from openerp.tools.translate import _
import logging

_logger = logging.getLogger(__name__)


class stock_move(osv.osv):
    _inherit = "stock.move"

    def run_check_op_stock_availability(self, cr, uid, use_new_cursor=False, context={}):
        """
        Runs through scheduler.
        @param use_new_cursor: False or the dbname
        """
        if context is None:
            context = {}
        try:
            if use_new_cursor:
                cr = pooler.get_db(use_new_cursor).cursor()
            _logger.info("Starting products availability check...")
            prod_list = self._check_op_stock_availability(cr, uid, context)
            if len(prod_list) > 0:
                _logger.info("...%s products out of stock found." % len(prod_list))
                mail_message_obj = self.pool['mail.message']
                user_obj = self.pool['res.users']
                group_obj = self.pool['res.groups']
                email_body = self.make_stock_out_email(cr, uid, prod_list, context)
                if _logger.isEnabledFor(logging.DEBUG):
                    _logger.debug("\n" + email_body)
                email_from = tools.config.get('email_from', False)
                if not email_from:
                    email_from = str(user_obj.browse(cr, uid, uid, context=context).user_email)
                wm_monitor_id = group_obj.search(cr, uid, [('name', '=', 'Stock Monitor'), ('category_id.name', '=', 'Warehouse Management')],
                                                 context=context)[0]
                email_to = [str(u.user_email) for u in group_obj.browse(cr, uid, wm_monitor_id, context=context).users]
                mail_message_obj.schedule_with_attach(cr, uid,
                                                      email_from,
                                                      email_to,
                                                      "ERP - " + str(len(prod_list)) + " " + _("products out of stock found"),
                                                      email_body,
                                                      attachments=None,
                                                      subtype='plain',
                                                      reply_to=email_from,
                                                      auto_delete=False,
                                                      context=context)
            else:
                _logger.info("...no product out of stock found.")
            if use_new_cursor:
                cr.commit()
        finally:
            if use_new_cursor:
                try:
                    cr.close()
                except Exception:
                    pass

    def _check_op_stock_availability(self, cr, uid, context={}):
        orderpoint_obj = self.pool.get('stock.warehouse.orderpoint')
        uom_obj = self.pool.get('product.uom')
        prod_list = []
        orderpoint_ids = orderpoint_obj.search(cr, uid, [('active', '=', True)], context=context)
        for op in orderpoint_obj.browse(cr, uid, orderpoint_ids, context=context):
            product = op.product_id
            uom = product.product_tmpl_id.uom_id
            uom_po = product.product_tmpl_id.uom_po_id
            product_min_qty = uom_obj._compute_qty(cr, uid, op.product_uom.id, op.product_min_qty, uom.id)
            qty = product_min_qty - product.virtual_available
            if qty > 0:
                prod = {}
                prod['uom'] = uom_po
                prod['qty'] = uom_obj._compute_qty(cr, uid, uom.id, qty, uom_po.id)
                prod['product'] = product
                prod['location'] = op.location_id
                prod['company'] = op.company_id
                prod_list.append(prod)
{'fraction_non_alphanumeric': 0.12152105209501478, 'fraction_numerical': 0.0018350494443878072, 'mean_word_length': 1.6920965971459934, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7555570', 'n_tokens_mistral': 2610, 'n_tokens_neox': 2485, 'n_words': 646}