Skip to Content
Menu
This question has been flagged
1 Reply
3053 Views

Good afternoon,

You are trying to round the price_subtotal to 6 decimal places, I am trying to redefine the field, but it always appears rounded.

Where can I make the field, the change has to be by code so that it does not affect the configuration of other fields.

Thanks a lot

I see that it is a question that is asked very often but there is not much information.

**the rounding change must be by python code.

My code is:

class AccountInvoiceLine(models.Model):

    _inherit = "account.invoice.line"

    price_subtotal=fields.Float("Precio Unitario",digits=(12,6),readonly=False) 

    @api.one

    @api.depends(

        'discount', 'invoice_line_tax_ids','quantity',

        'invoice_id.partner_id', 'invoice_id.currency_id', 'price_unit',

        'invoice_id.company_id','invoice_id.date_invoice','discount'

        )

    def _compute_price(self):

        price=0.000000

        taxes = False

        tasa=1+(self.invoice_line_tax_ids[0].amount/100)

        if self.invoice_line_tax_ids[0].price_include:

            self.price_unit=(self.price_unit2-( (self.price_unit2*self.discount/100)+self.descuento_unitario) ) 

            price=self.price_unit

            taxes = self.invoice_line_tax_ids.compute_all(price*tasa,currency, self.quantity, product=self.product_id,partner=self.invoice_id.partner_id )

        else:

            self.price_unit=(self.price_unit2-( (self.price_unit2*self.discount/100)+self.descuento_unitario) )*((100-self.invoice_id.descuento_global)/100)

            price=self.price_unit

            taxes = self.invoice_line_tax_ids.compute_all(price,currency, self.quantity, product=self.product_id,partner=self.invoice_id.partner_id )

        self.price_unit=price

        self.price_subtotal =taxes['total_excluded'] if taxes else self.quantity *price 

expected result:

quantity=3

price_unit=55.356

tax1=15

tax2=13

price_subtotal=55.356*3=166.068 (line value, not rounded)


Avatar
Discard
Best Answer

Hello GiancaFTx


You can use the rounding method of python.

subtotal = taxes['total_excluded'] if taxes else self.quantity *price

self.price_subtotal = round(subtotal,6)


See the example below:


>>> x = 12.3652894515

>>> y = round(x,6)

>>> print (y)


12.365289


FYI this example is of python 3 you can use this for lower versions also.

Regards,




Email:   odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

   

Avatar
Discard
Author

Hello,

Thanks for the reply.

try that, but as much as I round it to 6 decimal places, it always rounds to 2 decimal places (coin rounding setting).

I don't change the rounding of the coin to 6, because doing so changes the rounding for all totals and other settings.

changing the definition of the field to 6 and with the additional rounding is not reflected. There is another parameter that the system uses for the price_subtotal.

Hello GiancaFTx,

Can you please share which version of odoo you are using for this customization?

Author

hi, the version is odoo11