[IMP]calculate amt to invoice and display on kanban view
authorSanjay Gohel (Open ERP) <sgo@tinyerp.com>
Fri, 30 Mar 2012 11:47:05 +0000 (17:17 +0530)
committerSanjay Gohel (Open ERP) <sgo@tinyerp.com>
Fri, 30 Mar 2012 11:47:05 +0000 (17:17 +0530)
bzr revid: sgo@tinyerp.com-20120330114705-kgecxihkih0ftmvj

addons/project_timesheet/project_timesheet.py
addons/project_timesheet/project_timesheet_view.xml

index e9e53b1..b96d7b0 100644 (file)
@@ -29,12 +29,28 @@ from tools.translate import _
 class project_project(osv.osv):
     _inherit = 'project.project'
 
+    def _amt_to_invoiced(self, cr, uid, ids,field_name, arg, context=None):
+        res = {}
+        task_pool=self.pool.get('project.task')
+        for id in ids:
+            task_ids = task_pool.search(cr, uid, [('project_id', '=', id)])
+            total = 0.0
+            project_record = self.browse(cr,uid,id)
+            acc_model = self.pool.get("account.analytic.line")
+            acc_id = acc_model.search(cr, uid, [('account_id', '=', project_record.analytic_account_id.id),('to_invoice', '=', 1),('invoice_id', '=', False)])
+            if acc_id:
+                for record in acc_model.browse(cr,uid,acc_id):
+                    total += record.amount
+            res[id]= total
+        return res
     _columns = {
         'timesheets' : fields.boolean('Timesheets',help = "If you check this field timesheets appears in kanban view"),
+        'to_amt_invoice': fields.function(_amt_to_invoiced,string="Open Tasks")
     }
     _defaults = {
         'timesheets' : True,
     }
+
     def onchange_partner_id(self, cr, uid, ids, part=False, context=None):
         res = super(project_project, self).onchange_partner_id(cr, uid, ids, part, context)
         if part and res and ('value' in res):
index 3801b0d..d600611 100644 (file)
@@ -8,7 +8,8 @@
             <field name="inherit_id" ref="project.edit_project"/>
             <field name="arch" type="xml">
                <xpath expr="//field[@name='task']" position='after'>
-                   <field name="timesheets"/>
+                               <field name="timesheets"/>
+                               <field name="to_amt_invoice" invisible="True"/>
                 </xpath>
             
                 <field name="warn_customer" position="after">
@@ -33,6 +34,7 @@
                     <field name="timesheets"/>
                     <field name="total_hours"/>
                     <field name="effective_hours"/>
+                    <field name="to_amt_invoice"/>
                 </field>
                <xpath expr="//t[@t-name='tasks']" position="after">
                     <t t-name="timesheets">
@@ -45,6 +47,7 @@
                     <t t-if="record.timesheets.raw_value">
                         <button name="open_timesheets" class="oe_project_buttons" type="object" tooltip="timesheets"><img src="/project_timesheet/static/src/img/timesheet_icon.png" class="project_icon"/></button>
                     </t>
+                    <t t-esc = "to_amt_invoice"/>
                 </xpath>
                 <xpath expr="//td[@class='td_image']" position="inside">
                    <div class="sequence">
@@ -55,7 +58,7 @@
                <xpath expr="//td[@class='td_deadline']" position="inside">
                    <div class="sequence">
                        <kbd class="user">To invoice</kbd>
-                       <div class="manager"><b><field name="amount_invoiced"/> <field name="currency_id"/></b></div>
+                       <div class="manager"><b><field name="to_amt_invoice"/> <field name="currency_id"/></b></div>
                    </div>
                    <div class="sequence">
                        <button name="open_timesheets" class="oe_to_invoice_buttons" type="object" context="{'btn':'invoice'}">Invoice</button>