summaryrefslogtreecommitdiff
path: root/addons/account_analytic_analysis
diff options
context:
space:
mode:
authorFabien Pinckaers <fp@tinyerp.com>2011-11-08 23:53:37 +0100
committerFabien Pinckaers <fp@tinyerp.com>2011-11-08 23:53:37 +0100
commit3d9b149dcccf932cff09bc4e1c3dbcb167348e5d (patch)
tree6f0a6e029d360c7a3aa1db849d1efe5bfbaa7eb6 /addons/account_analytic_analysis
parent59ca0770d4c2e3e9a2399865101e7ac9936edee0 (diff)
parentb8519868a80cb76e0b18f021f134e3bc6105eb95 (diff)
[imp] merge + cleaning: contract managemeent, not perfect yet, but good enough -> to replace static email one day
bzr revid: fp@tinyerp.com-20111108225337-5muyehnvgqasv44i
Diffstat (limited to 'addons/account_analytic_analysis')
-rw-r--r--addons/account_analytic_analysis/__init__.py1
-rw-r--r--addons/account_analytic_analysis/__openerp__.py1
-rw-r--r--addons/account_analytic_analysis/account_analytic_analysis.py23
-rw-r--r--addons/account_analytic_analysis/account_analytic_analysis_cron.xml15
-rw-r--r--addons/account_analytic_analysis/account_analytic_analysis_menu.xml63
-rw-r--r--addons/account_analytic_analysis/cron_account_analytic_account.py79
6 files changed, 180 insertions, 2 deletions
diff --git a/addons/account_analytic_analysis/__init__.py b/addons/account_analytic_analysis/__init__.py
index a7bdb11ad67..429aa011f31 100644
--- a/addons/account_analytic_analysis/__init__.py
+++ b/addons/account_analytic_analysis/__init__.py
@@ -20,6 +20,7 @@
##############################################################################
import account_analytic_analysis
+import cron_account_analytic_account
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/account_analytic_analysis/__openerp__.py b/addons/account_analytic_analysis/__openerp__.py
index f75fe3d1615..f9bda19d405 100644
--- a/addons/account_analytic_analysis/__openerp__.py
+++ b/addons/account_analytic_analysis/__openerp__.py
@@ -42,6 +42,7 @@ user-wise as well as month wise.
"security/ir.model.access.csv",
"account_analytic_analysis_view.xml",
"account_analytic_analysis_menu.xml",
+ "account_analytic_analysis_cron.xml",
],
'demo_xml' : [],
'installable': True,
diff --git a/addons/account_analytic_analysis/account_analytic_analysis.py b/addons/account_analytic_analysis/account_analytic_analysis.py
index 22eb9401ad7..8ebb75244a1 100644
--- a/addons/account_analytic_analysis/account_analytic_analysis.py
+++ b/addons/account_analytic_analysis/account_analytic_analysis.py
@@ -374,7 +374,28 @@ class account_analytic_account(osv.osv):
res[id] = round(res.get(id, 0.0),2)
return res
- _columns ={
+ def _is_overdue_quantity(self, cr, uid, ids, fieldnames, args, context=None):
+ result = dict.fromkeys(ids, 0)
+
+ for record in self.browse(cr, uid, ids, context=context):
+ if record.quantity == 0.0 and record.quantity_max == 0.0:
+ result[record.id] = 0
+ else:
+ result[record.id] = int(record.quantity >= record.quantity_max)
+
+ return result
+
+ def _get_analytic_account(self, cr, uid, ids, context=None):
+ result = set()
+ for line in self.pool.get('account.analytic.line').browse(cr, uid, ids, context=context):
+ result.add(line.account_id.id)
+ return list(result)
+
+ _columns = {
+ 'is_overdue_quantity' : fields.function(_is_overdue_quantity, method=True, type='boolean', string='Overdue Quantity',
+ store={
+ 'account.analytic.line' : (_get_analytic_account, None, 20),
+ }),
'ca_invoiced': fields.function(_ca_invoiced_calc, type='float', string='Invoiced Amount',
help="Total customer invoiced amount for this account.",
digits_compute=dp.get_precision('Account')),
diff --git a/addons/account_analytic_analysis/account_analytic_analysis_cron.xml b/addons/account_analytic_analysis/account_analytic_analysis_cron.xml
new file mode 100644
index 00000000000..8564b1606eb
--- /dev/null
+++ b/addons/account_analytic_analysis/account_analytic_analysis_cron.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding='UTF-8'?>
+<openerp>
+ <data>
+ <record model="ir.cron" id="account_analytic_cron">
+ <field name="name">Analytic Account Report for Sales</field>
+ <field name="interval_number">1</field>
+ <field name="interval_type">weeks</field>
+ <field name="numbercall">-1</field>
+ <field eval="False" name="doall"/>
+ <field eval="'account.analytic.account'" name="model"/>
+ <field eval="'cron_account_analytic_account'" name="function"/>
+ <field eval="'()'" name="args"/>
+ </record>
+ </data>
+</openerp>
diff --git a/addons/account_analytic_analysis/account_analytic_analysis_menu.xml b/addons/account_analytic_analysis/account_analytic_analysis_menu.xml
index bfb7a892668..34840814154 100644
--- a/addons/account_analytic_analysis/account_analytic_analysis_menu.xml
+++ b/addons/account_analytic_analysis/account_analytic_analysis_menu.xml
@@ -20,6 +20,67 @@
<field name="view_mode">tree,form,graph</field>
<field name="domain">[('date','&lt;=',time.strftime('%Y-%m-%d')),('state','=','open')]</field>
</record>
- <menuitem action="action_account_analytic_managed_overpassed" id="menu_action_account_analytic_managed_overpassed" sequence="50" parent="menu_invoicing" groups="analytic.group_analytic_accounting"/>
+ <menuitem action="action_account_analytic_managed_overpassed" id="menu_action_account_analytic_managed_overpassed" sequence="50" parent="menu_invoicing" groups="base.group_extended"/>
+
+ <record id="view_account_analytic_account_overdue_search" model="ir.ui.view">
+ <field name="name">account.analytic.account.search</field>
+ <field name="model">account.analytic.account</field>
+ <field name="type">search</field>
+ <field name="arch" type="xml">
+ <search string="Analytic Account">
+ <group col="8" colspan="4">
+ <filter icon="terp-check" name="draft" string="Draft" domain="[('state','=','draft')]" help="Contracts not signed yet"/>
+ <filter icon="terp-camera_test" name="open" string="Open" domain="[('state','=','open')]" help="Contracts in progress"/>
+ <filter icon="terp-gtk-media-pause" name="pending" string="Pending" domain="[('state','=','pending')]" help="Pending contracts to renew with your customer"/>
+ <separator orientation="vertical"/>
+ <filter icon="terp-go-today" string="To Renew" domain="['|', '&amp;', ('date', '!=', False), ('date', '&lt;', time.strftime('%%Y-%%m-%%d')), ('is_overdue_quantity', '=', True)]"
+ name="renew"
+ help="The contracts to be renewed because the deadline is passed or the working hours are higher than the allocated hours" />
+ <filter icon="terp-go-month"
+ string=" +1 Month"
+ domain="[('date','&lt;=', (datetime.date.today() + relativedelta(months=1)).strftime('%%Y-%%m-%%d')),('date','>=', time.strftime('%%Y-%%m-%%d'))]"
+ help="Analytic Accounts with a past deadline in one month." />
+
+ <separator orientation="vertical"/>
+ <field name="name" select="1"/>
+ <field name="code" select="1"/>
+ <field name="partner_id" select="1">
+ <filter string="Has Partner" name="has_partner" domain="[('partner_id', '!=', False)]" icon="terp-partner" />
+ <filter string="Has No Partner" name="has_no_partner" domain="[('partner_id', '=', False)]" icon="terp-partner" />
+ </field>
+ <field name="user_id">
+ <filter string="My Accounts" domain="[('user_id','=',uid)]" icon="terp-personal" name="my_accounts" />
+ <filter string="No Account Manager" domain="[('user_id', '=', False)]" icon="terp-personal-" />
+ </field>
+
+ </group>
+ <newline/>
+ <group expand="0" string="Group By...">
+ <filter string="Manager" icon="terp-personal" domain="[]" context="{'group_by':'user_id'}"/>
+ <filter string="Associated Partner" icon="terp-partner" domain="[]" context="{'group_by':'partner_id'}"/>
+ <separator orientation="vertical"/>
+ <filter string="Parent" icon="terp-folder-orange" domain="[]" context="{'group_by':'parent_id'}"/>
+ <!--
+ <filter string="Start Date" icon="terp-go-month" domain="[]" context="{'group_by' : 'date_start'}" />
+ -->
+ <filter string="End Date" icon="terp-go-month" domain="[]" context="{'group_by' : 'date'}" />
+ </group>
+ </search>
+ </field>
+ </record>
+
+
+ <record id="action_account_analytic_overdue" model="ir.actions.act_window">
+ <field name="name">Overdue Accounts</field>
+ <field name="res_model">account.analytic.account</field>
+ <field name="view_type">form</field>
+ <field name="view_mode">tree,form,graph</field>
+ <field name="context">{'search_default_has_partner':1, 'search_default_my_accounts':1, 'search_default_draft':1, 'search_default_pending':1, 'search_default_open':1, 'search_default_renew':1}</field>
+ <field name="domain">[('type','=','normal')]</field>
+ <field name="search_view_id" ref="view_account_analytic_account_overdue_search"/>
+ <field name="help">You will find here the contracts to be renewed because the deadline is passed or the working hours are higher than the allocated hours. OpenERP automatically sets these analytic accounts to the pending state, in order to raise a warning during the timesheets recording. Salesmen should review all pending accounts and reopen or close the according to the negotiation with the customer.</field>
+ </record>
+ <menuitem action="action_account_analytic_overdue" id="menu_action_account_analytic_overdue" sequence="50" parent="sale.menu_invoiced" groups="base.group_extended"/>
+
</data>
</openerp>
diff --git a/addons/account_analytic_analysis/cron_account_analytic_account.py b/addons/account_analytic_analysis/cron_account_analytic_account.py
new file mode 100644
index 00000000000..581bbfe92e1
--- /dev/null
+++ b/addons/account_analytic_analysis/cron_account_analytic_account.py
@@ -0,0 +1,79 @@
+#!/usr/bin/env python
+from osv import osv
+from mako.template import Template
+import time
+try:
+ import cStringIO as StringIO
+except ImportError:
+ import StringIO
+
+import tools
+
+MAKO_TEMPLATE = u"""Hello ${user.name},
+
+Here is a list of contracts that have to be renewed for two
+possible reasons:
+ - the end of contract date is passed
+ - the customer consumed more hours than expected
+
+Can you contact the customer in order to sell a new or renew its contract.
+The contract has been set with a pending state, can you update the status
+of the analytic account following this rule:
+ - Set Done: if the customer does not want to renew
+ - Set Open: if the customer purchased an extra contract
+
+Here is the list of contracts to renew:
+% for partner, accounts in partners.iteritems():
+ * ${partner.name}
+ % for account in accounts:
+ - Name: ${account.name}
+ % if account.quantity_max != 0.0:
+ - Quantity: ${account.quantity}/${account.quantity_max} hours
+ % endif
+ - Dates: ${account.date_start} to ${account.date and account.date or '???'}
+ - Contacts:
+ % for address in account.partner_id.address:
+ . ${address.name}, ${address.phone}, ${address.email}
+ % endfor
+
+ % endfor
+% endfor
+
+You can use the report in the menu: Sales > Invoicing > Overdue Accounts
+
+Regards,
+
+--
+OpenERP
+"""
+
+class analytic_account(osv.osv):
+ _inherit = 'account.analytic.account'
+
+ def cron_account_analytic_account(self, cr, uid, context=None):
+ domain = [
+ ('name', 'not ilike', 'maintenance'),
+ ('partner_id', '!=', False),
+ ('user_id', '!=', False),
+ ('user_id.user_email', '!=', False),
+ ('state', 'in', ('draft', 'open')),
+ '|', ('date', '<', time.strftime('%Y-%m-%d')), ('date', '=', False),
+ ]
+
+ account_ids = self.search(cr, uid, domain, context=context, order='name asc')
+ accounts = self.browse(cr, uid, account_ids, context=context)
+
+ users = dict()
+ for account in accounts:
+ users.setdefault(account.user_id, dict()).setdefault(account.partner_id, []).append(account)
+
+ account.write({'state' : 'pending'}, context=context)
+
+ for user, data in users.iteritems():
+ subject = '[OPENERP] Reporting: Analytic Accounts'
+ body = Template(MAKO_TEMPLATE).render_unicode(user=user, partners=data)
+ tools.email_send('noreply@openerp.com', [user.user_email, ], subject, body)
+
+ return True
+
+analytic_account()