# -*- 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')
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 runPool(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 initlang=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_modulesload_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_graphcls.__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 executereturn 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.
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!
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
Many2One(model_name, string[, left[, right[, ondelete[, datetime_field[, **options]]]]])¶"services_concept = fields.Char('services_concept',size=50,"Concepto") #get the Description product
services_product = fields.Many2One('product.product','code') #get the product code
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-fieldsbut,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_name, string[, 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.
account_patient = fields.Many2One('gnuhealth.patient', 'Paciente')
account_services_line = fields.One2Many('medica.accounting_services.line',
'account_services_line', 'Servicios', help="Servicios")accountid = fields.Many2One('medica.accounting_services', 'accountid',readonly=True)services_concept = fields.Char('services_concept') #get the Description product
services_product = fields.Many2One('product.product','code') #get the product codeservices_description = fields.Many2One('product.template','name')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 modelaccount_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.