I am trying to add a new field on account.analytic.account. I have developed this module in python but I d'n't kbow how the filter product_uom_id for hours only:
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models, fields
class mod_analytic_account(models.Model):
_inherit = 'account.analytic.account'
analytic_lines_ids = fields.One2many('account.analytic.line', 'account_id' , string = 'Analytic Account', store = True)
hores_realitzades=fields.Float(String = 'Hores realitzades',
compute="sum_hores_realitzades",store = True,
)
@api.multi
def sum_hores_realitzades(self):
for sel in self:
visited = []
total = 0.0
for il in sel.analytic_lines_ids.filtered(lambda r: r.product_uom_id == 'product.product_uom_hour'):
if il.id not in visited:
total += il.unit_amount
visited.append(il.id)
sel.hores_realitzades = total
@api.multi
def sum_hores_realitzades(self):
for il in sel.analytic_lines_ids.filtered(lambda r: r.product_uom_id == 'product.product_uom_hour'):
visited = []
total = 0.0
for il in sel.analytic_lines_ids:
if il.id not in visited:
total += il.unit_amount
visited.append(il.id)
sel.hores_realitzades = total