56 lines
1.9 KiB
Python
Executable File
56 lines
1.9 KiB
Python
Executable File
# -*- coding: utf-8 -*-
|
|
from odoo import api, fields, models, _
|
|
from datetime import datetime
|
|
from odoo.exceptions import Warning
|
|
|
|
|
|
#class contact.type qui permet de stocker le type du contact et s'il est actif
|
|
class contactType(models.Model):
|
|
_name = 'contact.type'
|
|
|
|
|
|
_description ="Daily Transaction"
|
|
|
|
name = fields.Char(string='Type', size=128, required=True, translate=True)
|
|
Actif=fields.Boolean('Active', default=True, translate=True)
|
|
|
|
_sql_constraints = [
|
|
('name', 'unique(name)',
|
|
'Type must be unique!'),
|
|
]
|
|
|
|
#class heristé du class res.partner pour l'ajout des nouveaux champs au contact
|
|
class contactPerso(models.Model):
|
|
_inherit = "res.partner"
|
|
_order="dateOfFirstContact desc"
|
|
|
|
fullAddress = fields.Char(string="Full address",size =300, compute="get_adress", translate=True)
|
|
isVip = fields.Boolean(string="Is VIP",default=False, translate=True)
|
|
dateOfFirstContact = fields.Date(string="Date of first contact", default=fields.Date.today, translate=True)
|
|
type_id= fields.Many2one('contact.type', string="Contact type", required=True, translate=True)
|
|
|
|
#Calcul champs Addresse complete
|
|
|
|
@api.one
|
|
@api.depends('street','street2','city','zip')
|
|
def get_adress(self):
|
|
fullAddress =" "
|
|
if self.street :
|
|
fullAddress += self.street +' '
|
|
if self.street2:
|
|
fullAddress += self.street2+' '
|
|
if self.city:
|
|
fullAddress += self.city +' '
|
|
if self.zip:
|
|
fullAddress += self.zip
|
|
self.fullAddress = fullAddress
|
|
|
|
#Validation de la date pour empecher qu'elle soit apres la date courante
|
|
|
|
@api.constrains('dateOfFirstContact')
|
|
def constFirstContact(self):
|
|
current_date = datetime.now().date()
|
|
dateOfFirstContact = fields.Datetime.from_string(self.dateOfFirstContact).date()
|
|
if dateOfFirstContact > current_date:
|
|
raise Warning('Invalid Date!')
|