Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Real Estate
    • Real Estate Agency
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consulting
    • Accounting Firm
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Solar Energy Systems
    • Shoe Maker
    • Serveis de neteja
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Error Field is accesed before being computed.

Subscriure's

Get notified when there's activity on this post

This question has been flagged
apionchangecompute8.0
6990 Vistes
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
Descartar
Deepa Venkatesh

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

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
ODOO 8.0 @api.onchange problem
onchange 8.0
Avatar
Avatar
2
de maig 17
5018
API 8.0 onchange() and depends() decorators only work for UI changes and 1 record only?
api onchange
Avatar
Avatar
1
de juny 15
5902
@api.onchange causes looping page redirect 302 Solved
onchange 8.0
Avatar
Avatar
1
de març 15
5993
@api.onchange strange behavior in Odoo 8.0 Solved
onchange 8.0
Avatar
Avatar
Avatar
3
de març 15
5039
How to create chained selection fields in Odoo using API data?
api selection onchange
Avatar
Avatar
1
d’oct. 25
641
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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