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
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
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
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
1
thg 8 25
|
247 | ||
|
1
thg 8 25
|
505 | ||
|
2
thg 7 25
|
626 | ||
|
1
thg 7 25
|
740 | ||
|
1
thg 8 25
|
892 |