In 'purchase.order.line' model , I want to change the decimal precision for the 'unit_price' and 'price_subtotal' fields
These fields should have a precision of 4 digits and are displayed in the purchase order_line.
Here is my code :
class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"
price_unit = fields.Float(string='Unit Price', required=True, digits=(16, 4))
price_subtotal = fields.Monetary(compute='_compute_amount', string='Subtotal', store=True, digits = (16, 4))
I only got the field 'price_unit' with 4 digits , but nothing changing for 'price_subtotal'. Is it because of computed field?
How can I fix it please?
Thanks.
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ờ
You can do this at the UI level, you don't need to modify the code, see https://www.odoo.com/forum/help-1/decimal-accuracy-for-a-custom-studio-float-field-168259#answer-168268
I created a new Decimal Accuracy with named 'purchase' and digitis = 4 , I update the code to : price_subtotal = fields.Monetary(compute='_compute_amount', string='Subtotal', store=True, digits = 'purchase') , but doesn't work , @Ray Carnes (ray)
I see now you are referencing a MONETARY field. You are better making your own float field as the decimal precision is defined by the `currency_field` attribute. See the documentation at https://www.odoo.com/documentation/14.0/developer/reference/orm.html?highlight=monetary#odoo.fields.Monetary
@Ray Carnes (ray) , can you give me an example please , how to redefine the field price_subtotal in 'purchase.order.line' model
You should NOT redefine the field. Create your own. The value of YOUR field can be taken from the original, and shown in any precision you decide.
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 | |
---|---|---|---|---|
|
2
thg 8 24
|
6543 | ||
|
1
thg 10 22
|
24267 | ||
|
2
thg 9 21
|
12965 | ||
|
1
thg 8 21
|
8463 | ||
|
1
thg 7 21
|
4455 |
It's because of monetary field. Monetary field takes decimal places from Decimal Places defined in currency.
Either you should use float field or use decimal places from currency.