Skip to Content
Menu
This question has been flagged
1 Reply
1244 Views

Hi everyone,


Does anything exist like this https://www.thatsoftwareguy.com/zencart_table_discounts.html


We need a tiered discounting based on the category of a product and the quantity. 


Category A pricing

1-49 pieces = 1.00 each

50-99 pieces = 0.90 each

100+ = 0.75 each


Product 1 and Product 2 are in Category A.


Customer orders 40 of product 1 and 20 of product 2.


60 * 0.90 each = $54 total


I have reached out to about 10 odoo developers are having trouble getting a response. Any recommendations?

Avatar
Discard

My recommendation? Use a simpler pricing model. It is also easier to understand for your customers.

Author

Hello Ermin,

I appreciate your response. However we have been using this model for several years(almost 10) and we are wholesalers. This pricing model is our secret sauce that sets us apart from the competition in our market. Switching pricing models would have a poor outcome.

Best Answer

Hello Bob, 

I have quickly whipped something up this evening for you if you would like more details, feel free to email me: jackd@flowbird.co.uk. I will try and describe what I have done as best as I can. 

# - * - coding: utf-8 - * -
from odoo import models, fields, api

class SalesOrder (models.Model):
    _inherit = "sale.order"
    def write (self, vals):
        res = super (SalesOrder, self ) .write (vals)
        if len (self.order_line)> 0:
            # get all the product categories
            all_categories = self.env ["pricing.category"]. search ([])
            # for each category in all categories
            for category in all_categories:
                # get the total amount of product lines which relate to that category
                category_product_lines = self.order_line.search ([("product_id.related_category", "=", category.id)])
                if category_product_lines:
                    # get the total number of products which relate to the product category
                    category_products_amount = sum (category_product_lines.mapped ("product_uom_qty"))
                    if category_products_amount> 0:
                        # get the category pricing for that item which has the highest min value
                        category_qty_new_price = self.env ["pricing.category.qty"]. search ([
                            ("cat_name", "=", category.id),
                            ("min_qty", "<", category_products_amount)
                        ], limit = 1, order = "min_qty desc").
                        # for each line which the product category, change the price to new price defined in
                        # model
                        for line in category_product_lines:
                            if category_qty_new_price:
                                line.price_unit = category_qty_new_price
                            else:
                                # if there is no new price, set to default list price
                                line.price_unit = line.product_id.list_price
        return res

class Product (models.Model):
    _inherit = "product.template"
    related_category = fields.Many2one ("pricing.category", string = "Pricing Category")

class Category (models.Model):
    _name = "pricing.category"
    name = fields.Char ("Name")

class CategoryPricing (models.Model):
    _name = "pricing.category.qty"
    cat_name = fields.Many2one ("pricing .category ", string =" Category Name ")
    min_qty = fields.Integer (" Min Qty ")
    new_price = fields.Float (" New Price ")

Essentially, whenever a write event occurs on the sales order the algorithm will flow. It will get all categories defined in "pricing.category" and will map and sum all the quantities from each sales order line on the sales order. (Category is a new field which has been added to the product.template model). 

It will then check the highest min value and get the price which is referred to, this price will be updated on all sales order lines where applicable. 

Here are some images of the tables etc:

Price Category Names

Price Category Tiers

With the function being called on write, it would mean that the record would have to be saved before the price change takes effect. Also meaning the prices cannot be overridden without further development. 

I haven't done as much testing on this as I would have liked but I hope this helps as it is. 

Thanks, 

Avatar
Discard