Example #1
0
 def _migrate_property(cls, field_names, value_names, fields):
     field_names.append('sequence')
     value_names.append('sequence')
     fields.append('company')
     migrate_property(
         'account.journal', field_names, cls, value_names,
         parent='journal', fields=fields)
Example #2
0
 def _migrate_property(cls, field_names, value_names, fields):
     field_names.append('payment_group_sequence')
     value_names.append('payment_group_sequence')
     fields.append('company')
     migrate_property(
         'account.configuration', field_names, cls, value_names,
         fields=fields)
Example #3
0
 def _migrate_property(cls, field_names, value_names, fields):
     field_names.append('production_sequence')
     value_names.append('production_sequence')
     fields.append('company')
     migrate_property(
         'production.configuration', field_names, cls, value_names,
         fields=fields)
Example #4
0
 def _migrate_property(cls, field_names, value_names, fields):
     field_names.append('tax_rounding')
     value_names.append('tax_rounding')
     fields.append('company')
     migrate_property(
         'account.configuration', field_names, cls, value_names,
         parent='configuration', fields=fields)
Example #5
0
 def _migrate_property(cls, field_names, value_names, fields):
     field_names.append('sequence')
     value_names.append('sequence')
     fields.append('company')
     migrate_property(
         'account.journal', field_names, cls, value_names,
         parent='journal', fields=fields)
 def _migrate_property(cls, field_names, value_names, fields):
     field_names += ['journal']
     value_names += ['journal']
     fields.append('company')
     migrate_property(
         'contract.configuration', field_names, cls, value_names,
         fields=fields)
Example #7
0
 def _migrate_property(cls, field_names, value_names, fields):
     field_names.append('credit_limit_amount')
     value_names.append('credit_limit_amount')
     fields.append('company')
     migrate_property(
         'party.party', field_names, cls, value_names,
         parent='party', fields=fields)
Example #8
0
 def _migrate_property(cls, field_names, value_names, fields):
     field_names.extend(account_names)
     value_names.extend(account_names)
     fields.append('company')
     migrate_property(
         'party.party', field_names, cls, value_names,
         parent='party', fields=fields)
Example #9
0
 def _migrate_property(cls, field_names, value_names, fields):
     field_names.extend(['account_expense', 'account_revenue'])
     value_names.extend(['account_expense', 'account_revenue'])
     fields.append('company')
     migrate_property(
         'product.category', field_names, cls, value_names,
         parent='category', fields=fields)
Example #10
0
 def _migrate_property(cls, field_names, value_names, fields):
     field_names.append('pos')
     value_names.append('pos')
     fields.append('company')
     migrate_property(
         'sale.configuration', field_names, cls, value_names,
         fields=fields)
Example #11
0
 def _migrate_property(cls, field_names, value_names, fields):
     field_names.append('cost_price')
     value_names.append('cost_price')
     fields.append('company')
     migrate_property(
         'product.template', field_names, cls, value_names,
         parent='template', fields=fields)
Example #12
0
 def _migrate_property(cls, field_names, value_names, fields):
     field_names.extend(account_names)
     value_names.extend(account_names)
     fields.append('company')
     migrate_property(
         'party.party', field_names, cls, value_names,
         parent='party', fields=fields)
Example #13
0
    def write(cls, *args):
        table = cls.get_table()
        formula_fields = [x.name for x in table.fields if x.formula]

        table = cls.get_sql_table()
        cursor = Transaction().connection.cursor()

        has_formulas = False
        all_records = []
        actions = iter(args)
        for records, values in zip(actions, actions):
            all_records += records
            fields = []
            to_update = []
            for key, value in values.items():
                fields.append(sql.Column(table, key))
                to_update.append(value)
                if key in formula_fields:
                    has_formulas = True
            query = table.update(fields,
                                 to_update,
                                 where=table.id.in_([x.id for x in records]))
            cursor.execute(*query)

        if not has_formulas and formula_fields:
            cls.update_formulas(all_records)
Example #14
0
    def create(cls, vlist):
        table = cls.get_table()
        if table.singleton:
            assert len(vlist) == 1
            singleton = cls.get_singleton()
            if singleton:
                cls.write([singleton], vlist[0])
                return [singleton]

        sql_table = cls.get_sql_table()

        cursor = Transaction().connection.cursor()
        ids = []
        for record in vlist:
            fields = []
            values = []
            for key, value in record.items():
                fields.append(sql.Column(sql_table, key))
                values.append(value)

            query = sql_table.insert(fields,
                                     values=[values],
                                     returning=[sql_table.id])
            cursor.execute(*query)
            ids.append(cursor.fetchone()[0])
        records = cls.browse(ids)
        cls.update_formulas(records)
        return records
Example #15
0
 def _migrate_property(cls, field_names, value_names, fields):
     field_names.extend(sequences)
     value_names.extend(sequences)
     fields.append('company')
     migrate_property(
         'stock.configuration', field_names, cls, value_names,
         fields=fields)
Example #16
0
    def update_formulas(cls, records=None):
        cursor = Transaction().connection.cursor()
        pool = Pool()
        Compilation = Pool().get('lims.interface.compilation')
        TableField = pool.get('lims.interface.table.field')
        Column = pool.get('lims.interface.column')

        compilation_id = Transaction().context.get(
            'lims_interface_compilation')
        if not compilation_id:
            return

        compilation = Compilation(compilation_id)
        table = compilation.table
        interface = compilation.interface
        sql_table = SqlTable(table.name)

        formula_fields = []
        fields = TableField.search([
            ('table', '=', table),
            ('formula', 'not in', [None, '']),
            ])
        for field in fields:
            col = Column.search([
                ('interface', '=', interface),
                ('alias', '=', field.name),
                ])
            order = col and col[0].evaluation_order or 0
            formula_fields.append({
                'order': order,
                'field': field,
                })
        if not formula_fields:
            return
        formula_fields = sorted(formula_fields, key=lambda x: x['order'])

        if not records:
            records = cls.search([])
        for record in records:
            vals = {}
            fields = []
            values = []
            for field in formula_fields:
                for x in (field['field'].inputs or '').split():
                    if x not in vals:
                        vals[x] = getattr(record, x)
                field_name = field['field'].name
                value = record.get_formula_value(field['field'], vals)
                if value is None:
                    continue
                fields.append(SqlColumn(sql_table, field_name))
                values.append(value)
                vals[field_name] = value

            if not values:
                continue
            query = sql_table.update(fields, values,
                where=(sql_table.id == record.id))
            cursor.execute(*query)
Example #17
0
 def _migrate_property(cls, field_names, value_names, fields):
     field_names.append('asset_sequence')
     value_names.append('asset_sequence')
     fields.append('company')
     migrate_property('account.configuration',
                      field_names,
                      cls,
                      value_names,
                      fields=fields)
Example #18
0
 def _migrate_property(cls, field_names, value_names, fields):
     field_names.extend(['account_receivable',
             'account_payable'])
     value_names.extend(['default_account_receivable',
             'default_account_payable'])
     fields.append('company')
     migrate_property(
         'party.party', field_names, cls, value_names,
         fields=fields)
Example #19
0
 def _migrate_property(cls, field_names, value_names, fields):
     field_names.extend(['credit_account', 'debit_account'])
     value_names.extend(['credit_account', 'debit_account'])
     fields.append('company')
     migrate_property('account.journal',
                      field_names,
                      cls,
                      value_names,
                      parent='journal',
                      fields=fields)
Example #20
0
 def _migrate_property(cls, field_names, value_names, fields):
     field_names.append('cost_price')
     value_names.append('cost_price')
     fields.append('company')
     migrate_property('product.template',
                      field_names,
                      cls,
                      value_names,
                      parent='template',
                      fields=fields)
Example #21
0
 def _migrate_property(cls, field_names, value_names, fields):
     field_names.append('sale_price_list')
     value_names.append('sale_price_list')
     fields.append('company')
     migrate_property('party.party',
                      field_names,
                      cls,
                      value_names,
                      parent='party',
                      fields=fields)
Example #22
0
    def get_default_form_view(self):
        View = Pool().get('shine.view')

        view = View()
        view.sheet = self
        view.name = 'Default Form View'
        view.system = True
        view.type = 'custom'
        view.custom_type = 'form'

        fields = []
        for formula in self.formulas:
            fields.append('<label name="%s"/>' % formula.alias)
            if formula.type in ('datetime', 'timestamp'):
                fields.append('<group col="2">'
                              '<field name="%s" widget="date"/>'
                              '<field name="%s" widget="time"/>'
                              '</group>' % (formula.alias, formula.alias))
                continue
            if formula.type == 'icon':
                fields.append('<image name="%s"/>\n' % (formula.alias))
                continue

            attributes = []
            if formula.type == 'image':
                attributes.append('widget="image"')

            fields.append('<field name="%s" %s/>\n' %
                          (formula.alias, ' '.join(attributes)))

        view.custom_arch = ('<?xml version="1.0"?>\n'
                            '<form>\n'
                            '%s'
                            '</form>') % '\n'.join(fields)
        return view
Example #23
0
    def activate(cls, sheets):
        pool = Pool()
        Table = pool.get('shine.table')
        Field = pool.get('shine.table.field')
        Data = pool.get('shine.data')

        for sheet in sheets:
            sheet.check_formulas()
            sheet.check_icons()

            sheet.revision += 1
            table = Table()
            table.name = sheet.data_table_name
            table.singleton = (sheet.type == 'singleton')
            fields = []
            for formula in sheet.formulas:
                if not formula.type:
                    continue
                if not formula.store:
                    continue
                fields.append(
                    Field(
                        name=formula.alias,
                        string=formula.name,
                        type=formula.type,
                        help=formula.expression,
                        related_model=formula.related_model,
                        formula=(formula.expression if formula.expression
                                 and formula.expression.startswith('=') else
                                 None),
                    ))
            table.fields = fields
            table.create_table()
            table.save()

            if (not sheet.dataset and sheet.current_table
                    and sheet.current_table.count()):
                table.copy_from(sheet.current_table)
                with Transaction().set_context({'shine_table': table.id}):
                    Data.update_formulas()

            sheet.current_table = table

        cls.save(sheets)
        cls.reset_views(sheets)
Example #24
0
    def import_fields(cls, model_name, data, full_data, existing_models):
        model = full_data[model_name]['__instance']
        methods = {x.name: x for x in model.methods}

        Field = Pool().get('debug.model.field')
        fields = []
        for field_name, field_data in data['fields'].items():
            field = Field()
            field.name = field_name
            field.module = field_data['module']
            field.string = field_data['string']
            field.kind = field_data['kind']
            field.function = field_data['is_function']
            if field_data.get('target_model', None):
                if field_data['target_model'] in existing_models:
                    field.target_model = existing_models[
                        field_data['target_model']]
                else:
                    field.target_model = full_data[
                        field_data['target_model']]['__instance']
            field.default_method = methods.get('default_%s' % field_name, None)
            field.on_change_method = methods.get('on_change_%s' % field_name,
                                                 None)
            field.on_change_with_method = methods.get(
                'on_change_with_%s' % field_name, None)
            field.order_method = methods.get('order_%s' % field_name, None)
            field.selection_method = methods.get(
                field_data.get('selection_method', None), None)
            field.getter = methods.get(field_data.get('getter', None), None)
            field.setter = methods.get(field_data.get('setter', None), None)
            field.searcher = methods.get(field_data.get('searcher', None),
                                         None)
            if field_data.get('selection_values', None):
                field.selection_values = '\n'.join([
                    '%s :%s' % (k, v)
                    for k, v in field_data['selection_values'].items()
                ])
            field.domain = field_data.get('domain', '')
            field.invisible = field_data.get('state_invisible', '')
            field.required = 'True' if field_data['is_required'] else \
                field_data.get('state_required')
            field.readonly = 'True' if field_data['is_readonly'] else \
                field_data.get('state_readonly')
            fields.append(field)
        full_data[model_name]['__instance'].fields_ = fields
Example #25
0
    def write(cls, *args):
        sql_table = cls.get_sql_table()
        cursor = Transaction().connection.cursor()

        all_records = []
        actions = iter(args)
        for records, vals in zip(actions, actions):
            all_records += records
            fields = []
            values = []
            for key, value in vals.items():
                fields.append(SqlColumn(sql_table, key))
                values.append(value)

            query = sql_table.update(fields, values,
                where=sql_table.id.in_([x.id for x in records]))
            cursor.execute(*query)
        cls.update_formulas(all_records)
Example #26
0
    def create(cls, vlist):
        sql_table = cls.get_sql_table()
        cursor = Transaction().connection.cursor()

        ids = []
        for record in vlist:
            fields = []
            values = []
            for key, value in record.items():
                fields.append(SqlColumn(sql_table, key))
                values.append(value)

            query = sql_table.insert(fields, values=[values],
                returning=[sql_table.id])
            cursor.execute(*query)
            ids.append(cursor.fetchone()[0])
        records = cls.browse(ids)
        cls.update_formulas(records)
        return records
Example #27
0
    def get_tree_view(cls):
        pool = Pool()
        Department = pool.get('company.department')
        Translation = pool.get('ir.translation')
        language = Transaction().language

        fields = []
        definition = {}

        fields.append('<field name="t"/>')
        definition['t'] = {
            'name':
            't',
            'string': (Translation.get_source('%s,t' % cls.__name__, 'field',
                                              language, cls.t.string)
                       or cls.t.string),
            'type':
            'char',
            'readonly':
            True,
            'help':
            None,
        }

        fields.append('<field name="q"/>')
        definition['q'] = {
            'name': 'q',
            'string': gettext('lims_board.msg_no_department'),
            'type': 'integer',
            'readonly': True,
            'help': None,
        }

        i = 0
        departments = Department.search([],
                                        order=[('id', 'ASC')],
                                        limit=DEPARTMENTS_LIMIT)
        for d in departments:
            i += 1
            name = 'q%s' % str(i)
            fields.append('<field name="%s"/>' % name)
            definition[name] = {
                'name': name,
                'string': d.name,
                'type': 'integer',
                'readonly': True,
                'help': None,
            }

        xml = ('<?xml version="1.0"?>\n'
               '<tree>\n'
               '%s\n'
               '</tree>') % ('\n'.join(fields))
        res = {
            'type': 'tree',
            'arch': xml,
            'fields': definition,
        }
        return res
Example #28
0
    def get_view_info_table(self):
        # TODO: Duplicated from get_tree_view() but this one is not editable
        fields = []
        current_icon = None
        for line in self.table_formulas:
            formula = line.formula
            if formula.type in ('datetime', 'timestamp'):
                fields.append('<field name="%s" widget="date"/>\n' %
                              formula.alias)
                fields.append('<field name="%s" widget="time"/>\n' %
                              formula.alias)
                continue
            if formula.type == 'icon':
                current_icon = formula.alias
                continue
            attributes = []
            if formula.type in ('integer', 'float', 'numeric'):
                attributes.append('sum="Total %s"' % formula.name)
            if current_icon:
                attributes.append('icon="%s"' % current_icon)
                current_icon = None
            if formula.type == 'image':
                attributes.append('widget="image"')

            fields.append('<field name="%s" %s/>\n' %
                          (formula.alias, ' '.join(attributes)))

        attributes = ''
        if self.table_editable and self.table_editable != 'disabled':
            attributes = 'editable="%s"' % self.table_editable
        xml = ('<?xml version="1.0"?>\n'
               '<tree %s>\n'
               '%s'
               '</tree>') % (attributes, '\n'.join(fields))
        return {
            'type': 'tree',
            'fields': fields,
            'arch': xml,
        }
Example #29
0
    def user_view_set(cls, view_data={}):
        pool = Pool()
        View = pool.get('user.view')
        Field = pool.get('user.view.field')
        Model = pool.get('ir.model')
        TrytonView = pool.get('ir.ui.view')
        TrytonField = pool.get('ir.model.field')
        TrytonAction = pool.get('ir.action.act_window')

        if view_data['id'] > 0:
            view = View(view_data['id'])
        else:
            view = View()

        view.name = view_data['name']
        view.order = view_data['order'] or None
        view.list_view_style = view_data['list_view_style'] or ''
        view.current_search = view_data['search'] or None
        view.user = view_data['user']
        view.global_available = view_data['global_available']
        view.records_qty = view_data['records_qty']

        if view_data['view_id'] is not False:
            view.view = view_data['view_id']
            tview = TrytonView(view_data['view_id'])
            view.view_model = Model.search([('model', '=', tview.model)])[0].id

        elif 'field_data' in view_data:
            f_data = view_data['field_data']
            view.field_name = f_data['name']
            view.view_model = Model.search([('model', '=', f_data['relation'])
                                            ])[0].id
            view.field_model = Model.search([('model', '=', f_data['model'])
                                             ])[0].id

        elif 'action' in view_data:
            act_window = TrytonAction(view_data['action'])
            view.act_window = act_window
            view.view_model = Model.search([('model', '=',
                                             act_window.res_model)])[0].id

        def getField(field_data):
            f_id = field_data.get('id', -1)
            # check if the field and view exist
            if f_id > 0 and view_data['id']:
                field = Field(f_id)
            else:
                field = Field()

            if field_data['type'] == 'field':
                if not hasattr(field, 'field'):
                    field.field = TrytonField.search([
                        ('model', '=', view.view_model),
                        ('name', '=', field_data['name']),
                    ])[0].id

            field.name = field_data['name']
            field.type = field_data['type']
            field.width = field_data.get('width')
            field.visual = field_data.get('visual')
            field.field_widget = field_data.get('widget')
            field.sequence = field_data.get('sequence')

            return field

        fields = []
        for field in view_data['fields']:
            fields.append(getField(field))

        if len(fields) > 0:
            view.user_view_fields = fields

        view.save()

        view_id = view.id

        if view_data['default']:
            View.user_view_set_default_view(view_id, view_data['user'])

        return view_id