تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
5857 أدوات العرض

Hello Odoo Lovers
whenever I add an attachment in product.template model that time I need attachment in product.product model.

How can it's possible?

الصورة الرمزية
إهمال
أفضل إجابة

Hi Nikul,

Yes, you can do this by changing the domain in the JS file of the document module.

You would need to add the product.template object and template ID:

if (this.env.model == 'product.product') {
['res_model', 'in', [this.env.model, 'product.template']],
['res_id', 'in', activeId, templateId], # find the product templateID first
}

I hope this will help you to make progress.

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

Thank you Mr. Sudhir for answering and suggesting search_read method, But  Here I using Python code I added a product.template attachment in product.product model also same as vice versa.

_name = 'ir.attachment'
    @api.model
    def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None):
        if domain and len(domain) == 2:
            res_id = False
            res_model = False
            for domain_list in domain:
                if domain_list[0] == 'res_id':
                    res_id = domain_list[2]
                elif domain_list[0] == 'res_model':
                    res_model = domain_list[2]
            if res_id and res_model and res_model == 'product.template':
                product_variant_ids = self.env['product.template'].browse(res_id).product_variant_ids.ids
                if product_variant_ids:
                    domain.insert(0, '|')
                    domain.insert(1, '&')
                    domain += ['&', ['res_id', 'in', product_variant_ids], ['res_model', '=', 'product.product']]
            elif res_id and res_model and res_model == 'product.product':
                product_rec = self.env['product.product'].browse(res_id)
                if product_rec:
                    domain.insert(0, '|')
                    domain.insert(1, '&')
                    domain += ['&', ['res_id', '=', product_rec.product_tmpl_id.id], ['res_model', '=', 'product.template']]
        return super(IrAttachment, self).search_read(fields=fields, offset=offset, limit=limit, domain=domain, order=order)

For Attachment Count in template & product Added a methods like this:

_name = "product.product"
    @api.multi
    def _compute_message_attachment_count(self):
        attachment_obj = self.env['ir.attachment']
        for record in self:
            domain = ['|', '&', ['res_id', '=', record.product_tmpl_id.id], ['res_model', '=', 'product.template'],
                       '&', ['res_id', '=', record.id], ['res_model', '=', 'product.product']]
            record.message_attachment_count = attachment_obj.search_count(domain)

_name = "product.template"
    @api.multi
    def _compute_message_attachment_count(self):
        attachment_obj = self.env['ir.attachment']
        for record in self:
            domain = ['|', '&', ['res_id', '=', record.id], ['res_model', '=', 'product.template'],
                       '&', ['res_id', '=', record.product_variant_ids.ids], ['res_model', '=', 'product.product']]
            record.message_attachment_count = attachment_obj.search_count(domain)

الصورة الرمزية
إهمال
أفضل إجابة

Hi, can I ask why do you need to attach it to product.product template? Is it to view on the website?

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
2
أغسطس 23
4574
0
أكتوبر 21
1857
1
سبتمبر 19
5408
1
يونيو 25
982
1
فبراير 25
1582