mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-27 08:32:05 +02:00
19.0 vanilla
This commit is contained in:
parent
79f83631d5
commit
73afc09215
6267 changed files with 1534193 additions and 1130106 deletions
|
|
@ -1,28 +1,38 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo import SUPERUSER_ID
|
||||
from odoo.osv import expression
|
||||
from odoo.fields import Domain
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
expense_ids = fields.One2many('hr.expense', 'sale_order_id', string='Expenses', domain=[('state', '=', 'done')], readonly=True, copy=False)
|
||||
expense_ids = fields.One2many(
|
||||
comodel_name='hr.expense',
|
||||
inverse_name='sale_order_id',
|
||||
string='Expenses',
|
||||
domain=[('state', 'in', ('posted', 'in_payment', 'paid'))],
|
||||
readonly=True,
|
||||
)
|
||||
expense_count = fields.Integer("# of Expenses", compute='_compute_expense_count', compute_sudo=True)
|
||||
|
||||
@api.model
|
||||
def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None):
|
||||
""" For expense, we want to show all sales order but only their name_get (no ir.rule applied), this is the only way to do it. """
|
||||
if self._context.get('sale_expense_all_order') and self.user_has_groups('sales_team.group_sale_salesman') and not self.user_has_groups('sales_team.group_sale_salesman_all_leads'):
|
||||
domain = expression.AND([args or [], ['&', ('state', '=', 'sale'), ('company_id', 'in', self.env.companies.ids)]])
|
||||
return super(SaleOrder, self.sudo())._name_search(name=name, args=domain, operator=operator, limit=limit, name_get_uid=SUPERUSER_ID)
|
||||
return super(SaleOrder, self)._name_search(name=name, args=args, operator=operator, limit=limit, name_get_uid=name_get_uid)
|
||||
def _search_display_name(self, operator, value):
|
||||
""" For expense, we want to show all sales order but only their display_name (no ir.rule applied), this is the only way to do it. """
|
||||
if (
|
||||
self.env.context.get('sale_expense_all_order')
|
||||
and self.env.user.has_group('sales_team.group_sale_salesman')
|
||||
and not self.env.user.has_group('sales_team.group_sale_salesman_all_leads')
|
||||
):
|
||||
if operator in Domain.NEGATIVE_OPERATORS:
|
||||
return NotImplemented
|
||||
domain = super()._search_display_name(operator, value)
|
||||
company_domain = Domain('state', '=', 'sale') & ('company_id', 'in', self.env.companies.ids)
|
||||
query = self.sudo()._search(domain & company_domain)
|
||||
return Domain('id', 'in', query)
|
||||
return super()._search_display_name(operator, value)
|
||||
|
||||
@api.depends('expense_ids')
|
||||
def _compute_expense_count(self):
|
||||
expense_data = self.env['hr.expense']._read_group([('sale_order_id', 'in', self.ids)], ['sale_order_id'], ['sale_order_id'])
|
||||
mapped_data = dict([(item['sale_order_id'][0], item['sale_order_id_count']) for item in expense_data])
|
||||
for sale_order in self:
|
||||
sale_order.expense_count = mapped_data.get(sale_order.id, 0)
|
||||
sale_order.expense_count = len(sale_order.order_line.expense_ids)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue