Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

How to get ids from Kanban cards

Subscribe

Get notified when there's activity on this post

This question has been flagged
kanbanactive_id
2 Replies
3322 Views
Avatar
Sascha

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 :(

0
Avatar
Discard
Sascha
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. 




Avatar
Sascha
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?



0
Avatar
Discard
Avatar
MUHAMMAD Imran
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

0
Avatar
Discard
Sascha
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

MUHAMMAD Imran

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

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
How to make the order of "default_group_by" in kanban view?
kanban
Avatar
Avatar
1
Jan 25
2869
odoo 15 undraggable records in kanban view
kanban
Avatar
0
Aug 22
3364
add a second progressbar kanban
kanban
Avatar
0
Mar 22
3393
Not display Kanban view ? Solved
kanban
Avatar
Avatar
1
Oct 19
6508
replace the view tree with kanban
kanban
Avatar
Avatar
2
May 18
7547
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now