<commit_before># -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in module root
# directory
##############################################################################
from openerp import models, fields, api
from datetime import timedelta, datetime


class ProductProduct(models.Model):
    _inherit = 'product.product'

    @api.multi
    def get_product_rotation(self, location=False):
        self.ensure_one()
        # we should use cache for this date
        from_date = fields.Datetime.to_string(
            datetime.now() + timedelta(-90))
        base_domain = [
            ('date', '>=', from_date),
            ('state', '=', 'done'),
            ('product_id', '=', self.id),
        ]
        base_domain_send = base_domain + [
            ('location_dest_id.usage', '=', 'customer')]
        base_domain_return = base_domain + [
            ('location_id.usage', '=', 'customer')]

        if location:
            base_domain_send += [('location_id', '=', location.id)]
            base_domain_return += [
                ('location_dest_id', '=', location.id)]

        # from any location to customers
        rotation = sum(self.env['stock.move'].search(
            base_domain_send).mapped('product_qty'))
        # from customers to any location
        rotation -= sum(self.env['stock.move'].search(
            base_domain_return).mapped('product_qty'))
        return rotation / 3.0<commit_msg>IMP use child of on rotation by category<commit_after># -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in module root
# directory
##############################################################################
from openerp import models, fields, api
from datetime import timedelta, datetime


class ProductProduct(models.Model):
    _inherit = 'product.product'

    @api.multi
    def get_product_rotation(self, location=False):
        self.ensure_one()
        # we should use cache for this date
        from_date = fields.Datetime.to_string(
            datetime.now() + timedelta(-90))
        base_domain = [
            ('date', '>=', from_date),
            ('state', '=', 'done'),
            ('product_id', '=', self.id),
        ]
        base_domain_send = base_domain + [
            ('location_dest_id.usage', '=', 'customer')]
        base_domain_return = base_domain + [
            ('location_id.usage', '=', 'customer')]

        if location:
            base_domain_send += [('location_id', 'child_of', location.id)]
            base_domain_return += [
                ('location_dest_id', 'child_of', location.id)]

        # from any location to customers
        rotation = sum(self.env['stock.move'].search(
            base_domain_send).mapped('product_qty'))
        # from customers to any location
        rotation -= sum(self.env['stock.move'].search(
            base_domain_return).mapped('product_qty'))
        return rotation / 3.0
{'fraction_non_alphanumeric': 0.21944177093359, 'fraction_numerical': 0.003208213025344883, 'mean_word_length': 2.783980582524272, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3083846', 'n_tokens_mistral': 842, 'n_tokens_neox': 807, 'n_words': 184}