i can't update a new module

146 views
Skip to first unread message

Mauricio Martinez Garcia

unread,
Apr 22, 2017, 6:55:07 AM4/22/17
to tryton
I create a new module for one deployment that i need,  but when i plublish my module i receive the next error: 

gnuhealth@trytonserv01:~/gnuhealth/tryton/server/trytond-3.8.10/bin $ ./trytond -d gnuhealth -u medica
Traceback (most recent call last):
  File "./trytond", line 80, in <module>
    server.TrytonServer(options).run()
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.8.10/trytond/server.py", line 113, in run
    Pool(db_name).init(update=self.options.update, lang=lang)
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.8.10/trytond/pool.py", line 155, in init
    lang=lang)
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.8.10/trytond/modules/__init__.py", line 427, in load_modules
    _load_modules()
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.8.10/trytond/modules/__init__.py", line 394, in _load_modules
    load_module_graph(graph, pool, update, lang)
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.8.10/trytond/modules/__init__.py", line 234, in load_module_graph
    cls.__register__(module)
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.8.10/trytond/model/modelsql.py", line 138, in __register__
    table = TableHandler(Transaction().cursor, cls, module_name)
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.8.10/trytond/backend/postgresql/table.py", line 71, in __init__
    % (self.table_name, default))
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.8.10/trytond/backend/postgresql/database.py", line 296, in execute
    return self.cursor.execute(sql)
psycopg2.ProgrammingError: no existe la relación «medica_accounting_entpservices_id_seq»



This is the code, i don't see why receive this error, the model at database level is correct, i create this model on mysql for testing. But when i put this on tryton, doesn't work. 




# -*- coding: utf-8 -*-

##############################################################################

#

# Module developed by Mauricio Martinez for Torre Medica Santa Anita

##

##############################################################################

import datetime

from trytond.model import ModelView, ModelSQL, fields, ModelSingleton, Unique

from trytond.pyson import Eval, Equal

from trytond.pool import Pool

from trytond.modules.product import price_digits



__all__ = ['AccountingServices','AccountingServicesLine','AccountingEntpServices','AccountingEntpServicesLine']



class AccountingServices(ModelSQL, ModelView):

'Servicios de Cuenta Individual'

__name__ = 'medica.accounting_services'


name = fields.Char('ID',readonly=True)

account_code = fields.Char('Codigo')

clientAccount = fields.Many2One('gnuhealth.patient', 'Paciente')

accounting_date = fields.Date('Fecha')

state = fields.Selection([('1', 'Borrador'),

('2', 'Abierto'),

('3', 'Cancelado'),

('4', 'Cerrado'),], 'Estado')

account_type = fields.Selection([('1', 'Consulta Unica'),

('2', 'Tratamiento'),], 'Tipo')

accounting_services_line = fields.One2Many('medica.accounting_services.line',

'accounting_services_line', 'Servicios', help="Accounting Services Line")



@staticmethod

def default_accounting_date():

return datetime.date.today()




class AccountingServicesLine(ModelSQL, ModelView):

'Linea de Servicios de Cuenta Individual'

__name__ = 'medica.accounting_services.line'


#line_service = fields.Many2One('medica.accounting_services','Line Service',readonly=True)

code = fields.Char('ID',readonly=True)

concepto = fields.Char('Concepto')

producto = fields.Many2One('product.product','Producto')

descripcion = fields.Many2One('product.template','Descripcion')

cantidad = fields.Float('Cantidad',

digits=(16, Eval('unit_digits', 2)),

states={

'invisible': Eval('type') != 'line',

'required': Eval('type') == 'line',

},

depends=['type', 'unit_digits'])


unit_digits = fields.Function(fields.Integer('Unit Digits'),

'on_change_with_unit_digits')

costo_unitario = fields.Numeric('Costo Unitario', digits=price_digits,

states={

'invisible': Eval('type') != 'line',

'required': Eval('type') == 'line',

},

depends=['type'])

total_costo = fields.Numeric('Costo Total')

iva_aplicar = fields.Numeric('IVA')

event_type = fields.Selection([('1', 'Consumo'),

('2', 'Abono'),], 'Tipo Evento')



class AccountingEntpServices(ModelSQL, ModelView):

'Servicios de Cuenta Empresarial'

__name__ = 'medica.accounting_Entpservices'


name = fields.Char('ID',readonly=True)

enterprise_code = fields.Char('Cuenta Empresarial')

accountingEntp_date = fields.Date('Fecha')

clientAccount = fields.Many2One('company.company', 'Empresa')

state = fields.Selection([('1', 'Draft'),

('2', 'Abierto'),

('3', 'Cancelado'),

('4', 'Cerrado'),], 'Estado')

accounting_Eservices_line = fields.One2Many('medica.accounting_Entpservices.line',

'accounting_Entpservices_line', 'Servicios', help="Accounting EntpServices Line")


@staticmethod

def default_accountingEntp_date():

return datetime.date.today()



class AccountingEntpServicesLine(ModelSQL, ModelView):

'Linea de Cuenta Empresarial'

__name__ = 'medica.accounting_Entpservices.line'


employee_code = fields.Char('Clave Empleado')

#line_service = fields.Many2One('medica.accounting_services','Empleados',readonly=True)

line_service = fields.One2Many('medica.accounting_services',

'accounting_services', 'Empleados', help="Accounting Services Line")

employee_date = fields.Date('Fecha')

account_type = fields.Selection([('1', 'VIP'),

('2', 'Gerente'),

('3', 'Coordinador'),

('4', 'Empleado'),], 'Tipo Empleado')

adeudo_actual = fields.Numeric('Adeudo Actual')




please, help me to identify my error, i don't sleep because i don't see the error, jeejjejeje. 
thanks team!


Karla Stenger

unread,
Apr 22, 2017, 3:24:03 PM4/22/17
to try...@googlegroups.com
2017-04-22 7:39 GMT-03:00 Mauricio Martinez Garcia <morf...@gmail.com>:
I create a new module for one deployment that i need,  but when i plublish my module i receive the next error: 

gnuhealth@trytonserv01:~/gnuhealth/tryton/server/trytond-3.8.10/bin $ ./trytond -d gnuhealth -u medica

​Hi Mauricio,
for emailing errors to this list it would be better to prepent "LANG=C"​ to any command line in the case you have your default language as spanish (or any other than english). This way the output errors will be in english too.

 
Traceback (most recent call last):
  File "./trytond", line 80, in <module>
    server.TrytonServer(options).run()
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.8.10/trytond/server.py", line 113, in run
    Pool(db_name).init(update=self.options.update, lang=lang)
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.8.10/trytond/pool.py", line 155, in init
    lang=lang)
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.8.10/trytond/modules/__init__.py", line 427, in load_modules
    _load_modules()
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.8.10/trytond/modules/__init__.py", line 394, in _load_modules
    load_module_graph(graph, pool, update, lang)
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.8.10/trytond/modules/__init__.py", line 234, in load_module_graph
    cls.__register__(module)
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.8.10/trytond/model/modelsql.py", line 138, in __register__
    table = TableHandler(Transaction().cursor, cls, module_name)
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.8.10/trytond/backend/postgresql/table.py", line 71, in __init__
    % (self.table_name, default))
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.8.10/trytond/backend/postgresql/database.py", line 296, in execute
    return self.cursor.execute(sql)
psycopg2.ProgrammingError: no existe la relación «medica_accounting_e
​​
ntpservices_id_seq»


​​

This is the code,

​As you may know in python coding, indentation matters, so the code you are showing us is not very useful.
 
 
i don't see why receive this error,
 
the model at database level is correct,

​What do you mean? How did you check this?​
 

i create this model on mysql for testing. But when i put this on tryton, doesn't work. 

As far as I know, you create modules in tryton. Then you tell tryton what platform to choose.​
It's not clear what you meant, despite the fact that it doesn't work.

​As a side note I don't know how the uppercase will work in this value.​
 


name = fields.Char('ID',readonly=True)

enterprise_code = fields.Char('Cuenta Empresarial')

accountingEntp_date = fields.Date('Fecha')

clientAccount = fields.Many2One('company.company', 'Empresa')

state = fields.Selection([('1', 'Draft'),

('2', 'Abierto'),

('3', 'Cancelado'),

('4', 'Cerrado'),], 'Estado')

​​
accounting_Eservices_line = fields.One2Many('
​​
medica.accounting_Entpservices.line',

'

​​
accounting_Entpservices_line', 'Servicios', help="Accounting EntpServices Line")

​The second parameter of a One2Many field definition must match with a field on the model at the one you are pointing, and that field will be used to point back here. So in this case it will look for a field called ​'accounting_Entpservices_line' in the Model '​medica.accounting_Entpservices.line'.
You could simplify the names of your fields, seriously, it will help you have a cleaner and easier to read code.
As an example you can look at how the moves field is defined in the sale (sale.py and stock.py of the sale module).


@staticmethod

def default_accountingEntp_date():

return datetime.date.today()



class AccountingEntpServicesLine(ModelSQL, ModelView):

'Linea de Cuenta Empresarial'

__name__ = 'medica.accounting_Entpservices.line'


employee_code = fields.Char('Clave Empleado')

#line_service = fields.Many2One('medica.accounting_services','Empleados',readonly=True)

line_service = fields.One2Many('medica.accounting_services',

'accounting_services', 'Empleados', help="Accounting Services Line")

employee_date = fields.Date('Fecha')

account_type = fields.Selection([('1', 'VIP'),

('2', 'Gerente'),

('3', 'Coordinador'),

('4', 'Empleado'),], 'Tipo Empleado')

adeudo_actual = fields.Numeric('Adeudo Actual')




please, help me to identify my error, i don't sleep because i don't see the error, jeejjejeje. 
thanks team!

 
​That's all I can tell about your code.

​However I'll dare to advice you on other things in order for you to get better help:

If you post an error message from a command line on an english mailing list, and the error is not english, please prepend "LANG=C" to the command line, this way the error will be shown in english as much as possible.​
Otherwise you can seek for help on one of the spanish mailing lists tryton-es for instance.

​Also, in python indentation matters, your email lacks any, probably a better way to share your code (if it's not published somewhere you can link us to) is to put it in a pastebin service.

​Cheers,
Karla.


--
-------------------------
Karla  Mª  Stenger  Sábat
karla....@gmail.com

Mauricio Martinez Garcia

unread,
Apr 23, 2017, 1:55:07 PM4/23/17
to tryton

Thanks for your observations Karla, I reviewed only the GNU Health documentation and on this, is not explained how to use the differents fields model. 

I thought that the second parameter were the label, because by revision, on the other Health modules, i see more less the same. 

I will review better the fields model on 

  let me solve this part and i will manage better my code 

for this: 

​What do you mean? How did you check this?​
 
  Is because I developed first the datamodel in (MySQL Workbench/Toad Datamodeler/Oracle SQL Datamodeler) for review in case of i need normalize this, only i add the 2 next fields that i saw that tryton(gnuhealth) add to  created model (id, create_uid). I thought that the models was relationated by these fields and not by the fields that i create. anyway. I will review with more details the information. 

 obviously, tryton work with its database (postgres). My model is only for reference and normalization in necessary case before the creation of the tryton model. 

The Tryton community require more clear information about the use of the models and the models field. WIth examples more specific. 


thanks for your support. 

Karla Stenger

unread,
Apr 24, 2017, 2:36:11 PM4/24/17
to try...@googlegroups.com
2017-04-23 13:50 GMT-03:00 Mauricio Martinez Garcia <morf...@gmail.com>:

Thanks for your observations Karla, I reviewed only the GNU Health documentation and on this, is not explained how to use the differents fields model. 

I thought that the second parameter were the label, because by revision, on the other Health modules, i see more less the same. 
 
​You seem to have mistaken the docs of a Many2One instead of the One2Many​
 


​I don't know which tryton version you are using, this docs are for version 2.6, you can get the right version of the docs by changing the number in the url.​
 


  let me solve this part and i will manage better my code 


​It will be easier to help you then :-)

​Cheers,
Karla.​
​BTW: I just noticed I left twice some of my observations in my previous email, didn't mean to​.​

Mauricio Martinez Garcia

unread,
Apr 26, 2017, 3:55:06 AM4/26/17
to tryton
Hello again Karla. 

  I change my code and reduce only to the first part. 

 This is my code: https://pastebin.com/3c0RkQ63

  I want to associate first the account service with the line services of some client. 
( in this case i don't have the asociation with product and enteprise tryton models on my diagram)






















The model "medica.accounting_services" have the patient information, and in my case, i will associate to one enterprise or one DUMMY enterprise for individual transactions. 

Then, i review the information in the version 3.0 of tryton of this URL: http://doc.tryton.org/3.0/trytond/doc/ref/models/fields.html#ref-models-fields

but,I don't understand wich part of the class is "read" the field of the other module. 












































if you see, we have the next values: "Many2One(model_namestring[left[right[ondelete[datetime_field[**options]]]]])"
On which part can i define the field that i will need?

I mean, of my definition, i need associate the next fields with the corresponding model field of the product.product model of tryton:
(to the first field by the moment the relation is not implemented because i want to understand this association)

services_concept = fields.Char('services_concept',size=50,"Concepto") #get the Description product
services_product
= fields.Many2One('product.product','code') #get the product code









this is the output at database level. 
( i want to show the code and description of this model product.product)




















from the line 50 to below of the code aren't updated right now. 


could you help me with your recommendation for do this one?
the other question is, on which model do we have the price of the products?, i was review all models of kind product_* , but i don't see this one. 



thanks a lot for your help. 











Karla Stenger

unread,
Apr 26, 2017, 10:47:39 AM4/26/17
to try...@googlegroups.com
2017-04-26 4:28 GMT-03:00 Mauricio Martinez Garcia <morf...@gmail.com>:
Hello again Karla.
 

  I change my code and reduce only to the first part. 

 This is my code: https://pastebin.com/3c0RkQ63

​Hi Mauricio, that's much more clear​
I will try to clarify on the confusion because you seem to be talking about something different than I was.
 

  I want to associate first the account service with the line services of some client. 
( in this case i don't have the asociation with product and enteprise tryton models on my diagram)

​So you will need to define a lines field (which you have so far called 'accounting_services_line' line 32 of your pastebin) in the ​AccountingService Model

This field should be a One2Many (and this is the one I was referring to all the time in my previous email). And so you will need to add in the AccountingServiceLine Model a field that points to the AccountingService Model (this is the second parameter to your One2Many field on the first Model).



The model "medica.accounting_services" have the patient information, and in my case, i will associate to one enterprise or one DUMMY enterprise for individual transactions. 

Then, i review the information in the version 3.0 of tryton of this URL: http://doc.tryton.org/3.0/trytond/doc/ref/models/fields.html#ref-models-fields

but,I don't understand wich part of the class is "read" the field of the other module.

 
if you see, we have the next values: "Many2One(model_namestring[left[right[ondelete[datetime_field[**options]]]]])"
On which part can i define the field that i will need?

I was talking about One2Many (please check my quoted text)
 

I mean, of my definition, i need associate the next fields with the corresponding model field of the product.product model of tryton:
(to the first field by the moment the relation is not implemented because i want to understand this association)

services_concept = fields.Char('services_concept',size=50,"Concepto") #get the Description product
services_product
= fields.Many2One('product.product','code') #get the product code


Now ​about the field 'services_product'​

On tryton you create a field relation to the model, and tryton will save it in the database by using just it's id.
So I guess you don't need to force saving the 'code'.
Now I realize that code may not be the same of id in GNU health, so maybe you just want a reference (Many2One) to the product and then a function field to show the code on the screen.

 
this is the output at database level. 
( i want to show the code and description of this model product.product)

​I'm sorry, this tells nothing to me, it seems to me you are thinking backwards about tryton​
 
​putting the database first, it's true you need to​ build a database, but why do you insist in building first the database instead of thinking what tryton provides you first ?
Are you trying to import some external data into tryton? In that case you will likely just need to create a process that converts your database into a valid tryton model.

from the line 50 to below of the code aren't updated right now. 


could you help me with your recommendation for do this one?
the other question is, on which model do we have the price of the products?, i was review all models of kind product_* , but i don't see this one. 

Please open a new thread for new unrelated questions.

​Cheers,
Karla

​P.S: Don't top post in this mailing list. See http://groups.tryton.org/netiquette

Mauricio Martinez Garcia

unread,
Apr 26, 2017, 1:30:08 PM4/26/17
to tryton


Sorry if my explanation is not clear. 


I will try explain more clear. 

First, i try to create a new model medica.accounting_services related with medica.accounting_services.line.

on the first model (acounting_services) i try to asociate one field with the model (gnuhealth.patient) for get the information about the patient (or in the model case the employee)

account_patient = fields.Many2One('gnuhealth.patient', 'Paciente')

equally, i will asociate the same model with my servicesLine model 

account_services_line = fields.One2Many('medica.accounting_services.line',
 
'account_services_line', 'Servicios', help="Servicios")



then, after that, i will relate the ServicesLine with these models: 


accountid = fields.Many2One('medica.accounting_services', 'accountid',readonly=True)

I need asociate these fields to the model product.product (is part of the tryton base i checked this information on this URL http://doc.tryton.org/3.0/modules)

services_concept = fields.Char('services_concept') #get the Description product

services_product
= fields.Many2One('product.product','code') #get the product code


i need asociate these fields to the mode.template model, that equally is part of the tryton modules. 

services_description = fields.Many2One('product.template','name')


At the end, i see these "models" as one data structure that i need document in a schema. In my particular case, i do it with one datamodel. (sorry i'm old school)
But, finally, the tryton's models  are database models. 


I see this of this form: 







































then, if I don't need create the foreing key for the relation, i want to know how to relate tryton the models internally to get the information of the other model. 

i created the enterprise module and individual module of my code ignoring my FK | PK fields, but doesn't work, i receive the errors: 






















in english is "the relation doesn't exist" medica_accounting_entpservices_id_seq, this show me that tryton is not creating automatically the relation. 
due than this, i try understanding how tryton make to relate the models. 


Karla Stenger

unread,
Apr 29, 2017, 11:49:00 AM4/29/17
to try...@googlegroups.com

Hi Mauricio,
There are a few nettiquette rules to participate in mailing lists like this one, please check it [1]​.
If you break those rules *over and over* you will likely not get the help you need.
Specially learn to quote text and read what others are quoting you about when they answer.

Also it's not well seen that you post so many images, many people won't see them cause their
mailer doesn't handle them like gmail (not everyone uses gmail). Even gmail shows them wider
than my screen which is very unpleasant.
Code, and errors can almost always be copy/pasted in text, and images cannot be quoted to
answer your problem step by step.

Please follow me in between the lines below.

2017-04-26 14:21 GMT-03:00 Mauricio Martinez Garcia <morf...@gmail.com>:


Sorry if my explanation is not clear. 


I will try explain more clear. 

First, i try to create a new model medica.accounting_services related with medica.accounting_services.line.

on the first model (acounting_services) i try to asociate one field with the model (gnuhealth.patient) for get the information about the patient (or in the model case the employee)

account_patient = fields.Many2One('gnuhealth.patient', 'Paciente')

equally, i will asociate the same model with my servicesLine model 

account_services_line = fields.One2Many('medica.accounting_services.line',
 
'account_services_line', 'Servicios', help="Servicios")


Looks like the second parameter should be 'accountid' (I would just call it 'account' to follow tryton coding style).
 
then, after that, i will relate the ServicesLine with these models: 
​​
accountid = fields.Many2One('medica.accounting_services', 'accountid',readonly=True)

Again, I would just call this field 'account'. (It is true that the database just saved the id,
but internally to tryton, you get the whole structure. You would access the id by
using 'account.id' and the patient by using account.account_patient.
Notice also the redundance of the 'account_patient' field name (like the others).
If the field is on the account model, you already know it's the account's patient,
so just patient would be enough, then refer to it from the service lines with
'self.account.patient'

Also, in this case the second parameter is just a string (the label of the field)


I need asociate these fields to the model product.product (is part of the tryton base i checked this information on this URL http://doc.tryton.org/3.0/modules)

services_concept = fields.Char('services_concept') #get the Description product
 
​In this case the parameter is a string (for a label)​
 
​I don't understand the comment​, because you are not getting it from anywhere, a Char field is for the user to type it in.

services_product = fields.Many2One('product.product','code') #get the product code

Second parameter is just a string for the label.

i need asociate these fields to the mode.template model, that equally is part of the tryton modules. 

services_description = fields.Many2One('product.template','name')

​Again the second parameter is just a string for the label.
I don't understand why you assume this is a name, this is a relationship with the 'product.template' model.

Also I don't see why you need both relationships, product.product and product.template.
Usually you just need to relate to product.product​ and this will give you access
to all the fields in product.product.

If you really need it you can define a field.Function which calls a function that returns the name of the
services_product (so services_product.name).
But usually this is not needed unless the calculation is more complicate.
When you show the service_product on the screen, it will show up by it's name anyway.
And from a ServiceLine instance you can alwas access self.service_product.name


At the end, i see these "models" as one data structure that i need document in a schema. In my particular case, i do it with one datamodel. (sorry i'm old school)
But, finally, the tryton's models  are database models. 

​Yes, but if you think about it
e​xactly like a database you will build up your relationships wrong.
In tryton you relate once to the model and then you get access all it's fields through this relationship.
No need to relate to each and every field of the model, this would be wrong​
​.​


​If you are having a hard time understanding tryton internals versus your database knowledge
I would advice you to follow some simple tutorial [2] and check the database's structure
every time you make a change on the code.


I see this of this form: 

then, if I don't need create the foreing key for the relation, i want to know how to relate tryton the models internally to get the information of the other model. 

i created the enterprise module and individual module of my code ignoring my FK | PK fields, but doesn't work, i receive the errors: 


in english is "the relation doesn't exist" medica_accounting_entpservices_id_seq, this show me that tryton is not creating automatically the relation. 
due than this, i try understanding how tryton make to relate the models.

I wonder:
Did you update the database?
Did you define your views (in xml) correctly?
It looks weird because the error stays the same though it looks like you changed your model's names.


​I hope I help you clarify some​.
Cheers,
Karla.
​PS: I don't feel comfortable telling you all the rules, but I try to explain as kindly as possible.
PS2: using LANG=C to get the error in english is just a matter of kindness
(plus it helps other people searching your same error)
Reply all
Reply to author
Forward
0 new messages