コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
220 ビュー

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.

アバター
破棄
最善の回答

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

アバター
破棄
著作者 最善の回答

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

アバター
破棄
関連投稿 返信 ビュー 活動
1
8月 25
208
1
8月 25
489
2
7月 25
598
1
7月 25
726
1
8月 25
885