[FIX] sale: sales button on product variants

This rev. is comparable to 0b18a5afec

The action action_order_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 the 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 probably be performed in master.
This commit is contained in:
Denis Ledoux 2015-02-02 10:34:27 +01:00
parent c18a7eb82a
commit 68b8286d5f
2 changed files with 8 additions and 2 deletions

View File

@ -1270,6 +1270,12 @@ class product_product(osv.Model):
r[group['product_id'][0]] = group['product_uom_qty']
return r
def action_view_sales(self, cr, uid, ids, context=None):
result = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'sale.action_order_line_product_tree', raise_if_not_found=True)
result = self.pool['ir.actions.act_window'].read(cr, uid, [result], context=context)[0]
result['domain'] = "[('product_id','in',[" + ','.join(map(str, ids)) + "])]"
return result
_columns = {
'sales_count': fields.function(_sales_count, string='# Sales', type='integer'),
}

View File

@ -490,7 +490,7 @@
<field name="filter" eval="True"/>
</record>
<record id="action_order_line_product_tree" model="ir.actions.act_window">
<field name="context">{'search_default_product_id': active_id, 'default_product_id': active_id}</field>
<field name="context">{}</field><!-- force empty -->
<field name="name">Sales Order Lines</field>
<field name="res_model">sale.order.line</field>
<field name="view_id" ref="view_order_line_tree"/>
@ -502,7 +502,7 @@
<field name="groups_id" eval="[(4, ref('base.group_sale_salesman'))]"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='buttons']" position="inside">
<button class="oe_inline oe_stat_button" name="%(action_order_line_product_tree)d"
<button class="oe_inline oe_stat_button" name="action_view_sales"
type="action" icon="fa-strikethrough">
<field string="Sales" name="sales_count" widget="statinfo" />
</button>