From b33ef74d16d9a55d683bdfa62c1d49d6c6037c22 Mon Sep 17 00:00:00 2001
From: Simon Lejeune <sle@openerp.com>
Date: Mon, 9 Oct 2017 15:52:32 +0200
Subject: [PATCH] [FIX] purchase: amount of the purchase in the logged message

When a picking is created from a purchase order, a message is logged in
the chatter:  "This transfer has been created from: POXXX: XX$".

Ideally, an inventory user should not have access to the purchase
orders. Sadly, removing the access right brings a lot of access right
issues, so this commit only remove the amount from the logged message

We adapt the name_get that always displayed the total amount of the
purchase order since rev[1], as a message was logged in the chatter when
a picking is created from a purchase order and the message contained this
value.

We implement a context key to display the total amount in the name_get,
as it is used when linking a vendor bill to a purchase order.

[1] 0c618d79ff9ecc8ffaea1404931a62695890d6d2
---
 addons/purchase/models/purchase.py              | 2 +-
 addons/purchase/views/account_invoice_views.xml | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py
index 1865d20ee6e5..42cbde8ab4ac 100644
--- a/addons/purchase/models/purchase.py
+++ b/addons/purchase/models/purchase.py
@@ -188,7 +188,7 @@ class PurchaseOrder(models.Model):
             name = po.name
             if po.partner_ref:
                 name += ' ('+po.partner_ref+')'
-            if po.amount_total:
+            if self.env.context.get('show_total_amount') and po.amount_total:
                 name += ': ' + formatLang(self.env, po.amount_total, currency_obj=po.currency_id)
             result.append((po.id, name))
         return result
diff --git a/addons/purchase/views/account_invoice_views.xml b/addons/purchase/views/account_invoice_views.xml
index a85974931f4e..c112df772f35 100644
--- a/addons/purchase/views/account_invoice_views.xml
+++ b/addons/purchase/views/account_invoice_views.xml
@@ -60,7 +60,7 @@
         <field name="arch" type="xml">
             <field name="reference" position="after" >
                  <field name="purchase_id" attrs="{'invisible': [('state', '=', 'purchase')]}" class="oe_edit_only" 
-                    options="{'no_create': True}"/>
+                    options="{'no_create': True}" context="{'show_total_amount': True}"/>
             </field>
             <xpath expr="//field[@name='invoice_line_ids']/tree/field[@name='company_id']" position="after">
                 <field name="purchase_line_id" invisible="1" readonly="0"/>
-- 
GitLab