Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

How to set global discount to fixed amount on POS

Naroči se

Get notified when there's activity on this post

This question has been flagged
posdiscount
2 Odgovori
3822 Prikazi
Avatar
Fadil Kd

Hello,

I am working on Odoo 17e and I want to change the global discount to a fixed amount instead of percentage. How can I achieve that via custom module? Which functions should I target?

Any help is appreciated.

Thanks,

0
Avatar
Opusti
Avatar
Waleed Ali Mohsen
Best Answer

Hi,

You need to change the js in the below file:

odoo/addons/pos_discount/static/src/overrides/components/discount_button/discount_button.js at 17.0 · odoo/odoo (github.com)

1
Avatar
Opusti
Avatar
Nikolay B Petrov
Best Answer

Thank to @Waleen for pointing me in the right direction. The line to edit in that file is #27. This is only if you want to change the discount to apply as a fixed amount.

Here's a modification of the same file that first gives you a selection popup to choose whether you want a fixed or % discount, then you enter the discount amount

(sorry, code formatting is not applying properly so you'll have to copy-paste in your IDE and format)


/** @odoo-module **/

import { _t } from "@web/core/l10n/translation";import { ProductScreen } from "@point_of_sale/app/screens/product_screen/product_screen";import { useService } from "@web/core/utils/hooks";import { NumberPopup } from "@point_of_sale/app/utils/input_popups/number_popup";import { ErrorPopup } from "@point_of_sale/app/errors/popups/error_popup";import { SelectionPopup } from "@point_of_sale/app/utils/input_popups/selection_popup"; // Assuming SelectionPopup exists or create a similar componentimport { Component } from "@odoo/owl";import { usePos } from "@point_of_sale/app/store/pos_hook";import { parseFloat } from "@web/views/fields/parsers";

export class DiscountButton extends Component {    static template = "pos_discount.DiscountButton";

    setup() {        this.pos = usePos();        this.popup = useService("popup");    }

    async click() {        // First, ask the user to choose discount type        const { confirmed: typeConfirmed, payload: discountType } = await this.popup.add(SelectionPopup, {            title: _t("Discount Type"),            list: [                { id: 1, label: _t("Percentage"), item: "percentage", isSelected: true },                { id: 2, label: _t("Fixed Amount"), item: "fixed" },            ],            isInputSelected: true,        });        if (!typeConfirmed) return;

        // Ask for discount value based on the chosen type        const { confirmed, payload } = await this.popup.add(NumberPopup, {            title: discountType === "percentage" ? _t("Discount Percentage") : _t("Discount Amount"),            startingValue: this.pos.config.discount_pc || 0,            isInputSelected: true,        });        if (confirmed) {            const val = parseFloat(payload);            await this.apply_discount(val, discountType);        }    }

    async apply_discount(value, discountType) {        const order = this.pos.get_order();        const lines = order.get_orderlines();        const product = this.pos.db.get_product_by_id(this.pos.config.discount_product_id[0]);

        if (product === undefined) {            await this.popup.add(ErrorPopup, {                title: _t("No discount product found"),                body: _t(                    "The discount product seems misconfigured. Make sure it is flagged as 'Can be Sold' and 'Available in Point of Sale'."                ),            });            return;        }

        // Remove existing discounts        lines            .filter((line) => line.get_product() === product)            .forEach((line) => order._unlinkOrderline(line));

        // Add one discount line per tax group        const linesByTax = order.get_orderlines_grouped_by_tax_ids();        for (const [tax_ids, lines] of Object.entries(linesByTax)) {            const tax_ids_array = tax_ids                .split(",")                .filter((id) => id !== "")                .map((id) => Number(id));

            const baseToDiscount = order.calculate_base_amount(                tax_ids_array,                lines.filter((ll) => ll.isGlobalDiscountApplicable())            );

            // Calculate discount based on type            let discount = 0;            if (discountType === "percentage") {                discount = (-value / 100.0) * baseToDiscount;            } else if (discountType === "fixed") {                discount = -value;            }

            if (discount < 0) {                order.add_product(product, {                    price: discount,                    lst_price: discount,                    tax_ids: tax_ids_array,                    merge: false,                    description:                        `${discountType === "percentage" ? value + "%" : this.pos.currency.symbol + value}, ` +                        (tax_ids_array.length                            ? _t(                                  "Tax: %s",                                  tax_ids_array                                      .map((taxId) => this.pos.taxes_by_id[taxId].amount + "%")                                      .join(", ")                              )                            : _t("No tax")),                    extras: {                        price_type: "automatic",                    },                });            }        }    }}

ProductScreen.addControlButton({    component: DiscountButton,    condition: function () {        const { module_pos_discount, discount_product_id } = this.pos.config;        return module_pos_discount && discount_product_id;    },});


1
Avatar
Opusti
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
POS Loyalty Promotion Reapplies Discount on Same Product — Cannot Reward Unique Lines
pos discount
Avatar
Avatar
1
maj 25
1664
Give discount according to the product count
pos discount
Avatar
Avatar
Avatar
2
okt. 16
3637
How to enter discount manually in POS?
pos discount
Avatar
Avatar
1
mar. 15
5442
Buy 1 Get 1 Promotion in odoo 17.0 POS
pos discount buy1-get1
Avatar
Avatar
1
avg. 25
1581
Discount for first purchase at POS
pos discount Point Of Sale
Avatar
Avatar
1
jun. 25
1577
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now