Skip to Content
Menu
This question has been flagged
2 Replies
1209 Views

Hi everyone,

I have a short question : How to access ids of shown kanban cards?

Do I need to rebuild the search and domain for py use or can I grab them from form view?

def get_sap_no(self):
if self.order_id:
# We search for order_id to get the customers_id
first = self.env['esc.sst'].search([('order_id', '=', self.order_id)], limit=1)

view = self.env.ref('esc_et.esc_ship_spares_kanban_view_filtered')
action = {'type': 'ir.actions.act_window',
'res_model'
: 'esc.sst',
'view_type'
: 'kanban',
'view_mode'
: 'kanban',
'view_id'
: view.id,
'domain'
: [('partner', '=', first.partner)],
'target'
: 'main',
'context': {
'partner' : first.partner,
​ }
}
return action


edit: 

Wenn in JS, I don´t get a value.

_CloseSAPCase: function () {
var self = this;
alert(this.partner)
this._rpc({
model: 'esc.sst',
method: 'write_tch_order',
args: [],
context: {'partner': this.partner,}
}, {
shadow: true,
});

}


I only want to pass the partner number I got in my def get_sap_no to my def write_tch_order to perform  some stuff.

Programs way:

wizard button --> def_get_sap --> returns custom kanban view with domain filter -->JS Button to close case --> def write_thc_order

But after the Kanban return my partner is gone :(

Avatar
Discard
Author

Okay, ehhm... nope...

maybe I should have added request for Odoo 15.0.

short :

wizard --> search partner -->open Kanban domain = partner --> do some stuff --> action button for doin stuff (added in JS by Cybros tutorial).
But both, JS and py saying nothing in self.env.context.get or self.partner


long:

I fully understood that each kanban cards is a tuple of the record and I already did a search as you can see in my code.
I have a wizard to enter order_id and search for it to get it´s partner no. I pass this partner to an action to get a filtered kanban view (see above my code, plz) related to my search.

I added a context as I only need to have the partner from there (beacause I can search for related values in model then).

'context': {
​ 'partner'
: first.partner,
}

But I wrap my head around to understand why I don´t have a value in self.env.context.get('partner') on my filtered Kanban. 




Author Best Answer
First : How to post xml code? codeblocks and nomral text will crash the xml parts of my post, so I deleted first bracket
Here you go-full code for every part involved:
Form where enter SAPNumber:

recordid="esc_ship_spares_form_view"model=""\ rel="ugc">ir\.ui\.view">
\ fieldname="name">esc_ship_spares_form_view/field>
\ fieldname="model">esc\.ship\.spare/field>
\ fieldname="arch"type="xml">
\ formaction_buttons="false">
\ Buttonname="get_sap_no"string="GetData"type="object"class="oe_highlight"/>fieldname="order_id"/>
\ /form>
\ /field>
/record>

defget_sap_no\(self\):
\ ​\#ifself\.order_id:
\ ​\#Wesearchfororder_idtogetthecustomers_id
\ ​sst=self\.env\['esc\.sst'\]\.search\(\[\('order_id','=',self\.order_id\)\],limit=1\)
\ ​\#raiseValidationError\(sst\.partner\)
\ ​view=self\.env\.ref\('mymodule\.esc_ship_spares_kanban_view_filtered'\)
\ ​action=\{
\ \ ​'type':'ir\.actions\.act_window',
\ \ ​'res_model':'esc\.sst',
\ \ ​'view_type':'kanban',
\ \ ​'view_mode':'kanban',
\ \ ​'view_id':view\.id,
\ \ ​'domain':\[\('partner','=',sst\.partner\)\],
\ \ ​'target':'inline',
\ \ ​'context':\{
\ \ ​'partner':sst\.partner
\ \ ​\}
\ ​\}
\ ​returnaction

The\ Kanban\ is\ extended\ with\ a\ js_class\ for\ custom\ button\ \(below\ kanban\)

recordid="esc_ship_spares_kanban_view_filtered"model=""\ rel="ugc">ir\.ui\.view">
\ ​fieldname="name">esc_ship_spares_kanban_view/field>
\ ​fieldname="model">esc\.sst/field>
\ ​fieldname="arch"type="xml">
\ ​kanbangroup_create="false"default_group_by="service_state">
\ \ ​fieldname="order_id"/>
\ \ ​fieldname="partner"/>
\ \ ​fieldname="service_state"/>
\ ​progressbarfield="service_state"colors='\{"eingang":"danger","verzug_1":"warning","verzug_2":"warning","erledigt":"success"\}'/>
\ ​templates>
\ ​tt\-name="kanban\-box">
\ ​divclass="oe_kanban_content">
\ ​divclass="o_kanban_record_title">
\ ​strong>
\ ​fieldname="order_id"/>\-\-\-\-\-fieldname="sst_date"/>
\ ​/strong>
\ ​br>/br>
\ ​Artikel:fieldname="spare_no"/>
\ ​br>/br>
\ ​fieldname="spare_descr"/>
\ ​br>/br>
\ ​fieldname="fk_status"/>
\ ​/div>
\ ​/div>
\ \ ​divclass="oe_kanban_footer_right">
\ ​/div>
\ ​/t>
\ ​/templates>
\ ​/kanban>
\ ​/field>
/record>

JS:

odoo\.define\('mymodule\.kanban_close_button',function\(require\)\{
"usestrict";
\ ​var\ KanbanController=require\('web\.KanbanController'\);
\ ​var\ KanbanView=require\('web\.KanbanView'\);
\ ​var\ viewRegistry=require\('web\.view_registry'\);
\ ​var\ KanbanCloseButton=KanbanController\.extend\(\{
\ ​buttons_template:'mymodule\.closebutton',
\ ​events:_\.extend\(\{\},KanbanController\.prototype\.events,\{
\ ​'click\ \.close_sst_case':'_CloseSAPCase',
\}\),

_CloseSAPCase:function\(\)\{
\ ​var\ self=this;
\ ​alert\(this\.partner\)
\ ​this\._rpc\(\{\ \
\ ​model:'esc\.sst',
\ ​method:'write_tch_order',
\ ​args:\[\],
\ \ ​\},\{
\ ​shadow:true,
\ ​\}\);

\ ​\}
\ ​\}\);

var\ close_caseKanbanView=KanbanView\.extend\(\{
config:_\.extend\(\{\},KanbanView.prototype.config,{
Controller:KanbanCloseButton
}),
});
viewRegistry.add('PutSAP',close_caseKanbanView);
});

qweb template for button:


templatesid="template"xml:space="preserve">
​tt-extend="KanbanView.buttons"t-name="mymodule.closebutton">
​tt-jquery="button"t-operation="replace">
​buttont-if="widget.modelName=='esc.sst'"
​class="btnbtn-primaryclose_sst_caseoe_highlight"
​type="button">Auftragabschließen/button>
​/t>
​/t>
/templates>

defwrite_tch_order(self):
#ship_em=self.env['esc.sst'].search([('service_state','=','versenden')])
#sst_partner=ship_em[0].partner
#self.sst_state_changes(sst_partner)
#forsstinship_em:
#...

raiseValidationError(self.partner)

So whats wrong, please?



Avatar
Discard
Best Answer

, you can get the ids of Kanban cards by using the search() method on the model that represents the Kanban cards. For example, if the model is called project.task, you could use the following code to get the ids of all Kanban cards:


Copy code

from odoo import models


task_ids = models.execute_kw('project.task', 'search', [[]])

This will return a list of all task ids. If you want to filter the tasks based on some condition, you can pass a domain as the first argument to the search() method. For example, to get the ids of all Kanban cards with the status "Done", you could use the following code:


Copy code

task_ids = models.execute_kw('project.task', 'search', [[['state', '=', 'done']]])

You can also use the ORM API to get the ids of Kanban cards, like this:


Copy code

task_obj = self.env['project.task']

task_ids = task_obj.search([])

Also, you can use the ORM API to filter the ids of Kanban cards, like this:


Copy code

task_obj = self.env['project.task']

task_ids = task_obj.search([('state','=','done')])

Please note that this is just an example, and the exact code may vary depending on the specific version of Odoo and the customizations that have been made to the system

Avatar
Discard
Author

Hi Muhammed,
Thanks for your efforts, but maybe I don´t understand your answer or you are explaining what I already got?
I filtered my Kanban-Cards on domain and return it into kanban domain (you can see it in my code...). So I now want to get the shown ids but :

1.) I added a context :
'context': {
'partner' : partner,
}
self.env.context.get('partner') is none
2.) self.whatever is none

Why´s nothing in context of kanban view? Code is in first post

It's difficult to determine the issue without the complete code and context, but here are some possible reasons why the context may not be present in the kanban view:

The context is being overridden: Sometimes other code in the system may be modifying or clearing the context. It's possible that the context is being overridden before it reaches the kanban view.

The context is not being passed correctly: The context is not passed correctly if the method or view that adds the context is not called. Make sure that the method that adds the context is being called correctly and that the context is being passed correctly to the kanban view.

The context is not being correctly referenced: If the reference to the context is incorrect, it will not be able to retrieve the context values. For example, if the reference to the partner context is self.env.context.get('partner') but the context value is actually self.env.context.get('partners'), it will return None.

The value of self.whatever is None: If the value of self.whatever is None, it could be due to several reasons, such as it's not defined in the code or it's not being passed correctly to the view.

It is recommended to add some debugging statements to your code to help you understand what's happening, such as printing out the contents of the context or the value of self.whatever to see what's causing the issue

Related Posts Replies Views Activity
0
Nov 24
68
0
Aug 22
1265
0
Mar 22
1261
1
Oct 19
4118
2
May 18
5129