This question has been flagged
2 Replies
6850 Views

Hi community!

I'm curious if there is a way to start the import process from the side menu? For instance I havea an object called "Container".

I want to add an entry to the side menu that will take me directly to the "Import Container" screen, as opposed to clicking "Container", and then choosing the import link at the top of the screen.

Is this possible?

Avatar
Discard

Sure, you could definitely hack something like that together, but I'd have to ask how that would be worth implementing. Are you really importing so frequently that the additional click is worth bypassing? If that's the case, maybe you should focus your efforts on automating the import rather than the click.

Author

I realize it seems odd, but its a customer request. The customer wishes to have this functionality. Could you possible explain a little more further what the "hack" would entail? I'm a very capable openerp programmer, I'm just not sure how to set up the action to do this.

Best Answer

It's actually much easier than I expected. You set up a client action with the tag 'import', and the params set to {'model': 'container.model'}. Then just make a standard menuitem and link to that action. This code completely covers it for events (randomly picked as an example):

<openerp>
<data>

<record id="event_import_action" model="ir.actions.client">
    <field name="name">Import Events</field>
    <field name="tag">import</field>
    <field name="params" eval="{'model': 'event.event'}"/>
</record>

<menuitem id="event_import_menu" action="event_import_action" parent="base.menu_event_main" sequence="16"/>

</data>
</openerp>

The end result is a traditional menuitem that opens the import menu for events: import_menu.jpg Just change around the menuitem location and model to your liking.

Avatar
Discard
Author

See my answer above for my code/error. (couldn't post code in commen).Could you test all the way through an import and see if you get the same error? No idea where to start debugging since there is no output to the log (looks like a javascript web error)

Author Best Answer

Thank you for your answer! Everything looks awesome, and it even validates, however when I try to hit Import, I get this screen that says: "Uncaught an exception occurred in a caller-provided callback function". And nothing in the log file. Code:

    <record id="event_import_products" model="ir.actions.client">
            <field name="name">Ingreso de Notas de Pedido</field>
            <field name="tag">import</field>
            <field name="params" eval="{'model': 'product.product'}"/>
    </record>

    <menuitem id="ingresos_mend" action = "event_import_products" parent="menu_purchase_container" name="Ingreso de Notas de Pedido" />

The import I need to do is a product import, thats why I have product.product (I was wrong, its not a container import).

Avatar
Discard

Importing products is tricky, due to the product.template framework left in place for product variants. I don't know if that's actually playing a part here though. I'll have to look at that some more to replicate that error.

Author

Been debugging today. I set a break point and actually, the import goes through perfect despite the error. It looks like the error has to due with the fact that post-import, the program is trying to redirect somewhere, and its not finding where... Also, if you hit the cancel button while going to this screen through the new menu, the program also errors. But just to be clear: this does result in a sucessful import, just not a correct redirect. Any idea what I could do to eliminate this error?

The error is in the javascript, and only appears after a successful import. I believe all that is left for the process to do at that point is to reload the page. If you go into the module base_import and look for the file base_import/static/src/js/import.js, on line 394 change "tag: 'history_back'" to "tag: 'reload'" and that error goes away. Don't know how to make that a simple inherited fix though. Basically the JS needs to respond two different ways depending on where you came from, the menuitem or the traditional import method.