Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
2852 Vistas

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


Avatar
Descartar
Mejor respuesta

hello,

Please try this code, 

hores_realitzades=fields.Float(String = 'Hores realitzades', compute="sum_hores_realitzades",store = True)


@api.depends('analytic_lines_ids','analytic_lines_ids.unit_amount')
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.id == self.env.ref('product.product_uom_hour').id):
            if il.id not in visited:
                total += il.unit_amount
                visited.append(il.id)
        sel.hores_realitzades = total

Hope it will work for you,

thanks,

Avatar
Descartar
Autor Mejor respuesta

Thanks

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
ago 21
5824
2
jul 24
2246
2
may 24
2189
1
feb 24
1785
1
nov 22
5563