[FIX] purchase: purchases button on product variants

This rev. is related to 8381d47543

The action action_purchase_line_product_tree is used in both
product templates and product variants forms.
Therefore, the default_product_id: active_id in the context
cannot be used,
As sometimes it will active_id will be a product template,
sometimes it will be a product variant.

I believe two different window actions should be used,
instead of sharing a common one and making hacks.
Nevertheless, as we avoid taking risks in stable releases
This should be done in master.
This commit is contained in:
Denis Ledoux 2015-01-27 10:33:48 +01:00
parent 8381d47543
commit 0b18a5afec
2 changed files with 8 additions and 1 deletions

View File

@ -1444,6 +1444,13 @@ class product_product(osv.Model):
for product_id in ids
}
def action_view_purchases(self, cr, uid, ids, context=None):
if isinstance(ids, (int, long)):
ids = [ids]
result = self.pool['product.template']._get_act_window_dict(cr, uid, 'purchase.action_purchase_line_product_tree', context=context)
result['domain'] = "[('product_id','in',[" + ','.join(map(str, ids)) + "])]"
return result
_columns = {
'purchase_count': fields.function(_purchase_count, string='# Purchases', type='integer'),
}

View File

@ -648,7 +648,7 @@
<field name="groups_id" eval="[(4, ref('purchase.group_purchase_user'))]"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='buttons']" position="inside">
<button class="oe_inline oe_stat_button" name="%(action_purchase_line_product_tree)d" type="action"
<button class="oe_inline oe_stat_button" name="action_view_purchases" type="object"
icon="fa-shopping-cart">
<field string="Purchases" name="purchase_count" widget="statinfo"/>
</button>