Rational
For marketing reasons it should be possible to grant discounts to base prices
and inform customers about the price reduction on sale.
To have a fine-grained control what to discount or not, the feature is
implemented on line level.
The discount can be seen as a ratio between the unit price and the base price and as a difference discount amount between base price and unit price.
Discount is calculated with these formulas:
unit price
a) discount = 1 - ------------
base price
b) unit price = base price * (1 - discount )
c) discount_amount = base price - unit price
= base price * discount
E.g.:
base price = 100
unit price = 90
discount = 0.1
discount amount = 10
The discount is represented in percentage and as an amount.
It is possible to set a discount for sale lines without a product.
When calculating the discount from the unit price and vice versa,
rational numbers are resulted, which needs to be rounded.
Proposal
The feature is implemented in module:
sale_discount depends sale
The sale line gets the new fields discount and base_price.
Field base_price
base_price = fields.numeric(
'Base Price', digits=âŠ, states={
'readonly': Eval('product') | Eval('discount')})
The base price is filled at line creation time with 0.0.
Without a given product the base price is editable by the user,
but then it will be no longer editable, if there is a discount.
On change product the base_price is re-evaluated by a method per default
to the actual list_price of the product.
The base price can be influenced by functionalities provided by separate
modules.
Besides the product list price, the base price could be filled with a:
- price from a price list,
- price from a parent price list (when hierarchy is added),
- price from a catalog price
Field discount
discount = fields.Function(
fields.numeric('Discount', digits=âŠ,
getter='on_change_with_discount', setter='set_discount'))
Because the base price is constant for the same product and constant when
there is a discount, the ratio between unit price and the discount value is
always determined.
It calculates:
* a new discount value by a change of the unit price by formula a)
* a new unit price by a change of the discount value by formula b)
Field discount amount
discount_amount = fields.Function(
fields.numeric('Discount Amount', digits=âŠ,
getter='on_change_with_discount', setter='set_discount'))