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.

0

How know if a product has attachments from the list view

By
Shokri Alnajjar
on 3/1/14, 4:24 AM 1,762 views

Hi, is it possible to know if a product has an attachment from the list view ? I want to add a column to the list view indicating if this product has any attachments without pressing on each product and go to the form view

1

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 3/1/14, 5:26 AM

Add Functional Fields to calculate Number of document attached and shows the functional field in List view

For Example in Project Module No of document shows in the Kanban view you can also display in list view based on the requirement

Reference: addons\project\project.py

def _get_attached_docs(self, cr, uid, ids, field_name, arg, context):
        res = {}
        attachment = self.pool.get('ir.attachment')
        task = self.pool.get('project.task')
        for id in ids:
            project_attachments = attachment.search(cr, uid, [('res_model', '=', 'project.project'), ('res_id', '=', id)], context=context, count=True)
            task_ids = task.search(cr, uid, [('project_id', '=', id)], context=context)
            task_attachments = attachment.search(cr, uid, [('res_model', '=', 'project.task'), ('res_id', 'in', task_ids)], context=context, count=True)
            res[id] = (project_attachments or 0) + (task_attachments or 0)
        return res

thank you very much , it worked

Shokri Alnajjar
on 3/1/14, 10:27 AM
0

Ray Carnes

--Ray Carnes--
15717
| 9 7 9
Greater Los Angeles, United States
--Ray Carnes--

Senior Odoo Analyst

OpenERP 6.1, 7.0 and Odoo 8.0, 9.0 (Since 2012)

Completed Functional and Technical Training.

Major Skills:

  • Needs Discovery and Requirements Analysis;

  • Function and Technical Specifications;

  • Project Planning;

  • Prototyping and Proof of concepts;

  • Data migration;

  • Configuration & Customization (UI and modules);

  • Integration - data, business logic and service levels;

  • Training and Knowledge transfer;

  • Go Live support;

  • Help desk;

  • Version Migration.

I have over 20 years of experience empowering and enabling users with enterprise information systems that make a real and measurable difference in their ability to proactively manage their businesses and organizations. 

Ray Carnes
On 2/10/15, 7:16 PM

I have written this, which returns 0:

    def _get_attached_docs(self, cr, uid, ids, field_name, arg, context):
        res = {}
        attachment = self.pool.get('ir.attachment')
        for id in ids:
            product_attachments = attachment.search(cr, uid, [('res_model', '=', 'product.template'), ('res_id', '=', id)], context=context, count=True)
            res[id] = product_attachments or 0
        return res

Although, my code to show the actual attachments works:

   def attachment_tree_view(self, cr, uid, ids, context):
        domain = [
             '&', ('res_model', '=', 'product.template'), ('res_id', 'in', ids),
        ]
        res_id = ids and ids[0] or False
        return {
            'name': _('Attachments'),
            'domain': domain,
            'res_model': 'ir.attachment',
            'type': 'ir.actions.act_window',
            'view_id': False,
            'view_mode': 'kanban,tree,form',
            'view_type': 'form',
            'limit': 80,
            'context': "{'default_res_model': '%s','default_res_id': %d}" % (self._name, res_id)
        }

Can anyone see what is wrong with my _get_attached_docs code?  I have verified that the ir.attachment model does contain a record with model = product.template and res_id = product_id from the product I am testing, and I see my attachment in the standard Attachments dropdown menu.  Also, this testing is being done with the Admin user so document locations shouldn't be a problem.

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

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

Question tools

0 follower(s)

Stats

Asked: 3/1/14, 4:24 AM
Seen: 1762 times
Last updated: 3/16/15, 8:10 AM