[IMP] point_of_sale: Show customer only and increase customer ranking.

Following the removing of the vendor and customer field, when we wanted to display customer in the back end, we saw all. We added a default filter when clicking on the menu button that displays only customer with a customer rank higher than 0.
We also increase their customer ranks everytime they make an order in the front end.

closes odoo/odoo#41769

Task-id: 2092483
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
This commit is contained in:
Robin Heinz
2019-12-19 12:46:09 +00:00
parent 2312905fcf
commit ffd2502fb4
2 changed files with 16 additions and 1 deletions
+15
View File
@@ -366,6 +366,21 @@ class PosOrder(models.Model):
raise UserError(_("Order %s is not fully paid.") % self.name)
self.write({'state': 'paid'})
if self.partner_id:
try:
with self.env.cr.savepoint():
self.env.cr.execute("SELECT 'customer_rank' FROM res_partner WHERE ID=%s FOR UPDATE NOWAIT",
(self.partner_id.id,))
self.env.cr.execute("UPDATE res_partner SET customer_rank = customer_rank +1 WHERE ID=%s",
(self.partner_id.id,))
self.env.cache.remove(self.partner_id, self.partner_id._fields['customer_rank'])
except psycopg2.DatabaseError as e:
if e.pgcode == '55P03':
_logger.debug('Another transaction already locked partner rows. Cannot update partner ranks.')
else:
raise e
return True
def action_pos_order_invoice(self):
@@ -17,7 +17,7 @@
<menuitem id="menu_point_of_sale_customer"
name="Customers"
parent="menu_point_of_sale"
action="base.action_partner_customer_form"
action="account.res_partner_action_customer"
sequence="100"/>
<!-- Reporting menu -->