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 is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Boekhouding
- Voorraad
- PoS
- Project
- MRP
Deze vraag is gerapporteerd
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
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
AanmeldenGerelateerde posts | Antwoorden | Weergaven | Activiteit | |
---|---|---|---|---|
|
1
aug. 25
|
399 | ||
|
1
aug. 25
|
621 | ||
|
2
jul. 25
|
736 | ||
|
1
jul. 25
|
790 | ||
|
1
aug. 25
|
1001 |