[IMP] Add buttons product and product templates for analytic rules

This commit is contained in:
Josse Colpaert 2014-07-13 09:56:43 +02:00
parent 32dd003d60
commit 739a1d0051
2 changed files with 36 additions and 0 deletions

View File

@ -130,4 +130,26 @@ class product_product(osv.Model):
'rules_count': fields.function(_rules_count, string='# Analytic Rules', type='integer'),
}
class product_template(osv.Model):
_inherit = 'product.template'
def _rules_count(self, cr, uid, ids, field_name, arg, context=None):
Analytic = self.pool['account.analytic.default']
res = {}
for product_tmpl_id in self.browse(cr, uid, ids):
res[product_tmpl_id.id] = sum([p.rules_count for p in product_tmpl_id.product_variant_ids])
return res
_columns = {
'rules_count': fields.function(_rules_count, string='# Analytic Rules', type='integer'),
}
def action_view_rules(self, cr, uid, ids, context=None):
products = self._get_products(cr, uid, ids, context=context)
result = self._get_act_window_dict(cr, uid, 'account_analytic_default','action_product_default_list', context=context)
result['domain'] = "[('product_id','in',[" + ','.join(map(str, products)) + "])]"
result['context'] = "{}"
return result
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -87,6 +87,20 @@
</xpath>
</field>
</record>
<record model="ir.ui.view" id="product_template_view_default_analytic_button">
<field name="name">product.template.stock.move</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='buttons']" position="inside">
<button class="oe_inline oe_stat_button" name= "action_view_rules" type="object"
groups="analytic.group_analytic_accounting" icon="fa-xing">
<field string="Analytic Rules" name="rules_count" widget="statinfo" />
</button>
</xpath>
</field>
</record>
<act_window
name="Entries"