Add filter no_attachment on sale.order (same as on account.invoice)
This commit is contained in:
@@ -57,11 +57,11 @@ class AccountInvoice(models.Model):
|
||||
def _compute_has_attachment(self):
|
||||
iao = self.env['ir.attachment']
|
||||
for inv in self:
|
||||
if iao.search([
|
||||
if iao.search_count([
|
||||
('res_model', '=', 'account.invoice'),
|
||||
('res_id', '=', inv.id),
|
||||
('type', '=', 'binary'),
|
||||
('company_id', '=', inv.company_id.id)], limit=1):
|
||||
('company_id', '=', inv.company_id.id)]):
|
||||
inv.has_attachment = True
|
||||
else:
|
||||
inv.has_attachment = False
|
||||
|
||||
@@ -27,6 +27,9 @@ class SaleOrder(models.Model):
|
||||
# for reports
|
||||
has_discount = fields.Boolean(
|
||||
compute='_compute_has_discount', readonly=True)
|
||||
has_attachment = fields.Boolean(
|
||||
compute='_compute_has_attachment',
|
||||
search='_search_has_attachment', readonly=True)
|
||||
|
||||
@api.multi
|
||||
def _compute_has_discount(self):
|
||||
@@ -39,6 +42,30 @@ class SaleOrder(models.Model):
|
||||
break
|
||||
order.has_discount = has_discount
|
||||
|
||||
def _compute_has_attachment(self):
|
||||
iao = self.env['ir.attachment']
|
||||
for order in self:
|
||||
if iao.search_count([
|
||||
('res_model', '=', 'sale.order'),
|
||||
('res_id', '=', order.id),
|
||||
('type', '=', 'binary'),
|
||||
('company_id', '=', order.company_id.id)]):
|
||||
order.has_attachment = True
|
||||
else:
|
||||
order.has_attachment = False
|
||||
|
||||
def _search_has_attachment(self, operator, value):
|
||||
att_order_ids = {}
|
||||
if operator == '=':
|
||||
search_res = self.env['ir.attachment'].search_read([
|
||||
('res_model', '=', 'sale.order'),
|
||||
('type', '=', 'binary'),
|
||||
('res_id', '!=', False)], ['res_id'])
|
||||
for att in search_res:
|
||||
att_order_ids[att['res_id']] = True
|
||||
res = [('id', value and 'in' or 'not in', att_order_ids.keys())]
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def action_confirm(self):
|
||||
'''Reload view upon order confirmation to display the 3 qty cols'''
|
||||
|
||||
@@ -75,6 +75,10 @@
|
||||
<field name="project_id" position="attributes">
|
||||
<attribute name="groups">analytic.group_analytic_accounting</attribute>
|
||||
</field>
|
||||
<filter name="message_needaction" position="before">
|
||||
<filter name="no_attachment" string="Missing Attachment" domain="[('has_attachment', '=', False)]"/>
|
||||
<separator/>
|
||||
</filter>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user