Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
5673 Lượt xem

- When clicking on the button displays the list of all documents uploaded to that record

- Documents are taken from ir.attachment model, there are 2 logic:

1 / resource model = res.partner

2 / res_id = res_id of record

- Create a compute field for the button to count all uploaded documents.

my code:

class ResPartner(models.Model):
_inherit = "res.partner"

x_phanloai = fields.Selection(string="Phân loi",
selection=[('leader', 'Leader'), ('end-user', 'End-user')])
x_masothue = fields.Char(string='Mã s thuế', required=True)
x_mien = fields.Char(string='Min', related='state_id.x_mien', readonly=True)
x_attachment_kh = fields.Many2many('ir.attachment', string='Attachment')
attachment_count = fields.Integer(compute='_compute_attachment_count', string='Attachment')

ếm s tài liu khi được upload
@api.depends('x_attachment_kh')
def _compute_attachment_count(self):
for record in self:
total = 0
if record.x_attachment_kh:
for i in record.x_attachment_kh:
total += 1
record.attachment_count = total
---------
<button name="toggle_active" position="before">
<button class="oe_stat_button" type="action" name="%(base.action_attachment)d"
icon="fa-file-text-o"
context="{'search_default_res_id': id}">
<field string="Hp Đng" name="attachment_count" widget="statinfo"/>
</button>
</button>
All help is helpful for the bowl

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi, 

@api.multi
def _compute_attachment_count(self):
        Attachment = self.env['ir.attachment']
        for record in self:
            record.attachment_count = Attachment.search_count([('res_model', '=', self._name), ('res_id', '=', record.id)])

Upvote if this helps.

Thanks.


Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

thank you ibrahim, it does not work properly. I don't understand why it happened like that.

The problem becomes more complex than I think. when create does not manually res_model and res_id, so it cannot be counted.

Ảnh đại diện
Huỷ bỏ

does my answer work properly for you ? or is there a problem with it ?

Tác giả

nó không hoạt động trong khi create or import. tôi không biết nó ra lỗi gì mà không oạt động

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 24
15864
2
thg 9 23
8685
2
thg 3 23
10223
2
thg 3 23
2557
2
thg 5 22
4585