Browse Source

[MIG] pos_customer_required: Migration to 12.0

pull/450/head
Iván Todorovich 5 years ago
committed by Iván Todorovich
parent
commit
9954466d06
  1. 92
      pos_customer_required/README.rst
  2. 1
      pos_customer_required/__init__.py
  3. 7
      pos_customer_required/__manifest__.py
  4. 14
      pos_customer_required/demo/pos_config.xml
  5. 7
      pos_customer_required/demo/pos_config.yml
  6. 19
      pos_customer_required/migrations/9.0.1.0.0/post-migration.py
  7. 18
      pos_customer_required/migrations/9.0.1.0.0/pre-migration.py
  8. 1
      pos_customer_required/models/__init__.py
  9. 4
      pos_customer_required/models/pos_config.py
  10. 6
      pos_customer_required/models/pos_make_payment.py
  11. 17
      pos_customer_required/models/pos_order.py
  12. 8
      pos_customer_required/readme/CONFIGURE.rst
  13. 4
      pos_customer_required/readme/CONTRIBUTORS.rst
  14. 28
      pos_customer_required/readme/DESCRIPTION.rst
  15. 3
      pos_customer_required/readme/USAGE.rst
  16. 6
      pos_customer_required/static/src/js/pos_customer_required.js
  17. 6
      pos_customer_required/static/src/xml/templates.xml
  18. 1
      pos_customer_required/tests/__init__.py
  19. 32
      pos_customer_required/tests/test_pos.py
  20. 23
      pos_customer_required/views/pos_config_view.xml
  21. 3
      pos_customer_required/views/pos_order_view.xml

92
pos_customer_required/README.rst

@ -1,92 +0,0 @@
.. 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
=================================
Point Of Sale - Customer Required
=================================
This module was written to extend the functionality of odoo pos
and allows you to require a customer for each pos order. In the
pos session configuration, you can choose to require the customer for pos
orders.
If a customer is not selected, the pos ui will display an error message.
In the backend the customer field is required when needed.
Two new options are available:
* Customer 'Required before starting the order';
* Customer 'Required before paying';
'Required before starting the order' Option
-------------------------------------------
In the frontend PoS, the default screen is the screen to select customers.
* Users are not allowed to start selling before having selected a customer;
* Users can not 'deselect a customer', only select an other one;
'Required before paying' Option
-------------------------------
In the frontend PoS, the user can start selling, but if the user tries to
make payment and if a customer is not selected, the pos ui will display an
error message.
.. image:: /pos_customer_required/static/description/frontend_pos_error_message.png
Configuration
=============
To configure this module, you need to:
* go to point of sale -> configuration -> point of sales
* select the point of sales you want configure
* search for the "Require Customer" and choose between the following values:
* 'Optional'; (this module has no effect on this PoS config)
* 'Required before paying';
* 'Required before starting the order';
Usage
=====
.. 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/9.0
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.
Credits
=======
Contributors
------------
* Jos De Graeve <Jos.DeGraeve@apertoso.be>
* Sylvain LE GAL <https://twitter.com/legalsylvain>
* Pedro M. Baeza <pedro.baeza@gmail.com> ( reviews & feedback )
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 http://odoo-community.org.

1
pos_customer_required/__init__.py

@ -1,2 +1 @@
# -*- coding: utf-8 -*-
from . import models

7
pos_customer_required/__openerp__.py → pos_customer_required/__manifest__.py

@ -1,17 +1,18 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2004-Today Apertoso NV (<http://www.apertoso.be>)
# Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
# Copyright (C) 2019-Today: Druidoo (<https://www.druidoo.io>)
# @author: Jos DE GRAEVE (<Jos.DeGraeve@apertoso.be>)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html
{
'name': 'Point of Sale Require Customer',
'version': '9.0.1.0.0',
'version': '12.0.1.0.0',
'category': 'Point Of Sale',
'summary': 'Point of Sale Require Customer',
'author': 'Apertoso NV, La Louve, Odoo Community Association (OCA)',
'website': 'http://www.apertoso.be',
'license': 'AGPL-3',
'depends': [
'point_of_sale',
],
@ -21,7 +22,7 @@
'views/pos_order_view.xml',
],
'demo': [
'demo/pos_config.yml',
'demo/pos_config.xml',
],
'installable': True,
}

14
pos_customer_required/demo/pos_config.xml

@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!--
Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
Copyright (C) 2019-Today: Druidoo (<https://www.druidoo.io>)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<!-- POS Config: Require Customer(Required before starting the order) -->
<record id="point_of_sale.pos_config_main" model="pos.config">
<field name="require_customer">order</field>
</record>
</odoo>

7
pos_customer_required/demo/pos_config.yml

@ -1,7 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
- !record {model: pos.config, id: point_of_sale.pos_config_main}:
require_customer: order

19
pos_customer_required/migrations/9.0.1.0.0/post-migration.py

@ -1,19 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade
BOOLEAN_TO_SELECTION = [
('false', 'no'),
('true', 'order'),
]
@openupgrade.migrate()
def migrate(cr, installed_version):
openupgrade.map_values(
cr, openupgrade.get_legacy_name('require_customer'),
'require_customer', BOOLEAN_TO_SELECTION, table='pos_config')

18
pos_customer_required/migrations/9.0.1.0.0/pre-migration.py

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade
column_renames = {
'pos_config': [
('require_customer', None),
]
}
@openupgrade.migrate()
def migrate(cr, version):
openupgrade.rename_columns(cr, column_renames)

1
pos_customer_required/models/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from . import pos_config
from . import pos_order
from . import pos_make_payment

4
pos_customer_required/models/pos_config.py

@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2004-Today Apertoso NV (<http://www.apertoso.be>)
# Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
# Copyright (C) 2019-Today: Druidoo (<https://www.druidoo.io>)
# @author: Jos DE GRAEVE (<Jos.DeGraeve@apertoso.be>)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import fields, models
from odoo import fields, models
class PosConfig(models.Model):

6
pos_customer_required/models/pos_make_payment.py

@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
# Copyright (C) 2019-Today: Druidoo (<https://www.druidoo.io>)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, api, _
from openerp.exceptions import UserError
from odoo import models, api, _
from odoo.exceptions import UserError
class PosMakePayment(models.TransientModel):

17
pos_customer_required/models/pos_order.py

@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2004-Today Apertoso NV (<http://www.apertoso.be>)
# Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
# Copyright (C) 2019-Today: Druidoo (<https://www.druidoo.io>)
# @author: Jos DE GRAEVE (<Jos.DeGraeve@apertoso.be>)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import fields, models, exceptions, api
from openerp.tools.translate import _
from odoo import fields, models, exceptions, api, _
class PosOrder(models.Model):
@ -24,10 +23,12 @@ class PosOrder(models.Model):
help="True if a customer is required to begin the order.\n"
"See the PoS Config to change this setting")
@api.one
@api.constrains('partner_id', 'require_customer')
def _check_partner(self):
if (self.session_id.config_id.require_customer == 'order' and
not self.partner_id):
raise exceptions.ValidationError(
_('Customer is required for this order and is missing.'))
for rec in self:
if (
rec.session_id.config_id.require_customer == 'order' and
not rec.partner_id
):
raise exceptions.ValidationError(_(
'Customer is required for this order and is missing.'))

8
pos_customer_required/readme/CONFIGURE.rst

@ -0,0 +1,8 @@
To configure this module, you need to:
* go to point of sale -> configuration -> point of sales
* select the point of sales you want configure
* search for the "Require Customer" and choose between the following values:
* 'Optional'; (this module has no effect on this PoS config)
* 'Required before paying';
* 'Required before starting the order';

4
pos_customer_required/readme/CONTRIBUTORS.rst

@ -0,0 +1,4 @@
* Jos De Graeve <Jos.DeGraeve@apertoso.be>
* Sylvain LE GAL <https://twitter.com/legalsylvain>
* Pedro M. Baeza <pedro.baeza@gmail.com> ( reviews & feedback )
* Druidoo <https://www.druidoo.io>

28
pos_customer_required/readme/DESCRIPTION.rst

@ -0,0 +1,28 @@
This module was written to extend the functionality of odoo pos
and allows you to require a customer for each pos order. In the
pos session configuration, you can choose to require the customer for pos
orders.
If a customer is not selected, the pos ui will display an error message.
In the backend the customer field is required when needed.
Two new options are available:
* Customer 'Required before starting the order';
* Customer 'Required before paying';
'Required before starting the order' Option
-------------------------------------------
In the frontend PoS, the default screen is the screen to select customers.
* Users are not allowed to start selling before having selected a customer;
* Users can not 'deselect a customer', only select an other one;
'Required before paying' Option
-------------------------------
In the frontend PoS, the user can start selling, but if the user tries to
make payment and if a customer is not selected, the pos ui will display an
error message.
.. image:: /pos_customer_required/static/description/frontend_pos_error_message.png

3
pos_customer_required/readme/USAGE.rst

@ -0,0 +1,3 @@
.. 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/9.0

6
pos_customer_required/static/src/js/pos_customer_required.js

@ -5,7 +5,7 @@
@author: Jos DE GRAEVE (<Jos.DeGraeve@apertoso.be>)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
The licence is in the file __openerp__.py
The licence is in the file __manifest__.py
*/
@ -20,7 +20,7 @@ odoo.define('pos_customer_required.pos_customer_required', function (require) {
screens.PaymentScreenWidget.include({
validate_order: function(options) {
if(this.pos.config.require_customer != 'no'
&& !this.pos.get('selectedOrder').get_client()){
&& !this.pos.get_order().get_client()){
this.gui.show_popup('error',{
'title': _t('An anonymous order cannot be confirmed'),
'body': _t('Please select a customer for this order.'),
@ -45,7 +45,7 @@ odoo.define('pos_customer_required.pos_customer_required', function (require) {
var _show_screen_ = gui.Gui.prototype.show_screen;
gui.Gui.prototype.show_screen = function(screen_name, params, refresh){
if(this.pos.config.require_customer == 'order'
&& !this.pos.get('selectedOrder').get_client()
&& !this.pos.get_order().get_client()
&& screen_name != 'clientlist'){
// We call first the original screen, to avoid to break the
// 'previous screen' mecanism

6
pos_customer_required/static/src/xml/templates.xml

@ -6,10 +6,10 @@
@author: Jos DE GRAEVE (<Jos.DeGraeve@apertoso.be>)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
The licence is in the file __openerp__.py
The licence is in the file __manifest__.py
-->
<openerp>
<odoo>
<data>
<template id="assets_frontend" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
@ -17,4 +17,4 @@
</xpath>
</template>
</data>
</openerp>
</odoo>

1
pos_customer_required/tests/__init__.py

@ -1,2 +1 @@
# -*- coding: utf-8 -*-
from . import test_pos

32
pos_customer_required/tests/test_pos.py

@ -1,38 +1,48 @@
# -*- coding: utf-8 -*-
import openerp.tests.common as common
from openerp import exceptions
import odoo.tests.common as common
from odoo import exceptions
class TestPosRequireCustomer(common.TransactionCase):
def setUp(self):
super(TestPosRequireCustomer, self).setUp()
self.pos_config = self.env.ref('point_of_sale.pos_config_main')
def test_customer_not_required(self):
posconfig = self.env.ref('point_of_sale.pos_config_main')
posconfig.require_customer = 'no'
self.pos_config.require_customer = 'no'
# Now Create new session and create a
# pos order in this session
pos_session = self.env['pos.session'].create(
{'config_id': posconfig.id})
pos_session = self.env['pos.session'].create({
'user_id': 1,
'config_id': self.pos_config.id
})
# should not raise any exception
self.env['pos.order'].create({
'session_id': pos_session.id,
'partner_id': False,
'amount_tax': 0.0,
'amount_total': 0.0,
'amount_paid': 0.0,
'amount_return': 0.0
})
def test_customer_is_required(self):
posconfig = self.env.ref('point_of_sale.pos_config_main')
posconfig.require_customer = 'order'
self.pos_config.require_customer = 'order'
# Now Create new session and create a
# pos order in this session
pos_session = self.env['pos.session'].create(
{'config_id': posconfig.id})
pos_session = self.env['pos.session'].create({
'user_id': 1,
'config_id': self.pos_config.id
})
# should raise exceptions.ValidationError
with self.assertRaises(exceptions.ValidationError):
self.env['pos.order'].create({
'session_id': pos_session.id,
'partner_id': False,
'amount_tax': 0.0,
'amount_total': 0.0,
'amount_paid': 0.0,
'amount_return': 0.0
})

23
pos_customer_required/views/pos_config_view.xml

@ -6,18 +6,31 @@
@author: Jos DE GRAEVE (<Jos.DeGraeve@apertoso.be>)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
The licence is in the file __openerp__.py
The licence is in the file __manifest__.py
-->
<odoo>
<record model="ir.ui.view" id="view_pos_config_form">
<field name="name">view.pos.config.form</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.view_pos_config_form" />
<field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
<field name="arch" type="xml">
<field name="iface_tax_included" position="after">
<field name="require_customer" />
</field>
<div id="product_prices" position="after">
<div class="col-xs-12 col-lg-6 o_setting_box" id="require_customer">
<div class="o_setting_right_pane">
<label for="require_customer" string="Require Customer"/>
<div class="text-muted">
Require Customer
</div>
<div class="content-group">
<div class="mt16">
<field name="require_customer" class="o_light_label" widget="radio"/>
</div>
</div>
</div>
</div>
</div>
</field>
</record>

3
pos_customer_required/views/pos_order_view.xml

@ -6,12 +6,13 @@
@author: Jos DE GRAEVE (<Jos.DeGraeve@apertoso.be>)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
The licence is in the file __openerp__.py
The licence is in the file __manifest__.py
-->
<odoo>
<record model="ir.ui.view" id="view_pos_order_form">
<field name="name">view.pos.order.form</field>
<field name="model">pos.order</field>
<field name="inherit_id" ref="point_of_sale.view_pos_pos_form"/>
<field name="arch" type="xml">

Loading…
Cancel
Save