commit
5f3f52ec2e
|
|
@ -1,11 +1,45 @@
|
|||
from odoo import api, fields, models, _
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import api, fields, models
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
_inherit = 'account.move'
|
||||
|
||||
attach_no = fields.Integer(compute='get_attachments')
|
||||
res_model = fields.Char()
|
||||
res_id = fields.Integer()
|
||||
res_model = fields.Char()
|
||||
|
||||
def get_attachments(self):
|
||||
self.ensure_one()
|
||||
|
||||
action = self.env['ir.actions.act_window']._for_xml_id('base.action_attachment')
|
||||
action['domain'] = [
|
||||
('res_model', '=', 'account.move'),
|
||||
('res_id', 'in',self.ids), ]
|
||||
domain = [
|
||||
('res_model', '=', 'account.move'),
|
||||
('res_id', 'in', self.ids), ]
|
||||
related_ids = self.ids
|
||||
related_models = 'account.move'
|
||||
|
||||
if self.res_id and self.res_model:
|
||||
related_ids = self.ids + [self.res_id]
|
||||
related_models = ['account.move', self.res_model]
|
||||
action['domain'] = [
|
||||
('res_model', 'in', related_models),
|
||||
('res_id', 'in', related_ids), ]
|
||||
domain = [
|
||||
('res_model', 'in', related_models),
|
||||
('res_id', 'in', related_ids), ]
|
||||
|
||||
# Context for creating new attachments
|
||||
action['context'] = "{'default_res_model': '%s','default_res_id': %d}" % (self._name, self.id)
|
||||
# Update attachment count for smart button
|
||||
|
||||
|
||||
self.attach_no = self.env['ir.attachment'].search_count(domain)
|
||||
|
||||
return action
|
||||
|
||||
# def get_attachments(self):
|
||||
# action = self.env['ir.actions.act_window']._for_xml_id('base.action_attachment')
|
||||
|
|
@ -14,30 +48,3 @@ class AccountMove(models.Model):
|
|||
# domain = [('res_model', '=', 'account.move'), ('res_id', '=', self.id)]
|
||||
# self.attach_no = self.env['ir.attachment'].search_count(domain)
|
||||
# return action
|
||||
|
||||
def get_attachments(self):
|
||||
self.ensure_one()
|
||||
|
||||
action = self.env['ir.actions.act_window']._for_xml_id('base.action_attachment')
|
||||
related_ids = self.ids
|
||||
related_models = 'account.move'
|
||||
|
||||
if self.res_id and self.res_model:
|
||||
related_ids = self.ids + [res_id]
|
||||
related_models = ['account.move', self.res_model]
|
||||
|
||||
action['domain'] = [
|
||||
('res_model', 'in',related_models),
|
||||
('res_id', 'in', related_ids),]
|
||||
|
||||
# Context for creating new attachments
|
||||
action['context'] = "{'default_res_model': '%s','default_res_id': %d}" % (self._name, self.id)
|
||||
# Update attachment count for smart button
|
||||
domain = [
|
||||
('res_model', 'in', related_models),
|
||||
('res_id', 'in', related_ids),]
|
||||
|
||||
self.attach_no = self.env['ir.attachment'].search_count(domain)
|
||||
|
||||
return action
|
||||
|
||||
|
|
|
|||
|
|
@ -12,13 +12,12 @@
|
|||
<field name="attach_no" widget="statinfo" string="Documents"/>
|
||||
</button>
|
||||
</xpath>
|
||||
<xpath expr="//page[@name='other_info']" position="inside">
|
||||
<group name="model_info" string='Model Info'>
|
||||
<field name='res_model'/>
|
||||
<field name='res_id'/>
|
||||
</group>
|
||||
<xpath expr="//page[@name='other_info']" position="inside">
|
||||
<group name="model_info" string='Model Info'>
|
||||
<field readonly="1" name='res_model'/>
|
||||
<field readonly="1" name='res_id'/>
|
||||
</group>
|
||||
</xpath>
|
||||
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
|
|
|||
Loading…
Reference in New Issue