Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Producție
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

Error Field is accesed before being computed.

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
apionchangecompute8.0
6978 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
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!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
ODOO 8.0 @api.onchange problem
onchange 8.0
Imagine profil
Imagine profil
2
mai 17
5002
API 8.0 onchange() and depends() decorators only work for UI changes and 1 record only?
api onchange
Imagine profil
Imagine profil
1
iun. 15
5880
@api.onchange causes looping page redirect 302 Rezolvat
onchange 8.0
Imagine profil
Imagine profil
1
mar. 15
5976
@api.onchange strange behavior in Odoo 8.0 Rezolvat
onchange 8.0
Imagine profil
Imagine profil
Imagine profil
3
mar. 15
5012
How to create chained selection fields in Odoo using API data?
api selection onchange
Imagine profil
Imagine profil
1
oct. 25
622
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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