Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

Odoo 17 - How to correct total inconsistency?

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
subtotaltotalincorrectodoo17
1 Atsakyti
3968 Rodiniai
Portretas
Aws Dayoub

I have changed the way of computing price_subtotal in sale order line

price_subtotal = number of members * price unit


I tried to override the method that compute the following:

amount_total, amount_untaxed, amount_to_invoice and amount_untaxed_to_invoice But no change


Here is my code:

class SaleOrderLine(models.Model):    _inherit = 'sale.order.line'

    num_members = fields.Integer(string="Number of Members", default=1)    price_subtotal = fields.Monetary(        string="Subtotal",        compute='_compute_amount',        store=True, precompute=True)      @api.depends('num_members', 'price_unit')    def _compute_amount(self):        for line in self:                  line.price_subtotal = line.num_members * line.price_unit            line.price_tax = 0            line.price_total = line.price_subtotal

    def _prepare_invoice_line(self, **optional_vals):        res = super(SaleOrderLine, self)._prepare_invoice_line(**optional_vals)        res['num_members'] = self.num_members

        return res





    @api.depends('state', 'product_id', 'untaxed_amount_invoiced', 'qty_delivered', 'num_members', 'price_unit')    def _compute_untaxed_amount_to_invoice(self):        """ Total of remaining amount to invoice on the sale order line (taxes excl.) as                total_sol - amount already invoiced            where Total_sol depends on the invoice policy of the product.

            Note: Draft invoice are ignored on purpose, the 'to invoice' amount should            come only from the SO lines.        """        for line in self:            amount_to_invoice = 0.0            if line.state == 'sale':                # Note: do not use price_subtotal field as it returns zero when the ordered quantity is                # zero. It causes problem for expense line (e.i.: ordered qty = 0, deli qty = 4,                # price_unit = 20 ; subtotal is zero), but when you can invoice the line, you see an                # amount and not zero. Since we compute untaxed amount, we can use directly the price                # reduce (to include discount) without using `compute_all()` method on taxes.                price_subtotal = 0.0                uom_qty_to_consider = line.qty_delivered if line.product_id.invoice_policy == 'delivery' else line.num_members                price_reduce = line.price_unit * (1 - (line.discount or 0.0) / 100.0)                price_subtotal = price_reduce * uom_qty_to_consider                if len(line.tax_id.filtered(lambda tax: tax.price_include)) > 0:                    # As included taxes are not excluded from the computed subtotal, `compute_all()` method                    # has to be called to retrieve the subtotal without them.                    # `price_reduce_taxexcl` cannot be used as it is computed from `price_subtotal` field. (see upper Note)                    price_subtotal = line.tax_id.compute_all(                        price_reduce,                        currency=line.currency_id,                        quantity=uom_qty_to_consider,                        product=line.product_id,                        partner=line.order_id.partner_shipping_id)['total_excluded']                inv_lines = line._get_invoice_lines()                if any(inv_lines.mapped(lambda l: l.discount != line.discount)):                    # In case of re-invoicing with different discount we try to calculate manually the                    # remaining amount to invoice                    amount = 0                    for l in inv_lines:                        if len(l.tax_ids.filtered(lambda tax: tax.price_include)) > 0:                            amount += l.tax_ids.compute_all(l.currency_id._convert(l.price_unit, line.currency_id, line.company_id, l.date or fields.Date.today(), round=False) * l.quantity)['total_excluded']                        else:                            amount += l.currency_id._convert(l.price_unit, line.currency_id, line.company_id, l.date or fields.Date.today(), round=False) * l.quantity

                    amount_to_invoice = max(price_subtotal - amount, 0)                else:                    amount_to_invoice = price_subtotal - line.untaxed_amount_invoiced

            line.untaxed_amount_to_invoice = amount_to_invoice            print('YYYYYYYYYYYYYYYYYYYYYYYYY')            print('_compute_untaxed_amount_to_invoice', line.untaxed_amount_to_invoice)



class SaleOrder(models.Model):    _inherit = 'sale.order'


    amount_untaxed = fields.Monetary(string="Untaxed Amount", store=True, compute='_compute_amounts', tracking=5)    amount_total = fields.Monetary(string="Total", store=True, compute='_compute_amounts', tracking=4)    amount_to_invoice = fields.Monetary(string="Amount to invoice", store=True, compute='_compute_amount_to_invoice')

    @api.onchange('order_line.price_subtotal')    @api.depends('order_line.price_subtotal', 'order_line.price_tax', 'order_line.price_total')    def _compute_amounts(self):   #     super(SaleOrder, self)._compute_amounts()        for order in self:            amount_untaxed = 0            for line in order.order_line:                amount_untaxed += line.price_subtotal            order.amount_tax = 0            order.amount_untaxed = amount_untaxed            order.amount_total = amount_untaxed            print('TTTTTTTTTTTTTTTTTTTTTTTTTTGGGGGGGGGGGG')            print('amount_total', order.amount_total)

        #@api.depends('invoice_ids.state', 'currency_id', 'amount_total')    @api.depends('amount_total')    def _compute_amount_to_invoice(self):        for order in self:            order.amount_to_invoice = 99999            print('FFFFFFFFFFFFFEEEEEEEEEEEEEEEEE')            print("amount_to_invoice", order.amount_to_invoice)            '''            # If the invoice status is 'Fully Invoiced' force the amount to invoice to equal zero and return early.            if order.invoice_status == 'invoiced':                order.amount_to_invoice = 0.0                continue

            invoices = order.invoice_ids.filtered(lambda x: x.state == 'posted')            # Note: A negative amount can happen, since we can invoice more than the sales order amount.            # Care has to be taken when summing amount_to_invoice of multiple orders.            # E.g. consider one invoiced order with -100 and one uninvoiced order of 100: 100 + -100 = 0            order.amount_to_invoice = order.amount_total - invoices._get_sale_order_invoiced_amount(order)  


          '''


class AccountMoveLine(models.Model):    _inherit = 'account.move.line'

        num_members = fields.Integer(string="Number of Members", default=1, store=True, compute='_compute_num_members_from_sale_order')    price_subtotal = fields.Monetary(string='Subtotal', store=True, compute='_compute_price_subtotal')


    @api.depends('move_id', 'move_id.invoice_line_ids')    def _compute_num_members_from_sale_order(self):        for line in self:            sale_order_line = line.sale_line_ids            if sale_order_line:                line.num_members = sale_order_line.num_members             else:                line.num_members = 1              print('MEEEEEEEEEEEEMMMMMMMMMMMMM')


    @api.depends('num_members', 'price_unit', 'discount')    def _compute_price_subtotal(self):        for line in self:            print('PPPPPPPPRRRRRRRRRRRRRRIIIIICCCCCCCCCCEEEEEEEEEEEE')            print('num_members:', line.num_members)            price = line.num_members * line.price_unit             line.price_subtotal = line.move_id.currency_id.round(price)            #line.write({'price_subtotal': line.move_id.currency_id.round(price)})            print('FFFFFFFFFFFFGGGGGGGGGGGGGGGGG')





0
Portretas
Atmesti
Niyas Raphy (Walnut Software Solutions)

Could you add your full code here

Portretas
Gracious Joseph
Best Answer

To resolve the issue of total inconsistency in Odoo 17 when modifying the computation of price_subtotal in the sale.order.line, you need to ensure that the computations for related fields like amount_total, amount_untaxed, and others are consistently overridden and stored properly. Here's how to resolve this step by step:

Key Points to Address

  1. Incorrect or Missing Dependencies:
    • Fields like price_subtotal or amount_total need proper dependency tracking to trigger re-computation.
  2. Consistency Between Models:
    • The custom logic must align across sale.order, sale.order.line, and account.move.line to avoid mismatch issues.

Corrected Implementation

1. Sale Order Line Customization

Modify the price_subtotal computation in the sale.order.line.

from odoo import models, fields, api

class SaleOrderLine(models.Model):
    _inherit = 'sale.order.line'

    num_members = fields.Integer(string="Number of Members", default=1)
    price_subtotal = fields.Monetary(
        string="Subtotal", 
        compute='_compute_amount', 
        store=True
    )

    @api.depends('num_members', 'price_unit', 'product_uom_qty', 'discount', 'tax_id')
    def _compute_amount(self):
        for line in self:
            # Compute subtotal based on number of members
            line.price_subtotal = line.num_members * line.price_unit * (1 - (line.discount or 0.0) / 100.0)
            # Compute taxes (if needed)
            taxes = line.tax_id.compute_all(
                line.price_unit,
                line.order_id.currency_id,
                quantity=line.num_members,
                product=line.product_id,
                partner=line.order_id.partner_shipping_id
            ) if line.tax_id else {'total_excluded': 0.0, 'total_included': 0.0}

            line.price_tax = taxes['total_included'] - taxes['total_excluded']
            line.price_total = taxes['total_included']

2. Sale Order Customization

Update the amount_total and amount_untaxed computations in the sale.order model.

class SaleOrder(models.Model):
    _inherit = 'sale.order'

    amount_untaxed = fields.Monetary(
        string="Untaxed Amount", 
        store=True, 
        compute='_compute_amounts'
    )
    amount_total = fields.Monetary(
        string="Total", 
        store=True, 
        compute='_compute_amounts'
    )
    amount_tax = fields.Monetary(
        string="Taxes", 
        store=True, 
        compute='_compute_amounts'
    )

    @api.depends('order_line.price_subtotal', 'order_line.price_tax')
    def _compute_amounts(self):
        for order in self:
            amount_untaxed = sum(line.price_subtotal for line in order.order_line)
            amount_tax = sum(line.price_tax for line in order.order_line)
            order.update({
                'amount_untaxed': amount_untaxed,
                'amount_tax': amount_tax,
                'amount_total': amount_untaxed + amount_tax,
            })

3. Account Move Line Customization

Ensure the computation is consistent in the account.move.line for proper invoicing.

class AccountMoveLine(models.Model):
    _inherit = 'account.move.line'

    num_members = fields.Integer(
        string="Number of Members", 
        default=1, 
        compute='_compute_num_members_from_sale_order', 
        store=True
    )
    price_subtotal = fields.Monetary(
        string='Subtotal', 
        store=True, 
        compute='_compute_price_subtotal'
    )

    @api.depends('sale_line_ids', 'sale_line_ids.num_members')
    def _compute_num_members_from_sale_order(self):
        for line in self:
            sale_order_line = line.sale_line_ids[:1]  # Get the first linked sale order line
            line.num_members = sale_order_line.num_members if sale_order_line else 1

    @api.depends('num_members', 'price_unit', 'discount')
    def _compute_price_subtotal(self):
        for line in self:
            price = line.num_members * line.price_unit * (1 - (line.discount or 0.0) / 100.0)
            line.price_subtotal = line.move_id.currency_id.round(price)

4. Update Invoice Preparation

Ensure that the num_members field is included when preparing the invoice line.

class SaleOrderLine(models.Model):
    _inherit = 'sale.order.line'

    def _prepare_invoice_line(self, **optional_vals):
        invoice_line_vals = super(SaleOrderLine, self)._prepare_invoice_line(**optional_vals)
        invoice_line_vals['num_members'] = self.num_members
        return invoice_line_vals

5. Common Troubleshooting Tips

  1. Check Stored Fields:
    • Ensure all computed fields have store=True to persist values and trigger dependent computations.
  2. Recompute and Update:
    • After updating the models, trigger a recompute for existing records:
      odoo shell
      SaleOrder = env['sale.order']
      SaleOrderLine = env['sale.order.line']
      SaleOrderLine._compute_amount()
      SaleOrder._compute_amounts()
      
  3. Check Dependencies:
    • Verify that all dependent fields (e.g., num_members, price_unit) are included in the @api.depends() decorators.
  4. Validate Tax Calculations:
    • If taxes are included, ensure tax_id.compute_all() is called correctly in both the sale order line and account move line computations.

Key Changes

  • Subtotal Calculation: Updated in sale.order.line based on num_members.
  • Total Calculation: Updated in sale.order to reflect the modified subtotals and taxes.
  • Invoicing Consistency: Synchronized num_members and price_subtotal across sale.order.line and account.move.line.

By implementing these changes, you should resolve the inconsistency issues for totals in Odoo 17. Let me know if you encounter further challenges!

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

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

Registracija
Related Posts Replies Rodiniai Veikla
I have changed the way of computing price subtotal in sale.order.line but now the total and total untaxed is not correct
subtotal total untaxed odoo17
Portretas
0
gruod. 24
2143
How to Add "Subtotal & Total" in Report?
subtotal report total studio
Portretas
Portretas
1
vas. 22
6551
Error while posting invoice to ZATCA odoo sh Solved
odoo17
Portretas
Portretas
Portretas
Portretas
3
liep. 25
3119
How to send a real-time notification to POS UI using bus.bus in Odoo 17?
odoo17
Portretas
Portretas
1
birž. 25
5303
Odoo time-sheets rights to add
odoo17
Portretas
Portretas
2
geg. 25
3072
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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