Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

[Odoo 10] .write() stop working and rise error value = self._recs.env.cache[field][self._recs.id]

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
pythonrecordsodoo10self.write
5 Odpowiedzi
9820 Widoki
Awatar
FEDERICO LEONI

After almost a year I decided to update my Python code inside Odoo 10. I've a custom module writing on a different model:

from odoo import api, fields, models
import openerp.addons.decimal_precision as dp
import logging

_logger = logging.getLogger(__name__)

class AccountDivina(models.Model):
_inherit = ['account.bank.statement.line']

taxes = fields.Float(
'Taxes', compute='_compute_taxes', store=True, digits=(5, 2), default='0.00')

@api.multi
@api.depends('journal_id')
def _compute_taxes(self):

ptx = self.env['pos.config'].search([('id', '=', 1)])
acj = self.env['account.journal']

if self.journal_id.id == acj.search([('code', '=', 'CR01')]).id:
self.taxes = ((self.amount / 100) * ptx.cr_tax)
elif self.journal_id.id == acj.search([('code', '=', 'DB01')]).id:
self.taxes = ((self.amount / 100) * ptx.db_tax)

pos_tax = self.env['pos.order'].search([('id', '=', self.pos_statement_id.id)])
new_val = pos_tax.taxes + self.taxes
print self.pos_statement_id.id
print pos_tax, pos_tax.taxes, new_val, pos_tax.margin
pos_tax.write({'taxes': new_val})
self.env.cr.commit()

I can search and browse with no issues other models, but suddenly the write function stop working, and I don't remember if and when I change the code. 
The log: 

2019-01-23 10:34:09,005 11925 ERROR divina_test6 odoo.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/opt/odoo/odoo/http.py", line 641, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo/http.py", line 683, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/odoo/http.py", line 333, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo/service/model.py", line 101, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo/http.py", line 326, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo/odoo/http.py", line 941, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo/http.py", line 506, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/addons/web/controllers/main.py", line 892, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/opt/odoo/addons/web/controllers/main.py", line 884, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo/odoo/api.py", line 687, in call_kw
    return call_kw_model(method, model, args, kwargs)
  File "/opt/odoo/odoo/api.py", line 672, in call_kw_model
    result = method(recs, *args, **kwargs)
  File "/opt/odoo/addons/point_of_sale/models/pos_order.py", line 609, in create_from_ui
    pos_order = self._process_order(order)
  File "/opt/odoo/addons/point_of_sale/models/pos_order.py", line 115, in _process_order
    order.add_payment(self._payment_fields(payments[2]))
  File "/opt/odoo/addons/point_of_sale/models/pos_order.py", line 818, in add_payment
    self.env['account.bank.statement.line'].with_context(context).create(args)
  File "/opt/odoo/addons/account/models/account_bank_statement.py", line 393, in create
    line = super(AccountBankStatementLine, self).create(vals)
  File "/opt/odoo/odoo/models.py", line 3847, in create
    record = self.browse(self._create(old_vals))
  File "/opt/odoo/odoo/models.py", line 4006, in _create
    self.recompute()
  File "/opt/odoo/odoo/models.py", line 5336, in recompute
    vals = rec._convert_to_write({n: rec[n] for n in ns})
  File "/opt/odoo/odoo/models.py", line 5336, in <dictcomp>
    vals = rec._convert_to_write({n: rec[n] for n in ns})
  File "/opt/odoo/odoo/models.py", line 5232, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "/opt/odoo/odoo/fields.py", line 918, in __get__
    value = record._cache[self]
  File "/opt/odoo/odoo/models.py", line 5583, in __getitem__
    value = self._recs.env.cache[field][self._recs.id]

Using some print statement in my code I can clearly see the fields/values I need are present, simply I can't update them on model.

For now I'm backing using the cursor

new_val = pos_tax.taxes + self.taxes
new_margin = pos_tax.margin - new_val

sql_wrt_cst = 'UPDATE pos_order SET (taxes, margin) = (%s, %s) WHERE id = %s'
self.env.cr.execute(sql_wrt_cst, [new_val, new_margin, self.pos_statement_id.id])
self.env.cr.commit()

But I would like to migrate to the new method.

 Any clue for me?

F.

0
Awatar
Odrzuć
Awatar
Ibrahim Boudmir
Najlepsza odpowiedź
Hi, please try this:

@api.multi
@api.depends('journal_id')
def _compute_taxes(self):
ptx = self.env['pos.config'].search([('id', '=', 1)]) // should not be static
acj = self.env['account.journal']
for record in self:
if record.journal_id.id == acj.search([('code', '=', 'CR01')]).id:
record.taxes = ((record.amount / 100) * ptx.cr_tax)
elif record.journal_id.id == acj.search([('code', '=', 'DB01')]).id:
record.taxes = ((record.amount / 100) * ptx.db_tax)
@api.multi
def _write(self, vals):
res = super(AccountDivina, self)._write(vals)
for record in self:
record.set_pos_taxes(vals, record)
return res

def set_pos_taxes(self, vals, record): if vals.get('journal_id'): pos_tax = self.env['pos.order'].browse(record.pos_statement_id.id) new_val = pos_tax.taxes + record.taxes pos_tax.write({'taxes': new_val})


--- UPDATE ---
In order to understand well, you need to check how compute functions are written and what for. Yenthe's answer to this post may be helpful :
https://www.odoo.com/fr_FR/forum/aide-1/question/v12-api-one-vs-api-multi-in-calculated-field-144646
don't change other values than those related to your compute function.
That's why i have divided your function into two :
1- Your compputed field is the only field that will be calculated in your compute function.
2- the orther part of code will be placed in _write function: Now in this function, the new value of the compute
field will be taken into consideration, and not the old value. The new one that you need to update your taxes
from pos_order model.
set_pos_taxes() is just for code quality. 

I hope this may be helpful to understand my solution.
1
Awatar
Odrzuć
FEDERICO LEONI
Autor

Although your reply is virtually perfect for my specific issue, I would like to see a little comment by you on how do you end up with this solution. Not just for me, but for the sake of knowledge. Thanks.

Ibrahim Boudmir

You can read the UPDATE part where i explained the solution.

FEDERICO LEONI
Autor

Yes, much clear now.

Again, I tough could be useful have a little description to let other people trapped in this issue to understand the logic.

Thanks again.

Awatar
thomas
Najlepsza odpowiedź
Hi Ibrahim Boudmir .

I have a similar issue :

value = self._recs.env.cache[field][self._recs.id] KeyError: <odoo.models.NewId object at 0x7fbd7de98dd0>

I created a custom module and a new class 'pickingprocess' 

I have a compute method which is active when i change something on my input input_action (it works).


class PickingProcess(models.Model):
     _inherit = "mail.thread"
    _name = 'picking.process'

    input_action = fields.Char("Action")
    input_action2 = fields.Char("Action2", store=True, compute="_inputact")

    @api.multi
    @api.depends('input_action')
    def _inputact(self):
        for record in self:
             if record.input_action == False or record.input_action =="":
                    return    
#record.input_action2 = record.input_action doesn t work , it don t go through the write method why??
             record.write({"input_action2":record.input_action})

    @api.multi
    def write(self,vals):
            _logger.error("write !!")
             return super(PickingProcess, self).write(vals)

First thing, i tried to use record.myattribute = 'toto' but it doesn t work . All the time i need to use the write({...}). Do you know why ? 

Then my second issue is the same as Federico Leoni. I have this : 

  value = self._recs.env.cache[field][self._recs.id] KeyError: <odoo.models.NewId object at 0x7fbd7de98dd0>

Of course in my write method after fix this issue , i would like to do external things on others models...  :) 


Thanks by advance 


Thomas


0
Awatar
Odrzuć
Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
error ConfigParser.ParsingError: File contains parsing errors
python odoo10
Awatar
0
mar 21
7635
how to pass parameters using with_context ? Rozwiązane
python odoo10
Awatar
Awatar
3
lip 20
22279
odoo/python invalidate_all() Rozwiązane
python odoo10
Awatar
Awatar
Awatar
2
sty 19
8283
Function Python for Odoo 10
python odoo10
Awatar
Awatar
1
gru 18
3772
calculate expiration date from production date and duration
python odoo10
Awatar
Awatar
1
lip 18
8187
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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