Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
12684 Widoki

Specifically, I am trying to see all of the data included in a product record, and I'm doing it from the create() method of a stock.move child class I have created.

If I use: _logger.info(', '.join(dir(product)))

I get (exhibit A). It does have the fields, but it also has all of the models helper functions and properties, and there is so much there that it is very hard to see just the actual fields from the database that have to do with products (like weight, SKU, etc).

I found a function called get_fields() in the model source, but it seems to dump all available schema and metadata surrounding products, way more than I need, and does not provide the actual values in the record.

I just want a dictionary of key value pairs for product and it's related models that I have loaded using browse(). Does something like that exist?

 

Exhibit A:

CONCURRENCY_CHECK_FIELD, _BaseModel__export_rows, _BaseModel__export_xml_id, __add__, __and__, __class__, __contains__, __delattr__, __dict__, __doc__, __eq__, __format__, __ge__, __getattribute__, __getitem__, __gt__, __hash__, __init__, __int__, __iter__, __last_update, __le__, __len__, __lt__, __metaclass__, __module__, __ne__, __new__, __nonzero__, __or__, __reduce__, __reduce_ex__, __repr__, __setattr__, __setitem__, __sizeof__, __str__, __sub__, __subclasshook__, __unicode__, __weakref__, _add_field, _add_magic_fields, _add_missing_default_values, _add_sql_constraints, _all_columns, _apply_ir_rules, _auto, _auto_end, _auto_init, _browse, _build_model, _cache, _check_concurrency, _check_ean_key, _check_m2m_recursion, _check_qorder, _check_record_rules_result_count, _check_recursion, _check_removed_columns, _check_selection_field_value, _columns, _compute_display_name, _compute_uos_qty, _constraint_methods, _constraints, _context, _convert_records, _convert_to_cache, _convert_to_write, _cr, _create, _create_parent_columns, _create_table, _custom, _date_name, _defaults, _depends, _description, _dirty, _drop_constraint, _execute_sql, _extract_records, _field_create, _fields, _find_partner_from_emails, _garbage_collect_attachments, _generate_m2o_order_by, _generate_order_by, _get_access_link, _get_column_infos, _get_default_calendar_view, _get_default_form_view, _get_default_search_view, _get_default_tree_view, _get_domain_dates, _get_domain_locations, _get_external_ids, _get_followers, _get_image_variant, _get_inbox_action_xml_id, _get_message_data, _get_name_template_ids, _get_partner_code_name, _get_price_extra, _get_subscription_data, _get_tracked_fields, _get_user_chatter_options, _get_xml_ids, _group_by_full, _has_onchange, _ids, _in_cache_without, _inherit, _inherit_fields, _inherits, _inherits_check, _inherits_join_add, _inherits_join_calc, _inherits_reload, _inherits_reload_src, _init_constraints_onchanges, _init_function_fields, _init_manual_fields, _is_an_ordinary_table, _is_product_variant_impl, _local_constraints, _local_sql_constraints, _log_access, _log_create, _m2m_raise_or_create_relation, _m2o_add_foreign_key_checked, _m2o_add_foreign_key_unchecked, _m2o_fix_foreign_key, _mail_flat_thread, _mail_mass_mailing, _mail_post_access, _mapped_cache, _mapped_func, _message_add_suggested_recipient, _message_extract_payload, _message_find_partners, _message_get_auto_subscribe_fields, _message_preprocess_attachments, _model, _module, _name, _name_search, _needaction, _needaction_domain_get, _o2m_raise_on_missing_reference, _onchange_eval, _onchange_methods, _onchange_spec, _order, _original_module, _ormcache, _parent_columns_exist, _parent_name, _parent_order, _parent_store, _parent_store_compute, _patch_method, _pop_field, _prefetch_field, _prepare_setup_fields, _product_available, _product_available_text, _product_code, _product_lst_price, _product_partner_ref, _product_price, _purchase_count, _read_from_database, _read_group_fill_results, _read_group_format_result, _read_group_get_domain, _read_group_prepare, _read_group_prepare_data, _read_group_process_groupby, _rec_name, _rec_name_fallback, _recompute_check, _recompute_done, _recompute_todo, _register, _register_hook, _revert_method, _sales_count, _save_constraint, _save_relation_table, _search, _search_followers, _search_is_follower, _search_message_unread, _search_product_quantity, _select_column_data, _sequence, _set_default_value_on_column, _set_followers, _set_image_variant, _set_product_lst_price, _setup_fields, _sql_constraints, _stock_move_count, _store_get_values, _store_set_values, _table, _table_exist, _track, _transient, _transient_clean_old_rows, _transient_clean_rows_older_than, _transient_vacuum, _translate, _uid, _update_store, _validate_fields, _view_look_dom_arch, _website_url, _where_calc, _write, accessory_product_ids, action_view_routes, active, alternative_product_ids, attribute_line_ids, attribute_value_ids, browse, categ_id, check_access_rights, check_access_rule, check_field_access_rights, check_mail_message_access, check_recursion, clear_caches, code, color, company_id, compute_concurrency_field, compute_concurrency_field_with_access, copy, copy_data, copy_translations, cost_method, create, create_date, create_uid, create_workflow, default_code, default_get, delete_workflow, delivery_count, description, description_purchase, description_sale, display_name, distinct_field_get, ean13, ensure_one, env, exists, export_data, fields_get, fields_get_keys, fields_view_get, filtered, get_access_action, get_empty_list_help, get_external_id, get_formview_action, get_formview_id, get_metadata, get_suggested_thread, get_xml_id, id, ids, image, image_medium, image_small, image_variant, import_data, incoming_qty, invalidate_cache, is_product_variant, is_transient, list_price, load, loc_case, loc_rack, loc_row, location_id, log, lst_price, mapped, mes_type, message_auto_subscribe, message_capable_models, message_change_thread, message_follower_ids, message_get_default_recipients, message_get_email_values, message_get_reply_to, message_get_subscription_data, message_get_suggested_recipients, message_ids, message_is_follower, message_last_post, message_mark_as_read, message_mark_as_unread, message_new, message_parse, message_partner_info_from_emails, message_post, message_process, message_redirect_action, message_route, message_route_process, message_route_verify, message_subscribe, message_subscribe_users, message_summary, message_track, message_unread, message_unsubscribe, message_unsubscribe_users, message_update, modified, name, name_create, name_get, name_search, name_template, need_procurement, new, on_order, onchange, onchange_uom, open_product_template, optional_product_ids, orderpoint_ids, outgoing_qty, packaging_ids, partner_ref, pool, price, price_extra, price_get, pricelist_id, print_report, product_manager, product_tmpl_id, product_type_id, product_variant_count, product_variant_ids, property_account_creditor_price_difference, property_account_expense, property_account_income, property_stock_account_input, property_stock_account_output, property_stock_inventory, property_stock_procurement, property_stock_production, public_categ_ids, purchase_count, purchase_ok, qty_available, qty_available_text, read, read_followers_data, read_group, read_string, reception_count, recompute, redirect_workflow, refresh, rental, resolve_2many_commands, resolve_o2m_commands_to_record_dicts, route_ids, sale_delay, sale_ok, sales_count, search, search_count, search_read, seller_delay, seller_id, seller_ids, seller_qty, signal_workflow, sorted, standard_price, state, step_workflow, sudo, supplier_taxes_id, taxes_id, track_all, track_incoming, track_outgoing, type, unlink, uom_id, uom_po_id, uos_coeff, uos_id, update, user_has_groups, user_review, valuation, view_header_get, view_init, virtual_available, volume, warehouse_id, warranty, website_description, website_message_ids, website_meta_description, website_meta_keywords, website_meta_title, website_published, website_sequence, website_size_x, website_size_y, website_style_ids, website_url, weight, weight_net, with_context, with_env, write, write_date, write_string, write_uid

Awatar
Odrzuć
Autor Najlepsza odpowiedź

I eventually wrote a little function for this. Not sure if there is anything for this built into odoo.

        import pprint
        def model_data(obj):
            fields_dict = {}
            for key in obj.fields_get():
                fields_dict[key] = obj[key]
            return fields_dict

 

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
wrz 19
3554
2
lut 17
10991
4
paź 21
37750
1
mar 15
5130
1
sie 25
3905