Beispiel #1
0
    def _create_model_class(self, model):
        """Generate the model proxy class.

        :return: a :class:`odoorpc.models.Model` class
        """
        cls_name = model.replace('.', '_')
        # Hack for Python 2 (no need to do this for Python 3)
        if sys.version_info[0] < 3:
            if isinstance(cls_name, unicode):
                cls_name = cls_name.encode('utf-8')
        # Retrieve server fields info and generate corresponding local fields
        attrs = {
            '_env': self,
            '_odoo': self._odoo,
            '_name': model,
            '_columns': {},
        }
        fields_get = self._odoo.execute(model, 'fields_get')
        for field_name, field_data in fields_get.items():
            if field_name not in FIELDS_RESERVED:
                Field = fields.generate_field(field_name, field_data)
                attrs['_columns'][field_name] = Field
                attrs[field_name] = Field
        # Case where no field 'name' exists, we generate one (which will be
        # in readonly mode) in purpose to be filled with the 'name_get' method
        if 'name' not in attrs['_columns']:
            field_data = {'type': 'text', 'string': 'Name', 'readonly': True}
            Field = fields.generate_field('name', field_data)
            attrs['_columns']['name'] = Field
            attrs['name'] = Field
        return type(cls_name, (Model, ), attrs)
    def _create_model_class(self, model):
        """Generate the model proxy class.

        :return: a :class:`odoorpc.models.Model` class
        """
        cls_name = model.replace('.', '_')
        # Hack for Python 2 (no need to do this for Python 3)
        if sys.version_info[0] < 3:
            if isinstance(cls_name, unicode):
                cls_name = cls_name.encode('utf-8')
        # Retrieve server fields info and generate corresponding local fields
        attrs = {
            '_env': self,
            '_odoo': self._odoo,
            '_name': model,
            '_columns': {},
        }
        fields_get = self._odoo.execute(model, 'fields_get')
        for field_name, field_data in fields_get.items():
            if field_name not in FIELDS_RESERVED:
                Field = fields.generate_field(field_name, field_data)
                attrs['_columns'][field_name] = Field
                attrs[field_name] = Field
        # Case where no field 'name' exists, we generate one (which will be
        # in readonly mode) in purpose to be filled with the 'name_get' method
        if 'name' not in attrs['_columns']:
            field_data = {'type': 'text', 'string': 'Name', 'readonly': True}
            Field = fields.generate_field('name', field_data)
            attrs['_columns']['name'] = Field
            attrs['name'] = Field
        return type(cls_name, (Model,), attrs)
Beispiel #3
0
def desc_model(model):
    table_header = ['name', 'type', 'string']
    table_data = []

    attrs = {
        '_name': model,
        '_columns': {},
    }
    fields_get = odoo.execute(model, 'fields_get')
    for field_name, field_data in fields_get.items():
        if field_name not in FIELDS_RESERVED:
            Field = fields.generate_field(field_name, field_data)
            attrs['_columns'][field_name] = Field
            attrs[field_name] = Field
            # print(field_name, "%", field_data['type'])
            # print(field_data.keys())
            # ['searchable', 'sortable', 'depends', 'store',
            # 'manual', 'type', 'company_dependent',
            # 'change_default', 'readonly', 'string', 'required']
            table_data.append((abbrev(field_name, 20), field_data['type'],
                               abbrev(field_data['string'], 25)))
            # addi: type(Field)

    # print(tabulate(table_data, headers=table_header, tablefmt='grid'))
    # print(tabulate(table_data, headers=table_header, tablefmt='fancy_grid'))
    print(tabulate(table_data, headers=table_header, tablefmt='psql'))
Beispiel #4
0
    def _create_model_class(self, model):
        """Generate the model proxy class.

        :return: a :class:`odoorpc.models.Model` class
        """
        cls_name = model.replace('.', '_')
        # Hack for Python 2 (no need to do this for Python 3)
        if sys.version_info[0] < 3:
            # noqa: F821
            if isinstance(cls_name, unicode):  # noqa: F821
                cls_name = cls_name.encode('utf-8')
        # Retrieve server fields info and generate corresponding local fields
        attrs = {
            '_env': self,
            '_odoo': self._odoo,
            '_name': model,
            '_columns': {},
        }
        fields_get = self._odoo.execute(model, 'fields_get')
        for field_name, field_data in fields_get.items():
            if field_name not in FIELDS_RESERVED:
                Field = fields.generate_field(field_name, field_data)
                attrs['_columns'][field_name] = Field
                attrs[field_name] = Field
        return type(cls_name, (Model, ), attrs)
Beispiel #5
0
    return [
        'byday', 'recurrency', 'final_date', 'rrule_type', 'month_by',
        'interval', 'count', 'end_type', 'mo', 'tu', 'we', 'th', 'fr', 'sa',
        'su', 'day', 'week_list'
    ]


login()
fields_get = odoo.execute(model, 'fields_get')
for field_name, field_data in fields_get.items():
    field_type = field_data['type']
    if field_name not in FIELDS_RESERVED and \
            field_name not in get_recurrent_fields() and \
            not field_name.startswith("_") and \
            field_type not in ("many2many", "many2one", "one2many"):
        Field = fields.generate_field(field_name, field_data)
        FieldType = generate_field(field_name, field_data)
        attrs['_columns'][field_name] = Field
        attrs[field_name] = FieldType
        print(field_name, type(FieldType))

cls_name = normalize_class(model)
print(".. create class", cls_name)
model_cls = type(cls_name, (graphene.ObjectType, ), attrs)

import graphene


def create_with_attrs(model_cls, record):
    inst = model_cls()
    for fld in model_cls._columns.keys():