Current behaviour: In the context of a multilevel contact hierarchy, if a contact is creating an SO, only that contact and it's commercial partner (usually the first company when going up in hierarchy from that contact) can see the SO. The other contacts that are in that hierarchy could see the number of related SO on the smart button, but once clicking on it, no SO were shown. Expected behaviour: Every direct or indirect parent of a contact should be able to see the SO, as shown in the smart button count. Steps to reproduce: - Create 3 contacts with the following hierarchy: Company -> Contact 1 -> Contact 2 (Company is the root) - Create an SO with Contact 2 as a customer - On each of the contacts, click on the SO smart button, all of them have 1 SO shown on the button, but only Constact 1 has none shown once clicked. (Regardless if Contact 1 is an Individual or Company) Fix: Simplify domain search to only take into account the children's ids. There is no need to make a distinction between a contact that is a company or not, since all commercial_partners are also partners by default. Affected versions: - 14.0 - 15.0 - saas-15.2 - saas-15.3 - master opw-2961030 closes odoo/odoo#100544 X-original-commit: c34e0200b2db3ad191ee08f91f9293404a2c3340 Signed-off-by: Piryns Victor (pivi) <pivi@odoo.com>
56 lines
2.4 KiB
Python
56 lines
2.4 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)])
|
|
action["domain"] = [("partner_id", "in", all_child.ids)]
|
|
return action
|