Files
odoo_source/addons/account_analytic_default/models/product.py
T
Thibault Delavallée 4540b6595e [FIX] mrp, account_analytic_default: removed methods
When migrating stock, some dummies methods have been removed. Indeed those
calls make more problems than they solve by adding unnecessary complexity
around simple methods. However it seems some calls have been left in the
process :

 - _get_act_window_dict which is basically an env.ref or act_window.for_xml_id
 - _get_products which is basically having all product_ids from template by
   iterating on product_variant_ids.
2016-04-29 17:43:02 +02:00

34 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class ProductProduct(models.Model):
_inherit = 'product.product'
rules_count = fields.Integer(compute='_compute_rules_count', string='# Analytic Rules')
def _compute_rules_count(self):
Analytic = self.env['account.analytic.default']
for product in self:
product.rules_count = Analytic.search_count([('product_id', '=', product.id)])
class ProductTemplate(models.Model):
_inherit = 'product.template'
rules_count = fields.Integer(compute='_compute_rules_count', string='# Analytic Rules')
def _compute_rules_count(self):
for template in self:
template.rules_count = sum([p.rules_count for p in template.product_variant_ids])
@api.multi
def action_view_rules(self):
result = self.env.ref('account_analytic_default.action_product_default_list').read()[0]
result['domain'] = [('product_id', 'in', self.mapped('product_variant_ids').ids)]
# Remove context so it is not going to filter on product_id with active_id of template
result['context'] = "{}"
return result