Current behavior: If you made a sales with a partner wich is part of a company. And then archive that partner and click on the sales smart button from the company the sales from that partner wouldn't appear in the list. The problem is the same for the invoices Steps to reproduce: - Install sales and contacts - Create a sale for a partner (e.g. Edwin Hansen from Gemini) - Archive that partner - Go in the company view, click on sales button - The sale from the archived partner do not appear in the company sales list opw-2850115 closes odoo/odoo#93587 X-original-commit: 8e46a00356a85b42078637d97ec6d0ef204f370a Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com> Signed-off-by: Engels Robin (roen) <roen@odoo.com>
59 lines
2.6 KiB
Python
59 lines
2.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models
|
|
from odoo.addons.base.models.res_partner import WARNING_MESSAGE, WARNING_HELP
|
|
from odoo.osv import expression
|
|
|
|
class ResPartner(models.Model):
|
|
_inherit = 'res.partner'
|
|
|
|
sale_order_count = fields.Integer(compute='_compute_sale_order_count', string='Sale Order Count')
|
|
sale_order_ids = fields.One2many('sale.order', 'partner_id', 'Sales Order')
|
|
sale_warn = fields.Selection(WARNING_MESSAGE, 'Sales Warnings', default='no-message', help=WARNING_HELP)
|
|
sale_warn_msg = fields.Text('Message for Sales Order')
|
|
|
|
@api.model
|
|
def _get_sale_order_domain_count(self):
|
|
return []
|
|
|
|
def _compute_sale_order_count(self):
|
|
# retrieve all children partners and prefetch 'parent_id' on them
|
|
all_partners = self.with_context(active_test=False).search([('id', 'child_of', self.ids)])
|
|
all_partners.read(['parent_id'])
|
|
|
|
sale_order_groups = self.env['sale.order']._read_group(
|
|
domain=expression.AND([self._get_sale_order_domain_count(), [('partner_id', 'in', all_partners.ids)]]),
|
|
fields=['partner_id'], groupby=['partner_id']
|
|
)
|
|
partners = self.browse()
|
|
for group in sale_order_groups:
|
|
partner = self.browse(group['partner_id'][0])
|
|
while partner:
|
|
if partner in self:
|
|
partner.sale_order_count += group['partner_id_count']
|
|
partners |= partner
|
|
partner = partner.parent_id
|
|
(self - partners).sale_order_count = 0
|
|
|
|
def can_edit_vat(self):
|
|
''' Can't edit `vat` if there is (non draft) issued SO. '''
|
|
can_edit_vat = super(ResPartner, self).can_edit_vat()
|
|
if not can_edit_vat:
|
|
return can_edit_vat
|
|
SaleOrder = self.env['sale.order']
|
|
has_so = SaleOrder.search([
|
|
('partner_id', 'child_of', self.commercial_partner_id.id),
|
|
('state', 'in', ['sent', 'sale', 'done'])
|
|
], limit=1)
|
|
return can_edit_vat and not bool(has_so)
|
|
|
|
def action_view_sale_order(self):
|
|
action = self.env['ir.actions.act_window']._for_xml_id('sale.act_res_partner_2_sale_order')
|
|
all_child = self.with_context(active_test=False).search([('id', 'child_of', self.ids)])
|
|
if self.is_company:
|
|
action['domain'] = [('partner_id.commercial_partner_id', '=', self.id), ('partner_id', 'in', all_child.ids)]
|
|
else:
|
|
action['domain'] = [('partner_id', '=', self.id), ('partner_id', 'in', all_child.ids)]
|
|
return action
|