- 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 loại",
selection=[('leader', 'Leader'), ('end-user', 'End-user')])
x_masothue = fields.Char(string='Mã số thuế', required=True)
x_mien = fields.Char(string='Miền', 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 liệu 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="Hợp Đồng" name="attachment_count" widget="statinfo"/>
</button>
</button>
All help is helpful for the bowl