[FIX]point_of_sale:clients from pos sessions are now considered customers

Steps to reproduce:
-install the POS module
-install the Contacts module
-create or use an existing partner as a customer during the pos session
-go to contacts and activate the "customer" filter
-> partners used during the pos session are not showing in the list

The problem was that the 'customer_rank' property
https://github.com/odoo/odoo/blob/d8d7635d6cf2af60791f25201a7bd1c2d5ec238b/addons/account/models/partner.py#L430
was not updated properly after a pos account move was done

Previous behavior
After ending a POS session, partners that are created and/or used
during the session are not showing on the Contacts views when the
'customer' filter is active

Current behavior:
The customer_rank of the partners is increased by one for every sale
during the pos session
Partners created or linked during a POS session are now considered
customers and appear in the contact view when the "customer"
filter is active

opw-2148894

closes odoo/odoo#41792

X-original-commit: 22874376594f94232e0c4ad5a4db3ee76f24b39a
Signed-off-by: Jorge Pinna Puissant (jpp) <jpp@odoo.com>
This commit is contained in:
mightyjol (jhk)
2019-12-12 11:31:32 +00:00
committed by jerome hanke (jhk)
parent 32d8caf088
commit 346048be50
3 changed files with 22 additions and 17 deletions
+2 -17
View File
@@ -13,10 +13,6 @@ from json import dumps
import json
import re
import logging
import psycopg2
_logger = logging.getLogger(__name__)
#forbidden fields
INTEGRITY_HASH_MOVE_FIELDS = ('date', 'journal_id', 'company_id')
@@ -2121,22 +2117,11 @@ class AccountMove(models.Model):
for move in self:
if not move.partner_id: continue
if move.type.startswith('out_'):
field='customer_rank'
move.partner_id._increase_rank('customer_rank')
elif move.type.startswith('in_'):
field='supplier_rank'
move.partner_id._increase_rank('supplier_rank')
else:
continue
try:
with self.env.cr.savepoint():
self.env.cr.execute("SELECT "+field+" FROM res_partner WHERE ID=%s FOR UPDATE NOWAIT", (move.partner_id.id,))
self.env.cr.execute("UPDATE res_partner SET "+field+"="+field+"+1 WHERE ID=%s", (move.partner_id.id,))
self.env.cache.remove(move.partner_id, move.partner_id._fields[field])
except psycopg2.DatabaseError as e:
if e.pgcode == '55P03':
_logger.debug('Another transaction already locked partner rows. Cannot update partner ranks.')
continue
else:
raise e
def action_reverse(self):
action = self.env.ref('account.action_view_account_move_reversal').read()[0]
+17
View File
@@ -3,12 +3,15 @@
import time
import logging
import psycopg2
from odoo import api, fields, models, _
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
from odoo.exceptions import ValidationError
from odoo.addons.base.models.res_partner import WARNING_MESSAGE, WARNING_HELP
_logger = logging.getLogger(__name__)
class AccountFiscalPosition(models.Model):
_name = 'account.fiscal.position'
_description = 'Fiscal Position'
@@ -499,3 +502,17 @@ class ResPartner(models.Model):
elif is_supplier and 'supplier_rank' not in vals:
vals['supplier_rank'] = 1
return super().create(vals_list)
def _increase_rank(self, field):
if self.ids:
try:
with self.env.cr.savepoint():
self.env.cr.execute("SELECT "+field+" FROM res_partner WHERE ID IN %(partner_ids)s FOR UPDATE NOWAIT", {'partner_ids': tuple(self.ids)})
self.env.cr.execute("UPDATE res_partner SET "+field+"="+field+"+1 WHERE ID IN %(partner_ids)s", {'partner_ids': tuple(self.ids)})
for partner in self:
self.env.cache.remove(partner, partner._fields[field])
except psycopg2.DatabaseError as e:
if e.pgcode == '55P03':
_logger.debug('Another transaction already locked partner rows. Cannot update partner ranks.')
else:
raise e
@@ -455,6 +455,9 @@ class PosSession(models.Model):
diff = order.amount_paid - order.amount_total
rounding_difference = self._update_amounts(rounding_difference, {'amount': diff}, order.date_order)
# Increasing current partner's customer_rank
order.partner_id._increase_rank('customer_rank')
if self.company_id.anglo_saxon_accounting:
global_session_pickings = self.picking_ids.filtered(lambda p: not p.pos_order_id)
if global_session_pickings: