Configuration Model without Multivalue or ModelSingleton

(Oscar Alvarez) #1


I think that the current way for set sequences on configuration models need Multivalue, CompanyMultiValueMixin, CompanyValueMixin, default_func but this can be redesign to an easy way, removing indeed ModelSingleton


I propose not use ModelSingleton and Multivalue fields in configuration Models, instead set company by each configuration record, in other words it is simply replaced by ModelView and ModelSQL, using for example following structure:

class MyModelConfiguration(ModelSQL, ModelView):
    company = fields.Many2One(.....) # required=True
    sequence_foo = fields.Many2One('ir.sequence',....)
    parameter1 = fields.Char(....)

def default_company():
    return Transaction().context.get('company')

def get_configuration(cls):
    company_id = Transaction().context.get('company')
    if company_id:
        config, =[
            ('company', '=', company_id)
        return config

So the end we will see:

My Configuration (View tree)

companyA | sequenceA1 | field_fooA | sequenceA2 | field_barA
companyB | sequenceB1 | field_fooB | sequenceB2 | field_barB
companyC | sequenceC1 | field_fooC | sequenceC2 | field_barC
. . .

Here real example:

For me is a simple solution, easy understand, easy coding, easy debugging, easy to migrate, works with multiple companies, and the moment does not require API changes


(Cédric Krier) #2

I see many drawback for such design:

  • Prevent to extend to add other criteria than company which is solved by MultiValue
  • Do not work if no record is created. ModelSingleton allows to have default value even if no record was added.
  • Does not guarantee the uniqueness of the configuration.
  • Depend on the context only. MultiValue is more elaborated to be able to work without context:
  • Do not use the cache. A search is done on each access to the configuration.

(Oscar Alvarez) #3

Ok, I think those drawbacks can be solved, I am not expert, but I try search a solution for each one:

  • The start idea is not remove Multivalue feature of core Tryton, just in several configuration models
  • We can add some class style “ModelSingleton” or any variable in setup or register that automatic create a record configuration when is missing one, or the company is created.
  • We can add company “Unique” sql constraint to configuration model, with this avoid duplicate company configuration.
  • I dont know in which case context is not setted, but the piece code can be modified for above example:

def get_configuration(cls, company=None):
if not company:
company = Transaction().context.get(‘company’)
config, =[
(‘company’, ‘=’, company)
return config

  • Ok but we can add a new cache attribute to this models, for example:

class MyModelConfiguration(ModelSQL, ModelView):
__cache = True
company = fields.Many2One(…) # required=True
sequence_foo = fields.Many2One(‘ir.sequence’,…)

I can work around this features, maybe If you agree I can to open a new issue, maybe this help with:

(Cédric Krier) #4

I can not follow where you want to go.

But all most all of them need MultiValue.

What is the point? ModelSingleton manage that already.

But company is not the only contextual switch.

But we can want to have other switches than company.

For what purpose?