Skip to Content
Menu
This question has been flagged
1660 Views

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

Avatar
Discard
Related Posts Replies Views Activity
1
Jan 23
1326
3
Aug 20
4023
0
Apr 16
3390
0
Dec 22
925
1
Nov 22
1707