Improvements in Analytic Devaults

bzr revid: fp@tinyerp.com-20080902145406-bjz2javtfwvb71zy
This commit is contained in:
Fabien Pinckaers 2008-09-02 16:54:06 +02:00
parent 0a4430c53a
commit 4fa244a1d3
11 changed files with 154 additions and 115 deletions

View File

@ -2,10 +2,6 @@
<terp>
<data noupdate="True">
<!--
Minimal Tiny ERP Account Chart
-->
<record id="minimal_0" model="account.account">
<field name="code">x 0</field>
<field name="name">Chart For Automated Tests</field>
@ -16,8 +12,8 @@
This chart of account is used for automated testing purpose. It is installed
only if you selected demo data during your database creation. Modules can
do black box testing on entries on this chart of account, without modifying
your own chart of account.
</field>
your own accounts.
</field>
</record>
<record id="a_recv" model="account.account">

View File

@ -75,8 +75,8 @@
<field name="view_type">form</field>
<field name="view_id" ref="view_account_analytic_account_tree"/>
</record>
<menuitem id="next_id_39" name="Analytic Accounts" parent="account.menu_finance_configuration"/>
<menuitem action="action_account_analytic_account_form" id="account_analytic_def_account" parent="next_id_39"/>
<menuitem id="menu_analytic_account" name="Analytic Accounts" parent="account.menu_finance_configuration"/>
<menuitem action="action_account_analytic_account_form" id="account_analytic_def_account" parent="menu_analytic_account"/>
<record id="action_account_analytic_account_tree2" model="ir.actions.act_window">
<field name="name">Analytic Chart of Accounts</field>
@ -89,7 +89,7 @@
<menuitem
action="action_account_analytic_account_tree2"
id="account_analytic_def_chart"
parent="account.next_id_39"/>
parent="account.menu_analytic_account"/>
<menuitem action="action_account_analytic_account_tree2" id="account_analytic_chart" parent="account.menu_finance_charts"/>
<menuitem id="next_id_40" name="Analytic" parent="account.menu_finance_reporting"/><menuitem action="action_account_analytic_account_tree2" id="account_analytic_chart_balance" parent="next_id_40"/>

View File

@ -1,17 +1,22 @@
# -*- encoding: utf-8 -*-
{
"name" : "Product Analytic Default",
"name" : "Account Analytic Default",
"version" : "1.0",
"author" : "Tiny",
"website" : "http://tinyerp.com",
"category" : "Generic Modules/product_analytic_default",
"description": """
- add property field on product object and used this field on sale order line and invoice lines..
Allows to automatically select analytic accounts based on criterions:
* Product
* Partner
* User
* Company
* Date
""",
"depends" : ['base','account'],
"depends" : ['account'],
"init_xml" : [],
"demo_xml" : [],
"update_xml" : ["product_analytic_default.xml"],
"update_xml" : ["account_analytic_default.xml"],
"active": False,
"installable": True
}

View File

@ -0,0 +1,84 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2007 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from osv import fields,osv
from osv import orm
class account_analytic_default(osv.osv):
_name = 'account.analytic.default'
_description = 'Analytic Distributions'
_rec_name = 'analytic_id'
_order = 'sequence'
_columns = {
'sequence': fields.integer('Sequence'),
'analytic_id': fields.many2one('account.analytic.account', 'Analytic Account', required=True),
'product_id': fields.many2one('product.product', 'Product', ondelete='cascade'),
'partner_id': fields.many2one('res.partner', 'Partner', ondelete='cascade'),
'user_id': fields.many2one('res.users', 'User', ondelete='cascade'),
'company_id': fields.many2one('res.company', 'Company', ondelete='cascade'),
'date_start': fields.date('Start Date'),
'date_stop': fields.date('End Date'),
}
def account_get(self, cr, uid, product_id=None, partner_id=None, user_id=None, date=None, context={}):
domain = []
if product_id:
domain += ['|',('product_id','=',product_id),('product_id','=',False)]
if partner_id:
domain += ['|',('partner_id','=',partner_id),('partner_id','=',False)]
if partner_id:
domain += ['|',('user_id','=',uid),('user_id','=',False)]
if date:
domain += ['|',('date_start','<=',date),('date_start','=',False)]
domain += ['|',('date_stop','>=',date),('date_stop','=',False)]
best_index = -1
res = False
for rec in self.browse(cr, uid, self.search(cr, uid, domain, context=context), context=context):
index = 0
if rec.product_id: index+=1
if rec.partner_id: index+=1
if rec.user_id: index+=1
if rec.date_start: index+=1
if rec.date_stop: index+=1
if index>best_index:
res = rec
best_index = index
return res
account_analytic_default()
class account_invoice_line(osv.osv):
_inherit = 'account.invoice.line'
_description = 'account invoice line'
def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, price_unit=False, address_invoice_id=False, context={}):
res_prod = super(account_invoice_line,self).product_id_change(cr, uid, ids, product, uom, qty, name, type, partner_id, price_unit, address_invoice_id, context)
rec = self.pool.get('account.analytic.default').account_get(cr, uid, product, partner_id, uid, time.strftime('%Y-%m-%d'), context)
if rec:
res_prod['value'].update({'account_analytic_id':res.account_id.id})
return res_prod
account_invoice_line()

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<terp>
<data>
<record id="view_account_analytic_default_tree" model="ir.ui.view">
<field name="name">account.analytic.default.tree</field>
<field name="model">account.analytic.default</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Analytic Defaults" editable="bottom">
<field name="sequence" string="Seq"/>
<field name="analytic_id" select="1"/>
<field name="product_id" select="2"/>
<field name="partner_id" select="2"/>
<field name="user_id" select="2"/>
<field name="company_id" select="2"/>
<field name="date_start"/>
<field name="date_stop"/>
</tree>
</field>
</record>
<record id="view_account_analytic_default_form" model="ir.ui.view">
<field name="name">account.analytic.default.form</field>
<field name="model">account.analytic.default</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Analytic Defaults">
<field name="analytic_id" select="1"/>
<field name="sequence"/>
<separator string="Conditions" colspan="4"/>
<field name="product_id" select="2"/>
<field name="partner_id" select="2"/>
<field name="user_id" select="2"/>
<field name="company_id" select="2"/>
<field name="date_start"/>
<field name="date_stop"/>
</form>
</field>
</record>
<record id="action_analytic_default_form" model="ir.actions.act_window">
<field name="name">Analytic Defaults</field>
<field name="res_model">account.analytic.default</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem
action="action_analytic_default_form"
id="menu_analytic_defaul_form"
parent="account.menu_analytic_account"/>
</data>
</terp>

View File

@ -184,7 +184,7 @@
</record>
<menuitem
parent="account.next_id_39"
parent="account.menu_analytic_account"
id="menu_account_analytic_plan_action"
action="account_analytic_plan_form_action"/>

View File

@ -203,7 +203,7 @@
<field name="view_type">form</field>
<field name="view_id" ref="view_hr_timesheet_invoice_factor_tree"/>
</record>
<menuitem action="action_hr_timesheet_invoice_factor_form" id="hr_timesheet_invoice_factor_view" parent="account.next_id_39"/>
<menuitem action="action_hr_timesheet_invoice_factor_form" id="hr_timesheet_invoice_factor_view" parent="account.menu_analytic_account"/>
</data>
</terp>

View File

@ -290,7 +290,7 @@
<field name="type">ir.actions.act_window</field>
<field name="res_model">mrp.bom</field>
<field name="view_type">form</field>
<field name="view_form">form,tree</field>
<field name="view_mode">form,tree</field>
<field name="domain">[('bom_id','=',False)]</field>
</record>
<menuitem action="mrp_bom_form_action_new" id="menu_mrp_bom_form_action_new" parent="menu_mrp_bom_form_action"/>
@ -300,10 +300,10 @@
<field name="type">ir.actions.act_window</field>
<field name="res_model">mrp.bom</field>
<field name="view_type">form</field>
<field name="domain">[('bom_id','<>',False)]</field>
<field name="domain">[('bom_id','&lt;&gt;',False)]</field>
</record>
<menuitem action="mrp_bom_form_action2" id="menu_mrp_bom_form_action2" parent="menu_mrp_configuration"/>
<record id="action2" model="ir.actions.act_window">
<field name="name">Bill of Materials Structure</field>
<field name="type">ir.actions.act_window</field>

View File

@ -1,66 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2007 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from osv import fields,osv
from osv import orm
class product_product(osv.osv):
_name = 'product.product'
_inherit = 'product.product'
_description = 'Product'
_columns = {
'property_account_analytic': fields.property(
'account.analytic.account',
type='many2one',
relation='account.analytic.account',
string="Analytic Account",
method=True,
view_load=True,
group_name="Accounting Properties",
help="This Analytic Account will be use in sale order line and invoice lines",
),
}
product_product()
class account_invoice_line(osv.osv):
_inherit = 'account.invoice.line'
_description = 'account invoice line'
def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, price_unit=False, address_invoice_id=False, context={}):
res_prod = super(account_invoice_line,self).product_id_change(cr, uid, ids, product, uom, qty, name, type, partner_id, price_unit, address_invoice_id, context)
if product:
res = self.pool.get('product.product').browse(cr, uid, product, context=context)
res_prod['value'].update({'account_analytic_id':res.property_account_analytic.id})
return res_prod
account_invoice_line()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<terp>
<data>
<record id="view_template_property_analytic_form" model="ir.ui.view">
<field name="name">product.template.property.analytic.form.inherit</field>
<field name="model">product.template</field>
<field name="type">form</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<separator string="Sales" colspan="2" position="before">
<field name="property_account_analytic"/>
<newline/>
</separator>
</field>
</record>
<record id="view_normal_property_analytic_form" model="ir.ui.view">
<field name="name">product.normal.property.analytic.form.inherit</field>
<field name="model">product.product</field>
<field name="type">form</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="arch" type="xml">
<separator string="Sales" colspan="2" position="before">
<field name="property_account_analytic"/>
<newline/>
</separator>
</field>
</record>
</data>
</terp>