[PATCH] Upstream patch - 25072023

This commit is contained in:
Parthiv Patel
2023-07-25 08:33:56 +00:00
parent b981872e08
commit 3e5354b86d
7 changed files with 59 additions and 6 deletions

View File

@@ -168,7 +168,7 @@ class AccountPayment(models.Model):
self.journal_id.payment_credit_account_id,
):
liquidity_lines += line
elif line.account_id.internal_type in ('receivable', 'payable') or line.partner_id == line.company_id.partner_id:
elif line.account_id.internal_type in ('receivable', 'payable') or line.account_id == line.company_id.transfer_account_id:
counterpart_lines += line
else:
writeoff_lines += line

View File

@@ -186,7 +186,7 @@
<field name="reconcile_model_id" invisible="1"/>
<field name="date_maturity" optional="hide"/>
<field name="analytic_account_id" optional="hide" groups="analytic.group_analytic_accounting" attrs="{'readonly':[('parent_state','=','posted')]}"/>
<field name="analytic_tag_ids" optional="hide" readonly="1" groups="analytic.group_analytic_tags"/>
<field name="analytic_tag_ids" optional="hide" widget="many2many_tags" readonly="1" groups="analytic.group_analytic_tags"/>
<field name="debit" sum="Total Debit" readonly="1"/>
<field name="credit" sum="Total Credit" readonly="1"/>
<field name="balance" sum="Total Balance" readonly="1" optional="hide"/>

View File

@@ -6,6 +6,7 @@ from flectra.tools.pdf import FlectraPdfFileReader, FlectraPdfFileWriter
from flectra.osv import expression
from flectra.tools import html_escape
from flectra.exceptions import RedirectWarning
from PyPDF2.utils import PdfReadError
from lxml import etree
from struct import error as StructError
@@ -15,6 +16,7 @@ import logging
import pathlib
import re
_logger = logging.getLogger(__name__)
@@ -394,7 +396,7 @@ class AccountEdiFormat(models.Model):
try:
for xml_name, content in pdf_reader.getAttachments():
to_process.extend(self._decode_xml(xml_name, content))
except (NotImplementedError, StructError) as e:
except (NotImplementedError, StructError, PdfReadError) as e:
_logger.warning("Unable to access the attachments of %s. Tried to decrypt it, but %s." % (filename, e))
# Process the pdf itself.

View File

@@ -1741,7 +1741,8 @@ class Lead(models.Model):
s_lead_lost *= value_result['lost'] / total_lost
# 3. Compute Probability to win
lead_probabilities[lead_id] = round(100 * s_lead_won / (s_lead_won + s_lead_lost), 2)
probability = s_lead_won / (s_lead_won + s_lead_lost)
lead_probabilities[lead_id] = min(max(round(100 * probability, 2), 0.01), 99.99)
return lead_probabilities
# ---------------------------------

View File

@@ -379,6 +379,56 @@ class TestCRMPLS(TransactionCase):
self.assertEqual(tools.float_compare(leads[3].automated_probability, 4.21, 2), 0)
self.assertEqual(tools.float_compare(leads[8].automated_probability, 0.23, 2), 0)
def test_predictive_lead_scoring_always_won(self):
""" The computation may lead scores close to 100% (or 0%), we check that pending
leads are always in the ]0-100[ range."""
Lead = self.env['crm.lead']
LeadScoringFrequency = self.env['crm.lead.scoring.frequency']
country_id = self.env['res.country'].search([], limit=1).id
stage_id = self.env['crm.stage'].search([], limit=1).id
team_id = self.env['crm.team'].create({'name': 'Team Test 1'}).id
# create two leads
leads = Lead.create([
self._get_lead_values(team_id, 'edge pending', country_id, False, False, False, False, stage_id),
self._get_lead_values(team_id, 'edge lost', country_id, False, False, False, False, stage_id),
self._get_lead_values(team_id, 'edge won', country_id, False, False, False, False, stage_id),
])
# set a new tag
leads.tag_ids = self.env['crm.tag'].create({'name': 'lead scoring edge case'})
# Set the PLS config
self.env['ir.config_parameter'].sudo().set_param("crm.pls_start_date", "2000-01-01")
# tag_ids can be used in versions newer than v14
self.env['ir.config_parameter'].sudo().set_param("crm.pls_fields", "country_id")
# set leads as won and lost
leads[1].action_set_lost()
leads[2].action_set_won()
# recompute
Lead._cron_update_automated_probabilities()
Lead.invalidate_cache()
# adapt the probability frequency to have high values
# this way we are nearly sure it's going to be won
freq_stage = LeadScoringFrequency.search([('variable', '=', 'stage_id'), ('value', '=', str(stage_id))])
freq_tag = LeadScoringFrequency.search([('variable', '=', 'tag_id'), ('value', '=', str(leads.tag_ids.id))])
freqs = freq_stage + freq_tag
# check probabilities: won edge case
freqs.write({'won_count': 10000000, 'lost_count': 1})
leads._compute_probabilities()
self.assertEqual(tools.float_compare(leads[2].probability, 100, 2), 0)
self.assertEqual(tools.float_compare(leads[1].probability, 0, 2), 0)
self.assertEqual(tools.float_compare(leads[0].probability, 99.99, 2), 0)
# check probabilities: lost edge case
freqs.write({'won_count': 1, 'lost_count': 10000000})
leads._compute_probabilities()
self.assertEqual(tools.float_compare(leads[2].probability, 100, 2), 0)
self.assertEqual(tools.float_compare(leads[1].probability, 0, 2), 0)
self.assertEqual(tools.float_compare(leads[0].probability, 0.01, 2), 0)
def test_settings_pls_start_date(self):
# We test here that settings never crash due to ill-configured config param 'crm.pls_start_date'
set_param = self.env['ir.config_parameter'].sudo().set_param

View File

@@ -97,7 +97,7 @@
<notebook>
<page string="Operators" name="operators">
<group>
<field name="user_ids" nolabel="1" colspan="2">
<field name="user_ids" nolabel="1" colspan="2" domain="[['groups_id', 'not in', %(base.group_portal)d]]">
<kanban>
<field name="id"/>
<field name="name"/>

View File

@@ -36,7 +36,7 @@ def sitemap_qs2dom(qs, route, field='name'):
if len(needles) == 1:
dom = [(field, 'ilike', needles[0])]
else:
dom = FALSE_DOMAIN
dom = list(FALSE_DOMAIN)
return dom