-
-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5dfff4
commit 8edeac7
Showing
22 changed files
with
307 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (C) 2020 - Today: GRAP (http://www.grap.coop) | ||
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
|
||
def migrate(cr, version): | ||
cr.execute( | ||
""" | ||
ALTER TABLE pos_config | ||
ADD COLUMN iface_display_margin bool; | ||
""" | ||
) | ||
cr.execute( | ||
""" | ||
UPDATE pos_config | ||
SET iface_display_margin = false; | ||
""" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from . import pos_config | ||
from . import pos_order | ||
from . import pos_order_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright (C) 2021 - Today: GRAP (http://www.grap.coop) | ||
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class PosConfig(models.Model): | ||
_inherit = "pos.config" | ||
|
||
iface_display_margin = fields.Boolean( | ||
string="Diplay Margin", | ||
help="Display Margin and Margin Rate in the frontend", | ||
default=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* If you want to disable the display of the margin, in the front-office UI, you can | ||
uncheck the check box in the ``pos.config`` form: | ||
|
||
.. figure:: ../static/description/pos_config_form.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
* Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
* Wolfgang Pichler | ||
* Manuel Regidor (www.sygel.es) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.pos .order .orderline .order-line-margin { | ||
font-weight: normal; | ||
color: #888; | ||
} | ||
|
||
.pos .order .orderline .order-line-margin.margin-negative { | ||
color: #f00; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (C) 2021 - Today: GRAP (http://www.grap.coop) | ||
// @author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
odoo.define("pos_margin.models", function(require) { | ||
"use strict"; | ||
|
||
var models = require("point_of_sale.models"); | ||
|
||
// ///////////////////////////// | ||
// Overload models.Order | ||
// ///////////////////////////// | ||
var OrderMargin = models.Order.extend({ | ||
get_margin: function() { | ||
return this.get_orderlines().reduce( | ||
(margin, line) => (margin += line.get_margin()), | ||
0 | ||
); | ||
}, | ||
|
||
get_margin_rate: function() { | ||
var priceWithoutTax = this.get_total_without_tax(); | ||
return priceWithoutTax ? (this.get_margin() / priceWithoutTax) * 100 : 0; | ||
}, | ||
}); | ||
|
||
models.Order = OrderMargin; | ||
|
||
// ///////////////////////////// | ||
// Overload models.OrderLine | ||
// ///////////////////////////// | ||
var OrderLineMargin = models.Orderline.extend({ | ||
get_purchase_price: function() { | ||
// Overload the function to use another field that the default standard_price | ||
return this.product.standard_price; | ||
}, | ||
|
||
get_margin: function() { | ||
return ( | ||
this.get_all_prices().priceWithoutTax - | ||
this.quantity * this.get_purchase_price() | ||
); | ||
}, | ||
|
||
get_margin_rate: function() { | ||
var priceWithoutTax = this.get_all_prices().priceWithoutTax; | ||
return priceWithoutTax ? (this.get_margin() / priceWithoutTax) * 100 : 0; | ||
}, | ||
|
||
get_margin_rate_str: function() { | ||
return this.pos.chrome.format_pr(this.get_margin_rate(), 0.01) + "%"; | ||
}, | ||
}); | ||
|
||
models.Orderline = OrderLineMargin; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (C) 2021 - Today: GRAP (http://www.grap.coop) | ||
// @author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
odoo.define("pos_margin.screens", function(require) { | ||
"use strict"; | ||
|
||
var screens = require("point_of_sale.screens"); | ||
|
||
screens.OrderWidget.include({ | ||
update_summary: function() { | ||
this._super.apply(this, arguments); | ||
var order = this.pos.get_order(); | ||
if (!order.get_orderlines().length) { | ||
return; | ||
} | ||
if (this.pos.config.iface_display_margin) { | ||
this.el.querySelector( | ||
".summary .order-margin .value-margin-rate" | ||
).textContent = this.format_pr(order.get_margin_rate(), 0.01) + "%"; | ||
this.el.querySelector( | ||
".summary .order-margin .value-margin" | ||
).textContent = this.format_currency(order.get_margin()); | ||
} | ||
}, | ||
}); | ||
}); |
Oops, something went wrong.