Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

2

Print button on calendar view [Project.task] [Closed]

By
Laurens
on 5/28/13, 7:11 AM 4,746 views

The Question has been closed

by
Laurens
on 06/06/2013 10:26:55

Is it possible to create a print button on a view in a calendar?

I created a custom report for the project tasks. I can print this report from the form- and list-view. I would however prefer to print this report directly from the calendar.

Meaning I would click on one task in the calendar, and print the report generated from this task-view directly. (without going back to tree view, looking it up; and then printing it)

Is it possible to create a button that will call on my report? It can be any kind of button, doesn't necessarily have to be the same kind of print button.

Ideally I'd like to place my button in one of these red fields:

image description

I have found the corresponding code:

<!--button name="643" string="Print Werkbon" type="action" icon="gtk-cprint"/--> OR  
<button name="%(643)d" string="Print Werkbon" type="action" icon="gtk-print"/>

But I don't know where to add it, obviously adding it to the calendar view didn't help; as I only need it available in the project.task pop-up as depicted in the illustration.

Adding it here wouldn't help:

    <?xml version="1.0"?>
<calendar color="user_id" date_start="date_start" date_stop="date_end" string="Tasks">
                     <field name="notes"/>
                     <field name="name"/>
                </calendar>

But were can I enter this code so it would show up where it needs to?

Solution


I was able to set this up with the help of Nicolas Jeudy, and I credited him as author for the project_task module. I just had to fix some spacing and formatting errors in my code, before I could figure the rest out. Apart from that I renamed my report and module code to project_task.

The solution can be found in the project_task + my_reports module on the dropbox link below. There is a redundant part with the report being under both modules, and I haven't yet added an inherited view for project_task. The code isn't perfect, but it works.

Don't forget to add this line in the header section of the FormView of project_task. (or inherit the view):

<button name="print_task" string="Print" type="object"/>

https://www.dropbox.com/sh/u6xsduqnw7x5ttu/7ofCKCW4Eo

3

Jeudy Nicolas

--Jeudy Nicolas--
1171
| 6 7 8
PELOUSEY, France
--Jeudy Nicolas--

- Linux administrator - Functional guy with OpenERP - Python, html, css, javascript developer OpenERP Ready Partner

Jeudy Nicolas
On 5/28/13, 11:17 AM

Hello,

You can add a button action linked to an action define like this for project_task model in you need:

def print_task(self, cr, uid, ids, context=None):

    assert len(ids) == 1, 'This option should only be used for a single id at a time'

    datas = {
             'model': 'project_task',
             'ids': ids,
             'form': self.read(cr, uid, ids[0], context=context),
    }
    return {'type': 'ir.actions.report.xml', 'report_name': 'project.task', 'datas': datas, 'nodestroy': True}

And in your xml form view definition:

 <button name="print_task" string="Print" type="object"/>

You can see it in action in the sale module with print_quotation function and sale.order ir.actions.report.xml .

In addintion to this, if you want a full functionnal test, create a new module with projet_task.py file (and at least corresponding __init__.py and __openerp__.py) containing:

# -- coding: utf-8 --

from openerp.osv import fields, osv
from openerp.tools.translate import _

class projectTask(osv.osv):
    _name = "project.task"
    _inherit = "project.task"
    def print_task(...):
        ....

And you should have all you need.

Hey Nicolas, first off, thank you very much for your answer. I have almost accomplished what I want to. The "Print" button is visible when I add the button to my form view but I'm not sure where exactly I have to define the action.

As it stands I have added the code somewhere in project.py, but I'm not sure it is in the right place. When I use my print button, it sais: " AttributeError: 'project.task' object has no attribute 'print_task' ".

Either I need to define my action elsewhere in project.py or in another file? Or...

Laurens
on 5/29/13, 8:21 AM

I made my report based on Anas' answer in http://help.openerp.com/question/5224/put-report-in-module/ . Maybe I need to change my print_task action. The name of my report is still new_report.rml under the module my_reports. It is however linked to the model project_task.

Laurens
on 5/29/13, 8:25 AM
0
Laurens
On 5/30/13, 6:04 AM

Nicolas' answer got me pretty far. Definatly on the right track. I got the Print button in the header of my project task view under the calendar. And comparing the actions under sale.order and this one makes me believe this really is the best/only way to do this.

However looking at the code of sale.order doesn't give me any indication where exactly to put my code under project.task. I've been trying numerous locations, updating the module list and module and pressing the print button again. The print button I manually added in the original formview. (and I have to add the code again after every update)

I keep getting this error

OpenERP Server Error
Client Traceback (most recent call last):
  File "C:\Program Files\OpenERP 7\Server\server\openerp\addons\web\http.py", line 203, in dispatch
  File "C:\Program Files\OpenERP 7\Server\server\openerp\addons\web\controllers\main.py", line 1121, in call_button
  File "C:\Program Files\OpenERP 7\Server\server\openerp\addons\web\controllers\main.py", line 1109, in _call_kw
  File "C:\Program Files\OpenERP 7\Server\server\openerp\addons\web\session.py", line 43, in proxy
  File "C:\Program Files\OpenERP 7\Server\server\openerp\addons\web\session.py", line 31, in proxy_method
  File "C:\Program Files\OpenERP 7\Server\server\openerp\addons\web\session.py", line 104, in send


Server Traceback (most recent call last):
  File "C:\Program Files\OpenERP 7\Server\server\openerp\addons\web\session.py", line 90, in send
  File "C:\Program Files\OpenERP 7\Server\server\.\openerp\netsvc.py", line 293, in dispatch_rpc
  File "C:\Program Files\OpenERP 7\Server\server\.\openerp\service\web_services.py", line 626, in dispatch
  File "C:\Program Files\OpenERP 7\Server\server\.\openerp\osv\osv.py", line 188, in execute_kw
  File "C:\Program Files\OpenERP 7\Server\server\.\openerp\osv\osv.py", line 131, in wrapper
  File "C:\Program Files\OpenERP 7\Server\server\.\openerp\osv\osv.py", line 197, in execute
  File "C:\Program Files\OpenERP 7\Server\server\.\openerp\osv\osv.py", line 185, in execute_cr
AttributeError: 'project.task' object has no attribute 'print_task'

I think it is because the action print_task can't be found in the model project.task. I.e. it's in the wrong location. Can someone tell me where I should define this action so it is correctly linked to project.task?

Or do I also need to rename my report to project_task.rml? (see previous comment for more info)

I tried putting the code in various places in the project, project_gtd, project_timesheet and project_mrp .py files; but I keep getting "AttributeError: 'project.task' object has no attribute 'print_task'". To what does this refer exactly? I've tried changing the 'report_name' to the name of the report .rml file and the name under ir.actions pgsql table but the error remains the same each time. Also tried copying the report from my module my_reports to the project module, and renaming them project_task.rml and project_task.sxw. Same error.

What am I not seeing/doing?

Laurens
on 5/30/13, 2:14 PM

I update my answer to show where you can put it. you have to definie a new method in the project.task object definition. The better way is to create a new module.

Tuxservices, Jeudy Nicolas
on 5/30/13, 3:12 PM

Can you copy your view definition (only where button is located and the button line to view what can be wrong ..

Tuxservices, Jeudy Nicolas
on 5/30/13, 3:13 PM

Nicolas, I tried following your advice and created a new module to define the method. I named this module project_task. For the changes in the view I haven't yet made a custom view in my module, I have changed my FormView through the developper's mode in the OpenERP UI. Once I get it to work this way, I will try adding the view to my project_task module.

You can find my modules and the FormView Here: https://www.dropbox.com/sh/u6xsduqnw7x5ttu/7ofCKCW4Eo

I also added the my_reports module containing the report I am trying to print. My project module is still default.

Laurens
on 5/31/13, 9:13 AM

Are you sure your module can be installed ? - In __init__.py you have to import project_task (name of your .py) and not project - your report seems to be named new_report so you have to use this in button definition - def print_task seems not to be correctly indented to work, can you check this.

I will put an example module in few days when I will have time.

Tuxservices, Jeudy Nicolas
on 5/31/13, 12:43 PM

Yes my module can be installed, but it is very likely not complete. I will check all the points you mentioned, starting with verifying the indention and adding the import for project_task. Also nice to know for sure I need to use the actual rml report name in the button rather than the name referenced in the code or the name under the ir.actions table

I will keep trying, but this is one of my first modules and I'm still learning. I appreciate you checking up on me. An example would be helpful, but please take your time. No rush. I'm very grateful for all the feedback you have already given.

Laurens
on 5/31/13, 12:56 PM

Hey Nic, I was able to set it up - much thanks to you. I uploaded my modules in my original post, and credited you as author for your contributions and support. In the end switching a tab for four spaces is what fixed the Attribute error, so it was an indention error after all. Thanks for your help bro.

Laurens
on 6/6/13, 7:29 AM
0
Laurens
On 5/28/13, 9:06 AM

When you select a task in the calendar view, it automatically opens in edit-mode; so you can adjust the title or change certain values. You can choose to save this task, but this will also close it.

When editting a task in form-view, the print button disappears; until you save the record. Am I wrong to assume it is impossible to display a print button on a document that is being editted? So to follow that up, it would also be impossible to display a print button in the task view of the task calendar?

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 5/28/13, 7:11 AM
Seen: 4746 times
Last updated: 3/16/15, 8:10 AM