跳至內容
選單
此問題已被標幟
3 回覆
11651 瀏覽次數
Traceback (most recent call last):
  File "/home/odoo/src/odoo/odoo/api.py", line 899, in get
    return field_cache[record._ids[0]]
KeyError: 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/odoo/src/odoo/odoo/fields.py", line 1083, in __get__
    value = env.cache.get(record, self)
  File "/home/odoo/src/odoo/odoo/api.py", line 902, in get
    raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: 'pos.config(1,).last_session_closing_date'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/odoo/src/odoo/odoo/addons/base/models/ir_http.py", line 242, in _dispatch
    result = request.dispatch()
  File "/home/odoo/src/odoo/odoo/http.py", line 702, in dispatch
    result = self._call_function(**self.params)
  File "/home/odoo/src/odoo/odoo/http.py", line 368, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/odoo/src/odoo/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/odoo/src/odoo/odoo/http.py", line 357, in checked_call
    result = self.endpoint(*a, **kw)
  File "/home/odoo/src/odoo/odoo/http.py", line 925, in __call__
    return self.method(*args, **kw)
  File "/home/odoo/src/odoo/odoo/http.py", line 546, in response_wrap
    response = f(*args, **kw)
  File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 1282, in search_read
    return self.do_search_read(model, fields, offset, limit, domain, sort)
  File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 1301, in do_search_read
    return Model.web_search_read(domain, fields, offset=offset, limit=limit, order=sort)
  File "/home/odoo/src/odoo/addons/web/models/models.py", line 62, in web_search_read
    records = self.search_read(domain, fields, offset=offset, limit=limit, order=order)
  File "/home/odoo/src/odoo/odoo/models.py", line 5091, in search_read
    result = records.read(fields, **read_kwargs)
  File "/home/odoo/src/odoo/odoo/models.py", line 3243, in read
    return self._read_format(fnames=fields, load=load)
  File "/home/odoo/src/odoo/odoo/models.py", line 3263, in _read_format
    vals[name] = convert(record[name], record, use_name_get)
  File "/home/odoo/src/odoo/odoo/models.py", line 5936, in __getitem__
    return self._fields[key].__get__(self, self.env.registry[self._name])
  File "/home/odoo/src/odoo/odoo/fields.py", line 1132, in __get__
    self.compute_value(recs)
  File "/home/odoo/src/odoo/odoo/fields.py", line 1295, in compute_value
    records._compute_field_value(self)
  File "/home/odoo/src/odoo/odoo/models.py", line 4277, in _compute_field_value
    fields.determine(field.compute, self)
  File "/home/odoo/src/odoo/odoo/fields.py", line 88, in determine
    return needle(*args)
  File "/home/odoo/src/odoo/addons/point_of_sale/models/pos_config.py", line 240, in _compute_last_session
    pos_config.last_session_closing_date = session[0]['stop_at'].astimezone(timezone).date()
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/odoo/src/odoo/odoo/http.py", line 658, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/odoo/src/odoo/odoo/http.py", line 301, in _handle_exception
    raise exception.with_traceback(None) from new_cause
AttributeError: 'bool' object has no attribute 'astimezone'

頭像
捨棄
最佳答案

The root cause of the issue is that the code in the _compute_last_session method doesn’t handle cases where session[0]['stop_at'] might be False or missing. Adding a check to ensure session[0]['stop_at'] is a valid datetime object before calling astimezone() should resolve the problem. Additionally, reviewing the POS session data to ensure integrity will help prevent this issue in the future.

頭像
捨棄
最佳答案

Hello Mozamel,


I hope you are doing well.


I wanted to explain the following code snippet:


1 Conditional Check:

- The line session and session[0]['stop_at'] checks if the session list is not empty and verifies that the stop_at key exists in the first dictionary of the list.


2 Time Zone Conversion:


- The expression session[0]['stop_at'].astimezone(timezone) converts the stop_at datetime to the specified timezone.


3 Data Extraction:

- The .date() method extracts only the date part from the datetime object.


The final result is assigned to pos_config.last_session_closing_date. If the session is not valid, it assigns False.


Here's the code for your reference:


//Code in comment//

I hope this helps!


Thanks & Regards,

Email:  odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari

頭像
捨棄

Code :

self.pos_config.last_session_closing_date = (
session[0]['stop_at'].astimezone(timezone).date()
if session and session[0]['stop_at']
else False
)

最佳答案

Hi Mozamel,

You cannot access the session[0]['stop_at'] value directly. Print the result to check the output:

python Copy code print ( '\n session :' , session[ 0 ][ 'stop_at' ])

If the result is False , you need to ensure the condition is set correctly. Verify that session[0]['stop_at'] has the expected value before assigning it:

python Copy code if session[ 0 ][ 'stop_at' ]:
    pos_config.last_session_closing_date = session[ 0 ][ 'stop_at' ].astimezone(timezone).date()

Thanks & Regards,

Name: Yahoo Baba

Email: yahoobaba077@gmail.com

頭像
捨棄