Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
371 มุมมอง
I added a field to the product listings to calculate the profit margin. I use this formula:

for record in self:

record['x_studio_margen_de_utilidad'] = (record.list_price - record.standard_price) / record.list_price

What condition should I apply to the field to avoid errors in the database?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

I’d start by ensuring the universe doesn’t implode over a zero or negative list price—so, my first condition would be record.list_price > 0. After all, I'm not in the business of selling products with prices less than or equal to zero (unless we’ve entered some alternate dimension of reverse economics). Plus, dividing by zero isn’t just bad math; it’s a straight-up party pooper for your database. So, let’s keep things sensible and error-free!

And I guess sometimes you can sell product without any inventory which may result in standard price of 0 and the margin of 100%. 

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
มี.ค. 25
379
0
ก.พ. 25
350
3
ส.ค. 24
4336
1
เม.ย. 24
33
Modify field only if admin. แก้ไขแล้ว
3
เม.ย. 24
1393