Add filter no_attachment on sale.order (same as on account.invoice)

This commit is contained in:
Alexis de Lattre
2021-05-20 12:25:33 +02:00
parent d858634b91
commit 781e8989f5
3 changed files with 33 additions and 2 deletions

View File

@@ -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'''