Skip to content

Commit

Permalink
[IMP] pos_order_mgmt: black, isort, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
zamberjo committed Apr 13, 2023
1 parent f6b5e61 commit 3524475
Show file tree
Hide file tree
Showing 14 changed files with 479 additions and 374 deletions.
16 changes: 8 additions & 8 deletions pos_order_mgmt/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ POS Frontend Orders Management
: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/12.0/pos_order_mgmt
:target: https://github.com/OCA/pos/tree/14.0/pos_order_mgmt
:alt: OCA/pos
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/pos-12-0/pos-12-0-pos_order_mgmt
:target: https://translation.odoo-community.org/projects/pos-14.0/pos-14.0-pos_order_mgmt
: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/12.0
:target: https://runbot.odoo-community.org/runbot/184/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -40,7 +40,7 @@ Configuration
To configure this module, you need to go to *Point of Sale > Configuration >
Point of Sale* and enable *Order Management*

.. image:: https://raw.githubusercontent.com/OCA/pos/12.0/pos_order_mgmt/static/description/order-mgmt-config.png
.. image:: https://raw.githubusercontent.com/OCA/pos/14.0/pos_order_mgmt/static/description/order-mgmt-config.png

#. Change *Maximum orders to load* to your desired amount (10 by default).
Please note that the more you load, the more it will take to load
Expand All @@ -62,13 +62,13 @@ Usage
Once the PoS is loaded, you'll find a shopping trolley icon (🛒) in the top
bar that grants access to the order list screen.

.. image:: https://raw.githubusercontent.com/OCA/pos/12.0/pos_order_mgmt/static/description/order-mgmt-icon.png
.. image:: https://raw.githubusercontent.com/OCA/pos/14.0/pos_order_mgmt/static/description/order-mgmt-icon.png

There you can find the number of past orders loaded according to your
configuration (see Configuration) as well as the orders you checked out in
the current session:

.. image:: https://raw.githubusercontent.com/OCA/pos/12.0/pos_order_mgmt/static/description/order-mgmt-list.png
.. image:: https://raw.githubusercontent.com/OCA/pos/14.0/pos_order_mgmt/static/description/order-mgmt-list.png

#. You can see their totals as well as their custumers if registered.
#. You can reprint their tickets clicking on the printer icon (⎙).
Expand All @@ -93,7 +93,7 @@ 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_order_mgmt%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/pos/issues/new?body=module:%20pos_order_mgmt%0Aversion:%2014.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.

Expand Down Expand Up @@ -129,6 +129,6 @@ 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.

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
36 changes: 16 additions & 20 deletions pos_order_mgmt/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
'name': 'POS Frontend Orders Management',
'summary': 'Manage old POS Orders from the frontend',
'version': '12.0.1.1.4',
'category': 'Point of Sale',
'author': 'GRAP, '
'Tecnativa, '
'Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/pos',
'license': 'AGPL-3',
'depends': [
'point_of_sale',
"name": "POS Frontend Orders Management",
"summary": "Manage old POS Orders from the frontend",
"version": "14.0.1.0.0",
"category": "Point of Sale",
"author": "GRAP, " "Tecnativa, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/pos",
"license": "AGPL-3",
"depends": [
"point_of_sale",
],
'data': [
'views/assets.xml',
'views/view_pos_config.xml',
'views/view_pos_order.xml',
"data": [
"views/assets.xml",
"views/view_pos_config.xml",
"views/view_pos_order.xml",
],
'qweb': [
'static/src/xml/pos.xml'
],
'application': False,
'installable': True,
"qweb": ["static/src/xml/pos.xml"],
"application": False,
"installable": True,
}
26 changes: 13 additions & 13 deletions pos_order_mgmt/models/pos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,37 @@


class PosConfig(models.Model):
_inherit = 'pos.config'
_inherit = "pos.config"

iface_order_mgmt = fields.Boolean(
string='Order Management',
help='Allows to manage orders in the frontend',
string="Order Management",
help="Allows to manage orders in the frontend",
default=True,
)

iface_reprint_done_order = fields.Boolean(
string='Reprint Orders',
string="Reprint Orders",
default=True,
help='Allows to reprint already done orders in the frontend',
help="Allows to reprint already done orders in the frontend",
)

iface_return_done_order = fields.Boolean(
string='Return Orders',
string="Return Orders",
default=True,
help='Allows to return already done orders in the frontend',
help="Allows to return already done orders in the frontend",
)

iface_copy_done_order = fields.Boolean(
string='Duplicate Orders',
string="Duplicate Orders",
default=True,
help='Allows to duplicate already done orders in the frontend',
help="Allows to duplicate already done orders in the frontend",
)

iface_load_done_order_max_qty = fields.Integer(
string='Maximum Orders to load',
string="Maximum Orders to load",
default=10,
required=True,
help='Maximum number of orders to load on the PoS at its init. '
'Set it to 0 to load none (it\'s still possible to load them by '
'ticket code).',
help="Maximum number of orders to load on the PoS at its init. "
"Set it to 0 to load none (it's still possible to load them by "
"ticket code).",
)
117 changes: 62 additions & 55 deletions pos_order_mgmt/models/pos_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,37 @@
# Copyright 2018 Tecnativa S.L. - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, models, fields
from odoo import api, fields, models


class PosOrder(models.Model):
_inherit = 'pos.order'
_inherit = "pos.order"

returned_order_id = fields.Many2one(
comodel_name='pos.order',
string='Returned Order',
comodel_name="pos.order",
string="Returned Order",
readonly=True,
)

returned_order_reference = fields.Char(
related='returned_order_id.pos_reference',
string='Reference of the returned Order')
related="returned_order_id.pos_reference",
string="Reference of the returned Order",
)

refund_order_ids = fields.One2many(
comodel_name='pos.order',
inverse_name='returned_order_id',
string='Refund Orders',
comodel_name="pos.order",
inverse_name="returned_order_id",
string="Refund Orders",
readonly=True,
)

refund_order_qty = fields.Integer(
compute='_compute_refund_order_qty',
string='Refund Orders Quantity',
compute="_compute_refund_order_qty",
string="Refund Orders Quantity",
)

@api.multi
@api.depends('refund_order_ids')
@api.depends("refund_order_ids")
def _compute_refund_order_qty(self):
for order in self:
order.refund_order_qty = len(order.refund_order_ids)
Expand All @@ -40,66 +41,71 @@ def _compute_refund_order_qty(self):
def action_view_refund_orders(self):
self.ensure_one()

action = self.env.ref('point_of_sale.action_pos_pos_form').read()[0]
action = self.env.ref("point_of_sale.action_pos_pos_form").read()[0]

if self.refund_order_qty == 1:
action['views'] = [
(self.env.ref('point_of_sale.view_pos_pos_form').id, 'form')]
action['res_id'] = self.refund_order_ids.ids[0]
action["views"] = [
(self.env.ref("point_of_sale.view_pos_pos_form").id, "form")
]
action["res_id"] = self.refund_order_ids.ids[0]
else:
action['domain'] = [('id', 'in', self.refund_order_ids.ids)]
action["domain"] = [("id", "in", self.refund_order_ids.ids)]
return action

@api.multi
def refund(self):
return super(PosOrder, self.with_context(refund=True)).refund()

@api.multi
@api.returns('self', lambda value: value.id)
@api.returns("self", lambda value: value.id)
def copy(self, default=None):
self.ensure_one()
order = super().copy(default=default)
if self.env.context.get('refund', False):
if self.env.context.get("refund", False):
order.returned_order_id = self.id
return order

@api.model
def _prepare_filter_for_pos(self, pos_session_id):
return [
('state', 'in', ['paid', 'done', 'invoiced']),
("state", "in", ["paid", "done", "invoiced"]),
]

@api.model
def _prepare_filter_query_for_pos(self, pos_session_id, query):
return [
'|', '|',
('name', 'ilike', query),
('pos_reference', 'ilike', query),
('partner_id.display_name', 'ilike', query),
"|",
"|",
("name", "ilike", query),
("pos_reference", "ilike", query),
("partner_id.display_name", "ilike", query),
]

@api.model
def _prepare_fields_for_pos_list(self):
return [
'name', 'pos_reference', 'partner_id', 'date_order',
'amount_total',
"name",
"pos_reference",
"partner_id",
"date_order",
"amount_total",
]

@api.model
def search_done_orders_for_pos(self, query, pos_session_id):
session_obj = self.env['pos.session']
session_obj = self.env["pos.session"]
config = session_obj.browse(pos_session_id).config_id
condition = self._prepare_filter_for_pos(pos_session_id)
if not query:
# Search only this POS orders
condition += [('config_id', '=', config.id)]
condition += [("config_id", "=", config.id)]
else:
# Search globally by criteria
condition += self._prepare_filter_query_for_pos(
pos_session_id, query)
condition += self._prepare_filter_query_for_pos(pos_session_id, query)
field_names = self._prepare_fields_for_pos_list()
return self.search_read(
condition, field_names, limit=config.iface_load_done_order_max_qty)
condition, field_names, limit=config.iface_load_done_order_max_qty
)

@api.multi
def _prepare_done_order_for_pos(self):
Expand All @@ -110,42 +116,41 @@ def _prepare_done_order_for_pos(self):
order_line = self._prepare_done_order_line_for_pos(order_line)
order_lines.append(order_line)
for payment_line in self.statement_ids:
payment_line = self._prepare_done_order_payment_for_pos(
payment_line)
payment_line = self._prepare_done_order_payment_for_pos(payment_line)
payment_lines.append(payment_line)
res = {
'id': self.id,
'date_order': self.date_order,
'pos_reference': self.pos_reference,
'name': self.name,
'partner_id': self.partner_id.id,
'fiscal_position': self.fiscal_position_id.id,
'pricelist_id': self.pricelist_id.id,
'line_ids': order_lines,
'statement_ids': payment_lines,
'to_invoice': bool(self.invoice_id),
'returned_order_id': self.returned_order_id.id,
'returned_order_reference': self.returned_order_reference,
"id": self.id,
"date_order": self.date_order,
"pos_reference": self.pos_reference,
"name": self.name,
"partner_id": self.partner_id.id,
"fiscal_position": self.fiscal_position_id.id,
"pricelist_id": self.pricelist_id.id,
"line_ids": order_lines,
"statement_ids": payment_lines,
"to_invoice": bool(self.invoice_id),
"returned_order_id": self.returned_order_id.id,
"returned_order_reference": self.returned_order_reference,
}
return res

@api.multi
def _prepare_done_order_line_for_pos(self, order_line):
self.ensure_one()
return {
'product_id': order_line.product_id.id,
'qty': order_line.qty,
'price_unit': order_line.price_unit,
'discount': order_line.discount,
'pack_lot_names': order_line.pack_lot_ids.mapped('lot_name'),
"product_id": order_line.product_id.id,
"qty": order_line.qty,
"price_unit": order_line.price_unit,
"discount": order_line.discount,
"pack_lot_names": order_line.pack_lot_ids.mapped("lot_name"),
}

@api.multi
def _prepare_done_order_payment_for_pos(self, payment_line):
self.ensure_one()
return {
'journal_id': payment_line.journal_id.id,
'amount': payment_line.amount,
"journal_id": payment_line.journal_id.id,
"amount": payment_line.amount,
}

@api.multi
Expand All @@ -156,7 +161,9 @@ def load_done_order_for_pos(self):
@api.model
def _order_fields(self, ui_order):
res = super()._order_fields(ui_order)
res.update({
'returned_order_id': ui_order.get('returned_order_id', False),
})
res.update(
{
"returned_order_id": ui_order.get("returned_order_id", False),
}
)
return res
4 changes: 2 additions & 2 deletions pos_order_mgmt/static/src/css/pos.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
color: white;
}

.orderlist-screen table td[name='td_ol_amount_total'] {
.orderlist-screen table td[name="td_ol_amount_total"] {
text-align: right;
}

/* Keep the table from breaking when the customer name is too long */
.orderlist-screen table td:not([name='td_ol_customer']) {
.orderlist-screen table td:not([name="td_ol_customer"]) {
white-space: nowrap;
}
6 changes: 3 additions & 3 deletions pos_order_mgmt/static/src/js/models.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* Copyright 2018 Tecnativa - David Vidal
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */

odoo.define('pos_order_mgmt.models', function (require) {
'use strict';
odoo.define("pos_order_mgmt.models", function (require) {
"use strict";

var models = require('point_of_sale.models');
var models = require("point_of_sale.models");

var order_super = models.Order.prototype;

Expand Down
Loading

0 comments on commit 3524475

Please sign in to comment.