Skip to content

Commit

Permalink
sale_usability: add no-attachment filter on sale.order
Browse files Browse the repository at this point in the history
account_usability: small code improvement on has_attachment
  • Loading branch information
alexis-via committed May 20, 2021
1 parent e70e3b2 commit 42e014b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
4 changes: 2 additions & 2 deletions account_usability/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ def _compute_has_discount(self):
def _compute_has_attachment(self):
iao = self.env['ir.attachment']
for move in self:
if iao.search([
if iao.search_count([
('res_model', '=', 'account.move'),
('res_id', '=', move.id),
('type', '=', 'binary'),
('company_id', '=', move.company_id.id)], limit=1):
('company_id', '=', move.company_id.id)]):
move.has_attachment = True
else:
move.has_attachment = False
Expand Down
30 changes: 29 additions & 1 deletion sale_usability/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class SaleOrder(models.Model):
fiscal_position_id = fields.Many2one(tracking=True)
# for reports
has_discount = fields.Boolean(compute='_compute_has_discount')
has_attachment = fields.Boolean(
compute='_compute_has_attachment',
search='_search_has_attachment')

@api.depends('order_line.discount')
def _compute_has_discount(self):
Expand All @@ -34,6 +37,30 @@ def _compute_has_discount(self):
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', list(att_order_ids))]
return res

# for report
def py3o_lines_layout(self):
self.ensure_one()
Expand Down Expand Up @@ -67,7 +94,8 @@ class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'

# for optional display in tree view
product_barcode = fields.Char(related='product_id.barcode', string="Product Barcode")
product_barcode = fields.Char(
related='product_id.barcode', string="Product Barcode")

@api.onchange('product_uom', 'product_uom_qty')
def product_uom_change(self):
Expand Down
4 changes: 4 additions & 0 deletions sale_usability/views/sale_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
<filter name="order_month" position="after">
<filter string="State" name="state_groupby" context="{'group_by': 'state'}"/>
</filter>
<filter name="activities_upcoming_all" position="after">
<separator/>
<filter name="no_attachment" string="Missing Attachment" domain="[('has_attachment', '=', False)]"/>
</filter>
</field>
</record>

Expand Down

0 comments on commit 42e014b

Please sign in to comment.