<commit_before># -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models, tools
from odoo.fields import Datetime as fieldsDatetime


class StockHistory(models.Model):
    _name = 'stock.history'
    _auto = False
    _order = 'date asc'

    move_id = fields.Many2one('stock.move', 'Stock Move', required=True)
    location_id = fields.Many2one('stock.location', 'Location', required=True)
    company_id = fields.Many2one('res.company', 'Company')
    product_id = fields.Many2one('product.product', 'Product', required=True)
    product_categ_id = fields.Many2one('product.category', 'Product Category', required=True)
    quantity = fields.Float('Product Quantity')
    date = fields.Datetime('Operation Date')
    price_unit_on_quant = fields.Float('Value')
    inventory_value = fields.Float('Inventory Value', compute='_compute_inventory_value', readonly=True)
    source = fields.Char('Source')
    product_template_id = fields.Many2one('product.template', 'Product Template', required=True)
    serial_number = fields.Char('Lot/Serial Number', required=True)

    @api.model
    def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
        # Step 1: retrieve the standard read_group output. In case of inventory valuation, this
        # will be mostly used as a 'skeleton' since the inventory value needs to be computed based
        # on the individual lines.
        res = super(StockHistory, self).read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
        if 'inventory_value' in fields:
            groupby_list = groupby[:1] if lazy else groupby
            date = self._context.get('history_date', fieldsDatetime.now())

            # Step 2: retrieve the stock history lines. The result contains the 'expanded'
            # version of the read_group. We build the query manually for performance reason
            # (and avoid a costly 'WHERE id IN ...').
            fields_2 = set(
                ['id', 'product_id', 'price_unit_on_quant', 'company_id', 'quantity'] + groupby_list
            )
            query = self._where_calc(domain)
            self._apply_ir_rules(query, 'read')
            tables, where_clause, where_clause_params = query.get_sql()
            select = "SELECT %s FROM %s WHERE %s "
            query = select % (','.join(fields_2), tables, where_clause)
            self._cr.execute(query, where_clause_params)

            # Step 3: match the lines retrieved at step 2 with the aggregated results of step 1.
            # In other words, we link each item of the read_group result with the corresponding
            # lines.
            stock_history_data = {}
            stock_histories_by_group = {}
            for line in self._cr.dictfetchall():
                stock_history_data[line['id']] = line
                key = tuple(line[g] if g in line else False for g in groupby_list)
                stock_histories_by_group.setdefault(key, [])
                stock_histories_by_group[key] += [line['id']]

            histories_dict = {}
            not_real_cost_method_products = self.env['product.product'].browse(<commit_msg>[FIX] stock_account: group on empty field 65;5401;1c Line contains the value returned by a select clause on inventory lines. postgresql result returns None instead of False when no value is set.<commit_after># -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models, tools
from odoo.fields import Datetime as fieldsDatetime


class StockHistory(models.Model):
    _name = 'stock.history'
    _auto = False
    _order = 'date asc'

    move_id = fields.Many2one('stock.move', 'Stock Move', required=True)
    location_id = fields.Many2one('stock.location', 'Location', required=True)
    company_id = fields.Many2one('res.company', 'Company')
    product_id = fields.Many2one('product.product', 'Product', required=True)
    product_categ_id = fields.Many2one('product.category', 'Product Category', required=True)
    quantity = fields.Float('Product Quantity')
    date = fields.Datetime('Operation Date')
    price_unit_on_quant = fields.Float('Value')
    inventory_value = fields.Float('Inventory Value', compute='_compute_inventory_value', readonly=True)
    source = fields.Char('Source')
    product_template_id = fields.Many2one('product.template', 'Product Template', required=True)
    serial_number = fields.Char('Lot/Serial Number', required=True)

    @api.model
    def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
        # Step 1: retrieve the standard read_group output. In case of inventory valuation, this
        # will be mostly used as a 'skeleton' since the inventory value needs to be computed based
        # on the individual lines.
        res = super(StockHistory, self).read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
        if 'inventory_value' in fields:
            groupby_list = groupby[:1] if lazy else groupby
            date = self._context.get('history_date', fieldsDatetime.now())

            # Step 2: retrieve the stock history lines. The result contains the 'expanded'
            # version of the read_group. We build the query manually for performance reason
            # (and avoid a costly 'WHERE id IN ...').
            fields_2 = set(
                ['id', 'product_id', 'price_unit_on_quant', 'company_id', 'quantity'] + groupby_list
            )
            query = self._where_calc(domain)
            self._apply_ir_rules(query, 'read')
            tables, where_clause, where_clause_params = query.get_sql()
            select = "SELECT %s FROM %s WHERE %s "
            query = select % (','.join(fields_2), tables, where_clause)
            self._cr.execute(query, where_clause_params)

            # Step 3: match the lines retrieved at step 2 with the aggregated results of step 1.
            # In other words, we link each item of the read_group result with the corresponding
            # lines.
            stock_history_data = {}
            stock_histories_by_group = {}
            for line in self._cr.dictfetchall():
                stock_history_data[line['id']] = line
                key = tuple(line.get(g) or False for g in groupby_list)
                stock_histories_by_group.setdefault(key, [])
                stock_histories_by_group[key] += [line['id']]

            histories_dict = {}
            not_real_cost_method_products = self.env['product.product'].browse(
{'fraction_non_alphanumeric': 0.10284857571214392, 'fraction_numerical': 0.005847076461769116, 'mean_word_length': 2.9994004796163067, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2969285', 'n_tokens_mistral': 1905, 'n_tokens_neox': 1848, 'n_words': 555}