Skip to content

Commit

Permalink
[MIG]pos_margin: Migration to 13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelregidor committed Jul 23, 2021
1 parent e5dfff4 commit 8edeac7
Show file tree
Hide file tree
Showing 22 changed files with 307 additions and 34 deletions.
9 changes: 7 additions & 2 deletions pos_margin/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
{
"name": "PoS Order Margin",
"summary": "Margin on PoS Order",
"version": "13.0.1.0.0",
"version": "13.0.2.0.1",
"category": "Point Of Sale",
"author": "GRAP," "Odoo Community Association (OCA)",
"maintainers": ["legalsylvain"],
"website": "https://github.com/OCA/pos",
"license": "AGPL-3",
"depends": ["point_of_sale", "sale_margin"],
"data": ["views/view_pos_order.xml"],
"data": [
"views/templates.xml",
"views/view_pos_config.xml",
"views/view_pos_order.xml",
],
"qweb": ["static/src/xml/pos_margin.xml"],
"installable": True,
}
43 changes: 31 additions & 12 deletions pos_margin/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-12-12 10:19+0000\n"
"PO-Revision-Date: 2019-12-12 10:19+0000\n"
"POT-Creation-Date: 2021-06-11 14:57+0000\n"
"PO-Revision-Date: 2021-06-11 14:57+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
Expand All @@ -21,14 +20,21 @@ msgstr ""
msgid "Cost Price"
msgstr "Prix de revient"

#. module: pos_margin
#: model:ir.model.fields,field_description:pos_margin.field_pos_config__iface_display_margin
msgid "Diplay Margin"
msgstr "Afficher la marge"

#. module: pos_margin
#: model:ir.model.fields,help:pos_margin.field_pos_config__iface_display_margin
#: model_terms:ir.ui.view,arch_db:pos_margin.view_pos_config_form
msgid "Display Margin and Margin Rate in the frontend"
msgstr "Afficher la marge et le taux de marge sur l'interface tactile"

#. module: pos_margin
#: model:ir.model.fields,help:pos_margin.field_pos_order__margin
msgid ""
"It gives profitability by calculating the difference between the Unit Price "
"and the cost price."
msgstr ""
"Il donne la rentabilité en calculant la différence entre le prix unitaire et "
"le prix de revient."
msgid "It gives profitability by calculating the difference between the Unit Price and the cost price."
msgstr "Il donne la rentabilité en calculant la différence entre le prix unitaire et le prix de revient."

#. module: pos_margin
#: model:ir.model.fields,field_description:pos_margin.field_pos_order__margin
Expand All @@ -40,7 +46,7 @@ msgstr "Marge"
#: model:ir.model.fields,field_description:pos_margin.field_pos_order__margin_percent
#: model:ir.model.fields,field_description:pos_margin.field_pos_order_line__margin_percent
msgid "Margin (%)"
msgstr "Marge (%)"
msgstr "Taux de marque (%)"

#. module: pos_margin
#: model:ir.model.fields,field_description:pos_margin.field_report_pos_order__margin_rate
Expand All @@ -52,10 +58,22 @@ msgstr "Taux de marque"
msgid "Margin Total"
msgstr "Marge Totale"

#. module: pos_margin
#. openerp-web
#: code:addons/pos_margin/static/src/xml/pos_margin.xml:26
#, python-format
msgid "Margin:"
msgstr "Marge :"

#. module: pos_margin
#: model:ir.model,name:pos_margin.model_pos_config
msgid "Point of Sale Configuration"
msgstr "Paramétrage du point de vente"

#. module: pos_margin
#: model:ir.model,name:pos_margin.model_pos_order_line
msgid "Point of Sale Order Lines"
msgstr ""
msgstr "Lignes des commandes du point de vente"

#. module: pos_margin
#: model:ir.model,name:pos_margin.model_pos_order
Expand All @@ -70,4 +88,5 @@ msgstr "Rapport sur les commandes au point de vente"
#. module: pos_margin
#: model_terms:ir.ui.view,arch_db:pos_margin.view_pos_order_tree
msgid "Total"
msgstr "Total"
msgstr ""

27 changes: 26 additions & 1 deletion pos_margin/i18n/pos_margin.pot
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pos_margin
# * pos_margin
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-06-11 14:57+0000\n"
"PO-Revision-Date: 2021-06-11 14:57+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand All @@ -18,6 +20,17 @@ msgstr ""
msgid "Cost Price"
msgstr ""

#. module: pos_margin
#: model:ir.model.fields,field_description:pos_margin.field_pos_config__iface_display_margin
msgid "Diplay Margin"
msgstr ""

#. module: pos_margin
#: model:ir.model.fields,help:pos_margin.field_pos_config__iface_display_margin
#: model_terms:ir.ui.view,arch_db:pos_margin.view_pos_config_form
msgid "Display Margin and Margin Rate in the frontend"
msgstr ""

#. module: pos_margin
#: model:ir.model.fields,help:pos_margin.field_pos_order__margin
msgid "It gives profitability by calculating the difference between the Unit Price and the cost price."
Expand Down Expand Up @@ -45,6 +58,18 @@ msgstr ""
msgid "Margin Total"
msgstr ""

#. module: pos_margin
#. openerp-web
#: code:addons/pos_margin/static/src/xml/pos_margin.xml:26
#, python-format
msgid "Margin:"
msgstr ""

#. module: pos_margin
#: model:ir.model,name:pos_margin.model_pos_config
msgid "Point of Sale Configuration"
msgstr ""

#. module: pos_margin
#: model:ir.model,name:pos_margin.model_pos_order_line
msgid "Point of Sale Order Lines"
Expand Down
18 changes: 18 additions & 0 deletions pos_margin/migrations/12.0.2.0.0/pre-migration.py
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;
"""
)
1 change: 1 addition & 0 deletions pos_margin/models/__init__.py
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
15 changes: 15 additions & 0 deletions pos_margin/models/pos_config.py
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,
)
7 changes: 2 additions & 5 deletions pos_margin/models/pos_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from odoo import api, fields, models

import odoo.addons.decimal_precision as dp


class PosOrder(models.Model):
_inherit = "pos.order"
Expand All @@ -15,7 +13,7 @@ class PosOrder(models.Model):
string="Margin",
compute="_compute_margin",
store=True,
digits=dp.get_precision("Product Price"),
digits="Product Price",
help="It gives profitability by calculating the difference between"
" the Unit Price and the cost price.",
)
Expand All @@ -24,11 +22,10 @@ class PosOrder(models.Model):
string="Margin (%)",
compute="_compute_margin",
store=True,
digits=dp.get_precision("Product Price"),
digits="Product Price",
)

# Compute Section
@api.multi
@api.depends("lines.margin", "lines.price_subtotal")
def _compute_margin(self):
for order in self:
Expand Down
9 changes: 3 additions & 6 deletions pos_margin/models/pos_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from odoo import api, fields, models

import odoo.addons.decimal_precision as dp


class PosOrderLine(models.Model):
_inherit = "pos.order.line"
Expand All @@ -15,25 +13,24 @@ class PosOrderLine(models.Model):
string="Margin",
compute="_compute_multi_margin",
store=True,
digits=dp.get_precision("Product Price"),
digits="Product Price",
)

margin_percent = fields.Float(
string="Margin (%)",
compute="_compute_multi_margin",
store=True,
digits=dp.get_precision("Product Price"),
digits="Product Price",
)

purchase_price = fields.Float(
string="Cost Price",
compute="_compute_multi_margin",
store=True,
digits=dp.get_precision("Product Price"),
digits="Product Price",
)

# Compute Section
@api.multi
@api.depends("product_id", "qty", "price_subtotal")
def _compute_multi_margin(self):
for line in self.filtered("product_id"):
Expand Down
4 changes: 4 additions & 0 deletions pos_margin/readme/CONFIGURE.rst
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
1 change: 1 addition & 0 deletions pos_margin/readme/CONTRIBUTORS.rst
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)
10 changes: 10 additions & 0 deletions pos_margin/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
**In the PoS Front Office**

* Make an order. Each time a line is added, updated, or deleted, the margin and the margin rate
will be updated.

.. figure:: ../static/description/pos_front_end.png
:width: 800px

**In the PoS Back Office**

To use this module, you need to:

* Go to 'Point Of Sale' / 'Orders' / 'Orders'
Expand Down
Binary file added pos_margin/static/description/pos_config_form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pos_margin/static/description/pos_front_end.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions pos_margin/static/src/css/pos_margin.css
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;
}
56 changes: 56 additions & 0 deletions pos_margin/static/src/js/models.js
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;
});
27 changes: 27 additions & 0 deletions pos_margin/static/src/js/screens.js
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());
}
},
});
});
Loading

0 comments on commit 8edeac7

Please sign in to comment.