last day (29 days later) » 

4:49 AM
Hello!
I explain what I'm trying to solve in my code.
 
5:08 AM
My code is for a gym I have five main classes: Client, Reservation, Evaluation, Class and Progress.
The client can reserve a date, start time and end to go to an evaluation.
In evaluation, the client has two options.
1. First evaluation: To know your physical data such as weight, height, BMI, height, perimeters of the body.
2. Evaluating progress: To see how much the client has managed to move forward in the gym, we ask for weight, height, BMI, height and body perimeters.
The client will only have a first evaluation, the others will be all progress every month, for example, "first evaluatio
class Cliente (models.Model):
_name = 'gimnasio.cliente'
_rec_name = 'nombre'

nombre = fields.Char(string="Nombre", required='true')
edad= fields.Integer(string="Edad", required=True)
sexo=fields.Selection([('Femenino','Femenino'),('Masculino','Masculino')],string='Sexo')
correo=fields.Char(string="Correo electrónico")
telefono = fields.Integer(string="Telefono +56", size=9, required=True)
direccion = fields.Char(string="Dirección", required=True)
fecha_nacimiento=fields.Date(string="Fecha de nacimiento")
reserve view:
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<!-- explicit list view definition -->

<record model="ir.ui.view" id="gimnasio.reserva_list">
<field name="name">lista de reservas</field>
<field name="model">gimnasio.reserva</field>
<field name="arch" type="xml">
<tree>
<field name="id"/>
<field name='tipo_reserva'/>
<field name="fecha"/>
<field name="hora_inicio" widget="float_time"/>
<field name="hora_termino" widget="float_time"/>
<field name="cliente_id"/>
<field name="clase_id"/>
<field name="evaluacion_id"/>
my problem is that the method that does not work for me in the reserve class.
@api.constrains("hora_inicio","fecha")
def _check(self):
records = self.env["gimnasio.reserva"].search([('hora_inicio','=', self.hora_inicio), ('fecha','!=', self.fecha), ('tipo_reserva', '!=', 'evaluacion_id') ,('id', '!=', self.id)])
if len(records) > 0:
raise ValidationError('La evaluacion no esta disponible para esta hora')
 
6:19 AM
when do you want to execute _check method?
After filling hora_inicio & fecha fields in the reserve class?
before saving in the reserve class, right?
 
That's right, before saving in the reservation class I want a message to come out saying that the time is busy
For example: I want to book at 2:00 pm but that time someone else had taken it before then I want a message to appear saying that the time can not be taken
 
ok let me rebuild it
hora_inicio = fields.Float(string="hora inicio", compute="_hora_inicio")
hora_termino = fields.Float(string="hora termino", compute="_hora_termino")
you miss two compute method attach in your fieldhora_inicio & hora_termino
where are they
and what do they do
I can't saw _hora_inicio & _hora_termino in your class.
 
6:39 AM
in Reserva I only have the attributes start time and end time but not what you say
 
so hora_inicio is the start_time fo reservation and hora_termino is the end_time of reservation?
 
that's how you say
 
and why you add compute='' inside of this two field?
 
I was trying another method and forget to erase it, sorry
 
got it
The issue seems because you put wrong value on ('tipo_reserva', '!=', 'evaluacion_id')
'evaluacion_id' is not correct value in tipo_reserva field
tipo_reserva=fields.Selection([('0','Clase'),('1','Evaluacion')])
it's your definition of tipo_reserva
so the value must be 0 or 1
if you put a value did not belong that field
record always get none
this is why it did not work
what does tipo_reserva means
you use != as operator that confuse me
 
6:57 AM
reservation type is that there are two types of reservation, either for a class or evaluation
Different people can reserve a class hours at a defined time, but at the time of booking an evaluation they can not reserve the same time.
 
then you should use '=' as operator
 
ef _check(self):
records = self.env["gimnasio.reserva"].search([('hora_inicio','=', self.hora_inicio), ('fecha','=', self.fecha), ('tipo_reserva', '=', '1') ,('id', '=', self.id)])
?
 
because if len(record)> 0: execute warning means if there are a people choose for exmaple: 2019-07-03 01:00 pm evaluation reservation, then db has this record.
In order to prevent others order the same hour, you should tell odoo find this record.
yes, if my understanding is correct.
if you use != db can't find record type belongs to evaluation
they will exclude evaluation type
Selection([(value1,option_name1),(value2,option_name2)])
 
Now I get the message I wanted, thank you very much.
 
great
then see you
byebye
 
7:10 AM
sr
Do you know how to calculate the months between two dates?
 
yean
yes
 
start_date=fields.Date(string="Startdate", requiered=True)

end_date=fields.Date(string="End_date", requiered=True)

duration=fields.Char(string="Duration", computer="_duration")

@api.multi

@api.depends('start_date','end_date')

def _duration(self):

if self.start_date and self.end_date:

start_dt = fields.Datetime.from_string(self.start_date)

finish_dt = fields.Datetime.from_string(self.end_date)

difference = relativedelta(finish_dt, start_dt)

month = difference.month
I have this code but it does not work
 
there is a same issue in form
from datetime import datetime as dt
date_debut = fields.Date(string="Date debut")
date_fin = fields.Date(string="Date fin")
duree = fields.Char(string="Durée", compute="_duration", store=True)

@api.depends('date_debut','date_fin')
def _duration(self):
if self.date_debut and self.date_fin:
for rec in self:
init_date = dt.strptime(rec.date_debut, '%Y-%m-%d')
end_date = dt.strptime(rec.date_fin, '%Y-%m-%d')
rec.duree= str((end_date - init_date).days)
this is calcu days
let me find instance of month
ok, datetime does not support month calculate
forget this
 
this method is not for the reservation, this is for another class
 
have you try method here ?
2
A: calculate the months between two dates

Mihran ThalhathTry this code from datetime import datetime from dateutil import relativedelta date1 = datetime.strptime(str('2019-03-01'), '%Y-%m-%d') date2 = datetime.strptime(str('2019-07-01'), '%Y-%m-%d') r = relativedelta.relativedelta(date2, date1) print(r.months)

It's the same issue
 
7:19 AM
A friend tried it but could not, it was wrong
start_date = fields.Date (string = "Startdate", requiered = True)

end_date = fields.Date (string = "End_date", requiered = True)

duration = fields.Char (string = "Duration", computer = "_ duration")

@ api.multi

@ api.depends ('start_date', 'end_date')

def _duration (self):
date1 = datetime.strptime(str('2019-03-01'), '%Y-%m-%d')
date2 = datetime.strptime(str('2019-07-01'), '%Y-%m-%d')
r = relativedelta.relativedelta(date2, date1)
print(r.months)
Would that go like that?
 
you can try it.
I never use this method before.
same way as you post
 
@TerrencePoe with the method here I see error
 
what error you got
It's work for me
 
Modelo no encontrado: gimnasio.profesor

Contexto del error:
Vista `lista de profesores`
[view_id: 1620, xml_id: gimnasio.profesor_list, model: gimnasio.profesor, parent_id: n/a]
None" while parsing /mnt/c/odoo/customs/gimnasio/views/profesor.xml:6, near
<record model="ir.ui.view" id="gimnasio.profesor_list"> <!-- lo que se agrega a la pantalla Registro de Mascota -->
<field name="name">lista de profesores</field>
<field name="model">gimnasio.profesor</field>
<field name="arch" type="xml">
<tree>
using thist code @api.depends('fecha_inicio','fecha_termino')
def _duracion(self):
date1 = datetime.strptime (str ('2019-03-01'), '% Y-% m-% d')
date2 = datetime.strptime (str ('2019-07-01'), '% Y-% m-% d ')
r = relativedelta.relativedelta (date2, date1)
print (r.months)
I delete that code and it stops having an error
 
I'm not familiar with Spanish what it says
 
7:30 AM
Model not found: gym.professor

Error context:
View `list of teachers
[view_id: 1620, xml_id: gym.professor_list, model: gym.professor, parent_id: n / a]
None "while parsing /mnt/c/odoo/customs/gimnasio/views/profesor.xml:6, near
<record model = "ir.ui.view" id = "gym.professor_list"> <! - what is added to the Pet Registration screen ->
<field name = "name"> teacher list </ field>
<field name = "model"> gym.professor </ field>
<field name = "arch" type = "xml">
<tree>
<field name = "id" />
<field name = "name" />
using this code to calculate the month that error appears
using thist code @ api.depends ('start_date', 'start_date')
def _duracion (self):
date1 = datetime.strptime (str ('2019-03-01'), '% Y-% m-% d')
date2 = datetime.strptime (str ('2019-07-01'), '% Y-% m-% d')
r = relativedelta.relativedelta (date2, date1)
print (r.months)
 
'fecha_inicio' & 'fecha_termino' didn't define in class gym.professor , right?
@ api.depends ('start_date', 'start_date') refer to fields do not exist in class. I think
 
no, because it has no relation. The class that I want to calculate the duration in months is "Plan" not "professor"
example: I want to know how many months the gym hire. So the idea is that the system calculates only the months that uni starts and ends the gym.
 
extra pic of error
and post link
Model not found: gym.professor
<field name = "model"> gym.professor </ field>
maybe problem from here
None "while parsing /mnt/c/odoo/customs/gimnasio/views/profesor.xml:6, near
It says got error form Line 6 in profesor.xml
Is line 6 refer to <field name = "model"> gym.professor </ field>?
 
<record model = "ir.ui.view" id = "gym.professor_list"> <! - what is added to the Pet Registration screen ->
<field name = "name"> teacher list </ field>
<field name = "model"> gym.professor </ field>
<field name = "arch" type = "xml">
<tree>
<field name = "id" />
<field name = "name" />
<field name = "rut" />
<field name = "telefono" />
<field name = "address" />
<field name = "mail" />
</ tree>
</ field>
</ record>

<record model = "ir.ui.view" id = "gym.professor_form">
<field name = "name"> gym </ field>
first line = line 6
but I do not think it's teacher class error because where I put the method is in the "plan" class
 
if you remove this method still got this error
I think you delete or shift something
if you remove this method do you still got this error
 
7:45 AM
if I erase the method it runs odoo without problem
sr
I am testing the reservation and in all the dates that I put it tells me that I do not have available time :(
 
it confused me
 
Going back to the previous subject of the reservation of evaluation or classes
now he does not let me book any evaluation because on all the dates he says he tells me that I do not have time available
 
post ur code again
 
@ api.constrains ("start_time", "date")
def _check (self):
records = self.env ["gym.reserve"]. search ([('start_time', '=', self.home_home), ('date', '=', self.date), ('reserve_type', ' = ',' 1 '), (' id ',' = ', self.id)])
if len (records)> 0:
raise ValidationError ('The evaluation is not available for this time')
date = fields.Date (string = "Reservation date")
start_hour = fields.Float (string = "start time")
terminal_time = fields.Float (string = "end time")
 
I need to now the data in your db
can you take a pic of your db in the reservation class and upload it
 
8:00 AM
Class Reserva (models.Model):
_name = 'gym.reserve'
_rec_name = "reserve_type"

reserve_type = fields.Selection ([('0', 'Class'), ('1', 'Evaluation')])
date = fields.Date (string = "Reservation date")
start_hour = fields.Float (string = "start time")
terminal_time = fields.Float (string = "end time")

alumno_id = fields.Many2one (comodel_name = 'gimnasio.alumno', string = 'Student', required = False)

class_id = fields.Many2one (comodel_name = 'gym.clase', string = 'Class', required = False)

evaluation_id = fields.Many2one (comodel_name = 'gym.evaluation', string = 'Evaluation')
 
it's a local server?
or Can I link to it?
 
that's right, it's local
 
delete theses two record and then
1. evaluation, 2019-07-06, 01:00 to 02:00
2. evaluation, 2019-07-05, 01:00 to 02:00
add these two record
an what u got
 
I can not add anything, he tells me that there is time available
and erase the data I had in the system
 
what is self. home_home
 
8:14 AM
self.Start_Time
the translator was wrong
 
can you use debug mode in your editor and set breakpoint in records = self.env ["gym.reserve"]. search ([('start_time', '=', self.home_home), ('date', '=', self.date), ('reserve_type', ' = ',' 1 '), (' id ',' = ', self.id)])
then check the value of these fields
I need to have a break
check after break
 
8:50 AM
I get a message that says python does not recognize coo an internal or external command
Can not think of another way to solve the code?
 
the fastest way is let me connect to your pc and check it out. because I don't know which part get wrong
If you don't mind you can download anydesk or teamview to let me help
 
no tengo problema
perfecto
Which one would you recommend?
 
9:06 AM
anydesk
 
916 937 793
code anydesk
 
9:17 AM
what's db you use
 
do you have pgAdmin?
your tool is different with me
 
use ubuntu por windows, there it contains everything
 
save and restart server
restart agagin
the problem is
self.id
operator
you modified to =
it must be !=
do know why
the first vesion I told you is
search([('start_time','=', self.start_time), ('fecha','!=', self.fecha), ('tipo_reserva', '!=', 'evaluacion'),('id', '!=', self.id)])
I had told you the reason then
 
9:41 AM
then we change or keep the =?
 
you create a reservation order system will give you a new id
when click save system start to check
 
i think it works now
 
let me connect to explain
now the lastest id is 31
and next will be 32
 
yes because each reservation is a new id
 
now db have a record is 2019-07-07 evaluation 0100 - 0200
it's work
if you don't set ('id', '!=' , self.id)
 
9:50 AM
in conclusion you can maje the code
 
for some reason, it check two times, before saving into db and after saving into db.
so records = self.env["gimnasio.reserva"].search([('start_time','=', self.start_time),('id', '=', self.id)]) get one record
so it trigger constrain. if you do not exclude self.id
other questions?
 
for today no, thank you very much for you help
 
super grateful
 
where you come from
 
9:55 AM
Chile
jajaja and you?
 
Taiwan
 
see you
 
yes my bro
thank you
 
your welcome
 
 
7 hours later…
4:48 PM
Hello friend, I have a new question for you.
I want to add a conditional based on the selection of type_plan, I have this currently:
@ api.multi
@ api.depends ('type_plan', 'duration')
def _duracion (self):
if self.tipo_plan == 'Quarterly Student':
return "3"
else self.type_plan == 'Semestral Basic':
return "6"
else self.type_plan == 'Annual Full':
return "12"
duration = fields.Integer (string = "Duration (month)", computer = "_ duration")
tipo_plan = fields.Selection ([('Quarterly Student', 'Quarterly Student'), ('Basic Semester', 'Basic Semester'), ('Annual Full', 'Annual Full')])
 
5:30 PM
use onchange method
I'll reply you tomorrow
 

  last day (29 days later) »