İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
190 Görünümler

Hi, does anyone know if I can use custom fields with python code to calculate taxes? I have tried to update price_tax, but because of base compute_amount calculation it overides the price.

Avatar
Vazgeç
En İyi Yanıt

Odoo 18.0:

Assuming your custom product.product field is x_tax_percent with a value of 0.22:

1. Create a tax like this:

Note the tooltip for the Formula field:


2. An Invoice will then calculate the Tax like this:


See the Python Code section of the documentation at https://www.odoo.com/documentation/18.0/applications/finance/accounting/taxes.html#basic-options

Avatar
Vazgeç
Üretici En İyi Yanıt

I have some percentage on the price list (The field can change based on the pricelist), so I would have to do something to send that field from the pricelist to product.product in order to be available for the formula right? 


The code I have for the field and to get it from pricelist


from odoo import models, fields, api


class ProductProduct(models.Model):

    _inherit = 'product.product'


    fresh_percent = fields.Float(

        string="Porcentaje Fresca (runtime)",

        compute='_compute_fresh_percent',

        store=False

    )


    @api.depends_context('pricelist_id', 'pricelist')

    def _compute_fresh_percent(self):

        """

        Busca el fresh_percent en product.pricelist.item según la lista de precios

        en el contexto (pricelist_id/pricelist). Si no hay, devuelve 0.

        """

        PricelistItem = self.env['product.pricelist.item']

        for prod in self:

            val = 0.0

            pl_id = self._context.get('pricelist_id') or self._context.get('pricelist')

            if pl_id:

                item = PricelistItem.search([

                    ('pricelist_id', '=', pl_id),

                    '|',

                    ('product_id', '=', prod.id),

                    ('product_tmpl_id', '=', prod.product_tmpl_id.id)

                ], limit=1)

                if item and item.fresh_percent:

                    val = item.fresh_percent

            prod.fresh_percent = val



but I get this error: ount.tax/web_save HTTP/1.1" 200 - 5 0.002 0.004

2025-08-29 23:34:40,754 5154 WARNING odoo_dev odoo.http: Fórmula incorrecta "product.fresh_percent*price_unit" en la posición 0

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Ağu 25
204
1
Ağu 25
486
2
Tem 25
594
1
Tem 25
725
1
Ağu 25
881