Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
2615 Widoki

To make my code more readable, I need two methods so that the first one loads in memory the data that the second one will process.


class Sample(models.Model)

    data = []

    def get_data():

        self.data = _get_data

    def process_data():

       for item in self.data:

          _process_data(item)

The problem I'm having is that the first method can't write to the "field/attribute" because it says: : "'sample.sample' object attribute 'data' is read-only" while evaluating

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,
I think you should try to use Odoo Fields in order to achive your goal, I don't think it is appropriate to define lists and tuples or dictionaries in Odoo models.
instead, I suggest to write Cron Object that fetch those data (while you can define that 'data' list inside the function (temporary values) then process them and apply changes, you can also set your options about how many times you want that fuction to run or every how many minutes etc...

Awatar
Odrzuć
Autor

Thanks for your reply. I expand the context a bit:

* The _get_data function gets data from a remote server
* These data must be enriched with the information registered in Odoo
* The processes are complex and go through about 3 or 4 methods
* That's why my idea was to have a list with data in memory so as not to have to extend the list of arguments of those 3 or 4 methods.

Powiązane posty Odpowiedzi Widoki Czynność
1
lut 25
1187
3
maj 25
1695
1
kwi 25
1270
3
wrz 24
14156
0
sie 24
1247