Skip to Content
Menú
This question has been flagged
2 Respostes
1380 Vistes
.py:
colon_data = fields.Boolean('Colon Data',store=True,default=True) count_data = fields.Integer(string='Data check') @api.onchange('plot_colonization_ids') def compute_count_data(self): for rec in self: total_plot_no = 0 for line in rec.plot_colonization_ids: if line.plot_no: rec.count_data += int(line.plot_no) if rec.count_data > 0: self.colon_data = True elif rec.count_data == 0: self.colon_data = False

i use the following code for a graph in kanban card if there is data graph will be shown otherwise graph will not visible but there are few issue first i need the colonization heading should be invisble for those kanban card which has no data in graph, second thing is if there is no data in graph then the remaining graphs should be adjustable which is not adjust right now in sense of space occupying in kanban card

```

Colonization

```

Avatar
Descartar
Best Answer

To address the issues you're facing with the Odoo customization involving graphs on Kanban cards, there are a couple of modifications and clarifications needed in both your backend Python code and your frontend XML/JavaScript.

Python Code Corrections

First, let's correct and optimize your Python code. Your existing code seems to have an intention of counting some data related to plot_colonization_ids. However, there are a few issues in how you handle the counting and setting of colon_data. Here’s a refined version:

pythonCopy codefrom odoo import models, fields, api

class YourModelName(models.Model):
    _name = 'your.model.name'
    _description = 'Model Description'

    colon_data = fields.Boolean('Colon Data', store=True, default=True)
    count_data = fields.Integer(string='Data Check', compute='_compute_count_data', store=True)

    @api.depends('plot_colonization_ids.plot_no')
    def _compute_count_data(self):
        for rec in self:
            rec.count_data = sum(int(line.plot_no or 0) for line in rec.plot_colonization_ids)
            rec.colon_data = rec.count_data > 0

Key Changes:

  • I added @api.depends decorator to properly trigger the compute method when plot_colonization_ids.plot_no changes.
  • Used list comprehension for summation to make the calculation more Pythonic and efficient.
  • Removed the loop that was redundantly resetting colon_data for every record in the compute method, and instead directly set colon_data based on count_data.

Frontend XML/JS Adjustments

For your requirements on the Kanban card:

  1. Hiding the Colonization Heading on Kanban cards without data: You can use the attrs attribute in your XML to conditionally hide elements based on colon_data.
xmlCopy code
    
        

Colonization Data

  1. Adjusting Space for Kanban cards with no data: This typically requires custom CSS or adjustments in JavaScript to ensure that the layout adapts to the absence of certain elements. Here’s an idea on how to approach it using CSS:
cssCopy code

For dynamic behavior adjustments in the Kanban view, depending on whether the customization is heavy, you might also need to extend the Kanban view's JavaScript part using Odoo's JavaScript framework to manipulate the DOM based on colon_data.

These are the foundational adjustments needed. Depending on your specific module and setup, additional modifications might be required to perfectly fit your requirements.

Avatar
Descartar
Autor Best Answer

Thank you! by using css,js and the optimization of python worked for me.

Avatar
Descartar
Related Posts Respostes Vistes Activitat
2
de maig 24
1888
1
de maig 25
683
2
de set. 23
11399
2
de gen. 24
14357
0
d’abr. 15
4558