Skip to content

Commit

Permalink
[IMP] base/saas~18.1: remove res.partner.title model and field
Browse files Browse the repository at this point in the history
The enterprise and community PR does a lot of changes on the partner form.
One of the change was to remove the title field and so the model.
This commit will adapt the tests accordingly

closes #177

See: odoo/odoo#187357
See: odoo/enterprise#73879
See: odoo/upgrade#6779
Task: 4306429
Related: odoo/upgrade#6779
Signed-off-by: Alvaro Fuentes Suarez (afu) <[email protected]>
  • Loading branch information
malb-odoo committed Dec 20, 2024
1 parent 93e50b2 commit c65f16e
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions src/base/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,10 @@ def test_any_operator(self):
self.assertEqual(new_domain, expected)

# test it also works recursively
domain = [("partner_id", "any", [("title", "not any", [("shortcut", "like", "S.A.")])])]
expected = [("partner_id", "any", [("title", "not any", [("abbr", "like", "S.A.")])])]
domain = [("partner_id", "any", [("bank_ids", "not any", [("acc_number", "like", "S.A.")])])]
expected = [("partner_id", "any", [("bank_ids", "not any", [("acc_nbr", "like", "S.A.")])])]

new_domain = _adapt_one_domain(self.cr, "res.partner.title", "shortcut", "abbr", "res.company", domain)
new_domain = _adapt_one_domain(self.cr, "res.partner.bank", "acc_number", "acc_nbr", "res.company", domain)
self.assertEqual(new_domain, expected)


Expand Down Expand Up @@ -570,17 +570,17 @@ def test_iter_browse_call(self):
self.assertEqual(write.call_count, expected)

def test_iter_browse_create_non_empty(self):
RPT = self.env["res.partner.title"]
RP = self.env["res.partner"]
with self.assertRaises(ValueError):
util.iter_browse(RPT, [42]).create([{}])
util.iter_browse(RP, [42]).create([{}])

@parametrize([(True,), (False,)])
def test_iter_browse_create(self, multi):
chunk_size = 2
RPT = self.env["res.partner.title"]
RP = self.env["res.partner"]

names = [f"Title {i}" for i in range(7)]
ib = util.iter_browse(RPT, [], chunk_size=chunk_size)
names = [f"Name {i}" for i in range(7)]
ib = util.iter_browse(RP, [], chunk_size=chunk_size)
records = ib.create([{"name": name} for name in names], multi=multi)
self.assertEqual([t.name for t in records], names)

Expand Down Expand Up @@ -616,20 +616,20 @@ def test_alter_column_type(self):
cr = self.env.cr
cr.execute(
"""
ALTER TABLE res_partner_title ADD COLUMN x bool;
ALTER TABLE res_partner_bank ADD COLUMN x bool;
UPDATE res_partner_title
UPDATE res_partner_bank
SET x = CASE id % 3
WHEN 1 THEN NULL
WHEN 2 THEN True
ELSE False
END
"""
)
self.assertEqual(util.column_type(cr, "res_partner_title", "x"), "bool")
util.alter_column_type(cr, "res_partner_title", "x", "int", using="CASE {0} WHEN True THEN 2 ELSE 1 END")
self.assertEqual(util.column_type(cr, "res_partner_title", "x"), "int4")
cr.execute("SELECT id, x FROM res_partner_title")
self.assertEqual(util.column_type(cr, "res_partner_bank", "x"), "bool")
util.alter_column_type(cr, "res_partner_bank", "x", "int", using="CASE {0} WHEN True THEN 2 ELSE 1 END")
self.assertEqual(util.column_type(cr, "res_partner_bank", "x"), "int4")
cr.execute("SELECT id, x FROM res_partner_bank")
data = cr.fetchall()
self.assertTrue(
all(x == 1 or (x == 2 and id_ % 3 == 2) for id_, x in data),
Expand Down Expand Up @@ -700,22 +700,22 @@ def test_explode_mult_filters(self):
def test_explode_query_range(self):
cr = self.env.cr

cr.execute("SELECT count(id) FROM res_partner_title")
cr.execute("SELECT count(id) FROM res_partner_category")
count = cr.fetchone()[0]
# ensure there start with at least 10 records
for _ in range(10 - count):
count += 1
self.env["res.partner.title"].create({"name": "x"})
self.env["res.partner.category"].create({"name": "x"})

# set one record with very high id
tid = self.env["res.partner.title"].create({"name": "x"}).id
tid = self.env["res.partner.category"].create({"name": "x"}).id
count += 1
cr.execute("UPDATE res_partner_title SET id = 10000000 WHERE id = %s", [tid])
cr.execute("UPDATE res_partner_category SET id = 10000000 WHERE id = %s", [tid])

qs = util.explode_query_range(cr, "SELECT 1", table="res_partner_title", bucket_size=count)
qs = util.explode_query_range(cr, "SELECT 1", table="res_partner_category", bucket_size=count)
self.assertEqual(len(qs), 1) # one bucket should be enough for all records

qs = util.explode_query_range(cr, "SELECT 1", table="res_partner_title", bucket_size=count - 1)
qs = util.explode_query_range(cr, "SELECT 1", table="res_partner_category", bucket_size=count - 1)
self.assertEqual(len(qs), 1) # 10% rule for second bucket, 1 <= 0.1(count - 1) since count >= 11

def test_parallel_rowcount(self):
Expand Down Expand Up @@ -1060,8 +1060,8 @@ def test_rename_xmlid(self):

def test_update_record_from_xml(self):
# reset all fields on a <record>
xmlid = "base.res_partner_title_mister"
data_after = {"name": "Fortytwo", "shortcut": "42"}
xmlid = "base.res_partner_industry_A"
data_after = {"name": "42", "full_name": "Fortytwo"}
record = self.env.ref(xmlid)
data_before = {key: record[key] for key in data_after}
for key, value in data_after.items():
Expand Down Expand Up @@ -1158,14 +1158,14 @@ def test_update_record_translations_from_xml(self):
be_lang = self.env["res.lang"].with_context(active_test=False).search([("code", "=", "fr_BE")])
be_lang.write({"active": True})

xmlid = "base.res_partner_title_mister"
xmlid = "base.res_partner_industry_A"
util.update_record_from_xml(self.env.cr, xmlid, reset_translations=True)

# change the translations to something arbitrary for all installed languages
langs = self.env["res.lang"].get_installed()
filter_lang = [code for code, _ in langs]
self.assertIn(be_lang.code, filter_lang)
data_after = {"name": "Fortytwo", "shortcut": "42"}
data_after = {"name": "42", "full_name": "Fortytwo"}
fieldnames = list(data_after.keys())
template_record = self.env.ref(xmlid)

Expand Down Expand Up @@ -1268,31 +1268,31 @@ def test_ensure_xmlid_match_record(self):

@unittest.skipUnless(util.version_gte("16.0"), "Only work on Odoo >= 16")
def test_replace_in_all_jsonb_values(self):
test_partner_title = self.env["res.partner.title"].create(
test_partner_category = self.env["res.partner.category"].create(
{"name": r"""object.number '<"x">\y object.numbercombined"""}
)

pattern_old = re.compile(r"\b\.number\b")
pattern_new = re.compile(r"\b\.name\b")
pattern_notouch = re.compile(r"\b\.numbercombined\b")

self.assertNotRegex(test_partner_title.name, pattern_new)
self.assertRegex(test_partner_title.name, pattern_notouch)
self.assertRegex(test_partner_title.name, pattern_old)
self.assertNotRegex(test_partner_category.name, pattern_new)
self.assertRegex(test_partner_category.name, pattern_notouch)
self.assertRegex(test_partner_category.name, pattern_old)

extra_filter = self.env.cr.mogrify("t.id = %s", (test_partner_title.id,)).decode()
util.replace_in_all_jsonb_values(self.env.cr, "res_partner_title", "name", ".number", ".name", extra_filter)
extra_filter = self.env.cr.mogrify("t.id = %s", (test_partner_category.id,)).decode()
util.replace_in_all_jsonb_values(self.env.cr, "res_partner_category", "name", ".number", ".name", extra_filter)
util.replace_in_all_jsonb_values(
self.env.cr, "res_partner_title", "name", r"""'<"x">\y""", "GONE", extra_filter
self.env.cr, "res_partner_category", "name", r"""'<"x">\y""", "GONE", extra_filter
)
test_partner_title.invalidate_recordset(["name"])
test_partner_category.invalidate_recordset(["name"])

self.assertRegex(test_partner_title.name, pattern_new)
self.assertRegex(test_partner_title.name, pattern_notouch)
self.assertNotRegex(test_partner_title.name, pattern_old)
self.assertRegex(test_partner_category.name, pattern_new)
self.assertRegex(test_partner_category.name, pattern_notouch)
self.assertNotRegex(test_partner_category.name, pattern_old)
# ensure replacing works for patterns that do not start with a valid word start \w
# also ensure the replace works for multiple embedded quotes
self.assertEqual(test_partner_title.name, "object.name GONE object.numbercombined")
self.assertEqual(test_partner_category.name, "object.name GONE object.numbercombined")

def test_replace_record_references_batch__uniqueness(self):
c1 = self.env["res.country"].create(
Expand Down

0 comments on commit c65f16e

Please sign in to comment.