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):
|
def _compute_has_attachment(self):
|
||||||
iao = self.env['ir.attachment']
|
iao = self.env['ir.attachment']
|
||||||
for inv in self:
|
for inv in self:
|
||||||
if iao.search([
|
if iao.search_count([
|
||||||
('res_model', '=', 'account.invoice'),
|
('res_model', '=', 'account.invoice'),
|
||||||
('res_id', '=', inv.id),
|
('res_id', '=', inv.id),
|
||||||
('type', '=', 'binary'),
|
('type', '=', 'binary'),
|
||||||
('company_id', '=', inv.company_id.id)], limit=1):
|
('company_id', '=', inv.company_id.id)]):
|
||||||
inv.has_attachment = True
|
inv.has_attachment = True
|
||||||
else:
|
else:
|
||||||
inv.has_attachment = False
|
inv.has_attachment = False
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ class SaleOrder(models.Model):
|
|||||||
# for reports
|
# for reports
|
||||||
has_discount = fields.Boolean(
|
has_discount = fields.Boolean(
|
||||||
compute='_compute_has_discount', readonly=True)
|
compute='_compute_has_discount', readonly=True)
|
||||||
|
has_attachment = fields.Boolean(
|
||||||
|
compute='_compute_has_attachment',
|
||||||
|
search='_search_has_attachment', readonly=True)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _compute_has_discount(self):
|
def _compute_has_discount(self):
|
||||||
@@ -39,6 +42,30 @@ class SaleOrder(models.Model):
|
|||||||
break
|
break
|
||||||
order.has_discount = has_discount
|
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
|
@api.multi
|
||||||
def action_confirm(self):
|
def action_confirm(self):
|
||||||
'''Reload view upon order confirmation to display the 3 qty cols'''
|
'''Reload view upon order confirmation to display the 3 qty cols'''
|
||||||
|
|||||||
@@ -75,6 +75,10 @@
|
|||||||
<field name="project_id" position="attributes">
|
<field name="project_id" position="attributes">
|
||||||
<attribute name="groups">analytic.group_analytic_accounting</attribute>
|
<attribute name="groups">analytic.group_analytic_accounting</attribute>
|
||||||
</field>
|
</field>
|
||||||
|
<filter name="message_needaction" position="before">
|
||||||
|
<filter name="no_attachment" string="Missing Attachment" domain="[('has_attachment', '=', False)]"/>
|
||||||
|
<separator/>
|
||||||
|
</filter>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user