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

[MIG][16.0] pos margin #939

Merged
merged 16 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
139 changes: 139 additions & 0 deletions pos_margin/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
================
PoS Order Margin
================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/16.0/pos_margin
: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_margin
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/184/16.0
:alt: Try me on Runbot

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

This module shows margins in PoS frontend during an order creation.

**Table of contents**

.. contents::
:local:

Configuration
=============

* If you want to disable the display of the margin, in the front-office UI, you can
uncheck the check box in the ``res.config.settings`` form:

.. figure:: https://raw.githubusercontent.com/OCA/pos/16.0/pos_margin/static/description/pos_config_form.png

Usage
=====

**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:: https://raw.githubusercontent.com/OCA/pos/16.0/pos_margin/static/description/pos_front_end.png
:width: 800px


Known issues / Roadmap
======================

This dependency can be removed, when Odoo Core will be correctly refactored,
moving this ``@api.model`` function in a more generic module (``account``
for exemple).

Changelog
=========
16.0.1.0.0
~~~~~~~~~~

* Migrate to v16.0
* Remove ``pos.order`` and ``pos.order.line`` funcionality from V14.0.
It's already done by core V16.0.
* Remove tests.
* Create a ``res.config.settings`` field `pos_iface_display_margin`
to display margins in PoS frontend.


14.0.1.0.0
~~~~~~~~~~

* Migrate to V14.0

13.0.1.0.0
~~~~~~~~~~

* Migrate to V13.0
* Reuse ``sale_margin`` computation to handle multi currency context.
* Correct computation of margin, if a module that adds ``uom_id`` on
``pos.order.line`` is installed.
* Add test

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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/pos/issues/new?body=module:%20pos_margin%0Aversion:%2016.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
~~~~~~~

* GRAP

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

* Sylvain LE GAL (https://twitter.com/legalsylvain)
* Wolfgang Pichler
* Murtaza Mithaiwala (https://twitter.com/MurtazaMithaiw4)
* Dhara Solanki <dhara.solanki@initos.com>
* Juan Carlos <juancarlos.bonilla@factorlibre.com>

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.

.. |maintainer-legalsylvain| image:: https://github.com/legalsylvain.png?size=40px
:target: https://github.com/legalsylvain
:alt: legalsylvain

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-legalsylvain|

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions pos_margin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import report
30 changes: 30 additions & 0 deletions pos_margin/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (C) 2023 - 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).

{
"name": "PoS Order Margin",
"summary": "Margin on PoS Order",
"version": "16.0.1.0.0",
"category": "Point Of Sale",
"author": "GRAP, FactorLibre, Odoo Community Association (OCA)",
"maintainers": ["legalsylvain"],
"website": "https://github.com/OCA/pos",
"license": "AGPL-3",
"depends": [
"point_of_sale",
],
"data": [
"views/res_config_settings_view.xml",
"views/view_pos_order.xml",
],
"assets": {
"point_of_sale.assets": [
"pos_margin/static/src/xml/*.xml",
"pos_margin/static/src/js/models.esm.js",
"pos_margin/static/src/js/OrderSummaryMargin.esm.js",
"pos_margin/static/src/css/*.css",
],
},
"installable": True,
}
92 changes: 92 additions & 0 deletions pos_margin/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pos_margin
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-01-22 22:22+0000\n"
"PO-Revision-Date: 2023-01-22 22:22+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: pos_margin
#: model:ir.model,name:pos_margin.model_res_config_settings
msgid "Config Settings"
msgstr "Opciones de configuración"

#. module: pos_margin
#: model:ir.model.fields,field_description:pos_margin.field_pos_order_line__purchase_price
msgid "Cost Price"
msgstr "Precio de coste"

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

#. module: pos_margin
#: model:ir.model.fields,help:pos_margin.field_pos_config__iface_display_margin
#: model:ir.model.fields,help:pos_margin.field_res_config_settings__pos_iface_display_margin
#: model_terms:ir.ui.view,arch_db:pos_margin.res_config_settings_view_form_margin_inherit
msgid "Display Margin and Margin Rate in the frontend"
msgstr "Mostrar margen y tasa de margen en el frontend"

#. 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 ""
"Indica el beneficio calculando la diferencia entre el precio unitario y el "
"precio de coste."

#. module: pos_margin
#: model:ir.model.fields,field_description:pos_margin.field_pos_order__margin
#: model:ir.model.fields,field_description:pos_margin.field_pos_order_line__margin
msgid "Margin"
msgstr "Margen"

#. module: pos_margin
#: model:ir.model.fields,field_description:pos_margin.field_report_pos_order__margin_rate
msgid "Margin Rate (%)"
msgstr "Tasa de Margen (%)"

#. module: pos_margin
#: model:ir.model.fields,field_description:pos_margin.field_report_pos_order__margin_total
#: model_terms:ir.ui.view,arch_db:pos_margin.view_pos_order_tree
msgid "Margin Total"
msgstr "Margen total"

#. module: pos_margin
#. odoo-javascript
#: code:addons/pos_margin/static/src/xml/pos_margin.xml:0
#, python-format
msgid "Margin:"
msgstr "Margen:"

#. module: pos_margin
#: model:ir.model,name:pos_margin.model_pos_config
msgid "Point of Sale Configuration"
msgstr "Configuración del TPV"

#. module: pos_margin
#: model:ir.model,name:pos_margin.model_pos_order_line
msgid "Point of Sale Order Lines"
msgstr "Líneas de Orden de Punto de Venta"

#. module: pos_margin
#: model:ir.model,name:pos_margin.model_pos_order
msgid "Point of Sale Orders"
msgstr "Pedidos del TPV"

#. module: pos_margin
#: model:ir.model,name:pos_margin.model_report_pos_order
msgid "Point of Sale Orders Report"
msgstr "Informe de Órdenes del Punto de Venta"
6 changes: 6 additions & 0 deletions pos_margin/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (C) 2023 - 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 . import pos_config
from . import res_config_settings
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) 2023 - 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,
)
14 changes: 14 additions & 0 deletions pos_margin/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (C) 2023 - 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 ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

pos_iface_display_margin = fields.Boolean(
related="pos_config_id.iface_display_margin",
readonly=False,
)
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 `res.config.settings` shop form:

.. figure:: ../static/description/pos_config_setting.png
5 changes: 5 additions & 0 deletions pos_margin/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* Sylvain LE GAL (https://twitter.com/legalsylvain)
* Wolfgang Pichler
* Murtaza Mithaiwala (https://twitter.com/MurtazaMithaiw4)
* Dhara Solanki <dhara.solanki@initos.com>
* Juan Carlos Bonilla <juancarlos.bonilla@factorlibre.com>
1 change: 1 addition & 0 deletions pos_margin/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module shows margins in PoS frontend during an order creation.
23 changes: 23 additions & 0 deletions pos_margin/readme/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
16.0.1.0.0
~~~~~~~~~~

* Migrate to V16.0
* Remove ``pos.order`` and ``pos.order.line`` funcionality from V14.0.
It's already done by V16.0.
* Remove tests.
* Create a ``res.config.settings`` field `pos_iface_display_margin`
to display margins in PoS frontend.

14.0.1.0.0
~~~~~~~~~~

* Migrate to V14.0

13.0.1.0.0
~~~~~~~~~~

* Migrate to V13.0
* Reuse ``sale_margin`` computation to handle multi currency context.
* Correct computation of margin, if a module that adds ``uom_id`` on
``pos.order.line`` is installed.
* Add test
3 changes: 3 additions & 0 deletions pos_margin/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This dependency can be removed, when Odoo Core will be correctly refactored,
moving this ``@api.model`` function in a more generic module (``account``
for exemple).
Empty file added pos_margin/readme/USAGE.rst
Empty file.
5 changes: 5 additions & 0 deletions pos_margin/report/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (C) 2023 - 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 . import pos_order_report
28 changes: 28 additions & 0 deletions pos_margin/report/pos_order_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (C) 2023 - 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 PosOrderReport(models.Model):
_inherit = "report.pos.order"

margin_rate = fields.Float(string="Margin Rate (%)", group_operator="avg")

def _select(self):
return (
super(PosOrderReport, self)._select()
+ """,
SUM(l.price_subtotal - l.total_cost / CASE COALESCE(s.currency_rate, 0)
WHEN 0 THEN 1.0 ELSE s.currency_rate END) / NULLIF(SUM(l.price_subtotal), 0) * 100
AS margin_rate
"""
)

def _group_by(self):
group_by_append = """,
l.price_subtotal,
l.total_cost
"""
return super(PosOrderReport, self)._group_by() + group_by_append
Binary file added pos_margin/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.
Loading