Browse Source

[MIG] pos_margin: Migration to 12.0

pull/399/head
Sylvain LE GAL 5 years ago
committed by AmmarOfficewala
parent
commit
72a0f536e7
  1. 83
      pos_margin/README.rst
  2. 9
      pos_margin/__manifest__.py
  3. 56
      pos_margin/i18n/fr.po
  4. 31
      pos_margin/i18n/pos_margin.pot
  5. 2
      pos_margin/models/pos_order.py
  6. 28
      pos_margin/models/pos_order_line.py
  7. 2
      pos_margin/readme/CONTRIBUTORS.rst
  8. 5
      pos_margin/readme/DESCRIPTION.rst
  9. 8
      pos_margin/readme/HISTORY.rst
  10. 7
      pos_margin/readme/ROADMAP.rst
  11. 7
      pos_margin/readme/USAGE.rst
  12. BIN
      pos_margin/static/description/pos_order_form.png
  13. 1
      pos_margin/tests/__init__.py
  14. 68
      pos_margin/tests/test_module.py
  15. 20
      pos_margin/views/view_pos_order.xml

83
pos_margin/README.rst

@ -1,79 +1,4 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
===================
Margin on PoS order
===================
This module extends the functionality of point of sale to support margin on
pos orders.
This gives the profitability by calculating the difference between the Unit
Price and Cost Price.
Usage
=====
To use this module, you need to:
#. Go to 'Point Of Sale' / 'Daily Operations' / 'Orders'
#. Open an order
.. figure:: ./pos_margin/static/description/pos_order_form.png
:width: 800px
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/184/8.0
Technical information
=====================
This module is highly inspired from the module 'Sale Order Margin', by Odoo SA.
Known issues / Roadmap
======================
* include extra reporting, using the new margin field.
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 smash it by providing detailed and welcomed feedback.
Credits
=======
Contributors
------------
* Sylvain LE GAL (https://twitter.com/legalsylvain)
Funders
-------
The development of this module has been financially supported by:
* GRAP, Groupement Régional Alimentaire de Proximité (www.grap.coop)
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
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.
To contribute to this module, please visit https://odoo-community.org.
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

9
pos_margin/__manifest__.py

@ -3,16 +3,17 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
'name': 'POS Margin',
'version': '11.0.1.0.0',
'name': 'PoS Order Margin',
'summary': 'Margin on PoS Order',
'version': '12.0.1.0.0',
'category': 'Point Of Sale', 'category': 'Point Of Sale',
'sequence': 1,
'author': "GRAP," 'author': "GRAP,"
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
'summary': 'Margin on PoS Order',
'website': 'https://github.com/OCA/pos',
'license': 'AGPL-3', 'license': 'AGPL-3',
'depends': [ 'depends': [
'point_of_sale', 'point_of_sale',
'sale_margin',
], ],
'data': [ 'data': [
'views/view_pos_order.xml', 'views/view_pos_order.xml',

56
pos_margin/i18n/fr.po

@ -1,67 +1,61 @@
# Translation of Odoo Server. # Translation of Odoo Server.
# This file contains the translation of the following modules: # This file contains the translation of the following modules:
# * pos_margin
# * pos_margin
# #
# Translators:
# OCA Transbot <transbot@odoo-community.org>, 2017
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-04-25 02:39+0000\n"
"PO-Revision-Date: 2017-04-25 02:39+0000\n"
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2017\n"
"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n"
"Language: fr\n"
"POT-Creation-Date: 2019-08-15 11:05+0000\n"
"PO-Revision-Date: 2019-08-15 11:05+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n" "Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"Plural-Forms: \n"
#. module: pos_margin #. module: pos_margin
#: model:ir.model.fields,field_description:pos_margin.field_pos_order_line_purchase_price
#: model:ir.model.fields,field_description:pos_margin.field_pos_order_line__purchase_price
msgid "Cost Price" msgid "Cost Price"
msgstr "Prix de revient" msgstr "Prix de revient"
#. module: pos_margin #. 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."
#: 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 "" msgstr ""
"Il donne la rentabilité en calculant la différence entre le prix unitaire et " "Il donne la rentabilité en calculant la différence entre le prix unitaire et "
"le prix de revient." "le prix de revient."
#. module: pos_margin #. module: pos_margin
#: model:ir.model,name:pos_margin.model_pos_order_line
#, fuzzy
msgid "Lines of Point of Sale Orders"
msgstr "Lignes de Points de Vente"
#. module: pos_margin
#: model:ir.model.fields,field_description:pos_margin.field_pos_order_line_margin
#: model:ir.model.fields,field_description:pos_margin.field_pos_order_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" msgid "Margin"
msgstr "Marge" msgstr "Marge"
#. module: pos_margin #. module: pos_margin
#: model:ir.model.fields,field_description:pos_margin.field_report_pos_order_margin_rate
#, fuzzy
#: model:ir.model.fields,field_description:pos_margin.field_report_pos_order__margin_rate
msgid "Margin Rate" msgid "Margin Rate"
msgstr "Marge"
msgstr "Taux de marque"
#. module: pos_margin #. module: pos_margin
#: model:ir.model.fields,field_description:pos_margin.field_report_pos_order_margin_total
#, fuzzy
#: 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" msgid "Margin Total"
msgstr "Marge"
msgstr "Marge Totale"
#. module: pos_margin
#: model:ir.model,name:pos_margin.model_pos_order_line
msgid "Point of Sale Order Lines"
msgstr ""
#. module: pos_margin #. module: pos_margin
#: model:ir.model,name:pos_margin.model_pos_order #: model:ir.model,name:pos_margin.model_pos_order
msgid "Point of Sale Orders" msgid "Point of Sale Orders"
msgstr ""
msgstr "Commandes du point de vente"
#. module: pos_margin #. module: pos_margin
#: model:ir.model,name:pos_margin.model_report_pos_order #: model:ir.model,name:pos_margin.model_report_pos_order
msgid "Point of Sale Orders Statistics"
msgid "Point of Sale Orders Report"
msgstr "" msgstr ""

31
pos_margin/i18n/pos_margin.pot

@ -1,11 +1,13 @@
# Translation of Odoo Server. # Translation of Odoo Server.
# This file contains the translation of the following modules: # This file contains the translation of the following modules:
# * pos_margin
# * pos_margin
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-08-15 11:04+0000\n"
"PO-Revision-Date: 2019-08-15 11:04+0000\n"
"Last-Translator: <>\n" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -14,36 +16,37 @@ msgstr ""
"Plural-Forms: \n" "Plural-Forms: \n"
#. module: pos_margin #. module: pos_margin
#: model:ir.model.fields,field_description:pos_margin.field_pos_order_line_purchase_price
#: model:ir.model.fields,field_description:pos_margin.field_pos_order_line__purchase_price
msgid "Cost Price" msgid "Cost Price"
msgstr "" msgstr ""
#. module: pos_margin #. module: pos_margin
#: model:ir.model.fields,help:pos_margin.field_pos_order_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." msgid "It gives profitability by calculating the difference between the Unit Price and the cost price."
msgstr "" msgstr ""
#. module: pos_margin #. module: pos_margin
#: model:ir.model,name:pos_margin.model_pos_order_line
msgid "Lines of Point of Sale Orders"
msgstr ""
#. module: pos_margin
#: model:ir.model.fields,field_description:pos_margin.field_pos_order_line_margin
#: model:ir.model.fields,field_description:pos_margin.field_pos_order_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" msgid "Margin"
msgstr "" msgstr ""
#. module: pos_margin #. module: pos_margin
#: model:ir.model.fields,field_description:pos_margin.field_report_pos_order_margin_rate
#: model:ir.model.fields,field_description:pos_margin.field_report_pos_order__margin_rate
msgid "Margin Rate" msgid "Margin Rate"
msgstr "" msgstr ""
#. module: pos_margin #. module: pos_margin
#: model:ir.model.fields,field_description:pos_margin.field_report_pos_order_margin_total
#: 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" msgid "Margin Total"
msgstr "" msgstr ""
#. module: pos_margin
#: model:ir.model,name:pos_margin.model_pos_order_line
msgid "Point of Sale Order Lines"
msgstr ""
#. module: pos_margin #. module: pos_margin
#: model:ir.model,name:pos_margin.model_pos_order #: model:ir.model,name:pos_margin.model_pos_order
msgid "Point of Sale Orders" msgid "Point of Sale Orders"
@ -51,6 +54,6 @@ msgstr ""
#. module: pos_margin #. module: pos_margin
#: model:ir.model,name:pos_margin.model_report_pos_order #: model:ir.model,name:pos_margin.model_report_pos_order
msgid "Point of Sale Orders Statistics"
msgid "Point of Sale Orders Report"
msgstr "" msgstr ""

2
pos_margin/models/pos_order.py

@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models from odoo import api, fields, models
import openerp.addons.decimal_precision as dp
import odoo.addons.decimal_precision as dp
class PosOrder(models.Model): class PosOrder(models.Model):

28
pos_margin/models/pos_order_line.py

@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models from odoo import api, fields, models
import openerp.addons.decimal_precision as dp
import odoo.addons.decimal_precision as dp
class PosOrderLine(models.Model): class PosOrderLine(models.Model):
@ -22,11 +22,21 @@ class PosOrderLine(models.Model):
@api.multi @api.multi
@api.depends('product_id', 'qty', 'price_subtotal') @api.depends('product_id', 'qty', 'price_subtotal')
def _compute_multi_margin(self): def _compute_multi_margin(self):
for line in self:
if not line.product_id:
line.purchase_price = 0
line.margin = 0
else:
line.purchase_price = line.product_id.standard_price
line.margin = line.price_subtotal - (
line.product_id.standard_price * line.qty)
for line in self.filtered(lambda x: x.product_id):
purchase_price = self._get_purchase_price(line)
line.purchase_price = purchase_price
line.margin = line.price_subtotal - (purchase_price * line.qty)
@api.model
def _get_purchase_price(self, line):
# We call _get_purchase_price from sale_margin module, to reuse
# computation that handles multi currencies context and UoM
SaleOrderLine = self.env['sale.order.line']
# if used in combination with module which does add the uom_id to line
uom = hasattr(line, 'uom_id') and line.uom_id\
or line.product_id.uom_id
return SaleOrderLine._get_purchase_price(
line.order_id.pricelist_id, line.product_id, uom,
line.order_id.date_order)['purchase_price']

2
pos_margin/readme/CONTRIBUTORS.rst

@ -0,0 +1,2 @@
* Sylvain LE GAL (https://twitter.com/legalsylvain)
* Wolfgang Pichler

5
pos_margin/readme/DESCRIPTION.rst

@ -0,0 +1,5 @@
This module extends the functionality of point of sale to support margin on
pos orders.
This gives the profitability by calculating the difference between the Unit
Price and Cost Price.

8
pos_margin/readme/HISTORY.rst

@ -0,0 +1,8 @@
12.0.1.0.0
~~~~~~~~~~
* Migrate to V12.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

7
pos_margin/readme/ROADMAP.rst

@ -0,0 +1,7 @@
This module depends on ``sale_margin`` module to reuse algorithm present in the
function ``_get_purchase_price`` of the model ``sale.order.line`` to
compute correctly purchase price, in a multicurrency context.
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).

7
pos_margin/readme/USAGE.rst

@ -0,0 +1,7 @@
To use this module, you need to:
* Go to 'Point Of Sale' / 'Orders' / 'Orders'
* Open an order
.. figure:: ../static/description/pos_order_form.png
:width: 800px

BIN
pos_margin/static/description/pos_order_form.png

Before

Width: 776  |  Height: 419  |  Size: 28 KiB

After

Width: 896  |  Height: 379  |  Size: 30 KiB

1
pos_margin/tests/__init__.py

@ -0,0 +1 @@
from . import test_module

68
pos_margin/tests/test_module.py

@ -0,0 +1,68 @@
# Copyright 2019 - Today Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields
from odoo.tests.common import TransactionCase
class TestModule(TransactionCase):
def setUp(self):
super(TestModule, self).setUp()
self.PosOrder = self.env['pos.order']
self.pos_product = self.env.ref('point_of_sale.whiteboard_pen')
self.pricelist = self.env.ref('product.list0')
# Create a new pos config and open it
self.pos_config = self.env.ref('point_of_sale.pos_config_main').copy()
self.pos_config.open_session_cb()
def test_margin(self):
self.pos_product.list_price = 1.8
self.pos_product.standard_price = 0.5
order = self._create_order()
self.assertEqual(
order.margin, 10 * (1.8 - 0.5),
"Bad computation of margin")
def _create_order(self):
# Create order
order_data = {
'id': u'0006-001-0010',
'to_invoice': False,
'data': {
'pricelist_id': self.pricelist.id,
'user_id': 1,
'name': 'Order 0006-001-0010',
'partner_id': False,
'amount_paid': 0.9,
'pos_session_id': self.pos_config.current_session_id.id,
'lines': [[0, 0, {
'product_id': self.pos_product.id,
'price_unit': self.pos_product.list_price,
'qty': 10,
'price_subtotal': 18.0,
'price_subtotal_incl': 18.0,
}]],
'statement_ids': [[0, 0, {
'journal_id': self.pos_config.journal_ids[0].id,
'amount': 18.0,
'name': fields.Datetime.now(),
'account_id':
self.env.user.partner_id.property_account_receivable_id.id,
'statement_id':
self.pos_config.current_session_id.statement_ids[0].id,
}]],
'creation_date': u'2018-09-27 15:51:03',
'amount_tax': 0,
'fiscal_position_id': False,
'uid': u'00001-001-0001',
'amount_return': 0,
'sequence_number': 1,
'amount_total': 18.0,
}}
result = self.PosOrder.create_from_ui([order_data])
order = self.PosOrder.browse(result[0])
return order

20
pos_margin/views/view_pos_order.xml

@ -11,15 +11,23 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="model">pos.order</field> <field name="model">pos.order</field>
<field name="inherit_id" ref="point_of_sale.view_pos_pos_form"/> <field name="inherit_id" ref="point_of_sale.view_pos_pos_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//group[@name='order_total']" position="after">
<group name="margin">
<field name="margin" widget='monetary'/>
</group>
</xpath>
<field name="amount_total" position="after">
<field name="margin" widget="monetary"/>
</field>
<xpath expr="//field[@name='lines']/tree/field[@name='price_unit']" position="after"> <xpath expr="//field[@name='lines']/tree/field[@name='price_unit']" position="after">
<field name="purchase_price"/>
<field name="purchase_price" widget="monetary"/>
</xpath> </xpath>
</field> </field>
</record> </record>
<record id="view_pos_order_tree" model="ir.ui.view">
<field name="model">pos.order</field>
<field name="inherit_id" ref="point_of_sale.view_pos_order_tree"/>
<field name="arch" type="xml">
<field name="amount_total" position="before">
<field name="margin" widget="monetary" sum="Margin Total"/>
</field>
</field>
</record>
</odoo> </odoo>
Loading…
Cancel
Save