Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
2982 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor Nejlepší odpověď

Thanks

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
srp 21
5995
2
čvc 24
2405
2
kvě 24
3727
1
úno 24
1942
1
lis 22
5765