Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
368 Tampilan
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?

Avatar
Buang
Jawaban Terbai

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%. 

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
0
Mar 25
378
0
Feb 25
349
3
Agu 24
4334
1
Apr 24
33
3
Apr 24
1390