diff --git a/addons/account_analytic_default/__openerp__.py b/addons/account_analytic_default/__openerp__.py
index a8420228fdd..0b2191ea1c3 100644
--- a/addons/account_analytic_default/__openerp__.py
+++ b/addons/account_analytic_default/__openerp__.py
@@ -22,7 +22,8 @@ Allows to automatically select analytic accounts based on criterions:
'data': [
'security/ir.model.access.csv',
'security/account_analytic_default_security.xml',
- 'views/account_analytic_default_view.xml'
+ 'views/account_analytic_default_view.xml',
+ 'views/product_views.xml'
],
'installable': True,
}
diff --git a/addons/account_analytic_default/models/__init__.py b/addons/account_analytic_default/models/__init__.py
index 5bad4cb1c6f..0d3512e12fc 100644
--- a/addons/account_analytic_default/models/__init__.py
+++ b/addons/account_analytic_default/models/__init__.py
@@ -2,3 +2,6 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import account_analytic_default
+import stock
+import sale_order_line
+import product
\ No newline at end of file
diff --git a/addons/account_analytic_default/models/account_analytic_default.py b/addons/account_analytic_default/models/account_analytic_default.py
index 66fed7ceb4a..c990f0eeba4 100644
--- a/addons/account_analytic_default/models/account_analytic_default.py
+++ b/addons/account_analytic_default/models/account_analytic_default.py
@@ -69,78 +69,3 @@ class account_invoice_line(osv.osv):
else:
self.account_analytic_id = False
return res
-
-
-class stock_picking(osv.osv):
- _inherit = "stock.picking"
-
- def _get_account_analytic_invoice(self, cursor, user, picking, move_line):
- partner_id = picking.partner_id and picking.partner_id.id or False
- rec = self.pool.get('account.analytic.default').account_get(cursor, user, move_line.product_id.id, partner_id, user, time.strftime('%Y-%m-%d'))
-
- if rec:
- return rec.analytic_id.id
-
- return super(stock_picking, self)._get_account_analytic_invoice(cursor, user, picking, move_line)
-
-
-class sale_order_line(osv.osv):
- _inherit = "sale.order.line"
-
- @api.multi
- def _prepare_invoice_line(self, qty):
- res = super(sale_order_line, self)._prepare_invoice_line(qty)
- default_analytic_account = self.env['account.analytic.default'].account_get(self.product_id.id, self.order_id.partner_id.id, self.order_id.user_id.id, time.strftime('%Y-%m-%d'))
- if default_analytic_account:
- res.update({'account_analytic_id': default_analytic_account.analytic_id.id})
- return res
-
-
-class product_product(osv.Model):
- _inherit = 'product.product'
- def _rules_count(self, cr, uid, ids, field_name, arg, context=None):
- Analytic = self.pool['account.analytic.default']
- return {
- product_id: Analytic.search_count(cr, uid, [('product_id', '=', product_id)], context=context)
- for product_id in ids
- }
- _columns = {
- '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):
- res = {}
- for product_tmpl_id in self.browse(cr, uid, ids, context=context):
- 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)) + "])]"
- # Remove context so it is not going to filter on product_id with active_id of template
- result['context'] = "{}"
- return result
-
-
-class stock_move(osv.Model):
- _inherit = 'stock.move'
-
- def _create_invoice_line_from_vals(self, cr, uid, move, invoice_line_vals, context=None):
- # It will set the default analtyic account on the invoice line
- partner_id = self.pool['account.invoice'].browse(cr, uid, invoice_line_vals.get('invoice_id'), context=context).partner_id.id
- if 'account_analytic_id' not in invoice_line_vals or not invoice_line_vals.get('account_analytic_id'):
- rec = self.pool['account.analytic.default'].account_get(cr, uid, move.product_id.id, partner_id, uid, time.strftime('%Y-%m-%d'), company_id=move.company_id.id, context=context)
- if rec:
- invoice_line_vals.update({'account_analytic_id': rec.analytic_id.id})
- res = super(stock_move, self)._create_invoice_line_from_vals(cr, uid, move, invoice_line_vals, context=context)
- return res
diff --git a/addons/account_analytic_default/models/product.py b/addons/account_analytic_default/models/product.py
new file mode 100644
index 00000000000..261d47706e2
--- /dev/null
+++ b/addons/account_analytic_default/models/product.py
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from openerp.osv import fields, osv
+
+
+class product_product(osv.Model):
+ _inherit = 'product.product'
+
+ def _rules_count(self, cr, uid, ids, field_name, arg, context=None):
+ Analytic = self.pool['account.analytic.default']
+ return {
+ product_id: Analytic.search_count(cr, uid, [('product_id', '=', product_id)], context=context)
+ for product_id in ids
+ }
+ _columns = {
+ '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, context=context):
+ 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)) + "])]"
+ # Remove context so it is not going to filter on product_id with active_id of template
+ result['context'] = "{}"
+ return result
diff --git a/addons/account_analytic_default/models/sale_order_line.py b/addons/account_analytic_default/models/sale_order_line.py
new file mode 100644
index 00000000000..34cacad219c
--- /dev/null
+++ b/addons/account_analytic_default/models/sale_order_line.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+import time
+
+from openerp.osv import osv
+from openerp import api
+
+
+class sale_order_line(osv.osv):
+ _inherit = "sale.order.line"
+
+ @api.multi
+ def _prepare_invoice_line(self, qty):
+ res = super(sale_order_line, self)._prepare_invoice_line(qty)
+ default_analytic_account = self.env['account.analytic.default'].account_get(self.product_id.id, self.order_id.partner_id.id, self.order_id.user_id.id, time.strftime('%Y-%m-%d'))
+ if default_analytic_account:
+ res.update({'account_analytic_id': default_analytic_account.analytic_id.id})
+ return res
diff --git a/addons/account_analytic_default/models/stock.py b/addons/account_analytic_default/models/stock.py
new file mode 100644
index 00000000000..7a8f0df645f
--- /dev/null
+++ b/addons/account_analytic_default/models/stock.py
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+import time
+
+from openerp.osv import osv
+
+
+class stock_picking(osv.osv):
+ _inherit = "stock.picking"
+
+ def _get_account_analytic_invoice(self, cursor, user, picking, move_line):
+ partner_id = picking.partner_id and picking.partner_id.id or False
+ rec = self.pool.get('account.analytic.default').account_get(cursor, user, move_line.product_id.id, partner_id, user, time.strftime('%Y-%m-%d'))
+
+ if rec:
+ return rec.analytic_id.id
+
+ return super(stock_picking, self)._get_account_analytic_invoice(cursor, user, picking, move_line)
+
+
+class stock_move(osv.Model):
+ _inherit = 'stock.move'
+
+ def _create_invoice_line_from_vals(self, cr, uid, move, invoice_line_vals, context=None):
+ # It will set the default analtyic account on the invoice line
+ partner_id = self.pool['account.invoice'].browse(cr, uid, invoice_line_vals.get('invoice_id'), context=context).partner_id.id
+ if 'account_analytic_id' not in invoice_line_vals or not invoice_line_vals.get('account_analytic_id'):
+ rec = self.pool['account.analytic.default'].account_get(cr, uid, move.product_id.id, partner_id, uid, time.strftime('%Y-%m-%d'), company_id=move.company_id.id, context=context)
+ if rec:
+ invoice_line_vals.update({'account_analytic_id': rec.analytic_id.id})
+ res = super(stock_move, self)._create_invoice_line_from_vals(cr, uid, move, invoice_line_vals, context=context)
+ return res
diff --git a/addons/account_analytic_default/views/account_analytic_default_view.xml b/addons/account_analytic_default/views/account_analytic_default_view.xml
index a167e9f2f80..5dd9273454b 100644
--- a/addons/account_analytic_default/views/account_analytic_default_view.xml
+++ b/addons/account_analytic_default/views/account_analytic_default_view.xml
@@ -74,33 +74,6 @@
account.analytic.default
{'search_default_product_id': [active_id], 'default_product_id': active_id}
-
- product.product.stock.move
- product.product
-
-
-
-
-
-
-
-
-
- product.template.stock.move
- product.template
-
-
-
-
-
-
-
+
+
+
+ product.product.stock.move
+ product.product
+
+
+
+
+
+
+
+
+
+ product.template.stock.move
+ product.template
+
+
+
+
+
+
+
+
+
+