From 7eabfd06fe96182609b542693c0ff3a8f10dd4ca Mon Sep 17 00:00:00 2001 From: "Aurelien van Delft (avd)" Date: Wed, 10 Jan 2024 10:35:32 +0000 Subject: [PATCH] [FIX] point_of_sale: add missing indexes for create_from_ui MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add two missing indexes on pos.order and one on pos.payment. These speed up queries executed when calling create_from_ui from the pos interface. opw-3619270 closes odoo/odoo#151441 X-original-commit: 6f1b5bd530dbb211bb0dbc41b523233dfb57d002 Signed-off-by: Joseph Caburnay (jcb) Signed-off-by: Aurélien van Delft (avd) --- addons/point_of_sale/models/pos_order.py | 4 ++-- addons/point_of_sale/models/pos_payment.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index 7ce0d881475..ca3b7383599 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -298,7 +298,7 @@ class PosOrder(models.Model): is_total_cost_computed = fields.Boolean(compute='_compute_is_total_cost_computed', help="Allows to know if all the total cost of the order lines have already been computed") lines = fields.One2many('pos.order.line', 'order_id', string='Order Lines', copy=True) - company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True) + company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, index=True) country_code = fields.Char(related='company_id.account_fiscal_country_id.code') pricelist_id = fields.Many2one('product.pricelist', string='Pricelist') partner_id = fields.Many2one('res.partner', string='Customer', change_default=True, index='btree_not_null') @@ -325,7 +325,7 @@ class PosOrder(models.Model): note = fields.Text(string='Internal Notes') nb_print = fields.Integer(string='Number of Print', readonly=True, copy=False, default=0) - pos_reference = fields.Char(string='Receipt Number', readonly=True, copy=False) + pos_reference = fields.Char(string='Receipt Number', readonly=True, copy=False, index=True) sale_journal = fields.Many2one('account.journal', related='session_id.config_id.journal_id', string='Sales Journal', store=True, readonly=True, ondelete='restrict') fiscal_position_id = fields.Many2one( comodel_name='account.fiscal.position', string='Fiscal Position', diff --git a/addons/point_of_sale/models/pos_payment.py b/addons/point_of_sale/models/pos_payment.py index f6ba767ce6f..15d94f77c67 100644 --- a/addons/point_of_sale/models/pos_payment.py +++ b/addons/point_of_sale/models/pos_payment.py @@ -16,7 +16,7 @@ class PosPayment(models.Model): _order = "id desc" name = fields.Char(string='Label', readonly=True) - pos_order_id = fields.Many2one('pos.order', string='Order', required=True) + pos_order_id = fields.Many2one('pos.order', string='Order', required=True, index=True) amount = fields.Monetary(string='Amount', required=True, currency_field='currency_id', readonly=True, help="Total amount of the payment.") payment_method_id = fields.Many2one('pos.payment.method', string='Payment Method', required=True) payment_date = fields.Datetime(string='Date', required=True, readonly=True, default=lambda self: fields.Datetime.now())