Hi,
I need to know how to compute the sum of all building capacities in the center capacity (capacité) field of the model?
Model Centre :
# -*- coding: utf-8 -*-
from odoo import models, fields
#-------------------------------------------------------------#
#--------------------- Centres d'élevage ---------------------#
#-------------------------------------------------------------#
class TechniqueCentre(models.Model):
_name = 'technique.centre'
_description ="Les centres d'élevage"
_inherit = ['mail.thread']
name = fields.Char(string='Nom du centre d\'élevage', required=True, track_visibility='always')
description = fields.Text(string='Description', track_visibility='onchange')
adresse = fields.Text(string='Adresse', required=True, track_visibility='onchange')
capacite = fields.Integer(string='Capacité', readonly=True, track_visibility='onchange')
code_postal = fields.Char(string='Code postal', required=True, track_visibility='onchange')
gouvernorat = fields.Char(string='Gouvernorat', required=True, track_visibility='onchange')
emplacement_stock = fields.Many2one('stock.location', string='Emplacement de stock', ondelete='cascade', required=True, track_visibility='onchange')
_sql_constraints = [
('name_uniq', 'unique (name)', "Le nom du centre existe déjà !"),
]
Model Bâtiment
# -*- coding: utf-8 -*-
from odoo import models, fields, api
#-------------------------------------------------------------#
#-------------------- Bâtiments d'élevage --------------------#
#-------------------------------------------------------------#
class TechniqueBatiment(models.Model):
_name = 'technique.batiment'
_description ="Les bâtiments d'élevage"
_inherit = ['mail.thread']
name = fields.Char(string='Nom du bâtiment d\'élevage', required=True, track_visibility='always')
description = fields.Text(string='Description', track_visibility='onchange')
capacite = fields.Integer(string='Capacité', required=True, track_visibility='onchange')
centre_id = fields.Many2one('technique.centre', string='Centre', ondelete='cascade', required=True, track_visibility='onchange')
_sql_constraints = [
('name_uniq', 'unique (name)', "Le nom du bâtiment existe déjà !"),
]
@ api.onchange ( 'capacite' )
def onchange_capacite ( self ):
if self.capacite:
self .centre_id.write({'capacite': self.capacite})
Thanks.
Read odoo customization tips: https://www.scoop.it/t/learn-openerp