mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[ADD] First commit of the first generic modules to move in our new public branch
(lp:c2c-addons/6.1 rev 1)
This commit is contained in:
28
analytic_hours_block/__init__.py
Normal file
28
analytic_hours_block/__init__.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# @author Renaville Vincent, ported by Joel Grand-Guillaume
|
||||
# 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.
|
||||
#
|
||||
##############################################################################
|
||||
import hours_block
|
||||
import report
|
||||
54
analytic_hours_block/__openerp__.py
Normal file
54
analytic_hours_block/__openerp__.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
## @author Bessi Nicolas, ported by Joel Grand-Guillaume
|
||||
# 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.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
{
|
||||
"name" : "Project Hours Blocks Management",
|
||||
"description" : """
|
||||
This module allows you to handle hours blocks, to follow for example the user support contracts.
|
||||
This means, you sell a product of type "hours block" then you input the spent hours on the hours block and
|
||||
you can track and follow how much has been used.
|
||||
|
||||
""",
|
||||
"version" : "1.2",
|
||||
"author" : "Camptocamp",
|
||||
"category" : "Generic Modules/Projects & Services",
|
||||
"website": "http://www.camptocamp.com",
|
||||
"depends" : [
|
||||
"account",
|
||||
"hr_timesheet_invoice",
|
||||
"analytic"
|
||||
],
|
||||
"init_xml" : [],
|
||||
"update_xml" : [
|
||||
"hours_block_view.xml",
|
||||
"hours_block_menu.xml",
|
||||
"report.xml",
|
||||
"security/hours_block_security.xml",
|
||||
"security/ir.model.access.csv",
|
||||
],
|
||||
"active": False,
|
||||
"installable": True
|
||||
}
|
||||
211
analytic_hours_block/hours_block.py
Normal file
211
analytic_hours_block/hours_block.py
Normal file
@@ -0,0 +1,211 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# @author Bessi Nicolas
|
||||
# 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 osv, fields
|
||||
import time
|
||||
from mx import DateTime
|
||||
import netsvc
|
||||
import string
|
||||
|
||||
############################################################################
|
||||
## Add hours blocks on invoice
|
||||
############################################################################
|
||||
|
||||
class AccountHoursBlock(osv.osv):
|
||||
_name = "account.hours.block"
|
||||
|
||||
def _get_last_action(self, cr, uid, ids, name, arg, context={}):
|
||||
res = {}
|
||||
for block in self.browse(cr, uid, ids):
|
||||
cr.execute('SELECT max(al.date) FROM account_analytic_line AS al WHERE al.invoice_id = ' + str(block.invoice_id.id))
|
||||
date = map(lambda x: x[0], cr.fetchall() or [])
|
||||
res[block.id] = date[0]
|
||||
return res
|
||||
|
||||
def _compute_hours(self, cr, uid, ids, fields, args, context):
|
||||
# Return a dict of [id][fields]
|
||||
result = {}
|
||||
aal_obj = self.pool.get('account.analytic.line')
|
||||
for block in self.browse(cr,uid,ids):
|
||||
result[block.id] = {
|
||||
'amount_hours_block' : 0.0,
|
||||
'amount_hours_block_done' : 0.0,
|
||||
'amount_hours_block_delta' : 0.0
|
||||
}
|
||||
# Compute hours bought
|
||||
for line in block.invoice_id.invoice_line:
|
||||
hours_bought = 0.0
|
||||
if line.product_id:
|
||||
## We will now calculate the product_quantity
|
||||
factor = line.uos_id.factor
|
||||
if factor == 0.0:
|
||||
factor = 1.0
|
||||
amount = line.quantity
|
||||
hours_bought += (amount / factor)
|
||||
result[block.id]['amount_hours_block'] += hours_bought
|
||||
# Compute hours spent
|
||||
hours_used = 0.0
|
||||
# Get ids of analytic line generated from timesheet associated to current block
|
||||
cr.execute("SELECT al.id \
|
||||
FROM account_analytic_line AS al,account_analytic_journal AS aj \
|
||||
WHERE aj.id = al.journal_id AND\
|
||||
aj.type='general' AND\
|
||||
al.invoice_id = " + str(block.invoice_id.id)
|
||||
)
|
||||
ids2 = map(lambda x: x[0], cr.fetchall() or [])
|
||||
for line in aal_obj.browse(cr, uid, ids2, context):
|
||||
if line.product_uom_id:
|
||||
factor = line.product_uom_id.factor
|
||||
if factor == 0.0:
|
||||
factor = 1.0
|
||||
else:
|
||||
factor = 1.0
|
||||
factor_invoicing = 1.0
|
||||
if line.to_invoice and line.to_invoice.factor != 0.0:
|
||||
factor_invoicing = 1.0 - line.to_invoice.factor / 100
|
||||
hours_used += ((line.unit_amount / factor) * factor_invoicing)
|
||||
result[block.id]['amount_hours_block_done'] = hours_used
|
||||
return result
|
||||
|
||||
def _compute_amount(self, cr, uid, ids, fields, args, context):
|
||||
result = {}
|
||||
aal_obj = self.pool.get('account.analytic.line')
|
||||
pricelist_obj = self.pool.get('product.pricelist')
|
||||
for block in self.browse(cr,uid,ids):
|
||||
result[block.id] = {
|
||||
'amount_hours_block' : 0.0,
|
||||
'amount_hours_block_done' : 0.0,
|
||||
'amount_hours_block_delta' : 0.0
|
||||
}
|
||||
|
||||
# Compute amount bought
|
||||
for line in block.invoice_id.invoice_line:
|
||||
amount_bought = 0.0
|
||||
if line.product_id:
|
||||
## We will now calculate the product_quantity
|
||||
factor = line.uos_id.factor
|
||||
if factor == 0.0:
|
||||
factor = 1.0
|
||||
amount = line.quantity * line.price_unit
|
||||
amount_bought += (amount / factor)
|
||||
result[block.id]['amount_hours_block'] += amount_bought
|
||||
|
||||
# Compute total amount
|
||||
# Get ids of analytic line generated from timesheet associated to current block
|
||||
cr.execute("SELECT al.id \
|
||||
FROM account_analytic_line AS al,account_analytic_journal AS aj \
|
||||
WHERE aj.id = al.journal_id AND\
|
||||
aj.type='general' AND\
|
||||
al.invoice_id = " + str(block.invoice_id.id)
|
||||
)
|
||||
ids2 = map(lambda x: x[0], cr.fetchall() or [])
|
||||
total_amount = 0.0
|
||||
for line in aal_obj.browse(cr, uid, ids2, context):
|
||||
factor_invoicing = 1.0
|
||||
if line.to_invoice and line.to_invoice.factor != 0.0:
|
||||
factor_invoicing = 1.0 - line.to_invoice.factor / 100
|
||||
|
||||
ctx = {'uom': line.product_uom_id.id}
|
||||
amount = pricelist_obj.price_get(cr, uid,
|
||||
[line.account_id.pricelist_id.id],
|
||||
line.product_id.id,
|
||||
line.unit_amount or 1.0,
|
||||
line.account_id.partner_id.id or False,
|
||||
ctx)[line.account_id.pricelist_id.id]
|
||||
total_amount += amount * line.unit_amount * factor_invoicing
|
||||
result[block.id]['amount_hours_block_done'] += total_amount
|
||||
|
||||
return result
|
||||
|
||||
def _compute(self, cr, uid, ids, fields, args, context):
|
||||
result = {}
|
||||
block_per_types = {}
|
||||
for block in self.browse(cr, uid, ids, context=context):
|
||||
if not block.type in block_per_types.keys():
|
||||
block_per_types[block.type] = []
|
||||
block_per_types[block.type].append(block.id)
|
||||
|
||||
for block_type in block_per_types.keys():
|
||||
if block_type:
|
||||
result.update(eval("self._compute_%s" % (block_type,))(cr, uid, ids, fields, args, context))
|
||||
|
||||
for block in result:
|
||||
result[block]['amount_hours_block_delta'] = \
|
||||
result[block]['amount_hours_block'] - result[block]['amount_hours_block_done']
|
||||
return result
|
||||
|
||||
_columns = {
|
||||
'amount_hours_block': fields.function(_compute, method=True, type='float', string='Quantity /Amount bought', store=True,
|
||||
multi='amount_hours_block_delta',
|
||||
help="Amount bought by the customer. This amount is expressed in the base UoM (factor=1.0)"),
|
||||
'amount_hours_block_done': fields.function(_compute, method=True, type='float', string='Quantity / Amount used', store=True,
|
||||
multi='amount_hours_block_delta',
|
||||
help="Amount done by the staff. This amount is expressed in the base UoM (factor=1.0)"),
|
||||
'amount_hours_block_delta': fields.function(_compute, method=True, type='float', string='Difference', store=True,
|
||||
multi='amount_hours_block_delta',
|
||||
help="Difference between bought and used. This amount is expressed in the base UoM (factor=1.0)"),
|
||||
'last_action_date': fields.function(_get_last_action, method=True, type='date', string='Last action date',
|
||||
help="Date of the last analytic line linked to the invoice related to this block hours."),
|
||||
'close_date': fields.date('Closed Date'),
|
||||
'invoice_id': fields.many2one('account.invoice', 'Invoice', ondelete='cascade', required=True),
|
||||
'type': fields.selection([('hours','Hours'), ('amount','Amount')], 'Type of Block',
|
||||
required=True, help="Choose if you want a time or amount base block."),
|
||||
# Invoices related infos
|
||||
'date_invoice': fields.related('invoice_id', 'date_invoice', type="date", string="Invoice Date", store=True, readonly=True),
|
||||
'user_id': fields.related('invoice_id', 'user_id', type="many2one", relation="res.users", string="Salesman", store=True, readonly=True),
|
||||
'partner_id': fields.related('invoice_id', 'partner_id', type="many2one", relation="res.partner", string="Partner", store=True, readonly=True),
|
||||
'name': fields.related('invoice_id', 'name', type="char",size=64, string="Description", store=True,readonly=True),
|
||||
'number': fields.related('invoice_id', 'number', type="char",size=64, string="Number", store=True,readonly=True),
|
||||
'journal_id': fields.related('invoice_id', 'journal_id', type="many2one", relation="account.journal", string="Journal", store=True,readonly=True),
|
||||
'period_id': fields.related('invoice_id', 'period_id', type="many2one", relation="account.period", string="Period", store=True,readonly=True),
|
||||
'company_id': fields.related('invoice_id', 'company_id', type="many2one", relation="res.company", string="Company", store=True,readonly=True),
|
||||
'currency_id': fields.related('invoice_id', 'currency_id', type="many2one", relation="res.currency", string="Currency", store=True,readonly=True),
|
||||
'residual': fields.related('invoice_id', 'residual', type="float", string="Residual", store=True,readonly=True),
|
||||
'amount_total': fields.related('invoice_id', 'amount_total', type="float", string="Total", store=True,readonly=True),
|
||||
'state':fields.related('invoice_id','state',
|
||||
type='selection',
|
||||
selection=[
|
||||
('draft','Draft'),
|
||||
('proforma','Pro-forma'),
|
||||
('proforma2','Pro-forma'),
|
||||
('open','Open'),
|
||||
('paid','Paid'),
|
||||
('cancel','Cancelled')
|
||||
],
|
||||
string='State', readonly=True, store=True),
|
||||
}
|
||||
|
||||
AccountHoursBlock()
|
||||
|
||||
|
||||
class AccountInvoice(osv.osv):
|
||||
_inherit = 'account.invoice'
|
||||
_columns = {
|
||||
'account_hours_block_ids': fields.one2many('account.hours.block', 'invoice_id', 'Hours Block')
|
||||
}
|
||||
|
||||
AccountInvoice()
|
||||
26
analytic_hours_block/hours_block_menu.xml
Normal file
26
analytic_hours_block/hours_block_menu.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" ?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------
|
||||
# Hours block menu
|
||||
#---------------------------------------------------------------------------------------------------------
|
||||
|
||||
<record model="ir.actions.act_window" id="action_all_block_hour">
|
||||
<field name="name">Hours Block</field>
|
||||
<field name="res_model">account.hours.block</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field eval="False" name="view_id"/>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
name="Hours Block"
|
||||
parent="account.menu_finance_receivables"
|
||||
id="action_all_block_hour_account"
|
||||
action="action_all_block_hour" />
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
153
analytic_hours_block/hours_block_view.xml
Normal file
153
analytic_hours_block/hours_block_view.xml
Normal file
@@ -0,0 +1,153 @@
|
||||
<?xml version="1.0" ?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Hours block search form
|
||||
#---------------------------------------------------------------------
|
||||
<record id="view_account_invoice_filter" model="ir.ui.view">
|
||||
<field name="name">account.hours.block.select</field>
|
||||
<field name="model">account.hours.block</field>
|
||||
<field name="type">search</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Invoice">
|
||||
<group col="7" colspan="4">
|
||||
<filter name="draft" icon="terp-document-new" string="Draft" domain="[('state','=','draft')]" help="Draft Hours Blocks"/>
|
||||
<filter name="running" icon="terp-dolar" string="Running" domain="[('close_date','=',False),('state','<>','draft')]" help="All Running Hours Block"/>
|
||||
<separator orientation="vertical"/>
|
||||
<filter name="overdue" icon="terp-dolar_ok!" string="Overdue" domain="[('amount_hours_block_delta','<','0.0')]" help="Overdue Hours Block"/>
|
||||
<separator orientation="vertical"/>
|
||||
<field name="number"/>
|
||||
<field name="partner_id"/>
|
||||
<field name="user_id" select="1" widget="selection" string="Salesman">
|
||||
<filter domain="[('user_id','=',uid)]" help="My invoices" icon="terp-personal" separator="1"/>
|
||||
</field>
|
||||
<field name="company_id" widget="selection"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<group expand="0" string="Group By...">
|
||||
<filter string="Partner" icon="terp-partner" domain="[]" context="{'group_by':'partner_id'}"/>
|
||||
<filter string="Responsible" icon="terp-personal" domain="[]" context="{'group_by':'user_id'}"/>
|
||||
<filter string="State" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
# Hours Block View
|
||||
#------------------------------------------------------------------------
|
||||
<record id="hours_block_invoice_form" model="ir.ui.view">
|
||||
<field name="name">account.hours.block.form</field>
|
||||
<field name="model">account.hours.block</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Invoice">
|
||||
<field name="type" />
|
||||
<field name="invoice_id" />
|
||||
<field name="last_action_date" />
|
||||
<field name="close_date" />
|
||||
<group col="6" colspan="4">
|
||||
<separator colspan="6" string="Hours Quantity / Amount"/>
|
||||
<field name="amount_hours_block" string="Bought"/>
|
||||
<field name="amount_hours_block_done" string="Used"/>
|
||||
<field name="amount_hours_block_delta" string="Difference"/>
|
||||
</group>
|
||||
<separator colspan="4" string="Invoice's related information"/>
|
||||
<field name="date_invoice"/>
|
||||
<field name="name"/>
|
||||
<field name="number"/>
|
||||
<field name="partner_id" groups="base.group_user"/>
|
||||
<field name="user_id"/>
|
||||
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
|
||||
|
||||
<field name="journal_id" invisible="1"/>
|
||||
<field name="period_id" invisible="1" groups="account.group_account_user"/>
|
||||
|
||||
<field name="currency_id"/>
|
||||
<newline/>
|
||||
<field name="residual" sum="Residual Amount"/>
|
||||
<field name="amount_total" sum="Total Amount"/>
|
||||
<field name="state"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="invoice_tree_hour_block">
|
||||
<field name="name">account.hours.block.tree</field>
|
||||
<field name="model">account.hours.block</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree colors="blue:state in ('draft');black:state in ('proforma','proforma2','open');gray:state in ('cancel')" string="Invoice">
|
||||
<field name="date_invoice"/>
|
||||
<field name="partner_id" groups="base.group_user"/>
|
||||
<field name="name"/>
|
||||
|
||||
<field name="amount_hours_block" sum="Quantity of hours bought"/>
|
||||
<field name="amount_hours_block_done" sum="Quantity of hours used" />
|
||||
<field name="amount_hours_block_delta" sum="Quantity of hours difference"/>
|
||||
<field name="last_action_date" />
|
||||
<field name="close_date" />
|
||||
|
||||
<field name="journal_id" invisible="1"/>
|
||||
<field name="period_id" invisible="1" groups="account.group_account_user"/>
|
||||
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
|
||||
<field name="user_id"/>
|
||||
<field name="currency_id"/>
|
||||
<field name="residual" sum="Residual Amount"/>
|
||||
<field name="amount_total" sum="Total Amount"/>
|
||||
<field name="state"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------
|
||||
# Add related act_window from partner and Hours Block
|
||||
#---------------------------------------------------------------------------------------------------------
|
||||
<act_window name="All blocks hours"
|
||||
domain="[('partner_id', '=', active_id)]"
|
||||
res_model="account.hours.block"
|
||||
src_model="res.partner"
|
||||
id="act_block_hour_from_partner"/>
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------
|
||||
# Link to invoice on hours block view
|
||||
#---------------------------------------------------------------------------------------------------------
|
||||
<act_window
|
||||
domain="[('account_hours_block_ids', '=', active_id)]"
|
||||
id="act_invoice_from_hours_block"
|
||||
name="Invoice"
|
||||
res_model="account.invoice"
|
||||
src_model="account.hours.block"
|
||||
view_mode="tree,form"
|
||||
view_type="form"/>
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------
|
||||
# Link to analytic lines on hours block view
|
||||
#---------------------------------------------------------------------------------------------------------
|
||||
<act_window
|
||||
domain="[('invoice_id.account_hours_block_ids', '=', active_id)]"
|
||||
id="act_analytic_lines_from_hours_block"
|
||||
name="Analytic Lines"
|
||||
res_model="account.analytic.line"
|
||||
src_model="account.hours.block"
|
||||
view_mode="tree,form"
|
||||
view_type="form"/>
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------
|
||||
# Link to hours block on invoice view
|
||||
#---------------------------------------------------------------------------------------------------------
|
||||
<act_window
|
||||
domain="[('invoice_id', '=', active_id)]"
|
||||
id="act_hours_block_from_invoice"
|
||||
name="Hours Block"
|
||||
res_model="account.hours.block"
|
||||
src_model="account.invoice"
|
||||
view_mode="tree,form,calendar,graph"
|
||||
view_type="form"/>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
12
analytic_hours_block/report.xml
Normal file
12
analytic_hours_block/report.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<report id="block_hours_report"
|
||||
string="Block Hours State"
|
||||
model="account.hours.block"
|
||||
name="account.hours.block"
|
||||
rml="analytic_hours_block/report/hours_block.rml"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
27
analytic_hours_block/report/__init__.py
Normal file
27
analytic_hours_block/report/__init__.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
##############################################################################
|
||||
import hours_block
|
||||
60
analytic_hours_block/report/hours_block.py
Normal file
60
analytic_hours_block/report/hours_block.py
Normal file
@@ -0,0 +1,60 @@
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (c) 2005-2006 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.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
from mx.DateTime import *
|
||||
from report import report_sxw
|
||||
|
||||
#import xml.dom.minidom
|
||||
#import re
|
||||
|
||||
|
||||
class account_hours_block(report_sxw.rml_parse):
|
||||
def __init__(self, cr, uid, name, context=None):
|
||||
super(account_hours_block, self).__init__(cr, uid, name, context)
|
||||
self.localcontext.update({
|
||||
'time': time,
|
||||
'format_date': self._get_and_change_date_format_for_swiss,
|
||||
'analytic_lines': self._get_analytic_lines,
|
||||
})
|
||||
self.context = context
|
||||
|
||||
def _get_analytic_lines(self, hours_block):
|
||||
al_pool = self.pool.get('account.analytic.line')
|
||||
al_ids = al_pool.search(self.cr, self.uid,
|
||||
[['invoice_id', '=', hours_block.invoice_id.id]],
|
||||
order='date desc')
|
||||
res = al_pool.browse(self.cr, self.uid, al_ids)
|
||||
return res
|
||||
|
||||
def _get_and_change_date_format_for_swiss(self, date_to_format):
|
||||
date_formatted = ''
|
||||
if date_to_format:
|
||||
date_formatted = strptime(date_to_format, '%Y-%m-%d').strftime('%d.%m.%Y')
|
||||
return date_formatted
|
||||
|
||||
report_sxw.report_sxw('report.account.hours.block', 'account.hours.block', 'addons/analytic_hours_block/report/hours_block.rml', parser=account_hours_block)
|
||||
265
analytic_hours_block/report/hours_block.rml
Normal file
265
analytic_hours_block/report/hours_block.rml
Normal file
@@ -0,0 +1,265 @@
|
||||
<?xml version="1.0"?>
|
||||
<document filename="test.pdf">
|
||||
<template pageSize="(595.0,842.0)" title="Test" author="Martin Simon" allowSplitting="20">
|
||||
<pageTemplate id="first">
|
||||
<frame id="first" x1="35.0" y1="35.0" width="525" height="772"/>
|
||||
<pageGraphics>
|
||||
<setFont name="Helvetica-Bold" size="9"/>
|
||||
|
||||
<drawString x="1.0cm" y="28.1cm">[[ company.name ]]</drawString>
|
||||
<drawString x="17.7cm" y="28.1cm">Maintenance And Support Summary</drawString>
|
||||
|
||||
<setFont name="Helvetica" size="9"/>
|
||||
<drawString x="1.0cm" y="2cm"> [[ time.strftime("%m-%d-%y %H:%M", time.localtime()) ]]</drawString>
|
||||
<drawString x="17.7cm" y="2cm">Page <pageNumber/></drawString>
|
||||
|
||||
<lineMode width="0.7"/>
|
||||
<lines>0.6cm 27.9cm 20.3cm 27.9cm</lines>
|
||||
<setFont name="Helvetica" size="8"/>
|
||||
</pageGraphics>
|
||||
|
||||
</pageTemplate>
|
||||
</template>
|
||||
<stylesheet>
|
||||
<blockTableStyle id="Standard_Outline">
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="Table1">
|
||||
<lineStyle kind="LINEBELOW" colorName="#ffffff" start="0,0" stop="-1,-1"/>
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
<blockBackground colorName="#e6e6e6" start="0,0" stop="0,-1"/>
|
||||
<blockBackground colorName="#e6e6e6" start="1,0" stop="1,-1"/>
|
||||
<blockBackground colorName="#e6e6e6" start="2,0" stop="2,-1"/>
|
||||
<blockBackground colorName="#e6e6e6" start="0,1" stop="0,-1"/>
|
||||
<blockBackground colorName="#e6e6e6" start="1,1" stop="1,-1"/>
|
||||
<blockBackground colorName="#e6e6e6" start="2,1" stop="2,-1"/>
|
||||
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="Table6">
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
<lineStyle kind="LINEBEFORE" colorName="#000000" start="0,0" stop="0,-1"/>
|
||||
<lineStyle kind="LINEABOVE" colorName="#000000" start="0,0" stop="0,0"/>
|
||||
<lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="0,-1"/>
|
||||
<lineStyle kind="LINEBEFORE" colorName="#000000" start="1,0" stop="1,-1"/>
|
||||
<lineStyle kind="LINEABOVE" colorName="#000000" start="1,0" stop="1,0"/>
|
||||
<lineStyle kind="LINEBELOW" colorName="#000000" start="1,-1" stop="1,-1"/>
|
||||
<lineStyle kind="LINEBEFORE" colorName="#000000" start="2,0" stop="2,-1"/>
|
||||
<lineStyle kind="LINEABOVE" colorName="#000000" start="2,0" stop="2,0"/>
|
||||
<lineStyle kind="LINEBELOW" colorName="#000000" start="2,-1" stop="2,-1"/>
|
||||
<lineStyle kind="LINEBEFORE" colorName="#000000" start="3,0" stop="3,-1"/>
|
||||
<lineStyle kind="LINEAFTER" colorName="#000000" start="3,0" stop="3,-1"/>
|
||||
<lineStyle kind="LINEABOVE" colorName="#000000" start="3,0" stop="3,0"/>
|
||||
<lineStyle kind="LINEBELOW" colorName="#000000" start="3,-1" stop="3,-1"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="Table2">
|
||||
<lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,0"/>
|
||||
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,1" stop="-1,-1"/>
|
||||
|
||||
<blockValign value="TOP"/>
|
||||
<blockAlignment value="RIGHT" start="2,1" stop="-1,-1"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="Table3">
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="Table4">
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
<lineStyle kind="LINEBEFORE" colorName="#000000" start="0,0" stop="0,-1"/>
|
||||
<lineStyle kind="LINEABOVE" colorName="#000000" start="0,0" stop="0,0"/>
|
||||
<lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="0,-1"/>
|
||||
<lineStyle kind="LINEBEFORE" colorName="#000000" start="1,0" stop="1,-1"/>
|
||||
<lineStyle kind="LINEABOVE" colorName="#000000" start="1,0" stop="1,0"/>
|
||||
<lineStyle kind="LINEBELOW" colorName="#000000" start="1,-1" stop="1,-1"/>
|
||||
<lineStyle kind="LINEBEFORE" colorName="#000000" start="2,0" stop="2,-1"/>
|
||||
<lineStyle kind="LINEABOVE" colorName="#000000" start="2,0" stop="2,0"/>
|
||||
<lineStyle kind="LINEBELOW" colorName="#000000" start="2,-1" stop="2,-1"/>
|
||||
<lineStyle kind="LINEBEFORE" colorName="#000000" start="3,0" stop="3,-1"/>
|
||||
<lineStyle kind="LINEAFTER" colorName="#000000" start="3,0" stop="3,-1"/>
|
||||
<lineStyle kind="LINEABOVE" colorName="#000000" start="3,0" stop="3,0"/>
|
||||
<lineStyle kind="LINEBELOW" colorName="#000000" start="3,-1" stop="3,-1"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="Table7">
|
||||
<lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,0"/>
|
||||
</blockTableStyle>
|
||||
|
||||
<initialize>
|
||||
<paraStyle name="all" alignment="justify"/>
|
||||
</initialize>
|
||||
<paraStyle name="P1" fontName="Helvetica-Bold" fontSize="14.0" leading="25" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P2" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P2c" fontName="Helvetica" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P3" fontName="Helvetica" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P10" fontName="Helvetica" fontSize="8.0" leading="14" spaceBefore="0.0" spaceAfter="6.0" alignment="RIGHT"/>
|
||||
<paraStyle name="P9" fontName="Helvetica-Bold" alignment="CENTER" fontSize="14.5" leftIndent="-5.0"/>
|
||||
<paraStyle name="P9b" fontName="Helvetica" fontSize="8" alignment="LEFT"/>
|
||||
<paraStyle name="P9c" fontName="Helvetica" fontSize="8" alignment="RIGHT"/>
|
||||
<paraStyle name="P12" fontName="Helvetica" fontSize="8.0" leading="14" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P12a" fontName="Helvetica-Bold" fontSize="8.0" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P14" rightIndent="17.0" leftIndent="-0.0" fontName="Helvetica" fontSize="8.0" leading="10" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
|
||||
|
||||
<blockTableStyle id="TrLevel6">
|
||||
<blockLeftPadding length="60" start="1,0" stop="1,0"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="TrLevel5">
|
||||
<blockLeftPadding length="40" start="1,0" stop="1,0"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="TrLevel4">
|
||||
<blockLeftPadding length="20" start="1,0" stop="1,0"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="TrLevel3">
|
||||
<blockLeftPadding length="0" start="1,0" stop="1,0"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="TrLevel2">
|
||||
<blockLeftPadding length="0" start="1,0" stop="1,0"/>
|
||||
<lineStyle kind="LINEBELOW" colorName="#777777" start="1,0" stop="1,0"/>
|
||||
<blockTopPadding length="13" start="0,0" stop="-1,0"/>
|
||||
<blockBottomPadding length="2" start="0,0" stop="-1,0"/>
|
||||
<blockFont name="Times-Bold" start="0,0" stop="-1,-1"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="TrLevel1">
|
||||
<lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,0"/>
|
||||
<blockLeftPadding length="0" start="1,0" stop="1,0"/>
|
||||
<blockTopPadding length="26" start="0,0" stop="-1,0"/>
|
||||
<blockBottomPadding length="2" start="0,0" stop="-1,0"/>
|
||||
<blockFont name="Times-Bold" start="0,0" stop="-1,-1"/>
|
||||
</blockTableStyle>
|
||||
|
||||
<paraStyle
|
||||
name="Level5"
|
||||
fontName="Helvetica"
|
||||
fontSize="8.0" />
|
||||
<paraStyle
|
||||
name="Level4"
|
||||
fontName="Helvetica"
|
||||
fontSize="8.0" />
|
||||
<paraStyle
|
||||
name="Level3"
|
||||
fontName="Helvetica"
|
||||
fontSize="8.0" />
|
||||
<paraStyle
|
||||
name="Level2"
|
||||
firstLineIndent="-0.03cm"
|
||||
fontName="Helvetica-Bold"
|
||||
fontSize="8.0" />
|
||||
<paraStyle name="Level1"
|
||||
fontSize="8.0"
|
||||
fontName="Helvetica-Bold"
|
||||
/>
|
||||
<paraStyle name="Caption" fontName="Helvetica" fontSize="10.0" leading="13" spaceBefore="6.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="Index" fontName="Helvetica"/>
|
||||
</stylesheet>
|
||||
<images/>
|
||||
<story>
|
||||
|
||||
<para style="P2">[[ repeatIn(objects,'o') ]]</para>
|
||||
<para style="P2">[[ setLang(o.partner_id.lang) ]]</para>
|
||||
<para style="P1">Maintenance And Support Summary</para>
|
||||
|
||||
<para style="P12a"></para>
|
||||
<para style="P12a"></para>
|
||||
<blockTable colWidths="258.0,259.0" style="Table1" repeatRows="1">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P12a">Description :</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P2">[[ o.name ]]</para>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P12a">Report Date : </para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P2">[[ time.strftime("%d.%m.%Y", time.localtime()) ]]</para>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P12a">Invoice Date : </para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P2">[[ o.date_invoice and format_date(o.date_invoice) or '' ]]</para>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P12a">Amount bought : [[ (o.type == 'amount' or removeParentNode('para')) and '' ]]</para>
|
||||
<para style="P12a">Quantity of hours bought : [[ (o.type == 'hours' or removeParentNode('para')) and '' ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P2">[[ o.amount_hours_block ]]</para>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<!-- <para style="P12a">[[ o.type == 'hours' and "Quantity of hours" or "Amount"]] used : </para> -->
|
||||
<para style="P12a">Amount used : [[ (o.type == 'amount' or removeParentNode('para')) and '' ]]</para>
|
||||
<para style="P12a">Quantity of hours used : [[ (o.type == 'hours' or removeParentNode('para')) and '' ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P2">[[ round(o.amount_hours_block_done, 2) ]]</para>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<!-- <para style="P12a">Remaining [[ o.type == 'hours' and "hours" or "amount"]] : </para> -->
|
||||
<para style="P12a">Remaining amount : [[ (o.type == 'amount' or removeParentNode('para')) and '' ]]</para>
|
||||
<para style="P12a">Remaining hours : [[ (o.type == 'hours' or removeParentNode('para')) and '' ]]</para>
|
||||
|
||||
</td>
|
||||
<td>
|
||||
<para style="P2">[[ o.amount_hours_block and round(o.amount_hours_block_delta, 2) or '' ]]</para>
|
||||
</td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
<para style="P12a"></para>
|
||||
<para style="P12a"></para>
|
||||
<para style="P12a"></para>
|
||||
<blockTable colWidths="58,305.0,52.0,52.0,52.0" style="Table2" repeatRows="1">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P12a">Date</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P12a">Description</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P12a">Quantity</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P12a">Invoicing</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P12a">Deduced</para>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
[[ repeatIn(analytic_lines(o),'l') ]]
|
||||
<td>
|
||||
<para style="P2">[[ l.date and format_date(l.date) or '' ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P2">[[ l.name or '' ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P2c">[[ round(l.unit_amount or '0.0', 2) ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P2c">[[ l.to_invoice.customer_name ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P2c">[[ round((l.unit_amount and l.to_invoice) and (l.unit_amount - (l.unit_amount * l.to_invoice.factor) / 100 ) or '0.0', 2) ]]</para>
|
||||
</td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
|
||||
</story>
|
||||
</document>
|
||||
|
||||
11
analytic_hours_block/security/hours_block_security.xml
Normal file
11
analytic_hours_block/security/hours_block_security.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp><data>
|
||||
|
||||
<record id="hours_block_comp_rule" model="ir.rule">
|
||||
<field name="name">Hours Block multi company rule</field>
|
||||
<field model="ir.model" name="model_id" ref="model_account_hours_block"/>
|
||||
<field eval="True" name="global"/>
|
||||
<field name="domain_force">[]</field>
|
||||
</record>
|
||||
|
||||
</data></openerp>
|
||||
3
analytic_hours_block/security/ir.model.access.csv
Normal file
3
analytic_hours_block/security/ir.model.access.csv
Normal file
@@ -0,0 +1,3 @@
|
||||
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
|
||||
"access_hours_block_user","account.hours.block","model_account_hours_block","base.group_user",1,0,0,0
|
||||
"access_hours_block_invoice_manager","account.hours.block","model_account_hours_block","account.group_account_invoice",1,1,1,1
|
||||
|
Reference in New Issue
Block a user