From 7586194e0ca68e7c25b6a1725d368eb8d5c62b3a Mon Sep 17 00:00:00 2001 From: Joren Van Onder Date: Wed, 27 Jan 2016 10:02:14 +0100 Subject: [PATCH 01/15] [IMP] account: create an index on account.move.statement_line_id account.bank.statement.line has a journal_entry_ids field which is a o2m to account.move. During confirmation of bank statements (button_confirm_bank()) this o2m field is heavily used. When a database has a lot of account.move records this lookup starts taking up quite a bit of time. As an example, on a locally duplicated customer database with ~700000 account.move records attempting to resolve journal_entry_ids of an account.bank.statement.line record was observed to take > 1 second. This index improves it to be < 5 milliseconds. This is especially important when big POS sessions have to be closed, because those will contain a lot of account.bank.statement.line records. opw-665309 --- addons/account/account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/account.py b/addons/account/account.py index ac56c6891e2..1380a01d139 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1295,7 +1295,7 @@ class account_move(osv.osv): 'narration':fields.text('Internal Note'), 'company_id': fields.related('journal_id','company_id',type='many2one',relation='res.company',string='Company', store=True, readonly=True), 'balance': fields.float('balance', digits_compute=dp.get_precision('Account'), help="This is a field only used for internal purpose and shouldn't be displayed"), - 'statement_line_id': fields.many2one('account.bank.statement.line', 'Bank statement line reconciled with this entry', copy=False, readonly=True) + 'statement_line_id': fields.many2one('account.bank.statement.line', 'Bank statement line reconciled with this entry', copy=False, readonly=True, select=True) } _defaults = { From 634c62610efc784b47206a700a796fdbb343ec30 Mon Sep 17 00:00:00 2001 From: Joren Van Onder Date: Wed, 27 Jan 2016 12:21:40 +0100 Subject: [PATCH 02/15] [FIX] purchase: only search in requested model Because otherwise a user who has access to a view displaying supplier_invoice_count will get an access error if he doesn't also have access to purchase.order, even if that wouldn't have been displayed. opw-666935 --- addons/purchase/partner.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/addons/purchase/partner.py b/addons/purchase/partner.py index bc2255cca03..b86471fafaa 100644 --- a/addons/purchase/partner.py +++ b/addons/purchase/partner.py @@ -28,13 +28,17 @@ class res_partner(osv.osv): def _purchase_invoice_count(self, cr, uid, ids, field_name, arg, context=None): PurchaseOrder = self.pool['purchase.order'] Invoice = self.pool['account.invoice'] - return { - partner_id: { - 'purchase_order_count': PurchaseOrder.search_count(cr,uid, [('partner_id', 'child_of', partner_id)], context=context), - 'supplier_invoice_count': Invoice.search_count(cr,uid, [('partner_id', 'child_of', partner_id), ('type','=','in_invoice')], context=context) - } - for partner_id in ids - } + res = {} + + for partner_id in ids: + res[partner_id] = {} + + if 'purchase_order_count' in field_name: + res[partner_id]['purchase_order_count'] = PurchaseOrder.search_count(cr,uid, [('partner_id', 'child_of', partner_id)], context=context) + if 'supplier_invoice_count' in field_name: + res[partner_id]['supplier_invoice_count'] = Invoice.search_count(cr,uid, [('partner_id', 'child_of', partner_id), ('type','=','in_invoice')], context=context) + + return res def _commercial_fields(self, cr, uid, context=None): return super(res_partner, self)._commercial_fields(cr, uid, context=context) + ['property_product_pricelist_purchase'] From e2d16ea04a2ae98800086619ff5dc94dfa6eb5d3 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 27 Jan 2016 16:28:49 +0100 Subject: [PATCH 03/15] [FIX] account_voucher: unreconcile with deleted journal items This is possible to unreconcile and then remove journal items associated to `account.voucher.line`. When it's done, the voucher is within a corrupted state, with debits and credits lines without journal item, which is required. Because the journal item of this line is empty, while required, this is no longer possible to use the "Unreconcile" button, because the form is invalid. In order to allow to unreconcile a posted customer/supplier payments with missing journal items, we set the journal items as required only when the payment is within the `draft` stage. opw-667232 --- addons/account_voucher/account_voucher.py | 1 + addons/account_voucher/voucher_payment_receipt_view.xml | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index d942225d70b..949239f8124 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -1498,6 +1498,7 @@ class account_voucher_line(osv.osv): 'amount_unreconciled': fields.function(_compute_balance, multi='dc', type='float', string='Open Balance', store=True, digits_compute=dp.get_precision('Account')), 'company_id': fields.related('voucher_id','company_id', relation='res.company', type='many2one', string='Company', store=True, readonly=True), 'currency_id': fields.function(_currency_id, string='Currency', type='many2one', relation='res.currency', readonly=True), + 'state': fields.related('voucher_id', 'state', type='char', string='State', readonly=True), } _defaults = { 'name': '', diff --git a/addons/account_voucher/voucher_payment_receipt_view.xml b/addons/account_voucher/voucher_payment_receipt_view.xml index 073b1efed82..f70f47c54ef 100644 --- a/addons/account_voucher/voucher_payment_receipt_view.xml +++ b/addons/account_voucher/voucher_payment_receipt_view.xml @@ -163,10 +163,11 @@