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

Error Field is accesed before being computed.

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
apionchangecompute8.0
6982 Widoki
Awatar
Artur Bertram

I've written a custom modul which adds percent discount and fix discount to the invoice. Now i have rewrite it, so that it uses the new api, but every time i chage the selection field, I get the error "Warning: Field account.invoice.amount_untaxed is accessed before being computed.". There is an onchange event on that selection field and if I remove it, the error isn't occurring.

To me it looks like the onchange event is trying to get the compute field before it is set.

Code following.

modul.py

import itertools
from lxml import etree

from openerp import models, fields, api, _
from openerp.exceptions import except_orm, Warning, RedirectWarning
import openerp.addons.decimal_precision as dp


class eq_account_invoice(models.Model):
    _inherit = ['account.invoice']
    _name= "account.invoice"
    
    @api.one
    @api.depends('invoice_line.price_subtotal', 'tax_line.amount',)
    def _compute_amount(self):
        if self.eq_percent_discount:
            self.amount_tax = sum(line.amount for line in self.tax_line) * (1 - ((self.eq_percent_discount or 0) / 100))
            self.amount_untaxed = sum(line.price_subtotal for line in self.invoice_line)
            self.eq_amount_discount = self.amount_untaxed * ((self.eq_percent_discount or 0) / 100)
            self.eq_amount_net = self.amount_untaxed - self.eq_amount_discount
            self.amount_total = self.eq_amount_net + self.amount_tax
        elif self.eq_fix_discount:
            self.amount_untaxed = sum(line.price_subtotal for line in self.invoice_line)
            self.amount_discount = eq_fix_discount
            self.eq_amount_net = self.amount_untaxed - self.eq_amount_discount
            self.amount_tax = sum(line.amount for line in self.tax_line) + self.eq_amount_net / self.amount_untaxed
            self.amount_total = self.eq_amount_net + self.amount_tax
        else:
            self.amount_untaxed = sum(line.price_subtotal for line in self.invoice_line)
            self.amount_tax = sum(line.amount for line in self.tax_line)
            self.amount_total = self.amount_untaxed + self.amount_tax
        
    eq_discount_type = fields.Selection((('1', 'Percent'), ('2', 'Fixed'), ), 'Type', readonly=True, states={'draft': [('readonly', False)]})
    eq_percent_discount = fields.Float("Percentage", readonly=True, states={'draft': [('readonly', False)]})
    eq_fix_discount = fields.Float("Fixed", readonly=True, states={'draft': [('readonly', False)]})
    
    eq_amount_discount = fields.Float(string='Discount', digits=dp.get_precision('Account'),
        store=True, readonly=True, compute='_compute_amount')
    eq_amount_net = fields.Float(string='Net Amount', digits=dp.get_precision('Account'),
        store=True, readonly=True, compute='_compute_amount')
    amount_untaxed = fields.Float(string='Subtotal', digits=dp.get_precision('Account'),
        store=True, readonly=True, compute='_compute_amount', track_visibility='always')
    amount_tax = fields.Float(string='Tax', digits=dp.get_precision('Account'),
        store=True, readonly=True, compute='_compute_amount')
    amount_total = fields.Float(string='Total', digits=dp.get_precision('Account'),
        store=True, readonly=True, compute='_compute_amount')

    @api.one
    def on_change_discount_type(self):
        result = {'value': {
            'eq_fix_discount': False,
            'eq_percent_discount': False
        }}
        return result

modul_view.xml

<openerp>
    <data>

        <record id="eq_invoice_record_additional_discount" model="ir.ui.view">
            <field name="name">account.invoice.form</field>
            <field name="model">account.invoice</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="account.invoice_form"/>
            <field name="arch" type="xml">
                <xpath expr="//page[@string='Invoice Lines']//group[@class='oe_subtotal_footer oe_right']" position="replace">
                    <group colspan="2" col="4">
                        <group colspan="2">
                            <h3>
                            <label string="Discount" class="oe_inline"/>
                            </h3>
                            <newline/>
                            <field name="eq_discount_type" style="width:50%%" on_change="on_change_discount_type()"/>
                            <field name="eq_percent_discount" style="width:25%%" attrs="{'invisible':[('eq_discount_type', '!=', '1')]}"/>
                            <field name="eq_fix_discount" style="width:50%%" widget='monetary' options="{'currency_field': 'currency_id'}" attrs="{'invisible':[('eq_discount_type', '!=', '2')]}"/>
                        </group>
                        <group class="oe_subtotal_footer oe_right" colspan="2" name="sale_total">
                            <field name="amount_untaxed" widget='monetary' options="{'currency_field': 'currency_id'}"/>
                            <field name="eq_amount_discount" widget='monetary' options="{'currency_field': 'currency_id'}"/>
                            <field name="eq_amount_net" widget='monetary' options="{'currency_field': 'currency_id'}"/>
                            <field name="amount_tax" widget='monetary' options="{'currency_field': 'currency_id'}"/>
                            <div class="oe_subtotal_footer_separator oe_inline">
                                <label for="eq_amount_total"/>
                                <button name="button_reset_taxes" states="draft,proforma2" string="(update)" class="oe_link oe_edit_only" type="object" help="Recompute taxes and total"/>
                            </div>
                            <field name="amount_total" nolabel="1" class="oe_subtotal_footer_separator" widget='monetary' options="{'currency_field': 'currency_id'}"/>
                            <field name="residual" groups="account.group_account_user" widget="monetary" options="{'currency_field': 'currency_id'}"/>
                            <field name="reconciled" invisible="1"/>
                        </group>
                    </group>
                </xpath>
            </field>
        </record>
    </data>
</openerp>

Am i doing something wrong, or is it just an bug in the new api?

0
Awatar
Odrzuć
Deepa Venkatesh

Even I had faced same issue, i renamed the function field, and initialized all values to Zero first.. then proceeded with logic

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ść
ODOO 8.0 @api.onchange problem
onchange 8.0
Awatar
Awatar
2
maj 17
5012
API 8.0 onchange() and depends() decorators only work for UI changes and 1 record only?
api onchange
Awatar
Awatar
1
cze 15
5898
@api.onchange causes looping page redirect 302 Rozwiązane
onchange 8.0
Awatar
Awatar
1
mar 15
5989
@api.onchange strange behavior in Odoo 8.0 Rozwiązane
onchange 8.0
Awatar
Awatar
Awatar
3
mar 15
5032
How to create chained selection fields in Odoo using API data?
api selection onchange
Awatar
Awatar
1
paź 25
640
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