how i can create automatic in one2many field (gmat.dashboard), thos after change (click) date field (in gmat.board):
# -*- coding: utf-8 -*-
from openerp import api, exceptions, fields, models, _
import datetime
class Board(models.Model):
_name = 'gmat.board'
_description = 'Rapport Journalier'
_rec_name = 'date_d'
date_d = fields.Date(default=fields.Date.today(),required=True)
m2o_list = fields.One2many('gmat.dashboard','list_ids',string='Materiel')
class Dashboard(models.Model):
_name = "gmat.dashboard"
list_ids=fields.Many2one('gmat.board')
structures=fields.Many2one('gmat.journaleline')
panne_act = fields.Float(compute='nbr_pannes_act', store=True)
panne_prec = fields.Float(compute='nbr_pannes_prec', store=True)
@api.multi
def nbr_pannes_act(self):
if self.id:
np_a = 0
n_p=self.env['gmat.rapporjournal'].search([('rapJor_ids.date_rj','=',self.date_d)])
for line in n_p:
if line.o2m_materiels.exp_P>0:
np_a = np_a + line.o2m_materiels.exp_P
return np_a
@api.multi
def nbr_pannes_prec(self):
if self.id:
np_p = 0 n_p=self.env['gmat.rapporjournal'].search([('rapJor_ids.date_rj','=',datetime.datetime.strptime(self.rapJor_ids.date_rj,'%Y-%m-%d')-datetime.timedelta(days=1))])
for line in n_p:
if line.o2m_materiels.exp_P_JP>0:
np_p = np_p + line.o2m_materiels.exp_P_JP
return np_p