qdp (OpenERP) has proposed merging
lp:~openerp-dev/openobject-addons/trunk-analytic-distribution-hmo into
lp:openobject-addons.
Requested reviews:
OpenERP Core Team (openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-analytic-distribution-hmo/+merge/130803
just to see the diff, hmo is the author... not me
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-analytic-distribution-hmo/+merge/130803
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-addons/trunk-analytic-distribution-hmo.
=== modified file 'account_analytic_default/__openerp__.py'
--- account_analytic_default/__openerp__.py 2012-09-26 12:16:27 +0000
+++ account_analytic_default/__openerp__.py 2012-10-22 12:40:37 +0000
@@ -38,7 +38,7 @@
'author': 'OpenERP SA',
'website': 'http://www.openerp.com',
'images': ['images/analytic_defaults.jpeg'],
- 'depends': ['sale'],
+ 'depends': ['account'],
'data': [
'security/ir.model.access.csv',
'security/account_analytic_default_security.xml',
=== modified file 'account_analytic_default/account_analytic_default.py'
--- account_analytic_default/account_analytic_default.py 2012-07-20 09:26:53 +0000
+++ account_analytic_default/account_analytic_default.py 2012-10-22 12:40:37 +0000
@@ -83,41 +83,4 @@
return res_prod
account_invoice_line()
-
-
-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'), context={})
-
- if rec:
- return rec.analytic_id.id
-
- return super(stock_picking, self)._get_account_analytic_invoice(cursor, user, picking, move_line)
-
-stock_picking()
-
-class sale_order_line(osv.osv):
- _inherit = "sale.order.line"
-
- # Method overridden to set the analytic account by default on criterion match
- def invoice_line_create(self, cr, uid, ids, context=None):
- create_ids = super(sale_order_line, self).invoice_line_create(cr, uid, ids, context=context)
- if not ids:
- return create_ids
- sale_line = self.browse(cr, uid, ids[0], context=context)
- inv_line_obj = self.pool.get('account.invoice.line')
- anal_def_obj = self.pool.get('account.analytic.default')
-
- for line in inv_line_obj.browse(cr, uid, create_ids, context=context):
- rec = anal_def_obj.account_get(cr, uid, line.product_id.id, sale_line.order_id.partner_id.id, sale_line.order_id.user_id.id, time.strftime('%Y-%m-%d'), context=context)
-
- if rec:
- inv_line_obj.write(cr, uid, [line.id], {'account_analytic_id': rec.analytic_id.id}, context=context)
- return create_ids
-
-sale_order_line()
-
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== modified file 'account_analytic_plans/__openerp__.py'
--- account_analytic_plans/__openerp__.py 2012-09-26 12:16:27 +0000
+++ account_analytic_plans/__openerp__.py 2012-10-22 12:40:37 +0000
@@ -76,7 +76,8 @@
'wizard/account_crossovered_analytic_view.xml',
],
'demo': [],
- 'test': ['test/acount_analytic_plans_report.yml'],
+ 'test': ['test/acount_analytic_plans_report.yml',
+ 'test/account_analytic_plans.yml'],
'installable': True,
'auto_install': False,
}
=== modified file 'account_analytic_plans/account_analytic_plans.py'
--- account_analytic_plans/account_analytic_plans.py 2012-09-26 07:22:39 +0000
+++ account_analytic_plans/account_analytic_plans.py 2012-10-22 12:40:37 +0000
@@ -168,6 +168,7 @@
return self.name_get(cr, uid, ids, context or {})
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
+ #TOFIX: clean usability of vitual form
if context is None:
context = {}
wiz_id = self.pool.get('ir.actions.act_window').search(cr, uid, [("name","=","analytic.plan.create.model.action")], context=context)
@@ -442,26 +443,6 @@
analytic_default()
-class sale_order_line(osv.osv):
- _inherit = "sale.order.line"
-
- # Method overridden to set the analytic account by default on criterion match
- def invoice_line_create(self, cr, uid, ids, context=None):
- create_ids = super(sale_order_line,self).invoice_line_create(cr, uid, ids, context=context)
- inv_line_obj = self.pool.get('account.invoice.line')
- acct_anal_def_obj = self.pool.get('account.analytic.default')
- if ids:
- sale_line = self.browse(cr, uid, ids[0], context=context)
- for line in inv_line_obj.browse(cr, uid, create_ids, context=context):
- rec = acct_anal_def_obj.account_get(cr, uid, line.product_id.id, sale_line.order_id.partner_id.id, uid, time.strftime('%Y-%m-%d'), context)
-
- if rec:
- inv_line_obj.write(cr, uid, [line.id], {'analytics_id': rec.analytics_id.id}, context=context)
- return create_ids
-
-sale_order_line()
-
-
class account_bank_statement(osv.osv):
_inherit = "account.bank.statement"
_name = "account.bank.statement"
=== added file 'account_analytic_plans/test/account_analytic_plans.yml'
--- account_analytic_plans/test/account_analytic_plans.yml 1970-01-01 00:00:00 +0000
+++ account_analytic_plans/test/account_analytic_plans.yml 2012-10-22 12:40:37 +0000
@@ -0,0 +1,75 @@
+-
+ In order to test the Analytic Plans Distribution, we will create a Plans and Distribute invoice into two different analytic lines.
+-
+ I create analytic plan "Plan1" with two root analytic account "Project1" and "Project2".
+-
+ !record {model: account.analytic.plan, id: account_analytic_plan1}:
+ name: Plan1
+ plan_ids:
+ - name: Project1
+ root_analytic_id: account.analytic_project_1
+ min_required: 70
+ max_required: 70
+ sequence: 1
+ - name: project2
+ root_analytic_id: account.analytic_project_2
+ min_required: 30
+ max_required: 30
+ sequence: 2
+-
+ I create Analytic Distribution "Example1" and link plan "Plan1" and distribute them into two analytic account using 30% and 70% rate.
+-
+ !record {model: account.analytic.plan.instance, id: account_analytic_plan_instance_example1}:
+ name: Example1
+ plan_id: account_analytic_plan1
+ account_ids:
+ - analytic_account_id : account.analytic_super_product_trainings
+ rate: 30
+ - analytic_account_id : account.analytic_consultancy
+ rate: 70
+
+-
+ Create New invoice line and Assign Analytic Distribution to that supplier invoice line.
+-
+ !python {model: account.invoice}: |
+ invoice = self.browse(cr, uid, ref('account.demo_invoice_0'))
+ line_id = self.pool.get('account.invoice.line').create(cr, uid, {'analytics_id': ref("account_analytic_plan_instance_example1"),
+ 'account_id': ref('account.a_expense'), 'name': '[PCSC234] PC Assemble SC234',
+ 'price_unit' : 300.0, 'product_id': ref('product.product_product_3'),
+ 'quantity': 10.0, 'uos_id': ref('product.product_uom_unit'), 'invoice_id': ref('account.demo_invoice_0')})
+
+-
+ I check that Initially supplier invoice state is "Draft"
+-
+ !assert {model: account.invoice, id: account.demo_invoice_0}:
+ - state == 'draft'
+-
+ I change the state of invoice to open by clicking Validate button
+-
+ !workflow {model: account.invoice, action: invoice_open, ref: account.demo_invoice_0}
+-
+ I check that when line of invoice will be confirmed, it will generate 2 analytic lines,for one account entry
+ and Distribute amount based on two different rate.
+-
+ !python {model: account.analytic.line}: |
+ invoice_line_obj = self.pool.get('account.invoice.line')
+ inv_obj = self.pool.get('account.invoice')
+ acct_ins_obj = self.pool.get('account.analytic.plan.instance')
+ inv = inv_obj.browse(cr, uid, ref('account.demo_invoice_0'), context=context)
+ invoice_line_ids = invoice_line_obj.search(cr, uid, [('analytics_id', '=', ref("account_analytic_plan_instance_example1")), ('invoice_id', '=', ref('account.demo_invoice_0')), ('name', '=', '[PCSC234] PC Assemble SC234')])
+ inv_line = invoice_line_obj.browse(cr, uid, invoice_line_ids)[0]
+ move_line_data = inv_obj._get_analytic_lines(cr, uid, inv.id, context=context)
+ for line_data in move_line_data:
+ obj_move_line = acct_ins_obj.browse(cr, uid, line_data.get('analytics_id'), context=context)
+ if line_data.get('name') == 'PC Assemble SC234':
+ assert len(line_data.get('analytic_lines')) == 2,"Invoice are validate , but Two analytic line wasn't created."
+ for acc_line2 in obj_move_line.account_ids:
+ for line in line_data.get('analytic_lines'):
+ if acc_line2.rate == 30 and acc_line2.analytic_account_id.id == ref("account.analytic_super_product_trainings"):
+ amount = inv_line.price_subtotal * (acc_line2.rate/100)
+ if line[2]['account_id'] == ref("account.analytic_super_product_trainings"):
+ assert line[2]['amount'] == -900, "Analytic line amount mismatch: %s" % amount
+ if acc_line2.rate == 70 and acc_line2.analytic_account_id.id == ref("account.analytic_consultancy"):
+ amount = inv_line.price_subtotal * (acc_line2.rate/100)
+ if line[2]['account_id'] == ref("account.analytic_consultancy"):
+ assert line[2]['amount'] == -2100, "Analytic line amount mismatch: %s" % amount
=== modified file 'purchase_analytic_plans/purchase_analytic_plans.py'
--- purchase_analytic_plans/purchase_analytic_plans.py 2011-11-15 15:32:01 +0000
+++ purchase_analytic_plans/purchase_analytic_plans.py 2012-10-22 12:40:37 +0000
@@ -18,26 +18,18 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
-
+import time
from osv import fields, osv
-
-class purchase_order_line(osv.osv):
- _name='purchase.order.line'
- _inherit='purchase.order.line'
- _columns = {
- 'analytics_id':fields.many2one('account.analytic.plan.instance','Analytic Distribution'),
- }
-
-purchase_order_line()
-
class purchase_order(osv.osv):
_name='purchase.order'
_inherit='purchase.order'
def _prepare_inv_line(self, cr, uid, account_id, order_line, context=None):
res = super(purchase_order, self)._prepare_inv_line(cr, uid, account_id, order_line, context=context)
- res['analytics_id'] = order_line.analytics_id.id
+ rec = self.pool.get('account.analytic.default').account_get(cr, uid, order_line.product_id.id, order_line.order_id.partner_id.id, uid, time.strftime('%Y-%m-%d'), context)
+ if rec and rec.analytics_id:
+ res['analytics_id'] = rec.analytics_id.id
return res
purchase_order()
=== modified file 'purchase_analytic_plans/purchase_analytic_plans_view.xml'
--- purchase_analytic_plans/purchase_analytic_plans_view.xml 2012-09-17 11:31:13 +0000
+++ purchase_analytic_plans/purchase_analytic_plans_view.xml 2012-10-22 12:40:37 +0000
@@ -1,15 +1,12 @@
<?xml version="1.0"?>
<openerp>
<data>
-
<record model="ir.ui.view" id="purchase_order_line_form_inherit">
<field name="name">purchase.order.line.form.inherit</field>
<field name="model">purchase.order.line</field>
<field name="inherit_id" ref="purchase.purchase_order_line_form"/>
<field name="arch" type="xml">
- <field name="account_analytic_id" position="replace">
- <field name="analytics_id" domain="[('plan_id','<>',False)]"/>
- </field>
+ <field name="account_analytic_id" position="replace"/>
</field>
</record>
@@ -18,9 +15,7 @@
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
- <field name="account_analytic_id" position="replace">
- <field name="analytics_id" domain="[('plan_id','<>',False)]"/>
- </field>
+ <field name="account_analytic_id" position="replace"/>
</field>
</record>
=== added directory 'sale_analytic_default'
=== added file 'sale_analytic_default/__init__.py'
--- sale_analytic_default/__init__.py 1970-01-01 00:00:00 +0000
+++ sale_analytic_default/__init__.py 2012-10-22 12:40:37 +0000
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2010-2012 OpenERP s.a. (<http://openerp.com>).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+import sale_analytic_default
=== added file 'sale_analytic_default/__openerp__.py'
--- sale_analytic_default/__openerp__.py 1970-01-01 00:00:00 +0000
+++ sale_analytic_default/__openerp__.py 2012-10-22 12:40:37 +0000
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2010-2012 OpenERP s.a. (<http://openerp.com>).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+{
+ 'name': 'Sales Analytic Defaults',
+ 'version': '1.0',
+ 'category': 'Sales Management',
+ 'description': """
+Set default analytic accounts in Customer Invoice.
+=================================================================
+
+Allows to automatically link analytic accounts to customer invoice.
+ """,
+ 'author': 'OpenERP SA',
+ 'website': 'http://www.openerp.com',
+ 'depends': ['sale_stock', 'account_analytic_default'],
+ 'data': ['sale_analytic_default_view.xml'],
+ 'demo': [],
+ 'installable': True,
+ 'auto_install': True,
+}
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== added file 'sale_analytic_default/sale_analytic_default.py'
--- sale_analytic_default/sale_analytic_default.py 1970-01-01 00:00:00 +0000
+++ sale_analytic_default/sale_analytic_default.py 2012-10-22 12:40:37 +0000
@@ -0,0 +1,59 @@
+# -*- coding: utf-8 -*-
+###############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-Today OpenERP SA (http://www.openerp.com/).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+import time
+
+from osv import fields, 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'), context={})
+ if rec:
+ return rec.analytic_id.id
+ return super(stock_picking, self)._get_account_analytic_invoice(cursor, user, picking, move_line)
+
+stock_picking()
+
+class sale_order_line(osv.osv):
+ _inherit = "sale.order.line"
+
+ # Method overridden to set the analytic account by default on criterion match
+ def _prepare_order_line_invoice_line(self, cr, uid, order_line, account_id=False, context=None):
+ res = super(sale_order_line, self)._prepare_order_line_invoice_line(cr, uid, order_line, account_id, context=context)
+ rec = self.pool.get('account.analytic.default').account_get(cr, uid, order_line.product_id.id, order_line.order_id.partner_id.id, uid, time.strftime('%Y-%m-%d'), context)
+ if rec and rec.analytic_id:
+ res['account_analytic_id'] = rec.analytic_id.id
+ return res
+sale_order_line()
+
+class sale_order(osv.osv):
+ _inherit = "sale.order"
+
+ def onchange_shop_id(self, cr, uid, ids, shop_id, context=None):
+ # Remove the project_id from the result of super() call, if any, as this field is not in the view anymore
+ res = super(sale_order, self).onchange_shop_id(cr, uid, ids, shop_id, context=context)
+ if res.get('value',{}).get('project_id'):
+ del(res['value']['project_id'])
+ return res
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== renamed file 'sale_analytic_plans/sale_analytic_plans_view.xml' => 'sale_analytic_default/sale_analytic_default_view.xml'
--- sale_analytic_plans/sale_analytic_plans_view.xml 2012-09-09 11:02:14 +0000
+++ sale_analytic_default/sale_analytic_default_view.xml 2012-10-22 12:40:37 +0000
@@ -11,32 +11,6 @@
</field>
</record>
- <record model="ir.ui.view" id="view_order_form_inherit2">
- <field name="name">sale.order.form.inherit2</field>
- <field name="model">sale.order</field>
- <field name="inherit_id" ref="sale.view_order_form"/>
- <field name="arch" type="xml">
- <xpath expr="//field[@name='order_line']/form//field[@name='tax_id']" position="after">
- <field name="analytics_id" domain="[('plan_id','<>',False)]" groups="analytic.group_analytic_accounting"/>
- </xpath>
- </field>
- </record>
-
- <!-- the presence of 'analytics_id' makes the order lines non-editable -->
- <record id="sale.view_order_form_editable_list" model="ir.ui.view">
- <field name="groups_id" eval="[(4, ref('analytic.group_analytic_accounting'))]"/>
- </record>
-
- <record model="ir.ui.view" id="view_order_line_form2_inherit">
- <field name="name">sale.order.line.form2.inherit</field>
- <field name="model">sale.order.line</field>
- <field name="inherit_id" ref="sale.view_order_line_form2"/>
- <field name="arch" type="xml">
- <field name="product_id" position="after">
- <field name="analytics_id" domain="[('plan_id','<>',False)]" groups="analytic.group_analytic_accounting"/>
- </field>
- </field>
- </record>
-
+
</data>
</openerp>
=== modified file 'sale_analytic_plans/__openerp__.py'
--- sale_analytic_plans/__openerp__.py 2012-09-26 12:16:27 +0000
+++ sale_analytic_plans/__openerp__.py 2012-10-22 12:40:37 +0000
@@ -32,8 +32,7 @@
'author': 'OpenERP SA',
'website': 'http://www.openerp.com',
'images': ['images/sale_order_analytic_account.jpeg', 'images/sales_order_line.jpeg'],
- 'depends': ['sale', 'account_analytic_plans'],
- 'data': ['sale_analytic_plans_view.xml'],
+ 'depends': ['sale_analytic_default', 'account_analytic_plans'],
'demo': [],
'installable': True,
'auto_install': False,
=== modified file 'sale_analytic_plans/sale_analytic_plans.py'
--- sale_analytic_plans/sale_analytic_plans.py 2012-10-05 10:06:33 +0000
+++ sale_analytic_plans/sale_analytic_plans.py 2012-10-22 12:40:37 +0000
@@ -18,35 +18,21 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
-
+import time
from osv import fields, osv
class sale_order_line(osv.osv):
- _inherit = 'sale.order.line'
- _columns = {
- 'analytics_id': fields.many2one('account.analytic.plan.instance', 'Analytic Distribution'),
- }
- def invoice_line_create(self, cr, uid, ids, context=None):
- if context is None:
- context = {}
- line_obj = self.pool.get('account.invoice.line')
- create_ids = super(sale_order_line, self).invoice_line_create(cr, uid, ids, context=context)
- i = 0
- for line in self.browse(cr, uid, ids, context=context):
- line_obj.write(cr, uid, [create_ids[i]], {'analytics_id': line.analytics_id.id})
- i = i + 1
- return create_ids
+ _inherit = "sale.order.line"
+
+ # Method overridden to set the analytic account by default on criterion match
+ def _prepare_order_line_invoice_line(self, cr, uid, order_line, account_id=False, context=None):
+ res = super(sale_order_line, self)._prepare_order_line_invoice_line(cr, uid, order_line, account_id, context=context)
+ rec = self.pool.get('account.analytic.default').account_get(cr, uid, order_line.product_id.id, order_line.order_id.partner_id.id, uid, time.strftime('%Y-%m-%d'), context)
+ if rec and rec.analytics_id:
+ if 'account_analytic_id' in res:
+ del res['account_analytic_id']
+ res['analytics_id'] = rec.analytics_id.id
+ return res
sale_order_line()
-
-class sale_order(osv.osv):
- _inherit = "sale.order"
-
- def onchange_shop_id(self, cr, uid, ids, shop_id, context=None):
- # Remove the project_id from the result of super() call, if any, as this field is not in the view anymore
- res = super(sale_order, self).onchange_shop_id(cr, uid, ids, shop_id, context=context)
- if res.get('value',{}).get('project_id'):
- del(res['value']['project_id'])
- return res
-
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp