Browse Source

Merge PR #521 into 12.0

Signed-off-by legalsylvain
pull/449/head
OCA-git-bot 4 years ago
parent
commit
906d58fb3f
  1. 1
      pos_session_closing_stock_error/__init__.py
  2. 19
      pos_session_closing_stock_error/__manifest__.py
  3. 2
      pos_session_closing_stock_error/models/__init__.py
  4. 11
      pos_session_closing_stock_error/models/pos_config.py
  5. 20
      pos_session_closing_stock_error/models/pos_session.py
  6. 2
      pos_session_closing_stock_error/readme/CONFIGURE.rst
  7. 1
      pos_session_closing_stock_error/readme/CONTRIBUTORS.rst
  8. 7
      pos_session_closing_stock_error/readme/DESCRIPTION.rst
  9. BIN
      pos_session_closing_stock_error/static/description/error_msg.png
  10. BIN
      pos_session_closing_stock_error/static/description/session_with_errors.png
  11. 1
      pos_session_closing_stock_error/tests/__init__.py
  12. 64
      pos_session_closing_stock_error/tests/test_pos.py
  13. 22
      pos_session_closing_stock_error/views/pos_config_views.xml

1
pos_session_closing_stock_error/__init__.py

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

19
pos_session_closing_stock_error/__manifest__.py

@ -0,0 +1,19 @@
# Copyright 2020 Druidoo - Iván Todorovich
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
{
"name": "Point of Sale - Prevent closing sessions with stock errors",
"summary": "Prevent closing PoS Sessions that have stock errors",
"version": "12.0.1.0.0",
"development_status": "Beta",
"category": "Point of Sale",
"website": "https://github.com/OCA/pos",
"author": "Druidoo, Odoo Community Association (OCA)",
"maintainers": ["ivantodorovich"],
"license": "LGPL-3",
"depends": [
"point_of_sale",
],
"data": [
"views/pos_config_views.xml",
],
}

2
pos_session_closing_stock_error/models/__init__.py

@ -0,0 +1,2 @@
from . import pos_config
from . import pos_session

11
pos_session_closing_stock_error/models/pos_config.py

@ -0,0 +1,11 @@
from odoo import models, fields
class PosConfig(models.Model):
_inherit = 'pos.config'
allow_session_closing_with_stock_errors = fields.Boolean(
string="Allow closing sessions with stock errors",
help="If disabled, closing a session that has stock errors "
"will be blocked.",
)

20
pos_session_closing_stock_error/models/pos_session.py

@ -0,0 +1,20 @@
from odoo import models, _
from odoo.exceptions import ValidationError
class PosSession(models.Model):
_inherit = 'pos.session'
def action_pos_session_close(self):
for rec in self:
if (
rec.picking_count
and not rec.config_id.allow_session_closing_with_stock_errors
):
raise ValidationError(_(
"It's not possible to close the session %s because it has "
"%i picking error(s).\nPlease resolve them or enable "
"'Allow closing sessions with stock errors' in "
"PoS Configuration: %s.") % (
rec.name, rec.picking_count, rec.config_id.name))
return super().action_pos_session_close()

2
pos_session_closing_stock_error/readme/CONFIGURE.rst

@ -0,0 +1,2 @@
In any Point of Sale configuration (pos.config), disable "Allow closing sessions with stock errors"
to prevent closing sessions with stock errors.

1
pos_session_closing_stock_error/readme/CONTRIBUTORS.rst

@ -0,0 +1 @@
* Iván Todorovich <ivan.todorovich@gmail.com>

7
pos_session_closing_stock_error/readme/DESCRIPTION.rst

@ -0,0 +1,7 @@
Prevent closing PoS Sessions that have stock.picking errors.
These errors usually happen when selecting a wrong serial/lot number in the POS.
.. image:: ../static/description/session_with_errors.png
.. image:: ../static/description/error_msg.png

BIN
pos_session_closing_stock_error/static/description/error_msg.png

After

Width: 652  |  Height: 194  |  Size: 17 KiB

BIN
pos_session_closing_stock_error/static/description/session_with_errors.png

After

Width: 1264  |  Height: 592  |  Size: 59 KiB

1
pos_session_closing_stock_error/tests/__init__.py

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

64
pos_session_closing_stock_error/tests/test_pos.py

@ -0,0 +1,64 @@
from odoo import fields
from odoo.exceptions import ValidationError
from odoo.tests.common import TransactionCase
class TestPos(TransactionCase):
def setUp(self):
super().setUp()
self.pos_config = self.env.ref('point_of_sale.pos_config_main').copy({
'name': 'Block PoS Session with Stock Error',
'allow_session_closing_with_stock_errors': False,
})
self.product_tracking = self.env.ref(
'point_of_sale.desk_organizer'
).copy({
'name': 'Product with Tracking',
'tracking': 'serial',
})
def test_session_closing_with_errors(self):
pos_session = self.env['pos.session'].create({
'config_id': self.pos_config.id,
})
# We create an order that will generate errors
# (the product requires a serial number)
pos_order = self.env['pos.order'].create({
'session_id': pos_session.id,
'lines': [(0, 0, {
'name': 'OL/0001',
'product_id': self.product_tracking.id,
'tax_ids': False,
'qty': 1.0,
'price_unit': 1000,
'price_subtotal': 1000,
'price_subtotal_incl': 1000,
})],
'amount_total': 1000.0,
'amount_tax': 0.0,
'amount_paid': 1000.0,
'amount_return': 0.0,
})
# Register order payment
pos_order.add_payment({
'amount': 1000,
'payment_date': fields.Datetime.now(),
'statement_id': pos_session.statement_ids[0].id,
'payment_name': 'PAY',
'journal': pos_session.statement_ids[0].journal_id.id,
})
# Set ending balance in statement
pos_session.statement_ids[0].write({
'balance_end_real': pos_session.statement_ids[0].balance_end
})
pos_order.action_pos_order_paid()
# Blocked because we have errors
with self.assertRaises(ValidationError):
pos_session.action_pos_session_close()
# Enable closing with errors
self.pos_config.write({
'allow_session_closing_with_stock_errors': True,
})
# Should be possible to close now
pos_session.action_pos_session_close()

22
pos_session_closing_stock_error/views/pos_config_views.xml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="pos_config_view_form" model="ir.ui.view">
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
<field name="arch" type="xml">
<div id="inventory_location" position="inside">
<div id="allow_session_closing_with_stock_errors" class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="allow_session_closing_with_stock_errors"/>
</div>
<div class="o_setting_right_pane">
<label for="allow_session_closing_with_stock_errors"/>
<div class="text-muted">
If disabled, closing a session that has stock errors will be blocked.
</div>
</div>
</div>
</div>
</field>
</record>
</odoo>
Loading…
Cancel
Save