Zum Inhalt springen
Odoo Menü
  • Anmelden
  • Jetzt gratis testen
  • Apps
    Finanzen
    • Buchhaltung
    • Rechnungsstellung
    • Spesenabrechnung
    • Tabellenkalkulation (BI)
    • Dokumente
    • E-Signatur
    Vertrieb
    • CRM
    • Vertrieb
    • Kassensystem – Shop
    • Kassensystem – Restaurant
    • Abonnements
    • Vermietung
    Websites
    • Website-Builder
    • E-Commerce
    • Blog
    • Forum
    • Livechat
    • E-Learning
    Lieferkette
    • Lager
    • Fertigung
    • PLM
    • Einkauf
    • Wartung
    • Qualität
    Personalwesen
    • Mitarbeiter
    • Personalbeschaffung
    • Abwesenheiten
    • Mitarbeiterbeurteilung
    • Personalempfehlungen
    • Fuhrpark
    Marketing
    • Social Marketing
    • E-Mail-Marketing
    • SMS-Marketing
    • Veranstaltungen
    • Marketing-Automatisierung
    • Umfragen
    Dienstleistungen
    • Projekte
    • Zeiterfassung
    • Außendienst
    • Kundendienst
    • Planung
    • Termine
    Produktivität
    • Dialog
    • Genehmigungen
    • IoT
    • VoIP
    • Wissensdatenbank
    • WhatsApp
    Apps von Drittanbietern Odoo Studio Odoo Cloud-Plattform
  • Branchen
    Einzelhandel
    • Buchladen
    • Kleidergeschäft
    • Möbelhaus
    • Lebensmittelgeschäft
    • Baumarkt
    • Spielwarengeschäft
    Essen & Gastgewerbe
    • Bar und Kneipe
    • Restaurant
    • Fast Food
    • Gästehaus
    • Getränkehändler
    • Hotel
    Immobilien
    • Immobilienagentur
    • Architekturbüro
    • Baugewerbe
    • Immobilienverwaltung
    • Gartenarbeit
    • Eigentümervereinigung
    Beratung
    • Buchhaltungsfirma
    • Odoo-Partner
    • Marketingagentur
    • Anwaltskanzlei
    • Talentakquise
    • Prüfung & Zertifizierung
    Fertigung
    • Textil
    • Metall
    • Möbel
    • Speisen
    • Brauerei
    • Firmengeschenke
    Gesundheit & Fitness
    • Sportklub
    • Brillengeschäft
    • Fitnessstudio
    • Therapeut
    • Apotheke
    • Friseursalon
    Handel
    • Handyman
    • IT-Hardware & -Support
    • Solarenergiesysteme
    • Schuster
    • Reinigungsdienstleistungen
    • HLK-Dienstleistungen
    Sonstiges
    • Gemeinnützige Organisation
    • Umweltschutzagentur
    • Plakatwandvermietung
    • Fotostudio
    • Fahrrad-Leasing
    • Software-Händler
    Alle Branchen ansehen
  • Community
    Lernen
    • Tutorials
    • Dokumentation
    • Zertifizierungen
    • Schulung
    • Blog
    • Podcast
    Bildung fördern
    • Bildungsprogramm
    • Scale-Up! Planspiel
    • Odoo besuchen
    Software anfragen
    • Herunterladen
    • Editionen vergleichen
    • Releases
    Zusammenarbeiten
    • Github
    • Forum
    • Veranstaltungen
    • Übersetzungen
    • Partner werden
    • Dienstleistungen für Partner
    • Buchhaltungsfirma registrieren
    Services anfragen
    • Partner finden
    • Buchhalter finden
    • Einen Experten treffen
    • Implementierungsservices
    • Kundenreferenzen
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Eine Demo erhalten
  • Preiskalkulation
  • Hilfe

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

  • CRM
  • e-Commerce
  • Buchhaltung
  • Lager
  • PoS
  • Projekte
  • MRP
All apps
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Hilfe

Error Field is accesed before being computed.

Abonnieren

Erhalten Sie eine Benachrichtigung, wenn es eine Aktivität zu diesem Beitrag gibt

Diese Frage wurde gekennzeichnet
apionchangecompute8.0
6987 Ansichten
Avatar
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
Avatar
Verwerfen
Deepa Venkatesh

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

Diskutieren Sie gerne? Treten Sie bei, statt nur zu lesen!

Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!

Registrieren
Verknüpfte Beiträge Antworten Ansichten Aktivität
ODOO 8.0 @api.onchange problem
onchange 8.0
Avatar
Avatar
2
Mai 17
5016
API 8.0 onchange() and depends() decorators only work for UI changes and 1 record only?
api onchange
Avatar
Avatar
1
Juni 15
5900
@api.onchange causes looping page redirect 302 Gelöst
onchange 8.0
Avatar
Avatar
1
März 15
5992
@api.onchange strange behavior in Odoo 8.0 Gelöst
onchange 8.0
Avatar
Avatar
Avatar
3
März 15
5035
How to create chained selection fields in Odoo using API data?
api selection onchange
Avatar
Avatar
1
Okt. 25
640
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Herunterladen
  • Github
  • Runbot
  • Übersetzungen
Dienstleistungen
  • Odoo.sh-Hosting
  • Support
  • Upgrade
  • Individuelle Entwicklungen
  • Ausbildung
  • Buchhalter finden
  • Partner finden
  • Partner werden
Über uns
  • Unsere Firma
  • Markenwerte
  • Kontakt
  • Karriere
  • Veranstaltungen
  • Podcast
  • Blog
  • Kunden
  • Rechtliches • Datenschutz
  • Sicherheit
الْعَرَبيّة 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 ist eine Suite von Open-Source-Betriebsanwendungen, die alle Bedürfnisse Ihres Unternehmens abdecken: CRM, E-Commerce, Buchhaltung, Lager, Kassensystem, Projektmanagement etc.

Das einzigartige Wertversprechen von Odoo ist, dass es gleichzeitig sehr einfach zu bedienen und voll integriert ist.

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