Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] pos_multi_discount #985

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
11e250a
[14.0][ADD] pos_multi_discount + pos_fixed_discount_in_lines
ilyasProgrammer Sep 14, 2022
9eff4c1
[14.0][UPD] mult. discounts
ilyasProgrammer Sep 14, 2022
dece9a8
[14.0][UPD]
ilyasProgrammer Sep 14, 2022
36227eb
[14.0][UPD]
ilyasProgrammer Sep 14, 2022
93f43bb
[14.0][UPD] added pre commit files
ilyasProgrammer Sep 14, 2022
a7af31c
[14.0][UPD]
ilyasProgrammer Sep 14, 2022
f47d5bc
[14.0][UPD] price based computed deiscount fields
ilyasProgrammer Sep 15, 2022
db45bbe
[14.0][UPD] price based computed deiscount fields
ilyasProgrammer Sep 15, 2022
13396d9
[14.0][UPD]
ilyasProgrammer Sep 15, 2022
78e6a7c
[14.0][UPD] without discount rounding (truncate). + only_positive_dis…
ilyasProgrammer Sep 19, 2022
bc8d3fb
[14.0][FIX] no need to consider current_discount
ilyasProgrammer Sep 19, 2022
549aba3
[14.0][UPD] rounding
ilyasProgrammer Sep 20, 2022
ebeb3d5
[14.0][UPD] rename pos_fixed_discount_in_lines -> pos_multi_discount…
ilyasProgrammer Sep 20, 2022
335f79d
[14.0][UPD] percent discount feature
ilyasProgrammer Sep 20, 2022
4b12177
[14.0][UPD]
ilyasProgrammer Sep 20, 2022
b65d45c
[14.0][UPD] show percent discount abs. amount
ilyasProgrammer Sep 22, 2022
3da94ca
[14.0][FIX] recompute percent discount when fices discount is removed.
ilyasProgrammer Oct 6, 2022
1cff432
[14.0][ADD] pos_multi_discount + pos_fixed_discount_in_lines
ilyasProgrammer Sep 14, 2022
a7aaafd
[14.0][UPD] mult. discounts
ilyasProgrammer Sep 14, 2022
a3013b3
[14.0][UPD] added pre commit files
ilyasProgrammer Sep 14, 2022
b14f033
[14.0][UPD]
ilyasProgrammer Sep 14, 2022
6791bbb
[14.0][UPD] price based computed deiscount fields
ilyasProgrammer Sep 15, 2022
c43dffb
[14.0][UPD] price based computed deiscount fields
ilyasProgrammer Sep 15, 2022
05770fe
[14.0][UPD]
ilyasProgrammer Sep 15, 2022
6bd077f
[14.0][UPD] without discount rounding (truncate). + only_positive_dis…
ilyasProgrammer Sep 19, 2022
3f234a4
[14.0][FIX] no need to consider current_discount
ilyasProgrammer Sep 19, 2022
0413db6
[14.0][UPD] rounding
ilyasProgrammer Sep 20, 2022
a34ab87
[14.0][UPD] rename pos_fixed_discount_in_lines -> pos_multi_discount…
ilyasProgrammer Sep 20, 2022
38a09d3
[14.0][UPD] percent discount feature
ilyasProgrammer Sep 20, 2022
7bf8899
[14.0][UPD]
ilyasProgrammer Sep 20, 2022
686c8f0
[14.0][UPD] show percent discount abs. amount
ilyasProgrammer Sep 22, 2022
836128f
[14.0][REF] pre-commit
ilyasProgrammer Oct 6, 2022
b214b80
wip
ilyasProgrammer Sep 21, 2023
b7ea478
upd: only fixed or percent discount can be enabled. Set fixed and per…
ilyasProgrammer Aug 25, 2023
cc08e5e
wip
ilyasProgrammer Sep 21, 2023
53fec71
wip
ilyasProgrammer Sep 21, 2023
f487686
wip
ilyasProgrammer Sep 21, 2023
b04c8db
wip
ilyasProgrammer Sep 21, 2023
934fe97
-
ilyasProgrammer Nov 29, 2023
0233b00
pre commit
ilyasProgrammer Nov 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions pos_multi_discount/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
==================
pos_multi_discount
==================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e591052b7acf247f2e06959d5fbc4b43dd7f604fa82d6ea1d3eed379f5f9b7c7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github
:target: https://github.com/OCA/pos/tree/14.0/pos_multi_discount
:alt: OCA/pos
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/pos-14-0/pos-14-0-pos_multi_discount
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/pos&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|


**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/pos/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/pos/issues/new?body=module:%20pos_multi_discount%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Ilyas
* Ooops404

Contributors
~~~~~~~~~~~~

* Ooops404 <https://ooops404.com>

* Ilyas <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/pos <https://github.com/OCA/pos/tree/14.0/pos_multi_discount>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions pos_multi_discount/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions pos_multi_discount/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "pos_multi_discount",
"summary": "pos_multi discount",
"version": "14.0.1.0.0",
"category": "Point Of Sale",
"author": "Ilyas, Ooops404, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/pos",
"license": "AGPL-3",
"depends": [
"pos_discount",
],
"data": [
"views/pos_templates.xml",
"views/pos_views.xml",
],
"qweb": [
"static/src/xml/Screens/ProductScreen/Orderline.xml",
],
}
2 changes: 2 additions & 0 deletions pos_multi_discount/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import pos_config
from . import pos_order
5 changes: 5 additions & 0 deletions pos_multi_discount/models/pos_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from odoo import models


class PosConfig(models.Model):
_inherit = "pos.config"
18 changes: 18 additions & 0 deletions pos_multi_discount/models/pos_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from odoo import api, fields, models


class PosOrderLine(models.Model):
_inherit = "pos.order.line"

manual_discount = fields.Float("Manual Disc.%")
manual_amount = fields.Monetary(
"Manual Disc. Amount",
compute="_compute_relative_discounts",
help="Based on product price",
)

@api.depends("qty", "price_unit", "manual_discount")
def _compute_relative_discounts(self):
for rec in self:
subtotal = rec.qty * rec.price_unit
rec.manual_amount = subtotal * rec.manual_discount / 100

Check warning on line 18 in pos_multi_discount/models/pos_order.py

View check run for this annotation

Codecov / codecov/patch

pos_multi_discount/models/pos_order.py#L17-L18

Added lines #L17 - L18 were not covered by tests
Empty file.
3 changes: 3 additions & 0 deletions pos_multi_discount/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Ooops404 <https://ooops404.com>

* Ilyas <[email protected]>
Empty file.
Empty file.
Binary file added pos_multi_discount/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions pos_multi_discount/static/src/css/pos.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.payment-screen .discount-controls {
margin-top: 10px;
}

.payment-screen .paymentlines-empty .fixed_discount_line {
text-align: center;
font-size: 20px;
margin-bottom: 10px;
}

.payment-screen .fixed_discount_label {
font-size: 16px;
padding-right: 7px;
}

.payment-screen .fixed_discount_amount {
font-size: 16px;
}
46 changes: 46 additions & 0 deletions pos_multi_discount/static/src/js/models.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
odoo.define("pos_multi_discount.POSModels", function (require) {
"use strict";

var models = require("point_of_sale.models");
var field_utils = require("web.field_utils");

var _super_orderline = models.Orderline.prototype;
models.Orderline = models.Orderline.extend({
initialize: function (attr, options) {
_super_orderline.initialize.call(this, attr, options);
this.manual_discount = 0;
},
init_from_JSON: function (json) {
_super_orderline.init_from_JSON.apply(this, arguments);
this.manual_discount = json.manual_discount;
},
set_discount: function (discount) {
var parsed_discount =
typeof discount === "number"
? discount
: isNaN(parseFloat(discount))
? 0
: field_utils.parse.float(String(discount));
var disc = Math.min(Math.max(parsed_discount || 0, 0), 100);
this.manual_discount = disc;
this.discount = this.manual_discount + 0; // + fixed disc + % disc
this.discountStr = String(disc);
this.trigger("change", this);
},
get_show_total_discount_line: function () {
var mode = this.pos.env.isDebug();
if (mode === "assets" || mode === "1") {
return true;
}
return false;
},
get_manual_discount: function () {
return this.manual_discount;
},
export_as_JSON: function () {
var vals = _super_orderline.export_as_JSON.apply(this, arguments);
vals.manual_discount = this.manual_discount;
return vals;
},
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates id="template" xml:space="preserve">
<t t-inherit="point_of_sale.Orderline" t-inherit-mode="extension" owl="1">
<xpath
expr="//t[@t-esc='props.line.get_discount_str()']/../../.."
position="after"
>
<t t-if="props.line.get_manual_discount() !== 0">
<li class="info" id="pos_line_manual_discount">
Manual discount
<em>
<t t-esc="props.line.get_manual_discount()" />%
</em>
</li>
</t>
<t
t-if="props.line.get_discount_str() !== '0' and props.line.get_show_total_discount_line()"
>
<li class="info">
Total Discount
<em>
<t t-esc="props.line.get_discount_str()" />%
</em>
</li>
</t>
</xpath>
<xpath
expr="//t[@t-esc='props.line.get_discount_str()']/../../.."
position="replace"
>
</xpath>

</t>
</templates>
11 changes: 11 additions & 0 deletions pos_multi_discount/views/pos_templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script
type="text/javascript"
src="/pos_multi_discount/static/src/js/models.js"
/>
</xpath>
</template>
</odoo>
17 changes: 17 additions & 0 deletions pos_multi_discount/views/pos_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="pos_order_form_inherit" model="ir.ui.view">
<field name="name">pos.order.form.inherit</field>
<field name="model">pos.order</field>
<field name="inherit_id" ref="point_of_sale.view_pos_pos_form" />
<field name="arch" type="xml">
<xpath
expr="//field[@name='lines']//tree//field[@name='discount']"
position='before'
>
<field name="manual_discount" />
<field name="manual_amount" optional="hide" />
</xpath>
</field>
</record>
</odoo>
94 changes: 94 additions & 0 deletions pos_multi_discount_global/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
======================================
Point of Sale - Multi Discount in Line
======================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f0e2d442acd36b9a9576433ef30fd06970e2c68011698680648833e0b4863641
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github
:target: https://github.com/OCA/pos/tree/14.0/pos_multi_discount_global
:alt: OCA/pos
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/pos-14-0/pos-14-0-pos_multi_discount_global
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/pos&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows to apply a fixed discount on a POS order (similar to the feature of pos_fixed_discount) but instead of using a "discount" product with negative price, it applies a percentage discount in line to all products equal to the amount of the fixed discount inputed, eg:

If total amount of order is 200 and user inputs a fixed discount of 20, all lines will have a 10% discount.

If, due to rounding, there is a difference between inputted fixed discount and sum of applied discounts, a service product "Fixed discount rounding" will be added to the order with the amount needed to make the order amount match the fixed discount applied.

**Table of contents**

.. contents::
:local:

Usage
=====

- Fixed discount is applied on payment screen of POS interface, in order to make sure the discount is applied to all products in the order.

.. figure:: https://raw.githubusercontent.com/OCA/pos/14.0/pos_multi_discount_global/static/description/payment.png

- Once validated, in POS > Orders you can check the fixed discount applied to the order, the discount % on each line, and the necessary rounding amount.

.. figure:: https://raw.githubusercontent.com/OCA/pos/14.0/pos_multi_discount_global/static/description/order.png

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/pos/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/pos/issues/new?body=module:%20pos_multi_discount_global%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Ilyas
* Ooops404

Contributors
~~~~~~~~~~~~

* Ooops404 <https://ooops404.com>

* Ilyas <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/pos <https://github.com/OCA/pos/tree/14.0/pos_multi_discount_global>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions pos_multi_discount_global/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
25 changes: 25 additions & 0 deletions pos_multi_discount_global/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "Point of Sale - Multi Discount in Line",
"summary": "Order discount in POS lines instead of discount product",
"version": "14.0.1.0.0",
"category": "Point Of Sale",
"author": "Ilyas, Ooops404, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/pos",
"license": "AGPL-3",
"depends": [
"pos_multi_discount",
],
"data": [
"views/pos_templates.xml",
"views/pos_discount_views.xml",
"views/pos_views.xml",
"data/product.xml",
],
"qweb": [
"static/src/xml/Screens/ProductScreen/Orderline.xml",
"static/src/xml/Screens/ProductScreen/OrderSummary.xml",
"static/src/xml/Screens/ProductScreen/OrderWidget.xml",
"static/src/xml/Screens/PaymentScreen/PaymentScreen.xml",
"static/src/xml/Screens/PaymentScreen/PaymentScreenStatus.xml",
],
}
Loading
Loading