Technical archives des diffusions par email

technical@mail.odoo.com

Avatar

Re: How to get the id of selected records when calling python method from js code?

par
Alain Van Utterbeeck
- 06/09/2018 05:45:40
Take a look at for example purchase_merge: you select PO's in the view and can then select 'Merge' in the 'action' on top of the screen.

Greetings 

On Thu, Sep 6, 2018 at 4:54 AM meng xiaolin <mxl85@hotmail.com> wrote:

Guys:

       I want to share this with you,  it took me quite some time to figure out this problem, there actually is a method you can call to get the selected records ids in JS code , then pass to your python code , here is my code:

-----python------------------------------------

@api.multi

def action_confirm(self, ids=None):

      your python code

-------------javascript-------------------------

.call("action_confirm", [[]], {ids: this.groups.get_selection().ids})

.done(function(result){

    window.location.reload()}

------------------------------------------------

with all the above , ids are passed to python code and you perform whatever you want in python then reload the page by .done function.

Good luck with your odoo experience!


发件人: Alain Van Utterbeeck <alain@drgt.net>
发送时间: 2018年9月5日 12:59:29
收件人: Technical
主题: Re: How to get the id of selected records when calling python method from js code?
 
You don't need js code to add a button on a tree view, you do it in the xml.

Greetings,
Alain

On Wed, Sep 5, 2018 at 12:45 PM meng xiaolin <mxl85@hotmail.com> wrote:

Hi guys,

        I get a problem, I add a button in the list view, and when click the button , js code will call my python method, but there is no way I can get what record are chosen by user, do you have any way?

my python code:

 @api.multi

def action_confirm(self)

     for rec in self:

             rec.state = "confirmed"

it is always nothing in self

and my js code:( refer to http://vitraining.com/odoo-how-to-add-custom-button-on-tree-view/)

openerp.vit_staging = function(instance) {
 var ListView = instance.web.ListView;
 ListView.include({
 render_buttons: function() {

// GET BUTTON REFERENCE
 this._super.apply(this, arguments)
 if (this.$buttons) {
 var btn = this.$buttons.find('.confirm_button')
 }

// PERFORM THE ACTION
 btn.on('click', this.proxy('do_confrim'))

},
 do_confirm: function() {
 new instance.web.Model('hr.employee')
 .call('action_confirm', [[]])
 .done(function(result) {
 alert('done')
 })
 }
 });
}
The problem is I can not get the selected records from user in python method, do you know how?

Example, to add “Sync Data” button at the Employee list view. It will execute the existing “cron_process_staging” method on “hr.employee” model.


_______________________________________________
Mailing-List: https://www.odoo.com/groups/technical-62
Post to: mailto:technical@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe



--
Alain Van Utterbeeck

ODOO Developer


 

DR Gaming Technology Europe nv/sa
Office: +32 50 60.81.85 | Cell: +32 485.69.37.90


–––––––––––––––––––––––––––––––––


DISCLAIMER


This e-mail is from DR Gaming Technology nv/sa located in Belgium (BE).The messages you send and/or receive are transmitted via the Internet. It is therefore impossible for us to guarantee the confidentiality, accuracy and completeness of data and/or documents that are sent by electronic mail and we accept no liability for consequences and/or damage whatsoever related to data and/or documents which are thus communicated. The information in this e-mail is confidential and intended solely for the person to whom it is addressed. If this message is not addressed to you, please be aware that you have no authorisation to read the content of this e-mail, to copy it or to furnish it to any person other than the addressee or take any action in reliance on it. Should you have received this e-mail by mistake, please bring this immediately to the attention of the sender, after which you are kindly requested to destroy the message and not to disclose or disperse its content. Only when this message is supported by lawfully signed documents can any rights be derived from the content of this message with regard to DR Gaming Technology nv/sa.

_______________________________________________
Mailing-List: https://www.odoo.com/groups/technical-62
Post to: mailto:technical@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe

_______________________________________________
Mailing-List: https://www.odoo.com/groups/technical-62
Post to: mailto:technical@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe



--
Alain Van Utterbeeck

ODOO Developer


 

DR Gaming Technology Europe nv/sa


–––––––––––––––––––––––––––––––––


DISCLAIMER


This e-mail is from DR Gaming Technology nv/sa located in Belgium (BE).The messages you send and/or receive are transmitted via the Internet. It is therefore impossible for us to guarantee the confidentiality, accuracy and completeness of data and/or documents that are sent by electronic mail and we accept no liability for consequences and/or damage whatsoever related to data and/or documents which are thus communicated. The information in this e-mail is confidential and intended solely for the person to whom it is addressed. If this message is not addressed to you, please be aware that you have no authorisation to read the content of this e-mail, to copy it or to furnish it to any person other than the addressee or take any action in reliance on it. Should you have received this e-mail by mistake, please bring this immediately to the attention of the sender, after which you are kindly requested to destroy the message and not to disclose or disperse its content. Only when this message is supported by lawfully signed documents can any rights be derived from the content of this message with regard to DR Gaming Technology nv/sa.

Référence